Skip to content

Commit

Permalink
Add tests for bool, structs, lists
Browse files Browse the repository at this point in the history
  • Loading branch information
chmp committed Aug 9, 2024
1 parent 2198a11 commit 46edeae
Showing 1 changed file with 83 additions and 0 deletions.
83 changes: 83 additions & 0 deletions serde_arrow/src/test/schema_tracing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,86 @@ mod json_u64_null {
test!(pos_null, [{"value": 42}, {"value": null}]);
test!(null_pos, [{"value": null}, {"value": 42}]);
}

mod json_bool_null {
use super::*;

macro_rules! test {
($name:ident, $($data:tt)*) => {
#[test]
fn $name() -> PanicOnError<()> {
let expected = SerdeArrowSchema::from_value(&json!([
{"name": "value", "data_type": "Bool", "nullable": true},
]))?;

let data = json!($($data)*);
let actual = SerdeArrowSchema::from_samples(&data, TracingOptions::default())?;
assert_eq!(actual, expected);
Ok(())
}
};
}

test!(pos_null, [{"value": true}, {"value": null}]);
test!(null_pos, [{"value": null}, {"value": false}]);
}

mod json_struct_null {
use super::*;

macro_rules! test {
($name:ident, $($data:tt)*) => {
#[test]
fn $name() -> PanicOnError<()> {
let expected = SerdeArrowSchema::from_value(&json!([
{
"name": "value",
"data_type": "Struct",
"nullable": true,
"children": [
{"name": "child", "data_type": "U32"},
]
},
]))?;

let data = json!($($data)*);
let actual = SerdeArrowSchema::from_samples(&data, TracingOptions::default())?;
assert_eq!(actual, expected);
Ok(())
}
};
}

test!(struct_null, [{"value": {"child": 13}}, {"value": null}]);
test!(null_struct, [{"value": null}, {"value": {"child": 13}}]);
}

mod json_list_null {
use super::*;

macro_rules! test {
($name:ident, $($data:tt)*) => {
#[test]
fn $name() -> PanicOnError<()> {
let expected = SerdeArrowSchema::from_value(&json!([
{
"name": "value",
"data_type": "LargeList",
"nullable": true,
"children": [
{"name": "element", "data_type": "U32"},
]
},
]))?;

let data = json!($($data)*);
let actual = SerdeArrowSchema::from_samples(&data, TracingOptions::default())?;
assert_eq!(actual, expected);
Ok(())
}
};
}

test!(list_null, [{"value": [13]}, {"value": null}]);
test!(null_list, [{"value": null}, {"value": [13]}]);
}

0 comments on commit 46edeae

Please sign in to comment.