コード例 #1
0
    def test_concatenation(self):
        assert parse_regex(" foo bar ") == Concatenation(
            Symbol("foo"),
            Symbol("bar"),
        )

        assert parse_regex(" foo bar baz ") == Concatenation(
            Symbol("foo"),
            Concatenation(
                Symbol("bar"),
                Symbol("baz"),
            ),
        )
コード例 #2
0
    def test_union(self):
        assert parse_regex(" foo | ") == Union(
            Symbol("foo"),
            None,
        )

        assert parse_regex(" foo | bar ") == Union(
            Symbol("foo"),
            Symbol("bar"),
        )

        assert parse_regex(" foo | bar | baz ") == Union(
            Union(
                Symbol("foo"),
                Symbol("bar"),
            ),
            Symbol("baz"),
        )
コード例 #3
0
 def test_parentheses(self):
     assert parse_regex(" (foo) (bar baz) * (qux quo)") == Concatenation(
         Symbol("foo"),
         Concatenation(
             Star(Concatenation(
                 Symbol("bar"),
                 Symbol("baz"),
             ), ),
             Concatenation(
                 Symbol("qux"),
                 Symbol("quo"),
             ),
         ),
     )
コード例 #4
0
 def test_wildcard(self):
     assert parse_regex(" . ") == Symbol(".")
コード例 #5
0
 def test_symbol(self):
     assert parse_regex(" foo ") == Symbol("foo")
コード例 #6
0
 def test_empty(self):
     assert parse_regex(" ") is None
コード例 #7
0
 def test_unmatched_opening_parentheses(self):
     with pytest.raises(SymbolRegexSyntaxError,
                        match=r"Unmatched parentheses"):
         parse_regex(" ( ( foo )")
コード例 #8
0
 def test_modifier_at_start_of_expression(self):
     with pytest.raises(SymbolRegexSyntaxError,
                        match=r"Modifier at start of expression"):
         parse_regex(" ? foo ")
コード例 #9
0
 def test_modifier_before_parenthesis(self):
     with pytest.raises(SymbolRegexSyntaxError,
                        match=r"Modifier before '\(' at position 1"):
         parse_regex(" ( ? foo ) ")
コード例 #10
0
 def test_modifier_before_union(self):
     with pytest.raises(SymbolRegexSyntaxError,
                        match=r"Modifier before '\|' at position 2"):
         parse_regex("a | ? b")
コード例 #11
0
 def test_multiple_modifiers(self):
     with pytest.raises(SymbolRegexSyntaxError,
                        match=r"Multiple modifiers at position 4"):
         parse_regex("foo ? *")
コード例 #12
0
 def test_query(self):
     assert parse_regex(" foo ? ") == Union(Symbol("foo"), None)
コード例 #13
0
 def test_plus(self):
     assert parse_regex(" foo + ") == Concatenation(
         Symbol("foo"),
         Star(Symbol("foo")),
     )
コード例 #14
0
 def test_star(self):
     assert parse_regex(" foo * ") == Star(Symbol("foo"))