use super::*;
use serde_json::Result;
#[cfg(test)]
const SENML_CDDL: &str = r#"SenML-Pack = [1* record]
record = {
? bn => tstr, ; Base Name
? bt => numeric, ; Base Time
? bu => tstr, ; Base Units
? bv => numeric, ; Base Value
? bs => numeric, ; Base Sum
? bver => uint, ; Base Version
? n => tstr, ; Name
? u => tstr, ; Units
? s => numeric, ; Sum
? t => numeric, ; Time
? ut => numeric, ; Update Time
? ( v => numeric // ; Numeric Value
vs => tstr // ; String Value
vb => bool // ; Boolean Value
vd => binary-value ) ; Data Value
* key-value-pair
}
; now define the generic versions
key-value-pair = ( label => value )
label = non-b-label / b-label
non-b-label = tstr .regexp "[A-Zac-z0-9][-_:.A-Za-z0-9]*" / uint
b-label = tstr .regexp "b[-_:.A-Za-z0-9]+" / nint
value = tstr / binary-value / numeric / bool
numeric = number / decfrac
"#;
#[test]
#[ignore]
fn test_cddl_parse() {
use cddl::validate_json_from_str;
let row = r#"[{"bn": "urn:dev:mac:ffffaaaa0000eeee:", "n": "modio.test.test", "vs": "abc123", "t": 1628546838}] "#;
println!("Row is :{}", row);
let res = validate_json_from_str(SENML_CDDL, row);
res.expect("Something wrong");
}
#[test]
#[ignore]
fn test_json_roundtrip() -> Result<()> {
use cddl::validate_json_from_str;
let datum = LimitedSenML::make_one(
"urn:dev:mac:ffffaaaa0000eeee:",
"modio.test.test",
"abc123",
1_628_546_838.0,
None,
);
let data: std::vec::Vec<LimitedSenML> = vec![datum];
let row = serde_json::to_string(&data)?;
println!("Row is :{:?}", row);
validate_json_from_str(SENML_CDDL, &row).expect("test failed");
Ok(())
}