def test_expr(self): for text, node in ( ('$a', _SimpleExpression('a', '$a')), ('$a1', _SimpleExpression('a1', '$a1')), ('${ab}', _SimpleExpression('ab', '${ab}')), ('${ab:-}', _Expression('ab', ':', '-', [], '${ab:-}')), ('${ab:-${foo}}', _Expression('ab', ':', '-', [_SimpleExpression('foo', '${foo}')], '${ab:-${foo}}')), ('${ab:-${cd:-${foo}}}', _Expression( 'ab', ':', '-', [_Expression( 'cd', ':', '-', [_SimpleExpression('foo', '${foo}')], '${cd:-${foo}}'), ], '${ab:-${cd:-${foo}}}')), ): g = _grammar(text) self.expectThat(g.expr(), Equals(node)) for notname in ('1', ' ', '{'): g = _grammar(notname) self.expectThat(g.expr, Raises())
def test_name(self): for name in ('a', '_', 'A', 'ba', 'b_', 'b1', 'bA', '_a', '_1', '_A', 'Aa', 'A_', 'A0', 'adsd2343aweawe_'): g = _grammar(name) self.expectThat(g.name(), Equals(name)) for notname in ('1', ' ', '{'): g = _grammar(notname) self.expectThat(g.name, Raises())
def test_name(self): for name in ( 'a', '_', 'A', 'ba', 'b_', 'b1', 'bA', '_a', '_1', '_A', 'Aa', 'A_', 'A0', 'adsd2343aweawe_'): g = _grammar(name) self.expectThat(g.name(), Equals(name)) for notname in ('1', ' ', '{'): g = _grammar(notname) self.expectThat(g.name, Raises())
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())
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))
def test_expr(self): for text, node in ( ('$a', _SimpleExpression('a', '$a')), ('$a1', _SimpleExpression('a1', '$a1')), ('${ab}', _SimpleExpression('ab', '${ab}')), ('${ab:-}', _Expression('ab', ':', '-', [], '${ab:-}')), ('${ab:-${foo}}', _Expression('ab', ':', '-', [_SimpleExpression('foo', '${foo}')], '${ab:-${foo}}')), ('${ab:-${cd:-${foo}}}', _Expression('ab', ':', '-', [ _Expression('cd', ':', '-', [_SimpleExpression('foo', '${foo}')], '${cd:-${foo}}'), ], '${ab:-${cd:-${foo}}}')), ): g = _grammar(text) self.expectThat(g.expr(), Equals(node)) for notname in ('1', ' ', '{'): g = _grammar(notname) self.expectThat(g.expr, Raises())
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))