1 // pest. The Elegant Parser
2 // Copyright (c) 2018 Dragoș Tiselice
3 //
4 // Licensed under the Apache License, Version 2.0
5 // <LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0> or the MIT
6 // license <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7 // option. All files in the project carrying such notice may not be copied,
8 // modified, or distributed except according to those terms.
9
10 #[macro_use]
11 extern crate pest;
12 #[macro_use]
13 extern crate pest_derive;
14
15 #[derive(Parser)]
16 #[grammar = "../tests/lists.pest"]
17 struct ListsParser;
18
19 #[test]
item()20 fn item() {
21 parses_to! {
22 parser: ListsParser,
23 input: "- a",
24 rule: Rule::lists,
25 tokens: [
26 item(2, 3)
27 ]
28 };
29 }
30
31 #[test]
items()32 fn items() {
33 parses_to! {
34 parser: ListsParser,
35 input: "- a\n- b",
36 rule: Rule::lists,
37 tokens: [
38 item(2, 3),
39 item(6, 7)
40 ]
41 };
42 }
43
44 #[test]
children()45 fn children() {
46 parses_to! {
47 parser: ListsParser,
48 input: " - b",
49 rule: Rule::children,
50 tokens: [
51 children(0, 5, [
52 item(4, 5)
53 ])
54 ]
55 };
56 }
57
58 #[test]
nested_item()59 fn nested_item() {
60 parses_to! {
61 parser: ListsParser,
62 input: "- a\n - b",
63 rule: Rule::lists,
64 tokens: [
65 item(2, 3),
66 children(4, 9, [
67 item(8, 9)
68 ])
69 ]
70 };
71 }
72
73 #[test]
nested_items()74 fn nested_items() {
75 parses_to! {
76 parser: ListsParser,
77 input: "- a\n - b\n - c",
78 rule: Rule::lists,
79 tokens: [
80 item(2, 3),
81 children(4, 15, [
82 item(8, 9),
83 item(14, 15)
84 ])
85 ]
86 };
87 }
88
89 #[test]
nested_two_levels()90 fn nested_two_levels() {
91 parses_to! {
92 parser: ListsParser,
93 input: "- a\n - b\n - c",
94 rule: Rule::lists,
95 tokens: [
96 item(2, 3),
97 children(4, 17, [
98 item(8, 9),
99 children(10, 17, [
100 item(16, 17)
101 ])
102 ])
103 ]
104 };
105 }
106
107 #[test]
nested_then_not()108 fn nested_then_not() {
109 parses_to! {
110 parser: ListsParser,
111 input: "- a\n - b\n- c",
112 rule: Rule::lists,
113 tokens: [
114 item(2, 3),
115 children(4, 9, [
116 item(8, 9)
117 ]),
118 item(12, 13)
119 ]
120 };
121 }
122