File: lexer.rs

package info (click to toggle)
librsvg 2.60.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 140,720 kB
  • sloc: python: 2,913; ansic: 2,333; sh: 1,022; makefile: 95; xml: 14; javascript: 9
file content (64 lines) | stat: -rw-r--r-- 1,353 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
use cfg_expr::expr::lexer::{Lexer, Token};

macro_rules! test_lex {
    ($text:expr, [$($token:expr),+$(,)?]) => {
        let lexed: Vec<_> = Lexer::new($text).map(|lt| lt.unwrap().token).collect();
        let expected = vec![$($token),+];

        assert_eq!(lexed, expected);
    }
}

#[test]
fn handles_raw() {
    test_lex!("key", [Token::Key("key")]);
}

#[test]
fn strips_attribute() {
    test_lex!("cfg(key)", [Token::Key("key")]);
}

#[test]
fn handle_key_value() {
    test_lex!(
        "key = \"value\"",
        [Token::Key("key"), Token::Equals, Token::Value("value"),]
    );
}

#[test]
fn handle_empty_value() {
    test_lex!(
        "key = \"\"",
        [Token::Key("key"), Token::Equals, Token::Value(""),]
    );
}

#[test]
fn handle_short_key() {
    test_lex!("k", [Token::Key("k"),]);
}

#[test]
fn handle_cfg_keywords() {
    test_lex!(
        "all(any(not(anyblah,allnope,notany)))",
        [
            Token::All,
            Token::OpenParen,
            Token::Any,
            Token::OpenParen,
            Token::Not,
            Token::OpenParen,
            Token::Key("anyblah"),
            Token::Comma,
            Token::Key("allnope"),
            Token::Comma,
            Token::Key("notany"),
            Token::CloseParen,
            Token::CloseParen,
            Token::CloseParen,
        ]
    );
}