• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Licensed under the Apache License, Version 2.0
2 // <LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0> or the MIT
3 // license <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
4 // option. All files in the project carrying such notice may not be copied,
5 // modified, or distributed except according to those terms.
6 
7 #![cfg_attr(not(feature = "std"), no_std)]
8 extern crate alloc;
9 extern crate pest;
10 extern crate pest_derive;
11 
12 #[cfg(feature = "grammar-extras")]
13 use pest::Parser;
14 use pest_derive::Parser;
15 
16 #[derive(Parser)]
17 #[grammar = "../tests/opt.pest"]
18 struct TestOptParser;
19 
20 #[test]
21 #[cfg(feature = "grammar-extras")]
test_opt_tag()22 fn test_opt_tag() {
23     let successful_parse = TestOptParser::parse(Rule::expr, "*");
24     assert!(successful_parse.is_ok());
25     let pairs = successful_parse.unwrap();
26     assert!(pairs.find_first_tagged("prefix").is_some());
27     assert!(pairs.find_first_tagged("suffix").is_none());
28 
29     // Test with no STAR or DOT
30     let parse_no_components = TestOptParser::parse(Rule::expr, "");
31     assert!(parse_no_components.is_ok());
32     let pairs_no_components = parse_no_components.unwrap();
33     assert!(pairs_no_components.find_first_tagged("prefix").is_none());
34     assert!(pairs_no_components.find_first_tagged("suffix").is_none());
35 
36     // Test with only DOT
37     let parse_only_dot = TestOptParser::parse(Rule::expr, ".");
38     assert!(parse_only_dot.is_ok());
39     let pairs_only_dot = parse_only_dot.unwrap();
40     assert!(pairs_only_dot.find_first_tagged("prefix").is_none());
41     assert!(pairs_only_dot.find_first_tagged("suffix").is_some());
42 }
43