Skip to content

Commit

Permalink
Merge pull request strictdoc-project#1902 from haxtibal/tdmg/consiste…
Browse files Browse the repository at this point in the history
…nt_uid

Extend UID regex and use it in SDocNode
  • Loading branch information
stanislaw authored Jun 30, 2024
2 parents c190b82 + c44f2c2 commit e6713de
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 12 deletions.
7 changes: 5 additions & 2 deletions strictdoc/backend/sdoc/grammar/grammar.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
REGEX_UID = r"([A-Za-z0-9]+[A-Za-z0-9_\-]*)"
REGEX_UID = r"([\w]+[\w\-. ]*)"

NEGATIVE_MULTILINE_STRING_START = "(?!>>>\n)"
NEGATIVE_MULTILINE_STRING_END = "(?!^<<<)"
NEGATIVE_RELATIONS = "(?!^RELATIONS)"
NEGATIVE_UID = "(?!^UID)"
NEGATIVE_FREETEXT_END = "(?!^\\[\\/FREETEXT\\]\n)"
NEGATIVE_INLINE_LINK_START = rf"(?!\[LINK: {REGEX_UID})"
NEGATIVE_ANCHOR_START = rf"(?!^\[ANCHOR: {REGEX_UID})"
Expand Down Expand Up @@ -44,7 +45,7 @@
;
FieldName[noskipws]:
/{NEGATIVE_RELATIONS}[A-Z]+[A-Z_]*/
/{NEGATIVE_UID}{NEGATIVE_RELATIONS}[A-Z]+[A-Z_]*/
;
"""

Expand Down Expand Up @@ -188,6 +189,8 @@
SDocNodeField[noskipws]:
(
field_name = 'UID' ': ' parts+=/{REGEX_UID}/ '\n'
|
field_name = FieldName ':'
(
(' ' parts+=SingleLineTextPart '\n')
Expand Down
44 changes: 34 additions & 10 deletions tests/unit/strictdoc/backend/sdoc/test_dsl_passthrough.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,33 @@ def test_021_section_and_document_mid():
assert input_sdoc == output


def test_022_requirement_uid_and_link():
input_sdoc = """
[DOCUMENT]
TITLE: Test Doc
[REQUIREMENT]
UID: With spaces and _ and - and . and non latin 特点
STATEMENT: >>>
This is a statement.
[TEXT]
STATEMENT: >>>
[LINK: With spaces and _ and - and . and non latin 特点]
<<<
""".lstrip()

reader = SDReader()

document = reader.read(input_sdoc)
assert isinstance(document, SDocDocument)

writer = SDWriter()
output = writer.write(document)

assert input_sdoc == output


def test_030_multiline_statement():
input_sdoc = """
[DOCUMENT]
Expand Down Expand Up @@ -912,7 +939,7 @@ def test_edge_case_02_uid_present_but_empty_with_no_space_character():
_ = reader.read(input_sdoc)

assert exc_info.type is TextXSyntaxError
assert "Expected ' '" == exc_info.value.args[0].decode("utf-8")
assert "Expected ': '" == exc_info.value.args[0].decode("utf-8")


def test_edge_case_03_uid_present_but_empty_with_space_character():
Expand All @@ -931,9 +958,8 @@ def test_edge_case_03_uid_present_but_empty_with_space_character():
_ = reader.read(input_sdoc)

assert exc_info.type is TextXSyntaxError
assert (
"Expected '^\\[ANCHOR: ' or '[LINK: ' or '(?!>>>\\n)\\S.*' or '>>>\\n'"
in exc_info.value.args[0].decode("utf-8")
assert "Expected '([\\w]+[\\w\\-. ]*)'" in exc_info.value.args[0].decode(
"utf-8"
)


Expand All @@ -953,9 +979,8 @@ def test_edge_case_04_uid_present_but_empty_with_two_space_characters():
_ = reader.read(input_sdoc)

assert exc_info.type is TextXSyntaxError
assert (
"Expected '^\\[ANCHOR: ' or '[LINK: ' or '(?!>>>\\n)\\S.*' or '>>>\\n'"
in exc_info.value.args[0].decode("utf-8")
assert "Expected '([\\w]+[\\w\\-. ]*)'" in exc_info.value.args[0].decode(
"utf-8"
)


Expand All @@ -978,9 +1003,8 @@ def test_edge_case_10_empty_multiline_field():
assert (
"Expected '^\\[ANCHOR: ' or '[LINK: ' or "
"'(?ms)(?!^<<<)(?!^\\[\\/FREETEXT\\]\\n)(?!\\[LINK: "
"([A-Za-z0-9]+[A-Za-z0-9_\\-]*))(?!^\\[ANCHOR: "
"([A-Za-z0-9]+[A-Za-z0-9_\\-]*)).'"
in exc_info.value.args[0].decode("utf-8")
"([\\w]+[\\w\\-. ]*))(?!^\\[ANCHOR: "
"([\\w]+[\\w\\-. ]*)).'" in exc_info.value.args[0].decode("utf-8")
)


Expand Down

0 comments on commit e6713de

Please sign in to comment.