diff --git a/test_data/intermediate/expected/documentation/docstring_as_raw_string/expected_symbol_table.txt b/test_data/intermediate/expected/documentation/docstring_with_special_characters_in_literal/expected_symbol_table.txt similarity index 100% rename from test_data/intermediate/expected/documentation/docstring_as_raw_string/expected_symbol_table.txt rename to test_data/intermediate/expected/documentation/docstring_with_special_characters_in_literal/expected_symbol_table.txt diff --git a/test_data/intermediate/expected/documentation/docstring_as_raw_string/meta_model.py b/test_data/intermediate/expected/documentation/docstring_with_special_characters_in_literal/meta_model.py similarity index 100% rename from test_data/intermediate/expected/documentation/docstring_as_raw_string/meta_model.py rename to test_data/intermediate/expected/documentation/docstring_with_special_characters_in_literal/meta_model.py diff --git a/test_data/intermediate/expected/documentation/docstring_with_special_characters_outside_literal/expected_symbol_table.txt b/test_data/intermediate/expected/documentation/docstring_with_special_characters_outside_literal/expected_symbol_table.txt new file mode 100644 index 000000000..ed295e2f3 Binary files /dev/null and b/test_data/intermediate/expected/documentation/docstring_with_special_characters_outside_literal/expected_symbol_table.txt differ diff --git a/test_data/intermediate/expected/documentation/docstring_with_special_characters_outside_literal/meta_model.py b/test_data/intermediate/expected/documentation/docstring_with_special_characters_outside_literal/meta_model.py new file mode 100644 index 000000000..d0e7e6fb2 --- /dev/null +++ b/test_data/intermediate/expected/documentation/docstring_with_special_characters_outside_literal/meta_model.py @@ -0,0 +1,20 @@ +# We test for ``\x09`` and other special characters, and make sure they are represented +# adequately in the string dump of the symbol table. + + +class Non_empty_XML_serializable_string(str, DBC): + r""" + Represent a string with at least one character. + + The string should also be serializable to XML, which is the background for + the following constraint. + + :constraint AASd-130: + + An attribute with data type "string" shall consist of these characters only: + ^[\x09\x0A\x0D\x20-\uD7FF\uE000-\uFFFD\u00010000-\u0010FFFF]*$. + """ + + +__version__ = "dummy" +__xml_namespace__ = "https://dummy.com" diff --git a/tests/intermediate/test_translate.py b/tests/intermediate/test_translate.py index 99a2b47e7..9d63dba43 100644 --- a/tests/intermediate/test_translate.py +++ b/tests/intermediate/test_translate.py @@ -241,11 +241,24 @@ def test_cases(self) -> None: symbol_table_str = intermediate.dump(symbol_table) if tests.common.RERECORD: - expected_symbol_table_pth.write_text( - symbol_table_str, encoding="utf-8" - ) + # NOTE (mristin, 2023-11-07): + # We have to write the bytes since Git considers too long text + # files to be binaries. This is problematic when we re-record + # on Windows and Linux due to the different line endings. + # Therefore, we remove here carriage returns (``\r``) so that + # we have the same representation on both operating systems. + + symbol_table_bytes = symbol_table_str.encode( + "utf-8", errors="strict" + ).replace(b"\r", b"") + + expected_symbol_table_pth.write_bytes(symbol_table_bytes) else: try: + # NOTE (mristin, 2023-11-07): + # We assume that Python will automatically represent new lines + # as ``\n`` so that it matches ``symbol_table_bytes`` above. + expected_symbol_table_str = expected_symbol_table_pth.read_text( encoding="utf-8" )