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 #![cfg_attr(not(feature = "std"), no_std)]
11 extern crate alloc;
12 use alloc::vec;
13 
14 #[macro_use]
15 extern crate pest;
16 #[macro_use]
17 extern crate pest_derive;
18 
19 #[derive(Parser)]
20 #[grammar = "../tests/reporting.pest"]
21 struct ReportingParser;
22 
23 #[test]
choices()24 fn choices() {
25     fails_with! {
26         parser: ReportingParser,
27         input: "x",
28         rule: Rule::choices,
29         positives: vec![Rule::a, Rule::b, Rule::c],
30         negatives: vec![],
31         pos: 0
32     };
33 }
34 
35 #[test]
choices_no_progress()36 fn choices_no_progress() {
37     fails_with! {
38         parser: ReportingParser,
39         input: "x",
40         rule: Rule::choices_no_progress,
41         positives: vec![Rule::choices_no_progress],
42         negatives: vec![],
43         pos: 0
44     };
45 }
46 
47 #[test]
choices_a_progress()48 fn choices_a_progress() {
49     fails_with! {
50         parser: ReportingParser,
51         input: "a",
52         rule: Rule::choices_a_progress,
53         positives: vec![Rule::a],
54         negatives: vec![],
55         pos: 1
56     };
57 }
58 
59 #[test]
choices_b_progress()60 fn choices_b_progress() {
61     fails_with! {
62         parser: ReportingParser,
63         input: "b",
64         rule: Rule::choices_b_progress,
65         positives: vec![Rule::b],
66         negatives: vec![],
67         pos: 1
68     };
69 }
70 
71 #[test]
nested()72 fn nested() {
73     fails_with! {
74         parser: ReportingParser,
75         input: "x",
76         rule: Rule::level1,
77         positives: vec![Rule::a, Rule::b, Rule::c],
78         negatives: vec![],
79         pos: 0
80     };
81 }
82 
83 #[test]
negative()84 fn negative() {
85     fails_with! {
86         parser: ReportingParser,
87         input: "x",
88         rule: Rule::negative,
89         positives: vec![],
90         negatives: vec![Rule::d],
91         pos: 0
92     };
93 }
94 
95 #[test]
negative_match()96 fn negative_match() {
97     fails_with! {
98         parser: ReportingParser,
99         input: "x",
100         rule: Rule::negative_match,
101         positives: vec![Rule::b],
102         negatives: vec![],
103         pos: 0
104     };
105 }
106 
107 #[test]
mixed()108 fn mixed() {
109     fails_with! {
110         parser: ReportingParser,
111         input: "x",
112         rule: Rule::mixed,
113         positives: vec![Rule::a],
114         negatives: vec![Rule::d],
115         pos: 0
116     };
117 }
118 
119 #[test]
mixed_progress()120 fn mixed_progress() {
121     fails_with! {
122         parser: ReportingParser,
123         input: "b",
124         rule: Rule::mixed_progress,
125         positives: vec![Rule::a],
126         negatives: vec![],
127         pos: 1
128     };
129 }
130