aboutsummaryrefslogtreecommitdiffstats
path: root/src/parse/test.rs
blob: e1c20771a9a3f118b0cb2eeedb51fb905f9843dc (plain) (blame)
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
use super::*;

fn parse(x: &[u8]) -> Ast<PreExpansion> {
    do_parse(x).unwrap()
}

fn parse_test(l: Ast<PreExpansion>, r: Ast<PreExpansion>) {
    if l != r {
        let mut left = Vec::new();
        l.cdisplay(&mut left).unwrap();
        let mut right = Vec::new();
        r.cdisplay(&mut right).unwrap();
        let left = String::from_utf8_lossy(&left);
        let right = String::from_utf8_lossy(&right);
        panic!("parse equality error\nleft: {left}\nright: {right}")
    }
}

#[test]
fn command_interp() {
    parse_test(
        parse(br#""$(echo echo)""#),
        pipes([cmd([str([cmdp(pipes([cmd([
            estr(b"echo"),
            estr(b"echo"),
        ])]))])])]),
    )
}

#[test]
fn string_concat() {
    parse_test(
        parse(br#"  foo'bar'"baz"  "#),
        pipes([cmd([estr(b"foobarbaz")])]),
    );
}

#[test]
fn simple_string() {
    parse_test(parse(b"foo"), pipes([cmd([estr(b"foo")])]));
}

#[test]
fn simple_var() {
    parse_test(parse(b"$foo"), pipes([cmd([str([var(b"foo")])])]));
}