def test_multirule(): rule = """production: SYM1 SYM2 | SYM2 SYM2 SYM2""" parsed = parse(rule) assert len(parsed) == 1 assert parsed[0].format(pure_ply = False) == 'production : SYM1 SYM2 | SYM2 SYM2 SYM2'
def test_multirule(): rule = """production: SYM1 SYM2 | SYM2 SYM2 SYM2""" parsed = parse(rule) assert len(parsed) == 1 assert parsed[0].format( pure_ply=False) == 'production : SYM1 SYM2 | SYM2 SYM2 SYM2'
def test_multiline_rule(): rule = """ production: SYM1 SYM2 SYM3 SYM4 """ parsed = parse(rule) assert len(parsed) == 1 assert parsed[0].format() == 'production : SYM1 SYM2 SYM3 SYM4'
def test_two_rules(): rule = """ r1: SYM1 SYM2 r2: SYM2 SYM3""" parsed = parse(rule) assert len(parsed) == 2 assert parsed[0].format() == 'r1 : SYM1 SYM2' assert parsed[1].format() == 'r2 : SYM2 SYM3'
def test_multiline_rule_with_another_rule(): rule = """ production: SYM1 SYM2 SYM3 SYM4 production2: S1 S2 """ parsed = parse(rule) assert len(parsed) == 2 assert parsed[0].format() == 'production : SYM1 SYM2 SYM3 SYM4' assert parsed[1].format() == 'production2 : S1 S2'
def assert_expand(rule, result): assert_eq_list(expand_optionals(rule), result) assert_eq_list(expand_optionals(rule, format=False), parse('\n'.join(result)))
def test_printing(): rule = parse('r: w1 (w1 {w2:name})?')[0] assert rule.format(pure_ply=False) == 'r : w1 (w1 {w2:name})?' assert rule.format(pure_ply=True) == 'r : w1 w1 w2' assert rule.format() == 'r : w1 w1 w2'
def assert_expand(rule, result): assert_eq_list(expand_optionals(rule), result) assert_eq_list(expand_optionals(rule, format = False), parse('\n'.join(result)))
def test_printing(): rule = parse('r: w1 (w1 {w2:name})?')[0] assert rule.format(pure_ply = False) == 'r : w1 (w1 {w2:name})?' assert rule.format(pure_ply = True) == 'r : w1 w1 w2' assert rule.format() == 'r : w1 w1 w2'
def test_printing(): rule = parse('r: w1 (w1 {w2:name})?')[0] assert_eq(str(rule), 'r: w1 (w1 {w2:name})?') assert_eq(rule.format(), 'r : w1 w1 w2')