|
1 | 1 | use tstring_json as backend_json; |
2 | 2 | use tstring_syntax::{ |
3 | | - InterpolationTypeRequirement, TemplateInput, TemplateInterpolation, TemplateSegment, |
| 3 | + DslType, InterpolationTypeRequirement, StructuralRole, StructuralSite, TemplateInput, |
| 4 | + TemplateInterpolation, TemplateSegment, TypeRequirement, |
4 | 5 | }; |
5 | 6 | use tstring_toml as backend_toml; |
6 | 7 | use tstring_yaml as backend_yaml; |
@@ -38,6 +39,39 @@ fn json_backend_public_api_smoke_test() { |
38 | 39 | ); |
39 | 40 | } |
40 | 41 |
|
| 42 | +#[test] |
| 43 | +fn json_backend_structural_site_public_api_smoke_test() { |
| 44 | + let template = TemplateInput::from_segments(vec![ |
| 45 | + TemplateSegment::StaticText("{\"items\": [{\"id\": ".to_owned()), |
| 46 | + interpolation(0, "id", "{id}"), |
| 47 | + TemplateSegment::StaticText("}], \"name\": \"Ada\"}".to_owned()), |
| 48 | + ]); |
| 49 | + |
| 50 | + assert_eq!( |
| 51 | + backend_json::interpolation_type_requirements(&template) |
| 52 | + .expect("expected json type requirements"), |
| 53 | + vec![InterpolationTypeRequirement::with_site( |
| 54 | + 0, |
| 55 | + "str | int | float | bool | None | dict[str, object] | list[object] | tuple[object, ...]", |
| 56 | + "json value", |
| 57 | + StructuralSite::new("/items/0/id", StructuralRole::Value) |
| 58 | + )] |
| 59 | + ); |
| 60 | + assert_eq!( |
| 61 | + backend_json::requirement_for( |
| 62 | + &DslType::new("integer"), |
| 63 | + backend_json::JsonProfile::default() |
| 64 | + ), |
| 65 | + TypeRequirement::new("int", Vec::new()) |
| 66 | + ); |
| 67 | + |
| 68 | + let outline = backend_json::static_structure_outline(&template).expect("expected outline"); |
| 69 | + assert_eq!(outline.objects[0].pointer.as_deref(), Some("")); |
| 70 | + assert_eq!(outline.objects[1].pointer.as_deref(), Some("/items/0")); |
| 71 | + assert_eq!(outline.objects[0].static_keys[0].name, "items"); |
| 72 | + assert_eq!(outline.objects[0].static_keys[1].name, "name"); |
| 73 | +} |
| 74 | + |
41 | 75 | #[test] |
42 | 76 | fn toml_backend_public_api_smoke_test() { |
43 | 77 | let template = TemplateInput::from_segments(vec![ |
|
0 commit comments