Debian Codegraph @

debian/missing-sources/cfg-expr/tests/lexer.rs

raw
1 use cfg_expr::expr::lexer::{Lexer, Token};
2
3 macro_rules! test_lex {
4 ($text:expr, [$($token:expr),+$(,)?]) => {
5 let lexed: Vec<_> = Lexer::new($text).map(|lt| lt.unwrap().token).collect();
6 let expected = vec![$($token),+];
7
8 assert_eq!(lexed, expected);
9 }
10 }
11
12 #[test]
13 fn handles_raw() {
14 test_lex!("key", [Token::Key("key")]);
15 }
16
17 #[test]
18 fn strips_attribute() {
19 test_lex!("cfg(key)", [Token::Key("key")]);
20 }
21
22 #[test]
23 fn handle_key_value() {
24 test_lex!(
25 "key = \"value\"",
26 [Token::Key("key"), Token::Equals, Token::Value("value"),]
27 );
28 }
29
30 #[test]
31 fn handle_empty_value() {
32 test_lex!(
33 "key = \"\"",
34 [Token::Key("key"), Token::Equals, Token::Value(""),]
35 );
36 }
37
38 #[test]
39 fn handle_short_key() {
40 test_lex!("k", [Token::Key("k"),]);
41 }
42
43 #[test]
44 fn handle_cfg_keywords() {
45 test_lex!(
46 "all(any(not(anyblah,allnope,notany)))",
47 [
48 Token::All,
49 Token::OpenParen,
50 Token::Any,
51 Token::OpenParen,
52 Token::Not,
53 Token::OpenParen,
54 Token::Key("anyblah"),
55 Token::Comma,
56 Token::Key("allnope"),
57 Token::Comma,
58 Token::Key("notany"),
59 Token::CloseParen,
60 Token::CloseParen,
61 Token::CloseParen,
62 ]
63 );
64 }