kwalify 0.4.1 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,60 @@
1
+ ###
2
+ ### $Rev: 42 $
3
+ ### $Release: 0.5.0 $
4
+ ### copyright(c) 2005 kuwata-lab all rights reserved.
5
+ ###
6
+
7
+ unless defined?(TESTDIR)
8
+ TESTDIR = File.dirname(__FILE__)
9
+ libdir = File.dirname(TESTDIR) + "/lib"
10
+ $LOAD_PATH << libdir << TESTDIR
11
+ end
12
+
13
+ require 'test/unit'
14
+ require 'test/unit/ui/console/testrunner'
15
+ require 'kwalify'
16
+ require 'kwalify/util/assert-diff'
17
+ require 'yaml'
18
+
19
+
20
+ class RuleTest < Test::Unit::TestCase
21
+
22
+ ## define test methods
23
+ testdata_filename = __FILE__.sub(/\.rb$/, '.yaml')
24
+ str = File.read(testdata_filename)
25
+ @@docs = {}
26
+ YAML.load_documents(str) do |doc|
27
+ name = doc['name']
28
+ !@@docs.key?(name) or raise "*** test name '#name}' is duplicated."
29
+ @@docs[name] = doc
30
+ doc.each do |key, val|
31
+ if key =~ /\A(.*)\*\z/
32
+ doc[$1] ||= val['ruby']
33
+ end
34
+ end
35
+ doc['schema'] = YAML.load(doc['input'])
36
+ s = <<-END
37
+ def test_#{name}
38
+ doc = @@docs['#{name}']
39
+ @name = doc['name']
40
+ @desc = doc['desc']
41
+ @input = doc['input']
42
+ @schema = doc['schema']
43
+ @exception = #{doc['exception'] == nil ? 'nil' : doc['error']}
44
+ _test()
45
+ end
46
+ END
47
+ eval s
48
+ end
49
+
50
+ ## execute test
51
+ def _test()
52
+ assert_nothing_raised do
53
+ return if $target && $target != @name
54
+ schema = @schema
55
+ rule = Kwalify::Rule.new(schema)
56
+ end
57
+ end
58
+
59
+ end
60
+
@@ -0,0 +1,314 @@
1
+ ##
2
+ ## $Rev: 42 $
3
+ ## $Release: 0.5.0 $
4
+ ## copyright(c) 2005 kuwata-lab all rights reserved.
5
+ ##
6
+ ---
7
+ name: sequence1
8
+ desc: basic sequence
9
+ input: |
10
+ type: seq
11
+ sequence:
12
+ - type: str
13
+ #
14
+ ---
15
+ name: mapping1
16
+ desc: basic mapping
17
+ input: |
18
+ type: map
19
+ mapping:
20
+ "name":
21
+ type: str
22
+ required: yes
23
+ "email":
24
+ type: str
25
+ pattern: /@/
26
+ "age":
27
+ type: int
28
+ "birth":
29
+ type: date
30
+ #
31
+ ---
32
+ name: seqmap1
33
+ desc: mapping of sequence
34
+ input: |
35
+ type: seq
36
+ sequence:
37
+ - type: map
38
+ mapping:
39
+ "name":
40
+ type: str
41
+ required: true
42
+ "email":
43
+ type: str
44
+ #
45
+ ---
46
+ name: mapseq1
47
+ desc: mapping of sequence
48
+ input: |
49
+ type: map
50
+ mapping:
51
+ "company":
52
+ type: str
53
+ required: yes
54
+ "email":
55
+ type: str
56
+ "employees":
57
+ type: seq
58
+ sequence:
59
+ - type: map
60
+ mapping:
61
+ "code":
62
+ type: int
63
+ required: yes
64
+ "name":
65
+ type: str
66
+ required: yes
67
+ "email":
68
+ type: str
69
+ #
70
+ ---
71
+ name: unique1
72
+ desc: unique constraint
73
+ input: |
74
+ type: seq
75
+ sequence:
76
+ - type: map
77
+ required: yes
78
+ mapping:
79
+ "name":
80
+ type: str
81
+ required: yes
82
+ unique: yes
83
+ "email":
84
+ type: str
85
+ "groups":
86
+ type: seq
87
+ sequence:
88
+ - type: str
89
+ unique: yes
90
+ ---
91
+ name: constraints1
92
+ desc: some constraints
93
+ input: |
94
+ name: address-book
95
+ desc: Address book
96
+ type: seq
97
+ sequence:
98
+ - type: map
99
+ mapping:
100
+ "name":
101
+ type: str
102
+ required: yes
103
+ "email":
104
+ type: str
105
+ required: yes
106
+ pattern: /@/
107
+ "password":
108
+ type: str
109
+ length: { max: 16, min: 8 }
110
+ "age":
111
+ type: int
112
+ range: { max: 30, min: 18 }
113
+ # or assert: 18 <= val && val <= 30
114
+ "blood":
115
+ type: str
116
+ enum:
117
+ - A
118
+ - B
119
+ - O
120
+ - AB
121
+ "birth":
122
+ type: date
123
+ "memo":
124
+ type: any
125
+ #
126
+ ---
127
+ name: default1
128
+ desc: default rule
129
+ input: |
130
+ type: map
131
+ mapping:
132
+ "properties":
133
+ type: map
134
+ mapping:
135
+ =:
136
+ type: any
137
+ #
138
+ ---
139
+ name: default2
140
+ desc: default rule #2
141
+ input: |
142
+ type: seq
143
+ sequence:
144
+ - type: map
145
+ mapping:
146
+ "name":
147
+ type: str
148
+ required: yes
149
+ "email":
150
+ type: str
151
+ "birth":
152
+ type: date
153
+ =:
154
+ type: any
155
+ #
156
+ ---
157
+ name: merge1
158
+ desc: merge rule
159
+ input: |
160
+ type: map
161
+ mapping:
162
+ "group":
163
+ type: map
164
+ mapping:
165
+ "name": &name
166
+ type: str
167
+ required: yes
168
+ "email": &email
169
+ type: str
170
+ pattern: /@/
171
+ required: no
172
+ "user":
173
+ type: map
174
+ mapping:
175
+ "name":
176
+ <<: *name # merge
177
+ length: { max: 16 } # append
178
+ "email":
179
+ <<: *email # merge
180
+ required: yes # overwrite
181
+ #
182
+ ---
183
+ name: anchor1
184
+ desc: sharing rule with anchor and alias
185
+ input: |
186
+ desc: Bookshelf
187
+ type: seq
188
+ sequence:
189
+ - type: map
190
+ mapping:
191
+ "title":
192
+ type: str
193
+ required: yes
194
+ "author": &persons # anchor
195
+ type: seq
196
+ sequence:
197
+ - type: str
198
+ "translator": *persons # alias
199
+ "publisher":
200
+ type: str
201
+ "year":
202
+ type: int
203
+ #
204
+ ---
205
+ name: anchor2
206
+ desc: recursive definition of rule
207
+ input: |
208
+ &task # anchor
209
+ desc: WBS
210
+ type: map
211
+ mapping:
212
+ "name": { type: str, required: yes }
213
+ "assigned": { type: str }
214
+ "deadline": { type: date }
215
+ "subtasks":
216
+ type: seq
217
+ sequence:
218
+ - *task # alias
219
+ ---
220
+ name: meta_schema
221
+ desc: schema for meta-validator
222
+ #
223
+ input: |
224
+ name: MAIN
225
+ type: map
226
+ required: yes
227
+ mapping: &main-rule
228
+ "name":
229
+ type: str
230
+ "desc":
231
+ type: str
232
+ "type":
233
+ type: str
234
+ #required: yes
235
+ enum:
236
+ - seq
237
+ #- sequence
238
+ #- list
239
+ - map
240
+ #- mapping
241
+ #- hash
242
+ - str
243
+ #- string
244
+ - int
245
+ #- integer
246
+ - float
247
+ - number
248
+ #- numeric
249
+ - bool
250
+ #- boolean
251
+ - text
252
+ - date
253
+ - time
254
+ - timestamp
255
+ #- object
256
+ - any
257
+ - scalar
258
+ #- collection
259
+ "required":
260
+ type: bool
261
+ "enum":
262
+ type: seq
263
+ sequence:
264
+ - type: scalar
265
+ unique: yes
266
+ "pattern":
267
+ type: str
268
+ "assert":
269
+ type: str
270
+ pattern: /\bval\b/
271
+ "range":
272
+ type: map
273
+ mapping:
274
+ "max":
275
+ type: scalar
276
+ "min":
277
+ type: scalar
278
+ "max-ex":
279
+ type: scalar
280
+ "min-ex":
281
+ type: scalar
282
+ "length":
283
+ type: map
284
+ mapping:
285
+ "max":
286
+ type: int
287
+ "min":
288
+ type: int
289
+ "max-ex":
290
+ type: int
291
+ "min-ex":
292
+ type: int
293
+ "ident":
294
+ type: bool
295
+ "unique":
296
+ type: bool
297
+ "sequence":
298
+ name: SEQUENCE
299
+ type: seq
300
+ sequence:
301
+ - type: map
302
+ mapping: *main-rule
303
+ name: MAIN
304
+ #required: yes
305
+ "mapping":
306
+ name: MAPPING
307
+ type: map
308
+ mapping:
309
+ =:
310
+ type: map
311
+ mapping: *main-rule
312
+ name: MAIN
313
+ #required: yes
314
+
@@ -1,6 +1,6 @@
1
1
  ###
2
- ### $Rev: 39 $
3
- ### $Release: 0.4.1 $
2
+ ### $Rev: 42 $
3
+ ### $Release: 0.5.0 $
4
4
  ### copyright(c) 2005 kuwata-lab all rights reserved.
5
5
  ###
6
6
 
@@ -50,8 +50,8 @@ class ValidatorTest < Test::Unit::TestCase
50
50
  error2 = @error.gsub(/\(line \d+\)/, '')
51
51
  _test_body(validator, @valid, '' , false)
52
52
  _test_body(validator, @invalid, error2, false)
53
- # Kwalify::Parser
54
- schema = Kwalify::Parser.new(@schema).parse()
53
+ # Kwalify::YamlParser
54
+ schema = Kwalify::YamlParser.new(@schema).parse()
55
55
  validator = Kwalify::Validator.new(schema)
56
56
  _test_body(validator, @valid, '' , true)
57
57
  _test_body(validator, @invalid, @error, true)
@@ -59,7 +59,7 @@ class ValidatorTest < Test::Unit::TestCase
59
59
 
60
60
  def _test_body(validator, input, expected, flag_parser)
61
61
  if flag_parser
62
- parser = Kwalify::Parser.new(input)
62
+ parser = Kwalify::YamlParser.new(input)
63
63
  document = parser.parse()
64
64
  else
65
65
  document = YAML.load(input)
@@ -0,0 +1,816 @@
1
+ ##
2
+ ## $Rev: 42 $
3
+ ## $Release: 0.5.0 $
4
+ ## copyright(c) 2005 kuwata-lab all rights reserved.
5
+ ##
6
+ ---
7
+ name: sequence1
8
+ desc: sequence test
9
+ #
10
+ schema: |
11
+ type: seq
12
+ required: true
13
+ sequence:
14
+ - type: str
15
+ required: true
16
+ #
17
+ valid: |
18
+ - foo
19
+ - bar
20
+ - baz
21
+ #
22
+ invalid: |
23
+ - foo
24
+ - bar
25
+ -
26
+ - baz
27
+ - 100
28
+ #
29
+ error: |
30
+ :required_novalue : (line 3)[/2] value required but none.
31
+ :type_unmatch : (line 5)[/4] '100': not a string.
32
+ #
33
+ ---
34
+ name: mapping1
35
+ desc: mapping test
36
+ #
37
+ schema: |
38
+ type: map
39
+ required: true
40
+ mapping:
41
+ name:
42
+ type: str
43
+ required: true
44
+ email:
45
+ type: str
46
+ pattern: /@/
47
+ required: yes
48
+ age:
49
+ type: int
50
+ blood:
51
+ type: str
52
+ enum:
53
+ - A
54
+ - B
55
+ - O
56
+ - AB
57
+ birth:
58
+ type: date
59
+ #
60
+ valid: |
61
+ name: foo
62
+ email: foo@mail.com
63
+ age: 20
64
+ blood: AB
65
+ birth: 1985-01-01
66
+ #
67
+ invalid: |
68
+ nam: foo
69
+ email: foo(at)mail.com
70
+ age: twenty
71
+ blood: ab
72
+ birth: Jul 01, 1985
73
+ #
74
+ error: |
75
+ :required_nokey : (line 1)[/] key 'name:' is required.
76
+ :key_undefined : (line 1)[/nam] key 'nam:' is undefined.
77
+ :pattern_unmatch : (line 2)[/email] 'foo(at)mail.com': not matched to pattern /@/.
78
+ :type_unmatch : (line 3)[/age] 'twenty': not a integer.
79
+ :enum_notexist : (line 4)[/blood] 'ab': invalid blood value.
80
+ :type_unmatch : (line 5)[/birth] 'Jul 01, 1985': not a date.
81
+ #
82
+ ---
83
+ name: nested1
84
+ desc: nest of seq and map
85
+ #
86
+ schema: |
87
+ type: map
88
+ required: true
89
+ mapping:
90
+ address-book:
91
+ type: seq
92
+ required: true
93
+ sequence:
94
+ - type: map
95
+ mapping:
96
+ name:
97
+ type: str
98
+ required: yes
99
+ email:
100
+ type: str
101
+ pattern: /@/
102
+ required: yes
103
+ age:
104
+ type: int
105
+ blood:
106
+ type: str
107
+ enum:
108
+ - A
109
+ - B
110
+ - O
111
+ - AB
112
+ birth:
113
+ type: date
114
+ #
115
+ valid: |
116
+ address-book:
117
+ - name: foo
118
+ email: foo@mail.com
119
+ age: 20
120
+ blood: AB
121
+ birth: 1985-01-01
122
+ - name: bar
123
+ email: foo@mail.com
124
+ #
125
+ invalid: |
126
+ address-book:
127
+ - name: foo
128
+ mail: foo@mail.com
129
+ age: twenty
130
+ blood: ab
131
+ birth: 1985/01/01
132
+ - name: bar
133
+ email: bar(at)mail.com
134
+ #
135
+ error: |
136
+ :required_nokey : (line 2)[/address-book/0] key 'email:' is required.
137
+ :key_undefined : (line 3)[/address-book/0/mail] key 'mail:' is undefined.
138
+ :type_unmatch : (line 4)[/address-book/0/age] 'twenty': not a integer.
139
+ :enum_notexist : (line 5)[/address-book/0/blood] 'ab': invalid blood value.
140
+ :type_unmatch : (line 6)[/address-book/0/birth] '1985/01/01': not a date.
141
+ :pattern_unmatch : (line 8)[/address-book/1/email] 'bar(at)mail.com': not matched to pattern /@/.
142
+ #
143
+ ---
144
+ name: anchor1
145
+ desc: schema with anchor
146
+ #
147
+ schema: |
148
+ type: seq
149
+ required: true
150
+ sequence:
151
+ - type: map
152
+ required: true
153
+ mapping:
154
+ first-name: &name
155
+ type: str
156
+ required: yes
157
+ family-name: *name
158
+ #
159
+ valid: |
160
+ - first-name: foo
161
+ family-name: Foo
162
+ - first-name: bar
163
+ family-name: Bar
164
+ #
165
+ invalid: |
166
+ - first-name: foo
167
+ last-name: Foo
168
+ - first-name: bar
169
+ family-name: 100
170
+ #
171
+ error: |
172
+ :required_nokey : (line 1)[/0] key 'family-name:' is required.
173
+ :key_undefined : (line 2)[/0/last-name] key 'last-name:' is undefined.
174
+ :type_unmatch : (line 4)[/1/family-name] '100': not a string.
175
+ #
176
+ ---
177
+ name: anchor2
178
+ desc: schema with anchor 2
179
+ #
180
+ schema: |
181
+ type: map
182
+ required: true
183
+ mapping:
184
+ title: &name
185
+ type: str
186
+ required: true
187
+ address-book:
188
+ type: seq
189
+ required: true
190
+ sequence:
191
+ - type: map
192
+ mapping:
193
+ name: *name
194
+ email:
195
+ type: str
196
+ required: yes
197
+ #
198
+ valid: |
199
+ title: my friends
200
+ address-book:
201
+ - name: foo
202
+ email: foo@mail.com
203
+ - name: bar
204
+ email: bar@mail.com
205
+ #
206
+ invalid: |
207
+ title: my friends
208
+ address-book:
209
+ - name: 100
210
+ email: foo@mail.com
211
+ - first-name: bar
212
+ email: bar@mail.com
213
+ #
214
+ error: |
215
+ :type_unmatch : (line 3)[/address-book/0/name] '100': not a string.
216
+ :required_nokey : (line 5)[/address-book/1] key 'name:' is required.
217
+ :key_undefined : (line 5)[/address-book/1/first-name] key 'first-name:' is undefined.
218
+ #
219
+ ---
220
+ name: anchor3
221
+ desc: document with anchor
222
+ #
223
+ schema: |
224
+ type: seq
225
+ sequence:
226
+ - &employee
227
+ type: map
228
+ mapping:
229
+ name:
230
+ type: str
231
+ post:
232
+ type: str
233
+ enum:
234
+ - exective
235
+ - manager
236
+ - clerk
237
+ supervisor: *employee
238
+ #
239
+ valid: |
240
+ - &foo
241
+ name: foo
242
+ post: exective
243
+ - &bar
244
+ name: bar
245
+ post: manager
246
+ supervisor: *foo
247
+ - &baz
248
+ name: baz
249
+ post: clerk
250
+ supervisor: *bar
251
+ - &zak
252
+ name: zak
253
+ post: clerk
254
+ supervisor: *bar
255
+ #
256
+ invalid: |
257
+ - &foo
258
+ name: 100
259
+ post: exective
260
+ supervisor: *foo
261
+ - &bar
262
+ name: foo
263
+ post: worker
264
+ supervisor: *foo
265
+ #
266
+ error: |
267
+ :type_unmatch : (line 2)[/0/name] '100': not a string.
268
+ :enum_notexist : (line 7)[/1/post] 'worker': invalid post value.
269
+ #
270
+ ---
271
+ name: range1
272
+ desc: range test && bug#?????
273
+ #
274
+ schema: |
275
+ type: map
276
+ mapping:
277
+ "max-only":
278
+ type: seq
279
+ sequence:
280
+ - type: number
281
+ required: yes
282
+ range: { max: 100 }
283
+ "min-only":
284
+ type: seq
285
+ sequence:
286
+ - type: number
287
+ required: yes
288
+ range: { min: 10.0 }
289
+ "max-and-min":
290
+ type: seq
291
+ sequence:
292
+ - type: number
293
+ required: yes
294
+ range: { max: 100.0, min: 10.0 }
295
+ #
296
+ valid: |
297
+ max-only:
298
+ - 100
299
+ - 100.0
300
+ min-only:
301
+ - 10
302
+ - 10.0
303
+ max-and-min:
304
+ - 100
305
+ - 10
306
+ - 100.0
307
+ - 10.0
308
+ #
309
+ invalid: |
310
+ max-only:
311
+ - 101
312
+ - 100.1
313
+ min-only:
314
+ - 9
315
+ - 9.99
316
+ max-and-min:
317
+ - 101
318
+ - 100.1
319
+ - 9
320
+ - 9.99
321
+ #
322
+ error: |
323
+ :range_toolarge : (line 2)[/max-only/0] '101': too large (> max 100).
324
+ :range_toolarge : (line 3)[/max-only/1] '100.1': too large (> max 100).
325
+ :range_toosmall : (line 5)[/min-only/0] '9': too small (< min 10.0).
326
+ :range_toosmall : (line 6)[/min-only/1] '9.99': too small (< min 10.0).
327
+ :range_toolarge : (line 8)[/max-and-min/0] '101': too large (> max 100.0).
328
+ :range_toolarge : (line 9)[/max-and-min/1] '100.1': too large (> max 100.0).
329
+ :range_toosmall : (line 10)[/max-and-min/2] '9': too small (< min 10.0).
330
+ :range_toosmall : (line 11)[/max-and-min/3] '9.99': too small (< min 10.0).
331
+ #
332
+ ---
333
+ name: range2
334
+ desc: range test (with max-ex and min-ex)
335
+ #
336
+ schema: |
337
+ type: map
338
+ mapping:
339
+ "max-ex-only":
340
+ type: seq
341
+ sequence:
342
+ - type: number
343
+ required: yes
344
+ range: { max-ex: 100 }
345
+ "min-ex-only":
346
+ type: seq
347
+ sequence:
348
+ - type: number
349
+ required: yes
350
+ range: { min-ex: 10.0 }
351
+ "max-ex-and-min-ex":
352
+ type: seq
353
+ sequence:
354
+ - type: number
355
+ required: yes
356
+ range: { max-ex: 100.0, min-ex: 10.0 }
357
+ #
358
+ valid: |
359
+ max-ex-only:
360
+ - 99
361
+ - 99.99999
362
+ min-ex-only:
363
+ - 11
364
+ - 10.00001
365
+ max-ex-and-min-ex:
366
+ - 99
367
+ - 11
368
+ - 99.99999
369
+ - 10.00001
370
+ #
371
+ invalid: |
372
+ max-ex-only:
373
+ - 100
374
+ - 100.0
375
+ min-ex-only:
376
+ - 10
377
+ - 10.0
378
+ max-ex-and-min-ex:
379
+ - 100
380
+ - 100.0
381
+ - 10
382
+ - 10.0
383
+ #
384
+ error: |
385
+ :range_toolargeex : (line 2)[/max-ex-only/0] '100': too large (>= max 100).
386
+ :range_toolargeex : (line 3)[/max-ex-only/1] '100.0': too large (>= max 100).
387
+ :range_toosmallex : (line 5)[/min-ex-only/0] '10': too small (<= min 10.0).
388
+ :range_toosmallex : (line 6)[/min-ex-only/1] '10.0': too small (<= min 10.0).
389
+ :range_toolargeex : (line 8)[/max-ex-and-min-ex/0] '100': too large (>= max 100.0).
390
+ :range_toolargeex : (line 9)[/max-ex-and-min-ex/1] '100.0': too large (>= max 100.0).
391
+ :range_toosmallex : (line 10)[/max-ex-and-min-ex/2] '10': too small (<= min 10.0).
392
+ :range_toosmallex : (line 11)[/max-ex-and-min-ex/3] '10.0': too small (<= min 10.0).
393
+ #
394
+ ---
395
+ name: range3
396
+ desc: range test (with max, min, max-ex and min-ex)
397
+ #
398
+ schema: |
399
+ type: map
400
+ mapping:
401
+ "A":
402
+ type: seq
403
+ sequence:
404
+ - type: number
405
+ required: yes
406
+ range: { max: 100, min-ex: 10.0 }
407
+ "B":
408
+ type: seq
409
+ sequence:
410
+ - type: number
411
+ required: yes
412
+ range: { min: 10, max-ex: 100.0 }
413
+ #
414
+ valid: |
415
+ A:
416
+ - 100
417
+ - 10.00001
418
+ B:
419
+ - 10
420
+ - 99.99999
421
+ #
422
+ invalid: |
423
+ A:
424
+ - 100.00001
425
+ - 10.0
426
+ B:
427
+ - 9.99999
428
+ - 100.0
429
+ #
430
+ error: |
431
+ :range_toolarge : (line 2)[/A/0] '100.00001': too large (> max 100).
432
+ :range_toosmallex : (line 3)[/A/1] '10.0': too small (<= min 10.0).
433
+ :range_toosmall : (line 5)[/B/0] '9.99999': too small (< min 10).
434
+ :range_toolargeex : (line 6)[/B/1] '100.0': too large (>= max 100.0).
435
+ #
436
+ ---
437
+ name: length1
438
+ desc: length test
439
+ #
440
+ schema: |
441
+ type: map
442
+ mapping:
443
+ "max-only":
444
+ type: seq
445
+ sequence:
446
+ - type: str
447
+ length: { max: 8 }
448
+ "min-only":
449
+ type: seq
450
+ sequence:
451
+ - type: str
452
+ length: { min: 4 }
453
+ "max-and-min":
454
+ type: seq
455
+ sequence:
456
+ - type: str
457
+ length: { max: 8, min: 4 }
458
+ #
459
+ valid: |
460
+ max-only:
461
+ - hogehoge
462
+ - a
463
+ -
464
+ min-only:
465
+ - hoge
466
+ - hogehogehogehogehoge
467
+ max-and-min:
468
+ - hogehoge
469
+ - hoge
470
+ #
471
+ invalid: |
472
+ max-only:
473
+ - hogehoge!
474
+ min-only:
475
+ - foo
476
+ -
477
+ max-and-min:
478
+ - foobarbaz
479
+ - foo
480
+ #
481
+ error: |
482
+ :length_toolong : (line 2)[/max-only/0] 'hogehoge!': too long (length 9 > max 8).
483
+ :length_tooshort : (line 4)[/min-only/0] 'foo': too short (length 3 < min 4).
484
+ :length_toolong : (line 7)[/max-and-min/0] 'foobarbaz': too long (length 9 > max 8).
485
+ :length_tooshort : (line 8)[/max-and-min/1] 'foo': too short (length 3 < min 4).
486
+ #
487
+ ---
488
+ name: length2
489
+ desc: length test (with max-ex and min-ex)
490
+ #
491
+ schema: |
492
+ type: map
493
+ mapping:
494
+ "max-ex-only":
495
+ type: seq
496
+ sequence:
497
+ - type: str
498
+ length: { max-ex: 8 }
499
+ "min-ex-only":
500
+ type: seq
501
+ sequence:
502
+ - type: str
503
+ length: { min-ex: 4 }
504
+ "max-ex-and-min-ex":
505
+ type: seq
506
+ sequence:
507
+ - type: str
508
+ length: { max-ex: 8, min-ex: 4 }
509
+ #
510
+ valid: |
511
+ max-ex-only:
512
+ - hogehog
513
+ - a
514
+ -
515
+ min-ex-only:
516
+ - hoge!
517
+ max-ex-and-min-ex:
518
+ - hogehog
519
+ - hoge!
520
+ #
521
+ invalid: |
522
+ max-ex-only:
523
+ - hogehoge
524
+ min-ex-only:
525
+ - foo!
526
+ -
527
+ max-ex-and-min-ex:
528
+ - foobarba
529
+ - foo!
530
+ #
531
+ error: |
532
+ :length_toolongex : (line 2)[/max-ex-only/0] 'hogehoge': too long (length 8 >= max 8).
533
+ :length_tooshortex : (line 4)[/min-ex-only/0] 'foo!': too short (length 4 <= min 4).
534
+ :length_toolongex : (line 7)[/max-ex-and-min-ex/0] 'foobarba': too long (length 8 >= max 8).
535
+ :length_tooshortex : (line 8)[/max-ex-and-min-ex/1] 'foo!': too short (length 4 <= min 4).
536
+ #
537
+ ---
538
+ name: length3
539
+ desc: length test (with min, max, max-ex and min-ex)
540
+ #
541
+ schema: |
542
+ type: map
543
+ mapping:
544
+ "A":
545
+ type: seq
546
+ sequence:
547
+ - type: str
548
+ length: { max: 8, min-ex: 4 }
549
+ "B":
550
+ type: seq
551
+ sequence:
552
+ - type: str
553
+ length: { max-ex: 8, min: 4 }
554
+ #
555
+ valid: |
556
+ A:
557
+ - hogehoge
558
+ - hogeh
559
+ B:
560
+ - hogehog
561
+ - hoge
562
+ #
563
+ invalid: |
564
+ A:
565
+ - hogehoge!
566
+ - hoge
567
+ B:
568
+ - hogehoge
569
+ - hog
570
+ #
571
+ error: |
572
+ :length_toolong : (line 2)[/A/0] 'hogehoge!': too long (length 9 > max 8).
573
+ :length_tooshortex : (line 3)[/A/1] 'hoge': too short (length 4 <= min 4).
574
+ :length_toolongex : (line 5)[/B/0] 'hogehoge': too long (length 8 >= max 8).
575
+ :length_tooshort : (line 6)[/B/1] 'hog': too short (length 3 < min 4).
576
+ #
577
+ ---
578
+ name: assert1
579
+ desc: assert test
580
+ #
581
+ schema: |
582
+ type: seq
583
+ sequence:
584
+ - type: map
585
+ mapping:
586
+ "less-than":
587
+ type: number
588
+ assert: val < 8
589
+ "more-than":
590
+ type: number
591
+ assert: 3 < val
592
+ "between":
593
+ type: number
594
+ assert: 3 < val && val < 8
595
+ "except":
596
+ type: number
597
+ assert: val < 3 || 8 < val
598
+ #
599
+ valid: |
600
+ - less-than: 5
601
+ - more-than: 5
602
+ - between: 5
603
+ - except: 0
604
+ #
605
+ invalid*:
606
+ java: ~
607
+ ruby: |
608
+ - less-than: 8
609
+ - more-than: 3
610
+ - between: 2.9
611
+ - except: 3.1
612
+ #
613
+ error: |
614
+ :assert_failed : (line 1)[/0/less-than] '8': assertion expression failed (val < 8).
615
+ :assert_failed : (line 2)[/1/more-than] '3': assertion expression failed (3 < val).
616
+ :assert_failed : (line 3)[/2/between] '2.9': assertion expression failed (3 < val && val < 8).
617
+ :assert_failed : (line 4)[/3/except] '3.1': assertion expression failed (val < 3 || 8 < val).
618
+ #
619
+ ---
620
+ name: deftype1
621
+ desc: default type test
622
+ #
623
+ schema: |
624
+ type: seq
625
+ sequence:
626
+ - type: map
627
+ mapping:
628
+ "name":
629
+ "email":
630
+ #
631
+ valid: |
632
+ - name: foo
633
+ email: foo@mail.com
634
+ - name: bar
635
+ - email: baz@mail.com
636
+ #
637
+ invalid: |
638
+ - name: 123
639
+ email: true
640
+ - name: 3.14
641
+ - email: 2004-01-01
642
+ #
643
+ error*:
644
+ ruby: |
645
+ :type_unmatch : (line 1)[/0/name] '123': not a string.
646
+ :type_unmatch : (line 2)[/0/email] 'true': not a string.
647
+ :type_unmatch : (line 3)[/1/name] '3.14': not a string.
648
+ :type_unmatch : (line 4)[/2/email] '2004-01-01': not a string.
649
+ java: |
650
+ :type_unmatch : (line 1)[/0/name] '123': not a string.
651
+ :type_unmatch : (line 2)[/0/email] 'true': not a string.
652
+ :type_unmatch : (line 3)[/1/name] '3.14': not a string.
653
+ :type_unmatch : (line 4)[/2/email] 'Sun Feb 01 00:00:00 JST 2004': not a string.
654
+ #
655
+ ---
656
+ name: ident1
657
+ desc: ident constraint test
658
+ #
659
+ schema: |
660
+ type: seq
661
+ sequence:
662
+ - type: map
663
+ mapping:
664
+ "name":
665
+ ident: yes
666
+ "age":
667
+ type: int
668
+ #
669
+ valid: |
670
+ - name: foo
671
+ age: 10
672
+ - name: bar
673
+ age: 10
674
+ - name: baz
675
+ age: 10
676
+ #
677
+ invalid: |
678
+ - name: foo
679
+ age: 10
680
+ - name: bar
681
+ age: 10
682
+ - name: bar
683
+ age: 10
684
+ #
685
+ error: |
686
+ :value_notunique : (line 5)[/2/name] 'bar': is already used at '/1/name'.
687
+ #
688
+ ---
689
+ name: unique1
690
+ desc: unique constraint test with map
691
+ #
692
+ schema: |
693
+ type: seq
694
+ sequence:
695
+ - type: map
696
+ mapping:
697
+ "name":
698
+ unique: yes
699
+ "age":
700
+ type: int
701
+ #
702
+ valid: |
703
+ - name: foo
704
+ age: 10
705
+ - name: bar
706
+ age: 10
707
+ - name: baz
708
+ age: 10
709
+ #
710
+ invalid: |
711
+ - name: foo
712
+ age: 10
713
+ - name: bar
714
+ age: 10
715
+ - name: bar
716
+ age: 10
717
+ #
718
+ error: |
719
+ :value_notunique : (line 5)[/2/name] 'bar': is already used at '/1/name'.
720
+ #
721
+ ---
722
+ name: unique2
723
+ desc: unique constraint test with seq
724
+ #
725
+ schema: |
726
+ type: seq
727
+ sequence:
728
+ - type: str
729
+ unique: yes
730
+ #
731
+ valid: |
732
+ - foo
733
+ - ~
734
+ - bar
735
+ - ~
736
+ - baz
737
+ #
738
+ invalid: |
739
+ - foo
740
+ - ~
741
+ - bar
742
+ - ~
743
+ - bar
744
+ #
745
+ error: |
746
+ :value_notunique : (line 5)[/4] 'bar': is already used at '/2'.
747
+ #
748
+ ---
749
+ name: default1
750
+ desc: default value of map
751
+ #
752
+ schema: |
753
+ type: map
754
+ mapping:
755
+ =:
756
+ type: number
757
+ range: { min: -10, max: 10 }
758
+ #
759
+ valid: |
760
+ value1: 0
761
+ value2: 10
762
+ value3: -10
763
+ #
764
+ invalid: |
765
+ value1: 0
766
+ value2: 20
767
+ value3: -20
768
+ error: |
769
+ :range_toolarge : (line 2)[/value2] '20': too large (> max 10).
770
+ :range_toosmall : (line 3)[/value3] '-20': too small (< min -10).
771
+ ---
772
+ name: merge1
773
+ desc: merge maps
774
+ #
775
+ schema: |
776
+ type: map
777
+ mapping:
778
+ "group":
779
+ type: map
780
+ mapping:
781
+ "name": &name
782
+ type: str
783
+ required: yes
784
+ "email": &email
785
+ type: str
786
+ pattern: /@/
787
+ required: no
788
+ "user":
789
+ type: map
790
+ mapping:
791
+ "name":
792
+ <<: *name # merge
793
+ length: { max: 16 } # add
794
+ "email":
795
+ <<: *email # merge
796
+ required: yes # override
797
+ #
798
+ valid: |
799
+ group:
800
+ name: foo
801
+ email: foo@mail.com
802
+ user:
803
+ name: bar
804
+ email: bar@mail.com
805
+ #
806
+ invalid: |
807
+ group:
808
+ name: foo
809
+ email: foo@mail.com
810
+ user:
811
+ name: toooooo-looooong-naaaame
812
+ #
813
+ error: |
814
+ :required_nokey : (line 4)[/user] key 'email:' is required.
815
+ :length_toolong : (line 5)[/user/name] 'toooooo-looooong-naaaame': too long (length 24 > max 16).
816
+ #