@@ -143,11 +143,146 @@ def test_null_invalid():
143143 errors = validator .validate_instance (0 )
144144 assert any ("Expected null" in err for err in errors )
145145
146+
147+ def test_any_accepts_string ():
148+ """Test any type accepts string values"""
149+ schema = {"type" : "any" , "$schema" : "https://json-structure.org/meta/core/v0/#" ,
150+ "$id" : "dummy" , "name" : "anySchema" }
151+ validator = JSONStructureInstanceValidator (schema )
152+ errors = validator .validate_instance ("hello" )
153+ assert errors == []
154+
155+
156+ def test_any_accepts_number ():
157+ """Test any type accepts numeric values"""
158+ schema = {"type" : "any" , "$schema" : "https://json-structure.org/meta/core/v0/#" ,
159+ "$id" : "dummy" , "name" : "anySchema" }
160+ validator = JSONStructureInstanceValidator (schema )
161+ errors = validator .validate_instance (42.5 )
162+ assert errors == []
163+
164+
165+ def test_any_accepts_object ():
166+ """Test any type accepts object values"""
167+ schema = {"type" : "any" , "$schema" : "https://json-structure.org/meta/core/v0/#" ,
168+ "$id" : "dummy" , "name" : "anySchema" }
169+ validator = JSONStructureInstanceValidator (schema )
170+ errors = validator .validate_instance ({"key" : "value" })
171+ assert errors == []
172+
173+
174+ def test_any_accepts_array ():
175+ """Test any type accepts array values"""
176+ schema = {"type" : "any" , "$schema" : "https://json-structure.org/meta/core/v0/#" ,
177+ "$id" : "dummy" , "name" : "anySchema" }
178+ validator = JSONStructureInstanceValidator (schema )
179+ errors = validator .validate_instance ([1 , 2 , 3 ])
180+ assert errors == []
181+
182+
183+ def test_any_accepts_null ():
184+ """Test any type accepts null values"""
185+ schema = {"type" : "any" , "$schema" : "https://json-structure.org/meta/core/v0/#" ,
186+ "$id" : "dummy" , "name" : "anySchema" }
187+ validator = JSONStructureInstanceValidator (schema )
188+ errors = validator .validate_instance (None )
189+ assert errors == []
190+
191+
192+ def test_any_accepts_boolean ():
193+ """Test any type accepts boolean values"""
194+ schema = {"type" : "any" , "$schema" : "https://json-structure.org/meta/core/v0/#" ,
195+ "$id" : "dummy" , "name" : "anySchema" }
196+ validator = JSONStructureInstanceValidator (schema )
197+ errors = validator .validate_instance (True )
198+ assert errors == []
199+
200+
146201# -------------------------------------------------------------------
147202# Integer and Floating Point Tests (Numeric JSONStructureValidation Addins)
148203# -------------------------------------------------------------------
149204
150205
206+ def test_int8_valid ():
207+ schema = {"type" : "int8" , "$schema" : "https://json-structure.org/meta/core/v0/#" ,
208+ "$id" : "dummy" , "name" : "int8Schema" }
209+ validator = JSONStructureInstanceValidator (schema )
210+ errors = validator .validate_instance (127 )
211+ assert errors == []
212+
213+
214+ def test_int8_out_of_range ():
215+ schema = {"type" : "int8" , "$schema" : "https://json-structure.org/meta/core/v0/#" ,
216+ "$id" : "dummy" , "name" : "int8Schema" }
217+ validator = JSONStructureInstanceValidator (schema )
218+ errors = validator .validate_instance (128 )
219+ assert any ("out of range" in err for err in errors )
220+
221+
222+ def test_int8_negative_valid ():
223+ schema = {"type" : "int8" , "$schema" : "https://json-structure.org/meta/core/v0/#" ,
224+ "$id" : "dummy" , "name" : "int8Schema" }
225+ validator = JSONStructureInstanceValidator (schema )
226+ errors = validator .validate_instance (- 128 )
227+ assert errors == []
228+
229+
230+ def test_uint8_valid ():
231+ schema = {"type" : "uint8" , "$schema" : "https://json-structure.org/meta/core/v0/#" ,
232+ "$id" : "dummy" , "name" : "uint8Schema" }
233+ validator = JSONStructureInstanceValidator (schema )
234+ errors = validator .validate_instance (255 )
235+ assert errors == []
236+
237+
238+ def test_uint8_out_of_range ():
239+ schema = {"type" : "uint8" , "$schema" : "https://json-structure.org/meta/core/v0/#" ,
240+ "$id" : "dummy" , "name" : "uint8Schema" }
241+ validator = JSONStructureInstanceValidator (schema )
242+ errors = validator .validate_instance (256 )
243+ assert any ("out of range" in err for err in errors )
244+
245+
246+ def test_uint8_negative ():
247+ schema = {"type" : "uint8" , "$schema" : "https://json-structure.org/meta/core/v0/#" ,
248+ "$id" : "dummy" , "name" : "uint8Schema" }
249+ validator = JSONStructureInstanceValidator (schema )
250+ errors = validator .validate_instance (- 1 )
251+ assert any ("out of range" in err for err in errors )
252+
253+
254+ def test_int16_valid ():
255+ schema = {"type" : "int16" , "$schema" : "https://json-structure.org/meta/core/v0/#" ,
256+ "$id" : "dummy" , "name" : "int16Schema" }
257+ validator = JSONStructureInstanceValidator (schema )
258+ errors = validator .validate_instance (32767 )
259+ assert errors == []
260+
261+
262+ def test_int16_out_of_range ():
263+ schema = {"type" : "int16" , "$schema" : "https://json-structure.org/meta/core/v0/#" ,
264+ "$id" : "dummy" , "name" : "int16Schema" }
265+ validator = JSONStructureInstanceValidator (schema )
266+ errors = validator .validate_instance (32768 )
267+ assert any ("out of range" in err for err in errors )
268+
269+
270+ def test_uint16_valid ():
271+ schema = {"type" : "uint16" , "$schema" : "https://json-structure.org/meta/core/v0/#" ,
272+ "$id" : "dummy" , "name" : "uint16Schema" }
273+ validator = JSONStructureInstanceValidator (schema )
274+ errors = validator .validate_instance (65535 )
275+ assert errors == []
276+
277+
278+ def test_uint16_out_of_range ():
279+ schema = {"type" : "uint16" , "$schema" : "https://json-structure.org/meta/core/v0/#" ,
280+ "$id" : "dummy" , "name" : "uint16Schema" }
281+ validator = JSONStructureInstanceValidator (schema )
282+ errors = validator .validate_instance (65536 )
283+ assert any ("out of range" in err for err in errors )
284+
285+
151286def test_int32_valid ():
152287 schema = {"type" : "int32" , "$schema" : "https://json-structure.org/meta/core/v0/#" ,
153288 "$id" : "dummy" , "name" : "int32Schema" }
@@ -212,6 +347,105 @@ def test_uint64_invalid_format():
212347 assert any ("Expected uint64 as string" in err for err in errors )
213348
214349
350+ def test_int128_valid ():
351+ schema = {"type" : "int128" , "$schema" : "https://json-structure.org/meta/core/v0/#" ,
352+ "$id" : "dummy" , "name" : "int128Schema" }
353+ validator = JSONStructureInstanceValidator (schema )
354+ errors = validator .validate_instance ("170141183460469231731687303715884105727" )
355+ assert errors == []
356+
357+
358+ def test_int128_out_of_range ():
359+ schema = {"type" : "int128" , "$schema" : "https://json-structure.org/meta/core/v0/#" ,
360+ "$id" : "dummy" , "name" : "int128Schema" }
361+ validator = JSONStructureInstanceValidator (schema )
362+ errors = validator .validate_instance ("170141183460469231731687303715884105728" ) # 2^127
363+ assert any ("out of range" in err for err in errors )
364+
365+
366+ def test_int128_invalid_format ():
367+ schema = {"type" : "int128" , "$schema" : "https://json-structure.org/meta/core/v0/#" ,
368+ "$id" : "dummy" , "name" : "int128Schema" }
369+ validator = JSONStructureInstanceValidator (schema )
370+ errors = validator .validate_instance (12345 ) # Should be string
371+ assert any ("Expected int128 as string" in err for err in errors )
372+
373+
374+ def test_uint128_valid ():
375+ schema = {"type" : "uint128" , "$schema" : "https://json-structure.org/meta/core/v0/#" ,
376+ "$id" : "dummy" , "name" : "uint128Schema" }
377+ validator = JSONStructureInstanceValidator (schema )
378+ errors = validator .validate_instance ("340282366920938463463374607431768211455" ) # 2^128 - 1
379+ assert errors == []
380+
381+
382+ def test_uint128_out_of_range ():
383+ schema = {"type" : "uint128" , "$schema" : "https://json-structure.org/meta/core/v0/#" ,
384+ "$id" : "dummy" , "name" : "uint128Schema" }
385+ validator = JSONStructureInstanceValidator (schema )
386+ errors = validator .validate_instance ("340282366920938463463374607431768211456" ) # 2^128
387+ assert any ("out of range" in err for err in errors )
388+
389+
390+ def test_uint128_negative ():
391+ schema = {"type" : "uint128" , "$schema" : "https://json-structure.org/meta/core/v0/#" ,
392+ "$id" : "dummy" , "name" : "uint128Schema" }
393+ validator = JSONStructureInstanceValidator (schema )
394+ errors = validator .validate_instance ("-1" )
395+ assert any ("out of range" in err for err in errors )
396+
397+
398+ def test_float8_valid ():
399+ schema = {"type" : "float8" , "$schema" : "https://json-structure.org/meta/core/v0/#" ,
400+ "$id" : "dummy" , "name" : "float8Schema" }
401+ validator = JSONStructureInstanceValidator (schema )
402+ errors = validator .validate_instance (0.5 )
403+ assert errors == []
404+
405+
406+ def test_float8_integer_accepted ():
407+ schema = {"type" : "float8" , "$schema" : "https://json-structure.org/meta/core/v0/#" ,
408+ "$id" : "dummy" , "name" : "float8Schema" }
409+ validator = JSONStructureInstanceValidator (schema )
410+ errors = validator .validate_instance (1 ) # int is accepted for float8
411+ assert errors == []
412+
413+
414+ def test_float8_invalid ():
415+ schema = {"type" : "float8" , "$schema" : "https://json-structure.org/meta/core/v0/#" ,
416+ "$id" : "dummy" , "name" : "float8Schema" }
417+ validator = JSONStructureInstanceValidator (schema )
418+ errors = validator .validate_instance ("0.5" ) # Should be number, not string
419+ assert any ("Expected float8" in err for err in errors )
420+
421+
422+ def test_integer_valid ():
423+ """Test integer type (alias for int32)"""
424+ schema = {"type" : "integer" , "$schema" : "https://json-structure.org/meta/core/v0/#" ,
425+ "$id" : "dummy" , "name" : "integerSchema" }
426+ validator = JSONStructureInstanceValidator (schema )
427+ errors = validator .validate_instance (123 )
428+ assert errors == []
429+
430+
431+ def test_integer_out_of_range ():
432+ """Test integer type (alias for int32) range validation"""
433+ schema = {"type" : "integer" , "$schema" : "https://json-structure.org/meta/core/v0/#" ,
434+ "$id" : "dummy" , "name" : "integerSchema" }
435+ validator = JSONStructureInstanceValidator (schema )
436+ errors = validator .validate_instance (2 ** 31 )
437+ assert any ("out of range" in err for err in errors )
438+
439+
440+ def test_integer_invalid_type ():
441+ """Test integer type rejects non-integers"""
442+ schema = {"type" : "integer" , "$schema" : "https://json-structure.org/meta/core/v0/#" ,
443+ "$id" : "dummy" , "name" : "integerSchema" }
444+ validator = JSONStructureInstanceValidator (schema )
445+ errors = validator .validate_instance ("123" )
446+ assert any ("Expected integer" in err for err in errors )
447+
448+
215449def test_float_valid ():
216450 schema = {"type" : "float" , "$schema" : "https://json-structure.org/meta/core/v0/#" ,
217451 "$id" : "dummy" , "name" : "floatSchema" }
@@ -228,6 +462,39 @@ def test_float_invalid():
228462 assert any ("Expected float" in err for err in errors )
229463
230464
465+ def test_double_valid ():
466+ schema = {"type" : "double" , "$schema" : "https://json-structure.org/meta/core/v0/#" ,
467+ "$id" : "dummy" , "name" : "doubleSchema" }
468+ validator = JSONStructureInstanceValidator (schema )
469+ errors = validator .validate_instance (3.141592653589793 )
470+ assert errors == []
471+
472+
473+ def test_double_integer_accepted ():
474+ """Test that integers are accepted for double type"""
475+ schema = {"type" : "double" , "$schema" : "https://json-structure.org/meta/core/v0/#" ,
476+ "$id" : "dummy" , "name" : "doubleSchema" }
477+ validator = JSONStructureInstanceValidator (schema )
478+ errors = validator .validate_instance (42 )
479+ assert errors == []
480+
481+
482+ def test_double_invalid ():
483+ schema = {"type" : "double" , "$schema" : "https://json-structure.org/meta/core/v0/#" ,
484+ "$id" : "dummy" , "name" : "doubleSchema" }
485+ validator = JSONStructureInstanceValidator (schema )
486+ errors = validator .validate_instance ("3.14" )
487+ assert any ("Expected double" in err for err in errors )
488+
489+
490+ def test_float_invalid ():
491+ schema = {"type" : "float" , "$schema" : "https://json-structure.org/meta/core/v0/#" ,
492+ "$id" : "dummy" , "name" : "floatSchema" }
493+ validator = JSONStructureInstanceValidator (schema )
494+ errors = validator .validate_instance ("1.23" )
495+ assert any ("Expected float" in err for err in errors )
496+
497+
231498def test_decimal_valid ():
232499 schema = {"type" : "decimal" , "$schema" : "https://json-structure.org/meta/core/v0/#" ,
233500 "$id" : "dummy" , "name" : "decimalSchema" }
@@ -358,6 +625,23 @@ def test_time_invalid():
358625 errors = validator .validate_instance ("123456" )
359626 assert any ("Expected time" in err for err in errors )
360627
628+
629+ def test_duration_valid ():
630+ schema = {"type" : "duration" , "$schema" : "https://json-structure.org/meta/core/v0/#" ,
631+ "$id" : "dummy" , "name" : "durationSchema" }
632+ validator = JSONStructureInstanceValidator (schema )
633+ errors = validator .validate_instance ("P1Y2M3DT4H5M6S" ) # ISO 8601 duration
634+ assert errors == []
635+
636+
637+ def test_duration_invalid ():
638+ schema = {"type" : "duration" , "$schema" : "https://json-structure.org/meta/core/v0/#" ,
639+ "$id" : "dummy" , "name" : "durationSchema" }
640+ validator = JSONStructureInstanceValidator (schema )
641+ errors = validator .validate_instance (3600 ) # Should be string, not number
642+ assert any ("Expected duration" in err for err in errors )
643+
644+
361645# -------------------------------------------------------------------
362646# UUID and URI Tests
363647# -------------------------------------------------------------------
0 commit comments