File: error_test.py

package info (click to toggle)
python-tatsu 5.17.1%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,516 kB
  • sloc: python: 13,185; makefile: 127
file content (33 lines) | stat: -rw-r--r-- 896 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# Copyright (c) 2017-2026 Juancarlo AƱez (apalala@gmail.com)
# SPDX-License-Identifier: BSD-4-Clause
from __future__ import annotations

from tatsu.exceptions import GrammarError
from tatsu.tool import compile
from tatsu.util.asjson import asjsons


def test_missing_rule():
    grammar = """
        @@grammar::TestGrammar
          block = test ;
    """
    try:
        model = compile(grammar)
        print('MODEL', asjsons(model))
        model.parse('abc')
    except GrammarError as e:
        assert str(e) == 'Unknown rules, no parser generated:\ntest'


def test_missing_rules():
    grammar = """
        @@grammar::TestGrammar
          block = test | test2;
    """
    try:
        model = compile(grammar)
        print('MODEL', asjsons(model))
        model.parse('abc')
    except GrammarError as e:
        assert str(e) == 'Unknown rules, no parser generated:\ntest\ntest2'