json-schema 2.0.2 → 2.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -22,7 +22,7 @@ From the git repo:
22
22
 
23
23
  <pre>
24
24
  $ gem build json-schema.gemspec
25
- $ gem install json-schema-2.0.2.gem
25
+ $ gem install json-schema-2.0.3.gem
26
26
  </pre>
27
27
 
28
28
 
@@ -9,7 +9,7 @@ module JSON
9
9
  if data.is_a?(String)
10
10
  error_message = "The property '#{build_fragment(fragments)}' must be a date/time in the ISO-8601 format of YYYY-MM-DDThh:mm:ssZ or YYYY-MM-DDThh:mm:ss.ssZ"
11
11
  validation_error(processor, error_message, fragments, current_schema, self, options[:record_errors]) and return if !data.is_a?(String)
12
- r = Regexp.new('^\d\d\d\d-\d\d-\d\dT(\d\d):(\d\d):(\d\d)([\.,]\d+)?Z$')
12
+ r = Regexp.new('^\d\d\d\d-\d\d-\d\dT(\d\d):(\d\d):(\d\d)([\.,]\d+)?(Z|[+-](\d\d)(:\d\d)?)?$')
13
13
  if (m = r.match(data))
14
14
  parts = data.split("T")
15
15
  begin
@@ -12,7 +12,7 @@ class JSONSchemaDraft1Test < Test::Unit::TestCase
12
12
  data = {
13
13
  "a" => nil
14
14
  }
15
-
15
+
16
16
  # Test integers
17
17
  schema["properties"]["a"]["type"] = "integer"
18
18
  data["a"] = 5
@@ -20,14 +20,14 @@ class JSONSchemaDraft1Test < Test::Unit::TestCase
20
20
 
21
21
  data["a"] = 5.2
22
22
  assert(!JSON::Validator.validate(schema,data,:version => :draft1))
23
-
23
+
24
24
  data['a'] = 'string'
25
25
  assert(!JSON::Validator.validate(schema,data,:version => :draft1))
26
-
26
+
27
27
  data['a'] = true
28
28
  assert(!JSON::Validator.validate(schema,data,:version => :draft1))
29
-
30
-
29
+
30
+
31
31
  # Test numbers
32
32
  schema["properties"]["a"]["type"] = "number"
33
33
  data["a"] = 5
@@ -35,14 +35,14 @@ class JSONSchemaDraft1Test < Test::Unit::TestCase
35
35
 
36
36
  data["a"] = 5.2
37
37
  assert(JSON::Validator.validate(schema,data,:version => :draft1))
38
-
38
+
39
39
  data['a'] = 'string'
40
40
  assert(!JSON::Validator.validate(schema,data,:version => :draft1))
41
-
41
+
42
42
  data['a'] = true
43
43
  assert(!JSON::Validator.validate(schema,data,:version => :draft1))
44
-
45
-
44
+
45
+
46
46
  # Test strings
47
47
  schema["properties"]["a"]["type"] = "string"
48
48
  data["a"] = 5
@@ -50,14 +50,14 @@ class JSONSchemaDraft1Test < Test::Unit::TestCase
50
50
 
51
51
  data["a"] = 5.2
52
52
  assert(!JSON::Validator.validate(schema,data,:version => :draft1))
53
-
53
+
54
54
  data['a'] = 'string'
55
55
  assert(JSON::Validator.validate(schema,data,:version => :draft1))
56
-
56
+
57
57
  data['a'] = true
58
58
  assert(!JSON::Validator.validate(schema,data,:version => :draft1))
59
-
60
-
59
+
60
+
61
61
  # Test booleans
62
62
  schema["properties"]["a"]["type"] = "boolean"
63
63
  data["a"] = 5
@@ -65,17 +65,17 @@ class JSONSchemaDraft1Test < Test::Unit::TestCase
65
65
 
66
66
  data["a"] = 5.2
67
67
  assert(!JSON::Validator.validate(schema,data,:version => :draft1))
68
-
68
+
69
69
  data['a'] = 'string'
70
70
  assert(!JSON::Validator.validate(schema,data,:version => :draft1))
71
-
71
+
72
72
  data['a'] = true
73
73
  assert(JSON::Validator.validate(schema,data,:version => :draft1))
74
-
74
+
75
75
  data['a'] = false
76
76
  assert(JSON::Validator.validate(schema,data,:version => :draft1))
77
-
78
-
77
+
78
+
79
79
  # Test object
80
80
  schema["properties"]["a"]["type"] = "object"
81
81
  data["a"] = {}
@@ -83,14 +83,14 @@ class JSONSchemaDraft1Test < Test::Unit::TestCase
83
83
 
84
84
  data["a"] = 5.2
85
85
  assert(!JSON::Validator.validate(schema,data,:version => :draft1))
86
-
86
+
87
87
  data['a'] = 'string'
88
88
  assert(!JSON::Validator.validate(schema,data,:version => :draft1))
89
-
89
+
90
90
  data['a'] = true
91
91
  assert(!JSON::Validator.validate(schema,data,:version => :draft1))
92
-
93
-
92
+
93
+
94
94
  # Test array
95
95
  schema["properties"]["a"]["type"] = "array"
96
96
  data["a"] = []
@@ -98,14 +98,14 @@ class JSONSchemaDraft1Test < Test::Unit::TestCase
98
98
 
99
99
  data["a"] = 5.2
100
100
  assert(!JSON::Validator.validate(schema,data,:version => :draft1))
101
-
101
+
102
102
  data['a'] = 'string'
103
103
  assert(!JSON::Validator.validate(schema,data,:version => :draft1))
104
-
104
+
105
105
  data['a'] = true
106
106
  assert(!JSON::Validator.validate(schema,data,:version => :draft1))
107
-
108
-
107
+
108
+
109
109
  # Test null
110
110
  schema["properties"]["a"]["type"] = "null"
111
111
  data["a"] = nil
@@ -113,14 +113,14 @@ class JSONSchemaDraft1Test < Test::Unit::TestCase
113
113
 
114
114
  data["a"] = 5.2
115
115
  assert(!JSON::Validator.validate(schema,data,:version => :draft1))
116
-
116
+
117
117
  data['a'] = 'string'
118
118
  assert(!JSON::Validator.validate(schema,data,:version => :draft1))
119
-
119
+
120
120
  data['a'] = true
121
121
  assert(!JSON::Validator.validate(schema,data,:version => :draft1))
122
-
123
-
122
+
123
+
124
124
  # Test any
125
125
  schema["properties"]["a"]["type"] = "any"
126
126
  data["a"] = 5
@@ -128,43 +128,43 @@ class JSONSchemaDraft1Test < Test::Unit::TestCase
128
128
 
129
129
  data["a"] = 5.2
130
130
  assert(JSON::Validator.validate(schema,data,:version => :draft1))
131
-
131
+
132
132
  data['a'] = 'string'
133
133
  assert(JSON::Validator.validate(schema,data,:version => :draft1))
134
-
134
+
135
135
  data['a'] = true
136
136
  assert(JSON::Validator.validate(schema,data,:version => :draft1))
137
-
138
-
137
+
138
+
139
139
  # Test a union type
140
140
  schema["properties"]["a"]["type"] = ["integer","string"]
141
141
  data["a"] = 5
142
142
  assert(JSON::Validator.validate(schema,data,:version => :draft1))
143
-
143
+
144
144
  data["a"] = 'boo'
145
145
  assert(JSON::Validator.validate(schema,data,:version => :draft1))
146
-
146
+
147
147
  data["a"] = false
148
148
  assert(!JSON::Validator.validate(schema,data,:version => :draft1))
149
-
149
+
150
150
  # Test a union type with schemas
151
151
  schema["properties"]["a"]["type"] = [{ "type" => "string" }, {"type" => "object", "properties" => {"b" => {"type" => "integer"}}}]
152
-
152
+
153
153
  data["a"] = "test"
154
154
  assert(JSON::Validator.validate(schema,data,:version => :draft1))
155
-
155
+
156
156
  data["a"] = 5
157
157
  assert(!JSON::Validator.validate(schema,data,:version => :draft1))
158
-
158
+
159
159
  data["a"] = {"b" => 5}
160
160
  assert(JSON::Validator.validate(schema,data,:version => :draft1))
161
-
161
+
162
162
  data["a"] = {"b" => "taco"}
163
163
  assert(!JSON::Validator.validate(schema,data,:version => :draft1))
164
164
  end
165
-
166
-
167
-
165
+
166
+
167
+
168
168
  def test_optional
169
169
  # Set up the default datatype
170
170
  schema = {
@@ -173,24 +173,24 @@ class JSONSchemaDraft1Test < Test::Unit::TestCase
173
173
  }
174
174
  }
175
175
  data = {}
176
-
176
+
177
177
  assert(!JSON::Validator.validate(schema,data,:version => :draft1))
178
178
  data['a'] = "Hello"
179
179
  assert(JSON::Validator.validate(schema,data,:version => :draft1))
180
-
180
+
181
181
  schema = {
182
182
  "properties" => {
183
183
  "a" => {"type" => "integer", "optional" => "true"}
184
184
  }
185
185
  }
186
-
186
+
187
187
  data = {}
188
188
  assert(JSON::Validator.validate(schema,data,:version => :draft1))
189
-
189
+
190
190
  end
191
-
192
-
193
-
191
+
192
+
193
+
194
194
  def test_minimum
195
195
  # Set up the default datatype
196
196
  schema = {
@@ -198,49 +198,49 @@ class JSONSchemaDraft1Test < Test::Unit::TestCase
198
198
  "a" => {"minimum" => 5}
199
199
  }
200
200
  }
201
-
201
+
202
202
  data = {
203
203
  "a" => nil
204
204
  }
205
-
206
-
205
+
206
+
207
207
  # Test an integer
208
208
  data["a"] = 5
209
209
  assert(JSON::Validator.validate(schema,data,:version => :draft1))
210
-
210
+
211
211
  data["a"] = 4
212
212
  assert(!JSON::Validator.validate(schema,data,:version => :draft1))
213
-
213
+
214
214
  # Test a float
215
215
  data["a"] = 5.0
216
216
  assert(JSON::Validator.validate(schema,data,:version => :draft1))
217
-
217
+
218
218
  data["a"] = 4.9
219
219
  assert(!JSON::Validator.validate(schema,data,:version => :draft1))
220
-
220
+
221
221
  # Test a non-number
222
222
  data["a"] = "a string"
223
223
  assert(JSON::Validator.validate(schema,data,:version => :draft1))
224
-
224
+
225
225
  # Test exclusiveMinimum
226
226
  schema["properties"]["a"]["minimumCanEqual"] = false
227
-
227
+
228
228
  data["a"] = 6
229
229
  assert(JSON::Validator.validate(schema,data,:version => :draft1))
230
-
230
+
231
231
  data["a"] = 5
232
232
  assert(!JSON::Validator.validate(schema,data,:version => :draft1))
233
-
233
+
234
234
  # Test with float
235
235
  data["a"] = 5.00000001
236
236
  assert(JSON::Validator.validate(schema,data,:version => :draft1))
237
-
237
+
238
238
  data["a"] = 5.0
239
239
  assert(!JSON::Validator.validate(schema,data,:version => :draft1))
240
240
  end
241
-
242
-
243
-
241
+
242
+
243
+
244
244
  def test_maximum
245
245
  # Set up the default datatype
246
246
  schema = {
@@ -248,48 +248,48 @@ class JSONSchemaDraft1Test < Test::Unit::TestCase
248
248
  "a" => {"maximum" => 5}
249
249
  }
250
250
  }
251
-
251
+
252
252
  data = {
253
253
  "a" => nil
254
254
  }
255
-
256
-
255
+
256
+
257
257
  # Test an integer
258
258
  data["a"] = 5
259
259
  assert(JSON::Validator.validate(schema,data,:version => :draft1))
260
-
260
+
261
261
  data["a"] = 6
262
262
  assert(!JSON::Validator.validate(schema,data,:version => :draft1))
263
-
263
+
264
264
  # Test a float
265
265
  data["a"] = 5.0
266
266
  assert(JSON::Validator.validate(schema,data,:version => :draft1))
267
-
267
+
268
268
  data["a"] = 5.1
269
269
  assert(!JSON::Validator.validate(schema,data,:version => :draft1))
270
-
270
+
271
271
  # Test a non-number
272
272
  data["a"] = "a string"
273
273
  assert(JSON::Validator.validate(schema,data,:version => :draft1))
274
-
274
+
275
275
  # Test exclusiveMinimum
276
276
  schema["properties"]["a"]["maximumCanEqual"] = false
277
-
277
+
278
278
  data["a"] = 4
279
279
  assert(JSON::Validator.validate(schema,data,:version => :draft1))
280
-
280
+
281
281
  data["a"] = 5
282
282
  assert(!JSON::Validator.validate(schema,data,:version => :draft1))
283
-
283
+
284
284
  # Test with float
285
285
  data["a"] = 4.9999999
286
286
  assert(JSON::Validator.validate(schema,data,:version => :draft1))
287
-
287
+
288
288
  data["a"] = 5.0
289
289
  assert(!JSON::Validator.validate(schema,data,:version => :draft1))
290
290
  end
291
-
292
-
291
+
292
+
293
293
  def test_min_items
294
294
  # Set up the default datatype
295
295
  schema = {
@@ -297,25 +297,25 @@ class JSONSchemaDraft1Test < Test::Unit::TestCase
297
297
  "a" => {"minItems" => 1}
298
298
  }
299
299
  }
300
-
300
+
301
301
  data = {
302
302
  "a" => nil
303
303
  }
304
-
304
+
305
305
  # Test with an array
306
306
  data["a"] = ["boo"]
307
307
  assert(JSON::Validator.validate(schema,data,:version => :draft1))
308
-
308
+
309
309
  data["a"] = []
310
310
  assert(!JSON::Validator.validate(schema,data,:version => :draft1))
311
-
311
+
312
312
  # Test with a non-array
313
313
  data["a"] = "boo"
314
314
  assert(JSON::Validator.validate(schema,data,:version => :draft1))
315
315
  end
316
-
317
-
318
-
316
+
317
+
318
+
319
319
  def test_max_items
320
320
  # Set up the default datatype
321
321
  schema = {
@@ -323,24 +323,24 @@ class JSONSchemaDraft1Test < Test::Unit::TestCase
323
323
  "a" => {"maxItems" => 1}
324
324
  }
325
325
  }
326
-
326
+
327
327
  data = {
328
328
  "a" => nil
329
329
  }
330
-
330
+
331
331
  # Test with an array
332
332
  data["a"] = ["boo"]
333
333
  assert(JSON::Validator.validate(schema,data,:version => :draft1))
334
-
334
+
335
335
  data["a"] = ["boo","taco"]
336
336
  assert(!JSON::Validator.validate(schema,data,:version => :draft1))
337
-
337
+
338
338
  # Test with a non-array
339
339
  data["a"] = "boo"
340
340
  assert(JSON::Validator.validate(schema,data,:version => :draft1))
341
341
  end
342
-
343
-
342
+
343
+
344
344
  def test_pattern
345
345
  # Set up the default datatype
346
346
  schema = {
@@ -348,24 +348,24 @@ class JSONSchemaDraft1Test < Test::Unit::TestCase
348
348
  "a" => {"pattern" => "\\d+ taco"}
349
349
  }
350
350
  }
351
-
351
+
352
352
  data = {
353
353
  "a" => nil
354
354
  }
355
-
355
+
356
356
  # Test strings
357
357
  data["a"] = "156 taco bell"
358
358
  assert(JSON::Validator.validate(schema,data,:version => :draft1))
359
-
359
+
360
360
  # Test a non-string
361
361
  data["a"] = 5
362
362
  assert(JSON::Validator.validate(schema,data,:version => :draft1))
363
-
363
+
364
364
  data["a"] = "taco"
365
365
  assert(!JSON::Validator.validate(schema,data,:version => :draft1))
366
366
  end
367
-
368
-
367
+
368
+
369
369
  def test_min_length
370
370
  # Set up the default datatype
371
371
  schema = {
@@ -373,24 +373,24 @@ class JSONSchemaDraft1Test < Test::Unit::TestCase
373
373
  "a" => {"minLength" => 1}
374
374
  }
375
375
  }
376
-
376
+
377
377
  data = {
378
378
  "a" => nil
379
379
  }
380
-
380
+
381
381
  # Try out strings
382
382
  data["a"] = "t"
383
383
  assert(JSON::Validator.validate(schema,data,:version => :draft1))
384
-
384
+
385
385
  data["a"] = ""
386
386
  assert(!JSON::Validator.validate(schema,data,:version => :draft1))
387
-
387
+
388
388
  # Try out non-string
389
389
  data["a"] = 5
390
390
  assert(JSON::Validator.validate(schema,data,:version => :draft1))
391
391
  end
392
-
393
-
392
+
393
+
394
394
  def test_max_length
395
395
  # Set up the default datatype
396
396
  schema = {
@@ -398,24 +398,24 @@ class JSONSchemaDraft1Test < Test::Unit::TestCase
398
398
  "a" => {"maxLength" => 1}
399
399
  }
400
400
  }
401
-
401
+
402
402
  data = {
403
403
  "a" => nil
404
404
  }
405
-
405
+
406
406
  # Try out strings
407
407
  data["a"] = "t"
408
408
  assert(JSON::Validator.validate(schema,data,:version => :draft1))
409
-
409
+
410
410
  data["a"] = "tt"
411
411
  assert(!JSON::Validator.validate(schema,data,:version => :draft1))
412
-
412
+
413
413
  # Try out non-string
414
414
  data["a"] = 5
415
415
  assert(JSON::Validator.validate(schema,data,:version => :draft1))
416
416
  end
417
-
418
-
417
+
418
+
419
419
  def test_enum
420
420
  # Set up the default datatype
421
421
  schema = {
@@ -423,34 +423,34 @@ class JSONSchemaDraft1Test < Test::Unit::TestCase
423
423
  "a" => {"enum" => [1,'boo',[1,2,3],{"a" => "b"}], "optional" => true}
424
424
  }
425
425
  }
426
-
426
+
427
427
  data = {
428
428
  "a" => nil
429
429
  }
430
-
430
+
431
431
  # Make sure all of the above are valid...
432
432
  data["a"] = 1
433
433
  assert(JSON::Validator.validate(schema,data,:version => :draft1))
434
-
434
+
435
435
  data["a"] = 'boo'
436
436
  assert(JSON::Validator.validate(schema,data,:version => :draft1))
437
-
437
+
438
438
  data["a"] = [1,2,3]
439
439
  assert(JSON::Validator.validate(schema,data,:version => :draft1))
440
-
440
+
441
441
  data["a"] = {"a" => "b"}
442
442
  assert(JSON::Validator.validate(schema,data,:version => :draft1))
443
-
443
+
444
444
  # Test something that doesn't exist
445
445
  data["a"] = 'taco'
446
446
  assert(!JSON::Validator.validate(schema,data,:version => :draft1))
447
-
447
+
448
448
  # Try it without the key
449
449
  data = {}
450
450
  assert(JSON::Validator.validate(schema,data,:version => :draft1))
451
451
  end
452
-
453
-
452
+
453
+
454
454
  def test_max_decimal
455
455
  # Set up the default datatype
456
456
  schema = {
@@ -458,32 +458,32 @@ class JSONSchemaDraft1Test < Test::Unit::TestCase
458
458
  "a" => {"maxDecimal" => 2}
459
459
  }
460
460
  }
461
-
461
+
462
462
  data = {
463
463
  "a" => nil
464
464
  }
465
-
465
+
466
466
  data["a"] = 3.35
467
467
  assert(JSON::Validator.validate(schema,data,:version => :draft1))
468
-
468
+
469
469
  data["a"] = 3.455
470
470
  assert(!JSON::Validator.validate(schema,data,:version => :draft1))
471
-
472
-
471
+
472
+
473
473
  schema["properties"]["a"]["maxDecimal"] = 0
474
-
474
+
475
475
  data["a"] = 4.0
476
476
  assert(!JSON::Validator.validate(schema,data,:version => :draft1))
477
-
477
+
478
478
  data["a"] = 'boo'
479
479
  assert(JSON::Validator.validate(schema,data,:version => :draft1))
480
-
480
+
481
481
  data["a"] = 5
482
482
  assert(JSON::Validator.validate(schema,data,:version => :draft1))
483
483
  end
484
-
485
-
486
-
484
+
485
+
486
+
487
487
  def test_disallow
488
488
  # Set up the default datatype
489
489
  schema = {
@@ -491,33 +491,33 @@ class JSONSchemaDraft1Test < Test::Unit::TestCase
491
491
  "a" => {"disallow" => "integer"}
492
492
  }
493
493
  }
494
-
494
+
495
495
  data = {
496
496
  "a" => nil
497
497
  }
498
-
499
-
498
+
499
+
500
500
  data["a"] = 'string'
501
501
  assert(JSON::Validator.validate(schema,data,:version => :draft1))
502
-
502
+
503
503
  data["a"] = 5
504
504
  assert(!JSON::Validator.validate(schema,data,:version => :draft1))
505
-
506
-
505
+
506
+
507
507
  schema["properties"]["a"]["disallow"] = ["integer","string"]
508
508
  data["a"] = 'string'
509
509
  assert(!JSON::Validator.validate(schema,data,:version => :draft1))
510
-
510
+
511
511
  data["a"] = 5
512
512
  assert(!JSON::Validator.validate(schema,data,:version => :draft1))
513
-
513
+
514
514
  data["a"] = false
515
515
  assert(JSON::Validator.validate(schema,data,:version => :draft1))
516
516
 
517
517
  end
518
-
519
-
520
-
518
+
519
+
520
+
521
521
  def test_additional_properties
522
522
  # Test no additional properties allowed
523
523
  schema = {
@@ -526,15 +526,15 @@ class JSONSchemaDraft1Test < Test::Unit::TestCase
526
526
  },
527
527
  "additionalProperties" => false
528
528
  }
529
-
529
+
530
530
  data = {
531
531
  "a" => 10
532
532
  }
533
-
533
+
534
534
  assert(JSON::Validator.validate(schema,data,:version => :draft1))
535
535
  data["b"] = 5
536
536
  assert(!JSON::Validator.validate(schema,data,:version => :draft1))
537
-
537
+
538
538
  # Test additional properties match a schema
539
539
  schema["additionalProperties"] = { "type" => "string" }
540
540
  data["b"] = "taco"
@@ -542,41 +542,41 @@ class JSONSchemaDraft1Test < Test::Unit::TestCase
542
542
  data["b"] = 5
543
543
  assert(!JSON::Validator.validate(schema,data,:version => :draft1))
544
544
  end
545
-
546
-
545
+
546
+
547
547
  def test_items
548
548
  schema = {
549
549
  "items" => { "type" => "integer" }
550
550
  }
551
-
551
+
552
552
  data = [1,2,4]
553
553
  assert(JSON::Validator.validate(schema,data,:version => :draft1))
554
554
  data = [1,2,"string"]
555
555
  assert(!JSON::Validator.validate(schema,data,:version => :draft1))
556
-
556
+
557
557
  schema = {
558
558
  "items" => [
559
559
  {"type" => "integer"},
560
560
  {"type" => "string"}
561
561
  ]
562
562
  }
563
-
563
+
564
564
  data = [1,"string"]
565
565
  assert(JSON::Validator.validate(schema,data,:version => :draft1))
566
566
  data = [1,"string",3]
567
567
  assert(JSON::Validator.validate(schema,data,:version => :draft1))
568
568
  data = ["string",1]
569
569
  assert(!JSON::Validator.validate(schema,data,:version => :draft1))
570
-
570
+
571
571
  end
572
-
573
-
572
+
573
+
574
574
  def test_format_ipv4
575
575
  schema = {
576
576
  "type" => "object",
577
577
  "properties" => { "a" => {"type" => "string", "format" => "ip-address"}}
578
578
  }
579
-
579
+
580
580
  data = {"a" => "1.1.1.1"}
581
581
  assert(JSON::Validator.validate(schema,data,:version => :draft1))
582
582
  data = {"a" => "1.1.1"}
@@ -591,14 +591,14 @@ class JSONSchemaDraft1Test < Test::Unit::TestCase
591
591
  assert(!JSON::Validator.validate(schema,data,:version => :draft1))
592
592
  data = {"a" => "b1.1.1.1"}
593
593
  end
594
-
595
-
594
+
595
+
596
596
  def test_format_ipv6
597
597
  schema = {
598
598
  "type" => "object",
599
599
  "properties" => { "a" => {"type" => "string", "format" => "ipv6"}}
600
600
  }
601
-
601
+
602
602
  data = {"a" => "1111:2222:8888:9999:aaaa:cccc:eeee:ffff"}
603
603
  assert(JSON::Validator.validate(schema,data,:version => :draft1))
604
604
  data = {"a" => "1111:0:8888:0:0:0:eeee:ffff"}
@@ -614,13 +614,13 @@ class JSONSchemaDraft1Test < Test::Unit::TestCase
614
614
  data = {"a" => "1111:2222:8888:9999:aaaa:cccc:eeee:ffff:bbbb"}
615
615
  assert(!JSON::Validator.validate(schema,data,:version => :draft1))
616
616
  end
617
-
617
+
618
618
  def test_format_time
619
619
  schema = {
620
620
  "type" => "object",
621
621
  "properties" => { "a" => {"type" => "string", "format" => "time"}}
622
622
  }
623
-
623
+
624
624
  data = {"a" => "12:00:00"}
625
625
  assert(JSON::Validator.validate(schema,data,:version => :draft1))
626
626
  data = {"a" => "12:00"}
@@ -638,14 +638,14 @@ class JSONSchemaDraft1Test < Test::Unit::TestCase
638
638
  data = {"a" => "12:00:00b"}
639
639
  assert(!JSON::Validator.validate(schema,data,:version => :draft1))
640
640
  end
641
-
642
-
641
+
642
+
643
643
  def test_format_date
644
644
  schema = {
645
645
  "type" => "object",
646
646
  "properties" => { "a" => {"type" => "string", "format" => "date"}}
647
647
  }
648
-
648
+
649
649
  data = {"a" => "2010-01-01"}
650
650
  assert(JSON::Validator.validate(schema,data,:version => :draft1))
651
651
  data = {"a" => "2010-01-32"}
@@ -659,13 +659,13 @@ class JSONSchemaDraft1Test < Test::Unit::TestCase
659
659
  data = {"a" => "2010-01-01n"}
660
660
  assert(!JSON::Validator.validate(schema,data,:version => :draft1))
661
661
  end
662
-
662
+
663
663
  def test_format_datetime
664
664
  schema = {
665
665
  "type" => "object",
666
666
  "properties" => { "a" => {"type" => "string", "format" => "date-time"}}
667
667
  }
668
-
668
+
669
669
  data = {"a" => "2010-01-01T12:00:00Z"}
670
670
  assert(JSON::Validator.validate(schema,data,:version => :draft1))
671
671
  data = {"a" => "2010-01-32T12:00:00Z"}
@@ -678,19 +678,17 @@ class JSONSchemaDraft1Test < Test::Unit::TestCase
678
678
  assert(!JSON::Validator.validate(schema,data,:version => :draft1))
679
679
  data = {"a" => "2010-01-01T12:00:60Z"}
680
680
  assert(!JSON::Validator.validate(schema,data,:version => :draft1))
681
- data = {"a" => "2010-01-01T12:00:00"}
682
- assert(!JSON::Validator.validate(schema,data,:version => :draft1))
683
681
  data = {"a" => "2010-01-01T12:00:00z"}
684
682
  assert(!JSON::Validator.validate(schema,data,:version => :draft1))
685
683
  data = {"a" => "2010-01-0112:00:00Z"}
686
684
  assert(!JSON::Validator.validate(schema,data,:version => :draft1))
687
685
  end
688
-
689
-
686
+
687
+
690
688
  def test_format_union
691
689
  data1 = {"a" => "boo"}
692
690
  data2 = {"a" => nil}
693
-
691
+
694
692
  schema = {
695
693
  "type" => "object",
696
694
  "properties" => { "a" => {"type" => ["string","null"], "format" => "ip-address"}}
@@ -698,6 +696,6 @@ class JSONSchemaDraft1Test < Test::Unit::TestCase
698
696
  assert(!JSON::Validator.validate(schema,data1,:version => :draft1))
699
697
  assert(JSON::Validator.validate(schema,data2,:version => :draft1))
700
698
  end
701
-
699
+
702
700
  end
703
701