1
use ron::{
2
    error::{Error, Position, SpannedError},
3
    value::{Number, Value},
4
};
5

            
6
#[test]
7
4
fn test_array() {
8
4
    let array: [i32; 3] = [1, 2, 3];
9
4

            
10
4
    let ser = ron::to_string(&array).unwrap();
11
4
    assert_eq!(ser, "(1,2,3)");
12

            
13
4
    let de: [i32; 3] = ron::from_str(&ser).unwrap();
14
4
    assert_eq!(de, array);
15

            
16
4
    let value: Value = ron::from_str(&ser).unwrap();
17
4
    assert_eq!(
18
4
        value,
19
4
        Value::Seq(vec![
20
4
            Value::Number(Number::U8(1)),
21
4
            Value::Number(Number::U8(2)),
22
4
            Value::Number(Number::U8(3)),
23
4
        ])
24
4
    );
25

            
26
4
    let ser = ron::to_string(&value).unwrap();
27
4
    assert_eq!(ser, "[1,2,3]");
28

            
29
4
    let de: [i32; 3] = value.into_rust().unwrap();
30
4
    assert_eq!(de, array);
31

            
32
    // FIXME: fails and hence arrays do not roundtrip
33
4
    let de: SpannedError = ron::from_str::<[i32; 3]>(&ser).unwrap_err();
34
4
    assert_eq!(
35
4
        de,
36
4
        SpannedError {
37
4
            code: Error::ExpectedStructLike,
38
4
            position: Position { line: 1, col: 1 },
39
4
        }
40
4
    );
41

            
42
4
    let value: Value = ron::from_str(&ser).unwrap();
43
4
    assert_eq!(
44
4
        value,
45
4
        Value::Seq(vec![
46
4
            Value::Number(Number::U8(1)),
47
4
            Value::Number(Number::U8(2)),
48
4
            Value::Number(Number::U8(3)),
49
4
        ])
50
4
    );
51
4
}