#include #include #include #include #include #include #include "fesa/io/abaqus/input_reader.h" namespace { class TemporaryInputFile { public: TemporaryInputFile(const std::string& stem, const std::string& content) : path_{std::filesystem::temp_directory_path() / ("fesa-" + stem + ".inp")} { std::ofstream stream{path_, std::ios::binary | std::ios::trunc}; stream.write(content.data(), static_cast(content.size())); if (!stream) { throw std::runtime_error{"Unable to create INP syntax test fixture."}; } } ~TemporaryInputFile() { std::error_code error; std::filesystem::remove(path_, error); } const std::filesystem::path& Path() const noexcept { return path_; } private: std::filesystem::path path_; }; } // namespace TEST(InpSyntax, CanonicalizesKeywordAndParameterNamesOnly) { const std::string original_line = " *eLeMeNt, TyPe= b33 , generate, ELSET=Beam_Set "; const TemporaryInputFile input{"canonical-names", original_line + "\n"}; const auto result = fesa::AbaqusInputReader{}.Read(input.Path()); ASSERT_TRUE(result.HasValue()); ASSERT_EQ(result.Value().blocks.size(), 1U); const auto& block = result.Value().blocks[0]; EXPECT_EQ(block.canonical_name, "ELEMENT"); EXPECT_EQ(block.original_line, original_line); EXPECT_EQ(block.location.line, 1U); ASSERT_EQ(block.parameters.size(), 3U); EXPECT_EQ(block.parameters[0].name, "TYPE"); ASSERT_TRUE(block.parameters[0].value.has_value()); EXPECT_EQ(*block.parameters[0].value, "b33"); EXPECT_EQ(block.parameters[1].name, "GENERATE"); EXPECT_FALSE(block.parameters[1].value.has_value()); EXPECT_EQ(block.parameters[2].name, "ELSET"); ASSERT_TRUE(block.parameters[2].value.has_value()); EXPECT_EQ(*block.parameters[2].value, "Beam_Set"); } TEST(InpSyntax, PreservesDataAndSourceLocations) { const std::string exact_bytes = "** retained only in line accounting\r\n" "\r\n" "*NoDe\r\n" " 0007, Label_A, ,\r\n"; const TemporaryInputFile input{"data-and-locations", exact_bytes}; const auto result = fesa::AbaqusInputReader{}.Read(input.Path()); ASSERT_TRUE(result.HasValue()); EXPECT_EQ(result.Value().source_path, std::filesystem::absolute(input.Path()).lexically_normal()); EXPECT_EQ(result.Value().source_content_identity, "fnv1a64:c120b6ed2445be46"); ASSERT_EQ(result.Value().blocks.size(), 1U); const auto& block = result.Value().blocks[0]; EXPECT_EQ(block.canonical_name, "NODE"); EXPECT_EQ(block.original_line, "*NoDe"); EXPECT_EQ(block.location.file, result.Value().source_path); EXPECT_EQ(block.location.line, 3U); ASSERT_EQ(block.data.size(), 1U); EXPECT_EQ(block.data[0].fields, (std::vector{"0007", "Label_A", "", ""})); EXPECT_EQ(block.data[0].location.file, result.Value().source_path); EXPECT_EQ(block.data[0].location.line, 4U); }