1
//! Tests for the suggestion reply parser.
2

            
3
use super::super::parse_suggestions;
4

            
5
#[test]
6
1
fn a_reply_yields_its_strings() {
7
1
    let wire = r#"(:id 3 :value "(\"food\" \"a b\" \"q\\\"uote\")")"#;
8
1
    assert_eq!(
9
1
        parse_suggestions(wire),
10
1
        Some(vec![
11
1
            "food".to_string(),
12
1
            "a b".to_string(),
13
1
            "q\"uote".to_string()
14
1
        ])
15
    );
16
1
}
17

            
18
#[test]
19
1
fn an_empty_list_is_an_answer() {
20
1
    assert_eq!(
21
1
        parse_suggestions(r#"(:id 1 :value "()")"#),
22
1
        Some(Vec::new())
23
    );
24
1
}
25

            
26
#[test]
27
1
fn failures_and_other_lists_yield_nothing() {
28
1
    assert_eq!(
29
1
        parse_suggestions(r#"(:id 1 :error (:code args :message "no"))"#),
30
1
        None
31
    );
32
1
    assert_eq!(parse_suggestions(r#"(:id 1 :value "(1 2)")"#), None);
33
1
    assert_eq!(parse_suggestions("garbage"), None);
34
1
}