1pub mod annotation;
2pub mod bnode;
3pub mod exclusion;
4pub mod iri_ref_or_wildcard;
5pub mod lang_or_wildcard;
6pub mod node_constraint;
7pub mod node_kind;
8pub mod object_value;
9pub mod iri_or_str;
11pub mod schema;
12pub mod schema_json_error;
13pub mod sem_act;
14pub mod serde_string_or_struct;
15pub mod shape;
16pub mod shape_decl;
17pub mod shape_expr;
18pub mod shape_expr_label;
19pub mod simple_repr_schema;
20pub mod start_action;
21pub mod string_or_iri_stem;
22pub mod string_or_literal_stem;
23pub mod string_or_wildcard;
24pub mod triple_expr;
25pub mod triple_expr_label;
26pub mod value_set_value;
27pub mod xs_facet;
28
29use crate::ast::serde_string_or_struct::*;
30pub use crate::exclusion::*;
31pub use annotation::*;
32pub use bnode::*;
33pub use iri_or_str::*;
34pub use iri_ref_or_wildcard::*;
35pub use lang_or_wildcard::*;
36pub use node_constraint::*;
37pub use node_kind::*;
38pub use object_value::*;
39pub use simple_repr_schema::*;
40pub use schema::*;
42pub use schema_json_error::*;
43pub use sem_act::*;
44pub use shape::*;
45pub use shape_decl::*;
46pub use shape_expr::*;
47pub use shape_expr_label::*;
48pub use start_action::*;
49pub use string_or_iri_stem::*;
50pub use string_or_literal_stem::*;
51pub use string_or_wildcard::*;
52pub use triple_expr::*;
53pub use triple_expr_label::*;
54pub use value_set_value::*;
55pub use xs_facet::*;
56
57const BOOLEAN_STR: &str = "http://www.w3.org/2001/XMLSchema#boolean";
58const INTEGER_STR: &str = "http://www.w3.org/2001/XMLSchema#integer";
59const DOUBLE_STR: &str = "http://www.w3.org/2001/XMLSchema#double";
60const DECIMAL_STR: &str = "http://www.w3.org/2001/XMLSchema#decimal";
61
62#[derive(Debug, Clone)]
63pub struct FromStrRefError;
64
65#[cfg(test)]
66mod tests {
67
68 use std::str::FromStr;
69
70 use iri_s::IriS;
71 use prefixmap::IriRef;
72
73 use super::*;
74
75 #[test]
76 fn test_shape_expr_triple_constraint() {
77 let str = r#"{
78 "type": "Shape",
79 "expression": {
80 "type": "TripleConstraint",
81 "predicate": "http://a.example/p1"
82 }
83 }"#;
84 let se = serde_json::from_str::<ShapeExpr>(str).unwrap();
85 let expected = ShapeExpr::Shape(Shape::default().with_expression(
86 TripleExpr::TripleConstraint {
87 id: None,
88 negated: None,
89 inverse: None,
90 predicate: IriS::new_unchecked("http://a.example/p1").into(),
91 value_expr: None,
92 min: None,
93 max: None,
94 sem_acts: None,
95 annotations: None,
96 },
97 ));
98 assert_eq!(se, expected);
99 }
100
101 #[test]
102 fn test_shape_expr_ref() {
103 let str = r#"{
104 "type": "Shape",
105 "expression": {
106 "type": "TripleConstraint",
107 "predicate": "http://a.example/p1",
108 "valueExpr": "http://all.example/S5"
109 }
110 }"#;
111 let se = serde_json::from_str::<ShapeExpr>(str).unwrap();
112 let expected = ShapeExpr::Shape(Shape::default().with_expression(
113 TripleExpr::TripleConstraint {
114 id: None,
115 negated: None,
116 inverse: None,
117 predicate: IriS::new_unchecked("http://a.example/p1").into(),
118 value_expr: Some(Box::new(ShapeExpr::Ref(ShapeExprLabel::IriRef {
119 value: IriRef::iri(IriS::new_unchecked("http://all.example/S5")),
120 }))),
121 min: None,
122 max: None,
123 sem_acts: None,
124 annotations: None,
125 },
126 ));
127 assert_eq!(se, expected);
128 }
129
130 #[test]
131 fn test_triple_constraint1() {
132 let str = r#"{
133 "type": "TripleConstraint",
134 "predicate": "http://a.example/p1",
135 "valueExpr": "http://all.example/S5"
136}"#;
137 let te = serde_json::from_str::<TripleExpr>(str).unwrap();
138 let p1 = IriS::from_str("http://a.example/p1").unwrap();
139 let s5 = IriS::from_str("http://all.example/S5").unwrap();
140 let expected = TripleExpr::TripleConstraint {
141 id: None,
142 negated: None,
143 inverse: None,
144 predicate: p1.into(),
145 value_expr: Some(Box::new(ShapeExpr::Ref(ShapeExprLabel::IriRef {
146 value: IriRef::iri(s5),
147 }))),
148 max: None,
149 min: None,
150 sem_acts: None,
151 annotations: None,
152 };
153 assert_eq!(te, expected);
154 }
155
156 #[test]
157 fn test_json() {
158 let str = r#"{
159 "type": "NodeConstraint",
160 "values": [
161 {
162 "value": "0",
163 "type": "http://www.w3.org/2001/XMLSchema#integer"
164 }
165 ]
166 }"#;
167
168 let shape_expr = serde_json::from_str::<ShapeExpr>(str);
169 if let Ok(v) = &shape_expr {
170 let _serialized = serde_json::to_string(v).unwrap();
171 }
172 assert!(shape_expr.is_ok())
173 }
174
175 #[test]
176 fn test_triple() {
177 let str = r#"{
178 "type": "Shape",
179 "expression": "http://all.example/S2e"
180 }"#;
181
182 let shape_expr = serde_json::from_str::<ShapeExpr>(str);
183 if let Ok(v) = &shape_expr {
184 serde_json::to_string(v).unwrap();
185 }
186 assert!(shape_expr.is_ok())
187 }
188}