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

Method test_optional_literal

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

Source from the content-addressed store, hash-verified

173 )
174
175 def test_optional_literal(self) -> None:
176 grammar = """
177 start: sum NEWLINE
178 sum: term '+' ?
179 term: NUMBER
180 """
181 parser_class = make_parser(grammar)
182 node = parse_string("1+\n", parser_class)
183 self.assertEqual(
184 node,
185 [
186 [
187 TokenInfo(
188 NUMBER, string="1", start=(1, 0), end=(1, 1), line="1+\n"
189 ),
190 TokenInfo(OP, string="+", start=(1, 1), end=(1, 2), line="1+\n"),
191 ],
192 TokenInfo(NEWLINE, string="\n", start=(1, 2), end=(1, 3), line="1+\n"),
193 ],
194 )
195 node = parse_string("1\n", parser_class)
196 self.assertEqual(
197 node,
198 [
199 [
200 TokenInfo(NUMBER, string="1", start=(1, 0), end=(1, 1), line="1\n"),
201 None,
202 ],
203 TokenInfo(NEWLINE, string="\n", start=(1, 1), end=(1, 2), line="1\n"),
204 ],
205 )
206
207 def test_alt_optional_operator(self) -> None:
208 grammar = """

Callers

nothing calls this directly

Calls 4

make_parserFunction · 0.90
parse_stringFunction · 0.90
TokenInfoClass · 0.90
assertEqualMethod · 0.45

Tested by

no test coverage detected