示例#1
0
 def test_string(self):
     for text, nodes in (
         ('', []),
         ('1', [_Literal('1')]),
         ('$1', [_Literal('$1')]),
         ('1$a', [_Literal('1'), _SimpleExpression('a', '$a')]),
         ('1$a$b', [
             _Literal('1'), _SimpleExpression('a', '$a'),
             _SimpleExpression('b', '$b')]),
         ('1$a2$b3', [
             _Literal('1'), _SimpleExpression('a2', '$a2'),
             _SimpleExpression('b3', '$b3')]),
         ('1$a 2$b 3', [
             _Literal('1'), _SimpleExpression('a', '$a'), _Literal(' 2'),
             _SimpleExpression('b', '$b'),
             _Literal(' 3')]),
         ('1${ab:-${cd:-${foo}}}2', [
             _Literal('1'),
             _Expression(
                 'ab', ':', '-',
                 [_Expression(
                     'cd', ':', '-',
                     [_SimpleExpression('foo', '${foo}')],
                     '${cd:-${foo}}'),
                     ],
                 '${ab:-${cd:-${foo}}}'),
             _Literal('2'),
             ]),
         ):
         g = _grammar(text)
         self.expectThat(g.string(), Equals(nodes))
示例#2
0
 def test_notexpr(self):
     for text, node in (
         ('1', _Literal('1')),
         ('a', _Literal('a')),
         ('a1', _Literal('a1')),
         ('$', _Literal('$')),
         ('$1', _Literal('$1')),
         ):
         g = _grammar(text)
         self.expectThat(g.notexpr(), Equals(node))
     for expr in ('$a', ):
         g = _grammar(expr)
         self.expectThat(g.notexpr, Raises())
示例#3
0
 def test_notexpr(self):
     for text, node in (
         ('1', _Literal('1')),
         ('a', _Literal('a')),
         ('a1', _Literal('a1')),
         ('$', _Literal('$')),
         ('$1', _Literal('$1')),
     ):
         g = _grammar(text)
         self.expectThat(g.notexpr(), Equals(node))
     for expr in ('$a', ):
         g = _grammar(expr)
         self.expectThat(g.notexpr, Raises())
示例#4
0
 def test_string(self):
     for text, nodes in (
         ('', []),
         ('1', [_Literal('1')]),
         ('$1', [_Literal('$1')]),
         ('1$a', [_Literal('1'),
                  _SimpleExpression('a', '$a')]),
         ('1$a$b', [
             _Literal('1'),
             _SimpleExpression('a', '$a'),
             _SimpleExpression('b', '$b')
         ]),
         ('1$a2$b3', [
             _Literal('1'),
             _SimpleExpression('a2', '$a2'),
             _SimpleExpression('b3', '$b3')
         ]),
         ('1$a 2$b 3', [
             _Literal('1'),
             _SimpleExpression('a', '$a'),
             _Literal(' 2'),
             _SimpleExpression('b', '$b'),
             _Literal(' 3')
         ]),
         ('1${ab:-${cd:-${foo}}}2', [
             _Literal('1'),
             _Expression('ab', ':', '-', [
                 _Expression('cd', ':', '-',
                             [_SimpleExpression('foo', '${foo}')],
                             '${cd:-${foo}}'),
             ], '${ab:-${cd:-${foo}}}'),
             _Literal('2'),
         ]),
     ):
         g = _grammar(text)
         self.expectThat(g.string(), Equals(nodes))