Example #1
0
def test__parser__grammar_startswith_a(seg_list, fresh_ansi_dialect, caplog):
    """Test the StartsWith grammar simply."""
    baar = KeywordSegment.make("baar")
    bar = KeywordSegment.make("bar")
    with RootParseContext(dialect=fresh_ansi_dialect) as ctx:
        with caplog.at_level(logging.DEBUG, logger="sqluff.parser"):
            assert StartsWith(bar).match(seg_list, parse_context=ctx)
            assert not StartsWith(baar).match(seg_list, parse_context=ctx)
Example #2
0
def test__parser__grammar_startswith_a(keyword, match_truthy, seg_list,
                                       fresh_ansi_dialect, caplog):
    """Test the StartsWith grammar simply."""
    Keyword = StringParser(keyword, KeywordSegment)
    grammar = StartsWith(Keyword)
    with RootParseContext(dialect=fresh_ansi_dialect) as ctx:
        with caplog.at_level(logging.DEBUG, logger="sqlfluff.parser"):
            m = grammar.match(seg_list, parse_context=ctx)
            assert bool(m) is match_truthy
Example #3
0
def test__parser__grammar_startswith_b(
    include_terminator, match_length, seg_list, fresh_ansi_dialect, caplog
):
    """Test the StartsWith grammar with a terminator (included & exluded)."""
    baar = KeywordSegment.make("baar")
    bar = KeywordSegment.make("bar")
    grammar = StartsWith(bar, terminator=baar, include_terminator=include_terminator)
    with RootParseContext(dialect=fresh_ansi_dialect) as ctx:
        with caplog.at_level(logging.DEBUG, logger="sqlfluff.parser"):
            m = grammar.match(seg_list, parse_context=ctx)
            assert len(m) == match_length
Example #4
0
def test__parser__grammar_startswith_b(seg_list, fresh_ansi_dialect, caplog):
    """Test the StartsWith grammar with a terminator (included & exluded)."""
    baar = KeywordSegment.make("baar")
    bar = KeywordSegment.make("bar")
    with RootParseContext(dialect=fresh_ansi_dialect) as ctx:
        with caplog.at_level(logging.DEBUG, logger="sqluff.parser"):
            m = StartsWith(bar, terminator=baar).match(seg_list,
                                                       parse_context=ctx)
            assert len(m) == 3
            m = StartsWith(bar, terminator=baar,
                           include_terminator=True).match(seg_list,
                                                          parse_context=ctx)
            # NB: We'll end up matching the terminating whitespace too
            assert len(m) == 5
Example #5
0
def test__parser__grammar_startswith_a():
    """Test the StartsWith grammar fails when no terminator supplied."""
    Keyword = StringParser("foo", KeywordSegment)
    with pytest.raises(AssertionError):
        StartsWith(Keyword)