Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test for the array-Value roundtrip failure #404

Merged
merged 1 commit into from
Aug 22, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions tests/238_array.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
use ron::{
error::{Error, Position, SpannedError},
value::{Number, Value},
};

#[test]
fn test_array() {
let array: [i32; 3] = [1, 2, 3];

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

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

let value: Value = ron::from_str(&ser).unwrap();
assert_eq!(
value,
Value::Seq(vec![
Value::Number(Number::from(1)),
Value::Number(Number::from(2)),
Value::Number(Number::from(3)),
])
);

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

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

// FIXME: fails and hence arrays do not roundtrip
let de: SpannedError = ron::from_str::<[i32; 3]>(&ser).unwrap_err();
assert_eq!(
de,
SpannedError {
code: Error::ExpectedStructLike,
position: Position { line: 1, col: 1 },
}
);

let value: Value = ron::from_str(&ser).unwrap();
assert_eq!(
value,
Value::Seq(vec![
Value::Number(Number::from(1)),
Value::Number(Number::from(2)),
Value::Number(Number::from(3)),
])
);
}