MCPcopy Create free account
hub / github.com/python/cpython / test_gather

Method test_gather

Lib/test/test_peg_generator/test_pegen.py:87–116  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

85 )
86
87 def test_gather(self) -> None:
88 grammar = """
89 start: ','.thing+ NEWLINE
90 thing: NUMBER
91 """
92 rules = parse_string(grammar, GrammarParser).rules
93 self.assertEqual(str(rules["start"]), "start: ','.thing+ NEWLINE")
94 self.assertStartsWith(repr(rules["start"]),
95 "Rule('start', None, Rhs([Alt([NamedItem(None, Gather(StringLeaf(\"','\"), NameLeaf('thing'"
96 )
97 self.assertEqual(str(rules["thing"]), "thing: NUMBER")
98 parser_class = make_parser(grammar)
99 node = parse_string("42\n", parser_class)
100 node = parse_string("1, 2\n", parser_class)
101 self.assertEqual(
102 node,
103 [
104 [
105 TokenInfo(
106 NUMBER, string="1", start=(1, 0), end=(1, 1), line="1, 2\n"
107 ),
108 TokenInfo(
109 NUMBER, string="2", start=(1, 3), end=(1, 4), line="1, 2\n"
110 ),
111 ],
112 TokenInfo(
113 NEWLINE, string="\n", start=(1, 4), end=(1, 5), line="1, 2\n"
114 ),
115 ],
116 )
117
118 def test_expr_grammar(self) -> None:
119 grammar = """

Callers

nothing calls this directly

Calls 6

parse_stringFunction · 0.90
make_parserFunction · 0.90
TokenInfoClass · 0.90
strFunction · 0.85
assertStartsWithMethod · 0.80
assertEqualMethod · 0.45

Tested by

no test coverage detected