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 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
|
use std::collections::HashMap;
use ron::from_str;
use serde::Deserialize;
#[derive(Deserialize)]
#[allow(dead_code)]
struct Newtype(i32);
#[derive(Deserialize)]
#[allow(dead_code)]
struct Tuple(i32, i32);
#[derive(Deserialize)]
#[allow(dead_code)]
struct Struct {
a: i32,
b: i32,
}
#[derive(Deserialize)]
#[allow(dead_code)]
enum Enum {
Newtype(i32),
Tuple(i32, i32),
Struct { a: i32, b: i32 },
}
#[test]
fn test_trailing_comma_some() {
assert!(from_str::<Option<i32>>("Some(1)").is_ok());
assert!(from_str::<Option<i32>>("Some(1,)").is_ok());
assert!(from_str::<Option<i32>>("Some(1,,)").is_err());
}
#[test]
fn test_trailing_comma_tuple() {
assert!(from_str::<(i32, i32)>("(1,2)").is_ok());
assert!(from_str::<(i32, i32)>("(1,2,)").is_ok());
assert!(from_str::<(i32, i32)>("(1,2,,)").is_err());
}
#[test]
fn test_trailing_comma_list() {
assert!(from_str::<Vec<i32>>("[1,2]").is_ok());
assert!(from_str::<Vec<i32>>("[1,2,]").is_ok());
assert!(from_str::<Vec<i32>>("[1,2,,]").is_err());
}
#[test]
fn test_trailing_comma_map() {
assert!(from_str::<HashMap<i32, bool>>("{1:false,2:true}").is_ok());
assert!(from_str::<HashMap<i32, bool>>("{1:false,2:true,}").is_ok());
assert!(from_str::<HashMap<i32, bool>>("{1:false,2:true,,}").is_err());
}
#[test]
fn test_trailing_comma_newtype_struct() {
assert!(from_str::<Newtype>("(1)").is_ok());
assert!(from_str::<Newtype>("(1,)").is_ok());
assert!(from_str::<Newtype>("(1,,)").is_err());
}
#[test]
fn test_trailing_comma_tuple_struct() {
assert!(from_str::<Tuple>("(1,2)").is_ok());
assert!(from_str::<Tuple>("(1,2,)").is_ok());
assert!(from_str::<Tuple>("(1,2,,)").is_err());
}
#[test]
fn test_trailing_comma_struct() {
assert!(from_str::<Struct>("(a:1,b:2)").is_ok());
assert!(from_str::<Struct>("(a:1,b:2,)").is_ok());
assert!(from_str::<Struct>("(a:1,b:2,,)").is_err());
}
#[test]
fn test_trailing_comma_enum_newtype_variant() {
assert!(from_str::<Enum>("Newtype(1)").is_ok());
assert!(from_str::<Enum>("Newtype(1,)").is_ok());
assert!(from_str::<Enum>("Newtype(1,,)").is_err());
}
#[test]
fn test_trailing_comma_enum_tuple_variant() {
assert!(from_str::<Enum>("Tuple(1,2)").is_ok());
assert!(from_str::<Enum>("Tuple(1,2,)").is_ok());
assert!(from_str::<Enum>("Tuple(1,2,,)").is_err());
}
#[test]
fn test_trailing_comma_enum_struct_variant() {
assert!(from_str::<Enum>("Struct(a:1,b:2)").is_ok());
assert!(from_str::<Enum>("Struct(a:1,b:2,)").is_ok());
assert!(from_str::<Enum>("Struct(a:1,b:2,,)").is_err());
}
|