use toml::{value::Table, Value}; use schema_analysis::InferredSchema; mod shared; use shared::FormatTests; struct Toml; test_format!(Toml); impl FormatTests for Toml { fn convert_to_inferred_schema(value: Value) -> InferredSchema { let string_value: String = toml::to_string(&value).unwrap(); let processed_schema: InferredSchema = toml::from_str(&string_value).unwrap(); processed_schema } // Toml doesn't have null values fn null() -> Option { None } // Toml doesn't allow top-level primitives fn boolean() -> Option { None } fn integer() -> Option { None } fn float() -> Option { None } fn string() -> Option { None } // Toml doesn't allow top-level arrays fn empty_sequence() -> Option { None } fn string_sequence() -> Option { None } fn integer_sequence() -> Option { None } fn mixed_sequence() -> Option { None } fn optional_mixed_sequence() -> Option { None } fn empty_map_struct() -> Option { Some(Value::Table(Table::new())) } fn map_struct_single() -> Option { let mut mapping = Table::new(); mapping.insert("hello".into(), 1.into()); Some(Value::Table(mapping)) } fn map_struct_double() -> Option { let mut mapping = Table::new(); mapping.insert("hello".into(), 1.into()); mapping.insert("world".into(), "!".into()); Some(Value::Table(mapping)) } fn sequence_map_struct_mixed() -> Option { None // Toml doesn't allow top-level arrays } fn sequence_map_struct_optional_or_missing() -> Option { None // Toml doesn't allow top-level arrays } fn map_struct_mixed_sequence() -> Option { let mut mapping = Table::new(); mapping.insert("hello".into(), 1.into()); mapping.insert("world".into(), "!".into()); mapping.insert( "sequence".into(), Value::Array(vec!["one".into(), "two".into(), "three".into()]), ); Some(Value::Table(mapping)) } fn map_struct_mixed_sequence_optional() -> Option { None // Toml doesn't have null values } }