def test__parser__grammar_greedyuntil_bracketed(bracket_seg_list, fresh_ansi_dialect): """Test the GreedyUntil grammar with brackets.""" fs = KeywordSegment.make("foo") g = GreedyUntil(fs) with RootParseContext(dialect=fresh_ansi_dialect) as ctx: # Check that we can make it past the brackets assert len(g.match(bracket_seg_list, parse_context=ctx)) == 7
def test__parser__grammar_greedyuntil(keyword, seg_list, enforce_ws, slice_len, fresh_ansi_dialect): """Test the GreedyUntil grammar.""" grammar = GreedyUntil( StringParser(keyword, KeywordSegment), enforce_whitespace_preceding_terminator=enforce_ws, ) with RootParseContext(dialect=fresh_ansi_dialect) as ctx: assert (grammar.match( seg_list, parse_context=ctx).matched_segments == seg_list[:slice_len])
def test__parser__grammar_greedyuntil_bracketed(bracket_seg_list, fresh_ansi_dialect): """Test the GreedyUntil grammar with brackets.""" fs = StringParser("foo", KeywordSegment) g = GreedyUntil(fs) with RootParseContext(dialect=fresh_ansi_dialect) as ctx: # Check that we can make it past the brackets match = g.match(bracket_seg_list, parse_context=ctx) assert len(match) == 4 # Check we successfully constructed a bracketed segment assert match.matched_segments[2].is_type("bracketed") assert match.matched_segments[2].raw == "(foo )" # Check that the unmatched segments is foo AND the whitespace assert len(match.unmatched_segments) == 2
def test__parser__grammar_greedyuntil(seg_list, fresh_ansi_dialect): """Test the GreedyUntil grammar.""" fs = KeywordSegment.make("foo") bs = KeywordSegment.make("bar") bas = KeywordSegment.make("baar") g0 = GreedyUntil(bs) g1 = GreedyUntil(fs, code_only=False) g2 = GreedyUntil(bas) with RootParseContext(dialect=fresh_ansi_dialect) as ctx: # Greedy matching until the first item should return none assert not g0.match(seg_list, parse_context=ctx) # Greedy matching up to foo should return bar (as a raw!) assert g1.match(seg_list, parse_context=ctx).matched_segments == seg_list[:1] # Greedy matching up to baar should return bar, foo (as a raw!) assert g2.match(seg_list, parse_context=ctx).matched_segments == seg_list[:3]