json-schema 2.4.1 → 2.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (88) hide show
  1. checksums.yaml +6 -14
  2. data/README.textile +58 -7
  3. data/lib/json-schema.rb +3 -1
  4. data/lib/json-schema/attributes/additionalitems.rb +14 -11
  5. data/lib/json-schema/attributes/additionalproperties.rb +33 -43
  6. data/lib/json-schema/attributes/anyof.rb +4 -0
  7. data/lib/json-schema/attributes/dependencies.rb +31 -19
  8. data/lib/json-schema/attributes/disallow.rb +2 -3
  9. data/lib/json-schema/attributes/divisibleby.rb +11 -7
  10. data/lib/json-schema/attributes/enum.rb +14 -16
  11. data/lib/json-schema/attributes/format.rb +4 -7
  12. data/lib/json-schema/attributes/formats/date_time_v4.rb +5 -8
  13. data/lib/json-schema/attributes/formats/ip.rb +41 -0
  14. data/lib/json-schema/attributes/formats/uri.rb +10 -8
  15. data/lib/json-schema/attributes/items.rb +15 -16
  16. data/lib/json-schema/attributes/limit.rb +179 -0
  17. data/lib/json-schema/attributes/maxdecimal.rb +7 -6
  18. data/lib/json-schema/attributes/multipleof.rb +4 -11
  19. data/lib/json-schema/attributes/not.rb +1 -1
  20. data/lib/json-schema/attributes/oneof.rb +15 -6
  21. data/lib/json-schema/attributes/pattern.rb +7 -6
  22. data/lib/json-schema/attributes/patternproperties.rb +9 -12
  23. data/lib/json-schema/attributes/properties.rb +55 -39
  24. data/lib/json-schema/attributes/properties_optional.rb +13 -12
  25. data/lib/json-schema/attributes/ref.rb +4 -4
  26. data/lib/json-schema/attributes/required.rb +16 -13
  27. data/lib/json-schema/attributes/type.rb +13 -18
  28. data/lib/json-schema/attributes/type_v4.rb +11 -18
  29. data/lib/json-schema/attributes/uniqueitems.rb +5 -7
  30. data/lib/json-schema/schema.rb +8 -8
  31. data/lib/json-schema/schema/#validator.rb# +37 -0
  32. data/lib/json-schema/schema/reader.rb +113 -0
  33. data/lib/json-schema/util/uri.rb +16 -0
  34. data/lib/json-schema/validator.rb +123 -128
  35. data/lib/json-schema/validators/draft1.rb +1 -1
  36. data/lib/json-schema/validators/draft2.rb +1 -1
  37. data/lib/json-schema/validators/draft3.rb +1 -1
  38. data/lib/json-schema/validators/draft4.rb +1 -1
  39. data/lib/json-schema/validators/hyper-draft4.rb +1 -1
  40. data/test/schemas/address_microformat.json +18 -0
  41. data/test/schemas/definition_schema.json +15 -0
  42. data/test/schemas/ref john with spaces schema.json +11 -0
  43. data/test/schemas/relative_definition_schema.json +8 -0
  44. data/test/test_all_of_ref_schema.rb +12 -15
  45. data/test/test_any_of_ref_schema.rb +7 -9
  46. data/test/test_bad_schema_ref.rb +18 -12
  47. data/test/test_common_test_suite.rb +45 -29
  48. data/test/test_custom_format.rb +2 -3
  49. data/test/test_definition.rb +15 -0
  50. data/test/test_extended_schema.rb +25 -31
  51. data/test/test_extends_and_additionalProperties.rb +23 -21
  52. data/test/test_files_v3.rb +14 -23
  53. data/test/test_fragment_resolution.rb +6 -7
  54. data/test/test_fragment_validation_with_ref.rb +2 -8
  55. data/test/test_full_validation.rb +2 -3
  56. data/test/test_helper.rb +46 -1
  57. data/test/test_initialize_data.rb +118 -0
  58. data/test/test_jsonschema_draft1.rb +48 -600
  59. data/test/test_jsonschema_draft2.rb +48 -699
  60. data/test/test_jsonschema_draft3.rb +91 -861
  61. data/test/test_jsonschema_draft4.rb +173 -812
  62. data/test/test_list_option.rb +6 -7
  63. data/test/{test_merge_misisng_values.rb → test_merge_missing_values.rb} +2 -3
  64. data/test/test_minitems.rb +2 -4
  65. data/test/test_one_of.rb +9 -19
  66. data/test/test_ruby_schema.rb +5 -14
  67. data/test/test_schema_loader.rb +74 -0
  68. data/test/test_schema_type_attribute.rb +2 -3
  69. data/test/test_schema_validation.rb +4 -5
  70. data/test/test_stringify.rb +2 -3
  71. data/test/test_uri_related.rb +67 -0
  72. data/test/test_validator.rb +53 -0
  73. metadata +129 -51
  74. data/lib/json-schema/attributes/dependencies_v4.rb +0 -27
  75. data/lib/json-schema/attributes/formats/ip4.rb +0 -20
  76. data/lib/json-schema/attributes/formats/ip6.rb +0 -20
  77. data/lib/json-schema/attributes/maximum.rb +0 -17
  78. data/lib/json-schema/attributes/maximum_inclusive.rb +0 -17
  79. data/lib/json-schema/attributes/maxitems.rb +0 -14
  80. data/lib/json-schema/attributes/maxlength.rb +0 -16
  81. data/lib/json-schema/attributes/maxproperties.rb +0 -14
  82. data/lib/json-schema/attributes/minimum.rb +0 -17
  83. data/lib/json-schema/attributes/minimum_inclusive.rb +0 -17
  84. data/lib/json-schema/attributes/minitems.rb +0 -14
  85. data/lib/json-schema/attributes/minlength.rb +0 -16
  86. data/lib/json-schema/attributes/minproperties.rb +0 -14
  87. data/lib/json-schema/attributes/properties_v4.rb +0 -58
  88. data/lib/json-schema/uri/file.rb +0 -36
@@ -1,8 +1,41 @@
1
1
  # encoding: utf-8
2
- require 'test/unit'
3
- require File.dirname(__FILE__) + '/../lib/json-schema'
2
+ require File.expand_path('../test_helper', __FILE__)
3
+
4
+ class JSONSchemaDraft3Test < Minitest::Test
5
+ def schema_version
6
+ :draft3
7
+ end
8
+
9
+ def exclusive_minimum
10
+ { 'exclusiveMinimum' => true }
11
+ end
12
+
13
+ def exclusive_maximum
14
+ { 'exclusiveMaximum' => true }
15
+ end
16
+
17
+ def multiple_of
18
+ 'divisibleBy'
19
+ end
20
+
21
+ include ArrayValidation::ItemsTests
22
+ include ArrayValidation::AdditionalItemsTests
23
+ include ArrayValidation::UniqueItemsTests
24
+
25
+ include NumberValidation::MinMaxTests
26
+ include NumberValidation::MultipleOfTests
27
+
28
+ include ObjectValidation::AdditionalPropertiesTests
29
+ include ObjectValidation::PatternPropertiesTests
30
+
31
+ include StringValidation::ValueTests
32
+ include StringValidation::FormatTests
33
+ include StringValidation::DateAndTimeFormatTests
34
+
35
+ include TypeValidation::SimpleTypeTests
36
+ include TypeValidation::AnyTypeTests
37
+ include TypeValidation::SchemaUnionTypeTests
4
38
 
5
- class JSONSchemaDraft3Test < Test::Unit::TestCase
6
39
  def test_types
7
40
  # Set up the default datatype
8
41
  schema = {
@@ -15,197 +48,6 @@ class JSONSchemaDraft3Test < Test::Unit::TestCase
15
48
  "a" => nil
16
49
  }
17
50
 
18
- # Test integers
19
- schema["properties"]["a"]["type"] = "integer"
20
- data["a"] = 5
21
- assert(JSON::Validator.validate(schema,data))
22
-
23
- data["a"] = 5.2
24
- assert(!JSON::Validator.validate(schema,data))
25
-
26
- data['a'] = 'string'
27
- assert(!JSON::Validator.validate(schema,data))
28
-
29
- data['a'] = true
30
- assert(!JSON::Validator.validate(schema,data))
31
-
32
- assert(JSON::Validator.validate({"$schema" => "http://json-schema.org/draft-03/schema#",'type' => 'integer'}, 3))
33
- assert(!JSON::Validator.validate({"$schema" => "http://json-schema.org/draft-03/schema#",'type' => 'integer'}, "hello"))
34
-
35
- # Test numbers
36
- schema["properties"]["a"]["type"] = "number"
37
- data["a"] = 5
38
- assert(JSON::Validator.validate(schema,data))
39
-
40
- data["a"] = 5.2
41
- assert(JSON::Validator.validate(schema,data))
42
-
43
- data['a'] = 'string'
44
- assert(!JSON::Validator.validate(schema,data))
45
-
46
- data['a'] = true
47
- assert(!JSON::Validator.validate(schema,data))
48
-
49
- assert(JSON::Validator.validate({"$schema" => "http://json-schema.org/draft-03/schema#",'type' => 'number'}, 3))
50
- assert(JSON::Validator.validate({"$schema" => "http://json-schema.org/draft-03/schema#",'type' => 'number'}, 3.14159265358979))
51
- assert(!JSON::Validator.validate({"$schema" => "http://json-schema.org/draft-03/schema#",'type' => 'number'}, "hello"))
52
-
53
-
54
- # Test strings
55
- schema["properties"]["a"]["type"] = "string"
56
- data["a"] = 5
57
- assert(!JSON::Validator.validate(schema,data))
58
-
59
- data["a"] = 5.2
60
- assert(!JSON::Validator.validate(schema,data))
61
-
62
- data['a'] = 'string'
63
- assert(JSON::Validator.validate(schema,data))
64
-
65
- data['a'] = true
66
- assert(!JSON::Validator.validate(schema,data))
67
-
68
- assert(JSON::Validator.validate({"$schema" => "http://json-schema.org/draft-03/schema#",'type' => 'string'}, 'hello'))
69
- assert(!JSON::Validator.validate({"$schema" => "http://json-schema.org/draft-03/schema#",'type' => 'string'}, 3.14159265358979))
70
- assert(!JSON::Validator.validate({"$schema" => "http://json-schema.org/draft-03/schema#",'type' => 'string'}, []))
71
-
72
-
73
- # Test booleans
74
- schema["properties"]["a"]["type"] = "boolean"
75
- data["a"] = 5
76
- assert(!JSON::Validator.validate(schema,data))
77
-
78
- data["a"] = 5.2
79
- assert(!JSON::Validator.validate(schema,data))
80
-
81
- data['a'] = 'string'
82
- assert(!JSON::Validator.validate(schema,data))
83
-
84
- data['a'] = true
85
- assert(JSON::Validator.validate(schema,data))
86
-
87
- data['a'] = false
88
- assert(JSON::Validator.validate(schema,data))
89
-
90
- assert(JSON::Validator.validate({"$schema" => "http://json-schema.org/draft-03/schema#",'type' => 'boolean'}, true))
91
- assert(JSON::Validator.validate({"$schema" => "http://json-schema.org/draft-03/schema#",'type' => 'boolean'}, false))
92
- assert(!JSON::Validator.validate({"$schema" => "http://json-schema.org/draft-03/schema#",'type' => 'boolean'}, nil))
93
- assert(!JSON::Validator.validate({"$schema" => "http://json-schema.org/draft-03/schema#",'type' => 'boolean'}, 3))
94
- assert(!JSON::Validator.validate({"$schema" => "http://json-schema.org/draft-03/schema#",'type' => 'boolean'}, "hello"))
95
-
96
-
97
- # Test object
98
- schema["properties"]["a"]["type"] = "object"
99
- data["a"] = {}
100
- assert(JSON::Validator.validate(schema,data))
101
-
102
- data["a"] = 5.2
103
- assert(!JSON::Validator.validate(schema,data))
104
-
105
- data['a'] = 'string'
106
- assert(!JSON::Validator.validate(schema,data))
107
-
108
- data['a'] = true
109
- assert(!JSON::Validator.validate(schema,data))
110
-
111
- assert(JSON::Validator.validate({"$schema" => "http://json-schema.org/draft-03/schema#",'type' => 'object'}, {'a' => true}))
112
- assert(JSON::Validator.validate({"$schema" => "http://json-schema.org/draft-03/schema#",'type' => 'object'}, {}))
113
- assert(!JSON::Validator.validate({"$schema" => "http://json-schema.org/draft-03/schema#",'type' => 'object'}, []))
114
- assert(!JSON::Validator.validate({"$schema" => "http://json-schema.org/draft-03/schema#",'type' => 'object'}, 3))
115
- assert(!JSON::Validator.validate({"$schema" => "http://json-schema.org/draft-03/schema#",'type' => 'object'}, "hello"))
116
-
117
-
118
- # Test array
119
- schema["properties"]["a"]["type"] = "array"
120
- data["a"] = []
121
- assert(JSON::Validator.validate(schema,data))
122
-
123
- data["a"] = 5.2
124
- assert(!JSON::Validator.validate(schema,data))
125
-
126
- data['a'] = 'string'
127
- assert(!JSON::Validator.validate(schema,data))
128
-
129
- data['a'] = true
130
- assert(!JSON::Validator.validate(schema,data))
131
-
132
- assert(JSON::Validator.validate({"$schema" => "http://json-schema.org/draft-03/schema#",'type' => 'array'}, ['a']))
133
- assert(JSON::Validator.validate({"$schema" => "http://json-schema.org/draft-03/schema#",'type' => 'array'}, []))
134
- assert(!JSON::Validator.validate({"$schema" => "http://json-schema.org/draft-03/schema#",'type' => 'array'}, {}))
135
- assert(!JSON::Validator.validate({"$schema" => "http://json-schema.org/draft-03/schema#",'type' => 'array'}, 3))
136
- assert(!JSON::Validator.validate({"$schema" => "http://json-schema.org/draft-03/schema#",'type' => 'array'}, "hello"))
137
-
138
-
139
- # Test null
140
- schema["properties"]["a"]["type"] = "null"
141
- data["a"] = nil
142
- assert(JSON::Validator.validate(schema,data))
143
-
144
- data["a"] = 5.2
145
- assert(!JSON::Validator.validate(schema,data))
146
-
147
- data['a'] = 'string'
148
- assert(!JSON::Validator.validate(schema,data))
149
-
150
- data['a'] = true
151
- assert(!JSON::Validator.validate(schema,data))
152
-
153
- assert(JSON::Validator.validate({"$schema" => "http://json-schema.org/draft-03/schema#",'type' => 'null'}, nil))
154
- assert(!JSON::Validator.validate({"$schema" => "http://json-schema.org/draft-03/schema#",'type' => 'null'}, false))
155
- assert(!JSON::Validator.validate({"$schema" => "http://json-schema.org/draft-03/schema#",'type' => 'null'}, []))
156
- assert(!JSON::Validator.validate({"$schema" => "http://json-schema.org/draft-03/schema#",'type' => 'null'}, "hello"))
157
-
158
-
159
- # Test any
160
- schema["properties"]["a"]["type"] = "any"
161
- data["a"] = 5
162
- assert(JSON::Validator.validate(schema,data))
163
-
164
- data["a"] = 5.2
165
- assert(JSON::Validator.validate(schema,data))
166
-
167
- data['a'] = 'string'
168
- assert(JSON::Validator.validate(schema,data))
169
-
170
- data['a'] = true
171
- assert(JSON::Validator.validate(schema,data))
172
-
173
- assert(JSON::Validator.validate({"$schema" => "http://json-schema.org/draft-03/schema#",'type' => 'any'}, true))
174
- assert(JSON::Validator.validate({"$schema" => "http://json-schema.org/draft-03/schema#",'type' => 'any'}, nil))
175
- assert(JSON::Validator.validate({"$schema" => "http://json-schema.org/draft-03/schema#",'type' => 'any'}, {}))
176
- assert(JSON::Validator.validate({"$schema" => "http://json-schema.org/draft-03/schema#",'type' => 'any'}, 3))
177
- assert(JSON::Validator.validate({"$schema" => "http://json-schema.org/draft-03/schema#",'type' => 'any'}, "hello"))
178
-
179
-
180
- # Test a union type
181
- schema["properties"]["a"]["type"] = ["integer","string"]
182
- data["a"] = 5
183
- assert(JSON::Validator.validate(schema,data))
184
-
185
- data["a"] = 'boo'
186
- assert(JSON::Validator.validate(schema,data))
187
-
188
- data["a"] = false
189
- assert(!JSON::Validator.validate(schema,data))
190
-
191
- assert(JSON::Validator.validate({"$schema" => "http://json-schema.org/draft-03/schema#",'type' => ['string', 'null']}, "hello"))
192
- assert(!JSON::Validator.validate({"$schema" => "http://json-schema.org/draft-03/schema#",'type' => ['integer', 'object']}, "hello"))
193
-
194
- # Test a union type with schemas
195
- schema["properties"]["a"]["type"] = [{ "type" => "string" }, {"type" => "object", "properties" => {"b" => {"type" => "integer"}}}]
196
-
197
- data["a"] = "test"
198
- assert(JSON::Validator.validate(schema,data))
199
-
200
- data["a"] = 5
201
- assert(!JSON::Validator.validate(schema,data))
202
-
203
- data["a"] = {"b" => 5}
204
- assert(JSON::Validator.validate(schema,data))
205
-
206
- data["a"] = {"b" => "taco"}
207
- assert(!JSON::Validator.validate(schema,data))
208
-
209
51
  # Test an array of unioned-type objects that prevent additionalProperties
210
52
  schema["properties"]["a"] = {
211
53
  'type' => 'array',
@@ -224,7 +66,7 @@ class JSONSchemaDraft3Test < Test::Unit::TestCase
224
66
 
225
67
  # This should actually pass, because this matches the first schema in the union
226
68
  data["a"] << {"c" => false}
227
- assert(JSON::Validator.validate(schema,data))
69
+ assert_valid schema, data
228
70
  end
229
71
 
230
72
  def test_required
@@ -237,9 +79,9 @@ class JSONSchemaDraft3Test < Test::Unit::TestCase
237
79
  }
238
80
  data = {}
239
81
 
240
- assert(!JSON::Validator.validate(schema,data))
82
+ refute_valid schema, data
241
83
  data['a'] = "Hello"
242
- assert(JSON::Validator.validate(schema,data))
84
+ assert_valid schema, data
243
85
 
244
86
  schema = {
245
87
  "$schema" => "http://json-schema.org/draft-03/schema#",
@@ -249,236 +91,7 @@ class JSONSchemaDraft3Test < Test::Unit::TestCase
249
91
  }
250
92
 
251
93
  data = {}
252
- assert(JSON::Validator.validate(schema,data))
253
-
254
- end
255
-
256
-
257
-
258
- def test_minimum
259
- # Set up the default datatype
260
- schema = {
261
- "$schema" => "http://json-schema.org/draft-03/schema#",
262
- "properties" => {
263
- "a" => {"minimum" => 5}
264
- }
265
- }
266
-
267
- data = {
268
- "a" => nil
269
- }
270
-
271
-
272
- # Test an integer
273
- data["a"] = 5
274
- assert(JSON::Validator.validate(schema,data))
275
-
276
- data["a"] = 4
277
- assert(!JSON::Validator.validate(schema,data))
278
-
279
- # Test a float
280
- data["a"] = 5.0
281
- assert(JSON::Validator.validate(schema,data))
282
-
283
- data["a"] = 4.9
284
- assert(!JSON::Validator.validate(schema,data))
285
-
286
- # Test a non-number
287
- data["a"] = "a string"
288
- assert(JSON::Validator.validate(schema,data))
289
-
290
- # Test exclusiveMinimum
291
- schema["properties"]["a"]["exclusiveMinimum"] = true
292
-
293
- data["a"] = 6
294
- assert(JSON::Validator.validate(schema,data))
295
-
296
- data["a"] = 5
297
- assert(!JSON::Validator.validate(schema,data))
298
-
299
- # Test with float
300
- data["a"] = 5.00000001
301
- assert(JSON::Validator.validate(schema,data))
302
-
303
- data["a"] = 5.0
304
- assert(!JSON::Validator.validate(schema,data))
305
- end
306
-
307
-
308
-
309
- def test_maximum
310
- # Set up the default datatype
311
- schema = {
312
- "$schema" => "http://json-schema.org/draft-03/schema#",
313
- "properties" => {
314
- "a" => {"maximum" => 5}
315
- }
316
- }
317
-
318
- data = {
319
- "a" => nil
320
- }
321
-
322
-
323
- # Test an integer
324
- data["a"] = 5
325
- assert(JSON::Validator.validate(schema,data))
326
-
327
- data["a"] = 6
328
- assert(!JSON::Validator.validate(schema,data))
329
-
330
- # Test a float
331
- data["a"] = 5.0
332
- assert(JSON::Validator.validate(schema,data))
333
-
334
- data["a"] = 5.1
335
- assert(!JSON::Validator.validate(schema,data))
336
-
337
- # Test a non-number
338
- data["a"] = "a string"
339
- assert(JSON::Validator.validate(schema,data))
340
-
341
- # Test exclusiveMinimum
342
- schema["properties"]["a"]["exclusiveMaximum"] = true
343
-
344
- data["a"] = 4
345
- assert(JSON::Validator.validate(schema,data))
346
-
347
- data["a"] = 5
348
- assert(!JSON::Validator.validate(schema,data))
349
-
350
- # Test with float
351
- data["a"] = 4.9999999
352
- assert(JSON::Validator.validate(schema,data))
353
-
354
- data["a"] = 5.0
355
- assert(!JSON::Validator.validate(schema,data))
356
- end
357
-
358
-
359
- def test_min_items
360
- # Set up the default datatype
361
- schema = {
362
- "$schema" => "http://json-schema.org/draft-03/schema#",
363
- "properties" => {
364
- "a" => {"minItems" => 1}
365
- }
366
- }
367
-
368
- data = {
369
- "a" => nil
370
- }
371
-
372
- # Test with an array
373
- data["a"] = ["boo"]
374
- assert(JSON::Validator.validate(schema,data))
375
-
376
- data["a"] = []
377
- assert(!JSON::Validator.validate(schema,data))
378
-
379
- # Test with a non-array
380
- data["a"] = "boo"
381
- assert(JSON::Validator.validate(schema,data))
382
- end
383
-
384
-
385
-
386
- def test_max_items
387
- # Set up the default datatype
388
- schema = {
389
- "$schema" => "http://json-schema.org/draft-03/schema#",
390
- "properties" => {
391
- "a" => {"maxItems" => 1}
392
- }
393
- }
394
-
395
- data = {
396
- "a" => nil
397
- }
398
-
399
- # Test with an array
400
- data["a"] = ["boo"]
401
- assert(JSON::Validator.validate(schema,data))
402
-
403
- data["a"] = ["boo","taco"]
404
- assert(!JSON::Validator.validate(schema,data))
405
-
406
- # Test with a non-array
407
- data["a"] = "boo"
408
- assert(JSON::Validator.validate(schema,data))
409
- end
410
-
411
-
412
-
413
- def test_unique_items
414
- # Set up the default datatype
415
- schema = {
416
- "$schema" => "http://json-schema.org/draft-03/schema#",
417
- "properties" => {
418
- "a" => {"uniqueItems" => true}
419
- }
420
- }
421
-
422
- data = {
423
- "a" => nil
424
- }
425
-
426
- # Test with nulls
427
- data["a"] = [nil,5]
428
- assert(JSON::Validator.validate(schema,data))
429
-
430
- data["a"] = [nil,nil]
431
- assert(!JSON::Validator.validate(schema,data))
432
-
433
- # Test with booleans
434
- data["a"] = [true,4]
435
- assert(JSON::Validator.validate(schema,data))
436
-
437
- data["a"] = [true,false]
438
- assert(JSON::Validator.validate(schema,data))
439
-
440
- data["a"] = [true,true]
441
- assert(!JSON::Validator.validate(schema,data))
442
-
443
- # Test with numbers
444
- data["a"] = [4,true]
445
- assert(JSON::Validator.validate(schema,data))
446
-
447
- data["a"] = [4,4.1]
448
- assert(JSON::Validator.validate(schema,data))
449
-
450
- data["a"] = [4,4]
451
- assert(!JSON::Validator.validate(schema,data))
452
-
453
- # Test with strings
454
- data["a"] = ['a',true]
455
- assert(JSON::Validator.validate(schema,data))
456
-
457
- data["a"] = ['a','ab']
458
- assert(JSON::Validator.validate(schema,data))
459
-
460
- data["a"] = ['a','a']
461
- assert(!JSON::Validator.validate(schema,data))
462
-
463
- # Test with arrays
464
- data["a"] = [[1],true]
465
- assert(JSON::Validator.validate(schema,data))
466
-
467
- data["a"] = [[1,2],[1,3]]
468
- assert(JSON::Validator.validate(schema,data))
469
-
470
- data["a"] = [[1,2,3],[1,2,3]]
471
- assert(!JSON::Validator.validate(schema,data))
472
-
473
- # Test with objects
474
- data["a"] = [{"a" => 1},true]
475
- assert(JSON::Validator.validate(schema,data))
476
-
477
- data["a"] = [{"a" => 1},{"a" => 2}]
478
- assert(JSON::Validator.validate(schema,data))
479
-
480
- data["a"] = [{"a" => 1, "b" => 2}, {"a" => 1, "b" => 2}]
481
- assert(!JSON::Validator.validate(schema,data))
94
+ assert_valid schema, data
482
95
  end
483
96
 
484
97
  def test_strict_properties
@@ -580,84 +193,6 @@ class JSONSchemaDraft3Test < Test::Unit::TestCase
580
193
  assert(!JSON::Validator.validate(schema,data,:strict => true))
581
194
  end
582
195
 
583
- def test_pattern
584
- # Set up the default datatype
585
- schema = {
586
- "$schema" => "http://json-schema.org/draft-03/schema#",
587
- "properties" => {
588
- "a" => {"pattern" => "\\d+ taco"}
589
- }
590
- }
591
-
592
- data = {
593
- "a" => nil
594
- }
595
-
596
- # Test strings
597
- data["a"] = "156 taco bell"
598
- assert(JSON::Validator.validate(schema,data))
599
-
600
- # Test a non-string
601
- data["a"] = 5
602
- assert(JSON::Validator.validate(schema,data))
603
-
604
- data["a"] = "taco"
605
- assert(!JSON::Validator.validate(schema,data))
606
- end
607
-
608
-
609
- def test_min_length
610
- # Set up the default datatype
611
- schema = {
612
- "$schema" => "http://json-schema.org/draft-03/schema#",
613
- "properties" => {
614
- "a" => {"minLength" => 1}
615
- }
616
- }
617
-
618
- data = {
619
- "a" => nil
620
- }
621
-
622
- # Try out strings
623
- data["a"] = "t"
624
- assert(JSON::Validator.validate(schema,data))
625
-
626
- data["a"] = ""
627
- assert(!JSON::Validator.validate(schema,data))
628
-
629
- # Try out non-string
630
- data["a"] = 5
631
- assert(JSON::Validator.validate(schema,data))
632
- end
633
-
634
-
635
- def test_max_length
636
- # Set up the default datatype
637
- schema = {
638
- "$schema" => "http://json-schema.org/draft-03/schema#",
639
- "properties" => {
640
- "a" => {"maxLength" => 1}
641
- }
642
- }
643
-
644
- data = {
645
- "a" => nil
646
- }
647
-
648
- # Try out strings
649
- data["a"] = "t"
650
- assert(JSON::Validator.validate(schema,data))
651
-
652
- data["a"] = "tt"
653
- assert(!JSON::Validator.validate(schema,data))
654
-
655
- # Try out non-string
656
- data["a"] = 5
657
- assert(JSON::Validator.validate(schema,data))
658
- end
659
-
660
-
661
196
  def test_enum
662
197
  # Set up the default datatype
663
198
  schema = {
@@ -673,61 +208,26 @@ class JSONSchemaDraft3Test < Test::Unit::TestCase
673
208
 
674
209
  # Make sure all of the above are valid...
675
210
  data["a"] = 1
676
- assert(JSON::Validator.validate(schema,data))
211
+ assert_valid schema, data
677
212
 
678
213
  data["a"] = 'boo'
679
- assert(JSON::Validator.validate(schema,data))
214
+ assert_valid schema, data
680
215
 
681
216
  data["a"] = [1,2,3]
682
- assert(JSON::Validator.validate(schema,data))
217
+ assert_valid schema, data
683
218
 
684
219
  data["a"] = {"a" => "b"}
685
- assert(JSON::Validator.validate(schema,data))
220
+ assert_valid schema, data
686
221
 
687
222
  # Test something that doesn't exist
688
223
  data["a"] = 'taco'
689
- assert(!JSON::Validator.validate(schema,data))
224
+ refute_valid schema, data
690
225
 
691
226
  # Try it without the key
692
227
  data = {}
693
- assert(JSON::Validator.validate(schema,data))
694
- end
695
-
696
-
697
- def test_divisible_by
698
- # Set up the default datatype
699
- schema = {
700
- "$schema" => "http://json-schema.org/draft-03/schema#",
701
- "properties" => {
702
- "a" => {"divisibleBy" => 1.1}
703
- }
704
- }
705
-
706
- data = {
707
- "a" => nil
708
- }
709
-
710
- data["a"] = 3.3
711
- assert(JSON::Validator.validate(schema,data))
712
-
713
- data["a"] = 3.4
714
- assert(!JSON::Validator.validate(schema,data))
715
-
716
- schema["properties"]["a"]["divisibleBy"] = 2.0
717
-
718
- data["a"] = 4.0
719
- assert(JSON::Validator.validate(schema,data))
720
-
721
- data["a"] = 'boo'
722
- assert(JSON::Validator.validate(schema,data))
723
-
724
- data["a"] = 5
725
- schema["properties"]["a"]["divisibleBy"] = 0
726
- assert(!JSON::Validator.validate(schema,data))
228
+ assert_valid schema, data
727
229
  end
728
230
 
729
-
730
-
731
231
  def test_disallow
732
232
  # Set up the default datatype
733
233
  schema = {
@@ -743,21 +243,21 @@ class JSONSchemaDraft3Test < Test::Unit::TestCase
743
243
 
744
244
 
745
245
  data["a"] = 'string'
746
- assert(JSON::Validator.validate(schema,data))
246
+ assert_valid schema, data
747
247
 
748
248
  data["a"] = 5
749
- assert(!JSON::Validator.validate(schema,data))
249
+ refute_valid schema, data
750
250
 
751
251
 
752
252
  schema["properties"]["a"]["disallow"] = ["integer","string"]
753
253
  data["a"] = 'string'
754
- assert(!JSON::Validator.validate(schema,data))
254
+ refute_valid schema, data
755
255
 
756
256
  data["a"] = 5
757
- assert(!JSON::Validator.validate(schema,data))
257
+ refute_valid schema, data
758
258
 
759
259
  data["a"] = false
760
- assert(JSON::Validator.validate(schema,data))
260
+ assert_valid schema, data
761
261
 
762
262
  end
763
263
 
@@ -782,131 +282,14 @@ class JSONSchemaDraft3Test < Test::Unit::TestCase
782
282
  "a" => 10
783
283
  }
784
284
 
785
- assert(JSON::Validator.validate(schema,data))
285
+ assert_valid schema, data
786
286
  assert(!JSON::Validator.validate(schema2,data))
787
287
 
788
288
  schema["extends"] = schema2
789
289
 
790
- assert(!JSON::Validator.validate(schema,data))
290
+ refute_valid schema, data
791
291
  end
792
292
 
793
- def test_pattern_properties
794
- # Set up the default datatype
795
- schema = {
796
- "$schema" => "http://json-schema.org/draft-03/schema#",
797
- "patternProperties" => {
798
- "\\d+ taco" => {"type" => "integer"}
799
- }
800
- }
801
-
802
- data = {
803
- "a" => true,
804
- "1 taco" => 1,
805
- "20 tacos" => 20
806
- }
807
-
808
- assert(JSON::Validator.validate(schema,data))
809
- data["20 tacos"] = "string!"
810
- assert(!JSON::Validator.validate(schema,data))
811
- end
812
-
813
-
814
- def test_additional_properties
815
- # Test no additional properties allowed
816
- schema = {
817
- "$schema" => "http://json-schema.org/draft-03/schema#",
818
- "properties" => {
819
- "a" => { "type" => "integer" }
820
- },
821
- "additionalProperties" => false
822
- }
823
-
824
- data = {
825
- "a" => 10
826
- }
827
-
828
- assert(JSON::Validator.validate(schema,data))
829
- data["b"] = 5
830
- assert(!JSON::Validator.validate(schema,data))
831
-
832
- # Test additional properties match a schema
833
- schema["additionalProperties"] = { "type" => "string" }
834
- data["b"] = "taco"
835
- assert(JSON::Validator.validate(schema,data))
836
- data["b"] = 5
837
- assert(!JSON::Validator.validate(schema,data))
838
-
839
- # Make sure this works with pattern properties set, too
840
- schema = {
841
- "$schema" => "http://json-schema.org/draft-03/schema#",
842
- "patternProperties" => {
843
- "\\d+ taco" => {"type" => "integer"}
844
- },
845
- "additionalProperties" => false
846
- }
847
-
848
- data = {
849
- "5 tacos" => 5,
850
- "20 tacos" => 20
851
- }
852
-
853
- assert(JSON::Validator.validate(schema,data))
854
- data["b"] = 5
855
- assert(!JSON::Validator.validate(schema,data))
856
- end
857
-
858
-
859
- def test_items
860
- schema = {
861
- "$schema" => "http://json-schema.org/draft-03/schema#",
862
- "items" => { "type" => "integer" }
863
- }
864
-
865
- data = [1,2,4]
866
- assert(JSON::Validator.validate(schema,data))
867
- data = [1,2,"string"]
868
- assert(!JSON::Validator.validate(schema,data))
869
-
870
- schema = {
871
- "$schema" => "http://json-schema.org/draft-03/schema#",
872
- "items" => [
873
- {"type" => "integer"},
874
- {"type" => "string"}
875
- ]
876
- }
877
-
878
- data = [1,"string"]
879
- assert(JSON::Validator.validate(schema,data))
880
- data = [1,"string",3]
881
- assert(JSON::Validator.validate(schema,data))
882
- data = ["string",1]
883
- assert(!JSON::Validator.validate(schema,data))
884
-
885
- schema = {
886
- "$schema" => "http://json-schema.org/draft-03/schema#",
887
- "items" => [
888
- {"type" => "integer"},
889
- {"type" => "string"}
890
- ],
891
- "additionalItems" => false
892
- }
893
-
894
- data = [1,"string"]
895
- assert(JSON::Validator.validate(schema,data))
896
- data = [1,"string",3]
897
- assert(!JSON::Validator.validate(schema,data))
898
-
899
- schema = {"$schema" => "http://json-schema.org/draft-03/schema#","items" => [{"type" => "integer"},{"type" => "string"}],"additionalItems" => {"type" => "integer"}}
900
-
901
- data = [1,"string"]
902
- assert(JSON::Validator.validate(schema,data))
903
- data = [1,"string",3]
904
- assert(JSON::Validator.validate(schema,data))
905
- data = [1,"string","string"]
906
- assert(!JSON::Validator.validate(schema,data))
907
- end
908
-
909
-
910
293
  def test_list_option
911
294
  schema = {
912
295
  "$schema" => "http://json-schema.org/draft-03/schema#",
@@ -916,7 +299,7 @@ class JSONSchemaDraft3Test < Test::Unit::TestCase
916
299
 
917
300
  data = [{"a" => 1},{"a" => 2},{"a" => 3}]
918
301
  assert(JSON::Validator.validate(schema,data,:list => true))
919
- assert(!JSON::Validator.validate(schema,data))
302
+ refute_valid schema, data
920
303
 
921
304
  data = {"a" => 1}
922
305
  assert(!JSON::Validator.validate(schema,data,:list => true))
@@ -933,110 +316,8 @@ class JSONSchemaDraft3Test < Test::Unit::TestCase
933
316
  "properties" => { "a" => {"type" => "integer"}, "b" => {"$ref" => "#"}}
934
317
  }
935
318
 
936
- data = {"a" => 5, "b" => {"b" => {"a" => 1}}}
937
- assert(JSON::Validator.validate(schema,data))
938
- data = {"a" => 5, "b" => {"b" => {"a" => 'taco'}}}
939
- assert(!JSON::Validator.validate(schema,data))
940
- end
941
-
942
-
943
- def test_format_ipv4
944
- schema = {
945
- "$schema" => "http://json-schema.org/draft-03/schema#",
946
- "type" => "object",
947
- "properties" => { "a" => {"type" => "string", "format" => "ip-address"}}
948
- }
949
-
950
- data = {"a" => "1.1.1.1"}
951
- assert(JSON::Validator.validate(schema,data))
952
- data = {"a" => "1.1.1"}
953
- assert(!JSON::Validator.validate(schema,data))
954
- data = {"a" => "1.1.1.300"}
955
- assert(!JSON::Validator.validate(schema,data))
956
- data = {"a" => 5}
957
- assert(!JSON::Validator.validate(schema,data))
958
- data = {"a" => "1.1.1"}
959
- assert(!JSON::Validator.validate(schema,data))
960
- data = {"a" => "1.1.1.1b"}
961
- assert(!JSON::Validator.validate(schema,data))
962
- data = {"a" => "b1.1.1.1"}
963
- end
964
-
965
-
966
- def test_format_ipv6
967
- schema = {
968
- "$schema" => "http://json-schema.org/draft-03/schema#",
969
- "type" => "object",
970
- "properties" => { "a" => {"type" => "string", "format" => "ipv6"}}
971
- }
972
-
973
- data = {"a" => "1111:2222:8888:9999:aaaa:cccc:eeee:ffff"}
974
- assert(JSON::Validator.validate(schema,data))
975
- data = {"a" => "1111:0:8888:0:0:0:eeee:ffff"}
976
- assert(JSON::Validator.validate(schema,data))
977
- data = {"a" => "1111:2222:8888::eeee:ffff"}
978
- assert(JSON::Validator.validate(schema,data))
979
- data = {"a" => "1111:2222:8888:99999:aaaa:cccc:eeee:ffff"}
980
- assert(!JSON::Validator.validate(schema,data))
981
- data = {"a" => "1111:2222:8888:9999:aaaa:cccc:eeee:gggg"}
982
- assert(!JSON::Validator.validate(schema,data))
983
- data = {"a" => "1111:2222::9999::cccc:eeee:ffff"}
984
- assert(!JSON::Validator.validate(schema,data))
985
- data = {"a" => "1111:2222:8888:9999:aaaa:cccc:eeee:ffff:bbbb"}
986
- assert(!JSON::Validator.validate(schema,data))
987
- assert(JSON::Validator.validate(schema, {"a" => "::1"}), 'validate with shortcut')
988
- assert(!JSON::Validator.validate(schema, {"a" => "42"}), 'not validate a simple number')
989
- end
990
-
991
- def test_format_time
992
- schema = {
993
- "$schema" => "http://json-schema.org/draft-03/schema#",
994
- "type" => "object",
995
- "properties" => { "a" => {"type" => "string", "format" => "time"}}
996
- }
997
-
998
- data = {"a" => "12:00:00"}
999
- assert(JSON::Validator.validate(schema,data))
1000
- data = {"a" => "12:00"}
1001
- assert(!JSON::Validator.validate(schema,data))
1002
- data = {"a" => "12:00:60"}
1003
- assert(!JSON::Validator.validate(schema,data))
1004
- data = {"a" => "12:60:00"}
1005
- assert(!JSON::Validator.validate(schema,data))
1006
- data = {"a" => "24:00:00"}
1007
- assert(!JSON::Validator.validate(schema,data))
1008
- data = {"a" => "0:00:00"}
1009
- assert(!JSON::Validator.validate(schema,data))
1010
- data = {"a" => "-12:00:00"}
1011
- assert(!JSON::Validator.validate(schema,data))
1012
- data = {"a" => "12:00:00b"}
1013
- assert(!JSON::Validator.validate(schema,data))
1014
- data = {"a" => "12:00:00\nabc"}
1015
- assert(!JSON::Validator.validate(schema,data))
1016
- end
1017
-
1018
-
1019
- def test_format_date
1020
- schema = {
1021
- "$schema" => "http://json-schema.org/draft-03/schema#",
1022
- "type" => "object",
1023
- "properties" => { "a" => {"type" => "string", "format" => "date"}}
1024
- }
1025
-
1026
- data = {"a" => "2010-01-01"}
1027
- assert(JSON::Validator.validate(schema,data))
1028
- data = {"a" => "2010-01-32"}
1029
- assert(!JSON::Validator.validate(schema,data))
1030
- data = {"a" => "n2010-01-01"}
1031
- assert(!JSON::Validator.validate(schema,data))
1032
- data = {"a" => "2010-1-01"}
1033
- assert(!JSON::Validator.validate(schema,data))
1034
- data = {"a" => "2010-01-1"}
1035
- assert(!JSON::Validator.validate(schema,data))
1036
- data = {"a" => "2010-01-01n"}
1037
- assert(!JSON::Validator.validate(schema,data))
1038
- data = {"a" => "2010-01-01\nabc"}
1039
- assert(!JSON::Validator.validate(schema,data))
319
+ assert_valid schema, {"a" => 5, "b" => {"b" => {"a" => 1}}}
320
+ refute_valid schema, {"a" => 5, "b" => {"b" => {"a" => 'taco'}}}
1040
321
  end
1041
322
 
1042
323
  def test_format_datetime
@@ -1046,87 +327,36 @@ class JSONSchemaDraft3Test < Test::Unit::TestCase
1046
327
  "properties" => { "a" => {"type" => "string", "format" => "date-time"}}
1047
328
  }
1048
329
 
1049
- data = {"a" => "2010-01-01T12:00:00Z"}
1050
- assert(JSON::Validator.validate(schema,data))
1051
- data = {"a" => "2010-01-01T12:00:00.1Z"}
1052
- assert(JSON::Validator.validate(schema,data))
1053
- data = {"a" => "2010-01-01T12:00:00,1Z"}
1054
- assert(JSON::Validator.validate(schema,data))
1055
- data = {"a" => "2010-01-32T12:00:00Z"}
1056
- assert(!JSON::Validator.validate(schema,data))
1057
- data = {"a" => "2010-13-01T12:00:00Z"}
1058
- assert(!JSON::Validator.validate(schema,data))
1059
- data = {"a" => "2010-01-01T24:00:00Z"}
1060
- assert(!JSON::Validator.validate(schema,data))
1061
- data = {"a" => "2010-01-01T12:60:00Z"}
1062
- assert(!JSON::Validator.validate(schema,data))
1063
- data = {"a" => "2010-01-01T12:00:60Z"}
1064
- assert(!JSON::Validator.validate(schema,data))
1065
- data = {"a" => "2010-01-01T12:00:00z"}
1066
- assert(!JSON::Validator.validate(schema,data))
1067
- data = {"a" => "2010-01-0112:00:00Z"}
1068
- assert(!JSON::Validator.validate(schema,data))
1069
- data = {"a" => "2010-01-01T12:00:00.1Z\nabc"}
1070
- assert(!JSON::Validator.validate(schema,data))
330
+ assert_valid schema, {"a" => "2010-01-01T12:00:00Z"}
331
+ assert_valid schema, {"a" => "2010-01-01T12:00:00.1Z"}
332
+ assert_valid schema, {"a" => "2010-01-01T12:00:00,1Z"}
333
+ refute_valid schema, {"a" => "2010-01-32T12:00:00Z"}
334
+ refute_valid schema, {"a" => "2010-13-01T12:00:00Z"}
335
+ refute_valid schema, {"a" => "2010-01-01T24:00:00Z"}
336
+ refute_valid schema, {"a" => "2010-01-01T12:60:00Z"}
337
+ refute_valid schema, {"a" => "2010-01-01T12:00:60Z"}
338
+ refute_valid schema, {"a" => "2010-01-01T12:00:00z"}
339
+ refute_valid schema, {"a" => "2010-01-0112:00:00Z"}
340
+ refute_valid schema, {"a" => "2010-01-01T12:00:00.1Z\nabc"}
1071
341
 
1072
342
  # test with a specific timezone
1073
- data = {"a" => "2010-01-01T12:00:00+01"}
1074
- assert(JSON::Validator.validate(schema,data))
1075
- data = {"a" => "2010-01-01T12:00:00+01:00"}
1076
- assert(JSON::Validator.validate(schema,data))
1077
- data = {"a" => "2010-01-01T12:00:00+01:30"}
1078
- assert(JSON::Validator.validate(schema,data))
1079
- data = {"a" => "2010-01-01T12:00:00+0234"}
1080
- assert(JSON::Validator.validate(schema,data))
1081
- data = {"a" => "2010-01-01T12:00:00+01:"}
1082
- assert(!JSON::Validator.validate(schema,data))
1083
- data = {"a" => "2010-01-01T12:00:00+0"}
1084
- assert(!JSON::Validator.validate(schema,data))
343
+ assert_valid schema, {"a" => "2010-01-01T12:00:00+01"}
344
+ assert_valid schema, {"a" => "2010-01-01T12:00:00+01:00"}
345
+ assert_valid schema, {"a" => "2010-01-01T12:00:00+01:30"}
346
+ assert_valid schema, {"a" => "2010-01-01T12:00:00+0234"}
347
+ refute_valid schema, {"a" => "2010-01-01T12:00:00+01:"}
348
+ refute_valid schema, {"a" => "2010-01-01T12:00:00+0"}
1085
349
  # do not allow mixing Z and specific timezone
1086
- data = {"a" => "2010-01-01T12:00:00Z+01"}
1087
- assert(!JSON::Validator.validate(schema,data))
1088
- data = {"a" => "2010-01-01T12:00:00+01Z"}
1089
- assert(!JSON::Validator.validate(schema,data))
1090
- data = {"a" => "2010-01-01T12:00:00+01:30Z"}
1091
- assert(!JSON::Validator.validate(schema,data))
1092
- data = {"a" => "2010-01-01T12:00:00+0Z"}
1093
- assert(!JSON::Validator.validate(schema,data))
350
+ refute_valid schema, {"a" => "2010-01-01T12:00:00Z+01"}
351
+ refute_valid schema, {"a" => "2010-01-01T12:00:00+01Z"}
352
+ refute_valid schema, {"a" => "2010-01-01T12:00:00+01:30Z"}
353
+ refute_valid schema, {"a" => "2010-01-01T12:00:00+0Z"}
1094
354
 
1095
355
  # test without any timezone
1096
- data = {"a" => "2010-01-01T12:00:00"}
1097
- assert(JSON::Validator.validate(schema,data))
1098
- data = {"a" => "2010-01-01T12:00:00.12345"}
1099
- assert(JSON::Validator.validate(schema,data))
1100
- data = {"a" => "2010-01-01T12:00:00,12345"}
1101
- assert(JSON::Validator.validate(schema,data))
1102
- data = {"a" => "2010-01-01T12:00:00.12345"}
1103
- assert(JSON::Validator.validate(schema,data))
1104
- end
1105
-
1106
- def test_format_unknown
1107
- schema = {
1108
- "type" => "object",
1109
- "properties" => { "a" => {"type" => "string", "format" => "unknown"}}
1110
- }
1111
-
1112
- data = {"a" => "I can write what I want here"}
1113
- assert(JSON::Validator.validate(schema,data,:version => :draft3))
1114
- data = {"a" => ""}
1115
- assert(JSON::Validator.validate(schema,data,:version => :draft3))
1116
- end
1117
-
1118
-
1119
- def test_format_union
1120
- data1 = {"a" => "boo"}
1121
- data2 = {"a" => nil}
1122
-
1123
- schema = {
1124
- "$schema" => "http://json-schema.org/draft-03/schema#",
1125
- "type" => "object",
1126
- "properties" => { "a" => {"type" => ["string","null"], "format" => "ip-address"}}
1127
- }
1128
- assert(!JSON::Validator.validate(schema,data1))
1129
- assert(JSON::Validator.validate(schema,data2))
356
+ assert_valid schema, {"a" => "2010-01-01T12:00:00"}
357
+ assert_valid schema, {"a" => "2010-01-01T12:00:00.12345"}
358
+ assert_valid schema, {"a" => "2010-01-01T12:00:00,12345"}
359
+ assert_valid schema, {"a" => "2010-01-01T12:00:00.12345"}
1130
360
  end
1131
361
 
1132
362
  def test_format_uri
@@ -1154,13 +384,13 @@ class JSONSchemaDraft3Test < Test::Unit::TestCase
1154
384
  }
1155
385
 
1156
386
  data = {"a" => "taco"}
1157
- assert(!JSON::Validator.validate(schema,data))
387
+ assert(!JSON::Validator.validate(schema, data))
1158
388
 
1159
389
  schema = {
1160
390
  "$schema" => "http://json-schema.org/draft-03/schema#",
1161
391
  "type" => "object"
1162
392
  }
1163
- assert(JSON::Validator.validate(schema,data))
393
+ assert_valid schema, data
1164
394
  end
1165
395
 
1166
396
  def test_dependency
@@ -1177,9 +407,9 @@ class JSONSchemaDraft3Test < Test::Unit::TestCase
1177
407
  }
1178
408
 
1179
409
  data = {"a" => 1, "b" => 2}
1180
- assert(JSON::Validator.validate(schema,data))
410
+ assert_valid schema, data
1181
411
  data = {"a" => 1}
1182
- assert(!JSON::Validator.validate(schema,data))
412
+ refute_valid schema, data
1183
413
 
1184
414
  schema = {
1185
415
  "$schema" => "http://json-schema.org/draft-03/schema#",
@@ -1195,9 +425,9 @@ class JSONSchemaDraft3Test < Test::Unit::TestCase
1195
425
  }
1196
426
 
1197
427
  data = {"a" => 1, "c" => 2}
1198
- assert(!JSON::Validator.validate(schema,data))
428
+ refute_valid schema, data
1199
429
  data = {"a" => 1, "b" => 2, "c" => 3}
1200
- assert(JSON::Validator.validate(schema,data))
430
+ assert_valid schema, data
1201
431
  end
1202
432
 
1203
433
  def test_default
@@ -1211,7 +441,7 @@ class JSONSchemaDraft3Test < Test::Unit::TestCase
1211
441
  }
1212
442
 
1213
443
  data = {:b => 2}
1214
- assert(JSON::Validator.validate(schema,data))
444
+ assert_valid schema, data
1215
445
  assert_nil(data["a"])
1216
446
  assert(JSON::Validator.validate(schema,data, :insert_defaults => true))
1217
447
  assert_equal(42, data["a"])
@@ -1227,7 +457,7 @@ class JSONSchemaDraft3Test < Test::Unit::TestCase
1227
457
  }
1228
458
 
1229
459
  data = {:b => 2}
1230
- assert(!JSON::Validator.validate(schema,data))
460
+ refute_valid schema, data
1231
461
  assert_nil(data["a"])
1232
462
  assert(JSON::Validator.validate(schema,data, :insert_defaults => true))
1233
463
  assert_equal(42, data["a"])
@@ -1243,7 +473,7 @@ class JSONSchemaDraft3Test < Test::Unit::TestCase
1243
473
  }
1244
474
 
1245
475
  data = {:b => 2}
1246
- assert(!JSON::Validator.validate(schema,data))
476
+ refute_valid schema, data
1247
477
  assert_nil(data["a"])
1248
478
  assert(!JSON::Validator.validate(schema,data, :insert_defaults => true))
1249
479
  assert_nil(data["a"])
@@ -1259,7 +489,7 @@ class JSONSchemaDraft3Test < Test::Unit::TestCase
1259
489
  }
1260
490
 
1261
491
  data = {:b => 2}
1262
- assert(JSON::Validator.validate(schema,data))
492
+ assert_valid schema, data
1263
493
  assert_nil(data["a"])
1264
494
  assert(!JSON::Validator.validate(schema,data, :insert_defaults => true))
1265
495
  assert_equal("42",data["a"])