import pyparsing import pytest import bootstraparse.modules.syntax as sy ############################################################################################################## # PRE-PARSER ############################################################################################################## # Dictionary of all label and associated token used in the Pre_parser list_of_token_types = { "alias": sy.AliasToken, "image": sy.ImageToken, } # Dictionary of all lexical elements and a list of matching strings for the Pre_parser expressions_to_match = { # Base elements "quotes": ["'hi, there'", "'hi, there'"], "value": ["0.1", "'hello'"], "assignation": ["a=1", "a=1.33", "tr2='hu'"], # Composite elements "var": ['["a"]', '[a=12]', '[a=12, b=13]', '[12,"a",1.1,a=12, b=13, c=14]', ], # Specific elements "image_element": ["@{image}", "@{image123_456}"], "alias_element": ["@[alias]", "@[alias123_456]"], "expression": ["a+b+c"], "html_insert": ['{test=12, 22=3, "=5}', "{testing=12, 22=3, 4=5, 6='7'}"], # Optional elements "optional": ["a=1", "a=1.33", "tr2='hu'"], # Pre_parser elements "image": ["@{image}{test=22}[a=12,22,c,d,ERE,r,3]", "@{image123_456}{a=12,22,c,d,ERE,r,3}", "@{image123_456}[a=12,22,c,d,ERE,r,3]"], "alias": ["@[alias]{test=22}[a=12,22,c,d,ERE,r,3]", "@[alias123_456]{a=12,22,c,d,ERE,r,3}", "@[alias123_456]{a=12,22,c,d,ERE,r,3]"], # Syntax elements "line_to_replace": ["@{image}", "@{image}{é=12}", "@{image}{test=22}", "@{image}{test=22}[a=12,22,c,d,ERE,r,3]", "@[alias]{test=22}[a=12,22,c,d,ERE,r,3]", ], } ############################################################################################################## # PARSER ############################################################################################################## # Testing the parser lexical elements dict_advanced_syntax_input_and_expected_output = { # Enhanced text # TODO : Test optional inline args "et_em": [ # Single em element, should only match the first "*" ("*", (sy.EtEmToken("*"), )), ], "et_strong": [ # Single strong element, should only match the first "**" ("**", sy.EtEmToken("**"), ), ], "et_underline": [ # Single underline element, should only match the first "__" ("__", (sy.EtUnderlineToken("__"), )), ], "et_strikethrough": [ # Single strikethrough element, should only match the first "~~" ("~~", (sy.EtStrikethroughToken("~~"), )), ], "et_custom_span": [ # Single custom span element, should only match the first "(#number)" ("(#12345)", (sy.EtCustomSpanToken("#12345"), )), ], "il_link": [ # Single link element, should only match the first "[link_name](link)" # TODO: Text tokens ? or Link token and hyperlink token ? ("[text_link]('text://www.website.com/link.html')", sy.HyperlinkToken("[text_link]('text://www.website.com/link.html')")) ], # Enhanced Text "enhanced_text": [ # Matches a line of text, with or without inline elements ("*test*", (sy.EtEmToken(["*"]), sy.TextToken(["test"]), sy.EtEmToken(["*"]))), ("**test**", (sy.EtEmToken(["**"]), sy.TextToken(["test"]), sy.EtEmToken(["**"]))), ("__test__", (sy.EtUnderlineToken(["__"]), sy.TextToken(["test"]), sy.EtUnderlineToken(["__"]))), ("~~test~~", (sy.EtStrikethroughToken(["~~"]), sy.TextToken(["test"]), sy.EtStrikethroughToken(["~~"]))), ("(#12345)", (sy.EtCustomSpanToken(["#12345"]), )), ("*test*test*", (sy.EtEmToken(["*"]), sy.TextToken(["test"]), sy.EtEmToken(["*"]), sy.TextToken(["test"]), sy.EtEmToken(["*"]))), ("**test**test**", (sy.EtEmToken(["**"]), sy.TextToken(["test"]), sy.EtEmToken(["**"]), sy.TextToken(["test"]), sy.EtEmToken(["**"]), )), ("__test__test__", (sy.EtUnderlineToken(["__"]), sy.TextToken(["test"]), sy.EtUnderlineToken(["__"]), sy.TextToken(["test"]), sy.EtUnderlineToken(["__"]), )), ("~~test~~test~~", (sy.EtStrikethroughToken(["~~"]), sy.TextToken(["test"]), sy.EtStrikethroughToken(["~~"]), sy.TextToken(["test"]), sy.EtStrikethroughToken(["~~"]), )), ("(#12345)test(#12345)", (sy.EtCustomSpanToken(["#12345"]), sy.TextToken(["test"]), sy.EtCustomSpanToken(["#12345"]), )), ("__test(#12)test**test__test~~", (sy.EtUnderlineToken("__"), sy.TextToken(["test"]), sy.EtCustomSpanToken(["#12"]), sy.TextToken(["test"]), sy.EtEmToken(["**"]), sy.TextToken(["test"]), sy.EtStrikethroughToken(["~~"]), sy.TextToken(["test"]), sy.EtUnderlineToken(["__"]), )), ("12. List of elements", (sy.EtUlistToken(["12", "List of elements"]), )), ("Test text with a link [link_name](link)", (sy.TextToken(["Test text with a link "]), sy.HyperlinkToken(["link_name", "link"]), )), ("Test text with a link [link_name](link) and a *bold* text", (sy.TextToken(["Test text with a link "]), sy.HyperlinkToken(["link_name", "link"]), sy.TextToken([" and a "]), sy.EtEmToken(["*"]), sy.TextToken(["bold"]), sy.EtEmToken(["*"]), )), ], # Structural Elements "se_start": [ # Matches a start of a structural element ("<