dc-kwalify 0.7.2 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +1 -0
- data/contrib/kwalify +1 -1
- data/dc-kwalify.gemspec +27 -0
- data/lib/kwalify/main.rb +1 -1
- data/lib/kwalify/util/testcase-helper.rb +1 -1
- data/lib/kwalify/version.rb +5 -0
- data/lib/kwalify.rb +1 -7
- metadata +83 -203
- data/setup.rb +0 -1585
- data/test/Rookbook.yaml +0 -10
- data/test/data/users-guide/AddressBook.java.expected +0 -40
- data/test/data/users-guide/BABEL.data.yaml +0 -24
- data/test/data/users-guide/BABEL.schema.yaml +0 -30
- data/test/data/users-guide/ExampleAddressBook.java +0 -47
- data/test/data/users-guide/Group.java.expected +0 -24
- data/test/data/users-guide/Person.java.expected +0 -44
- data/test/data/users-guide/address_book.rb +0 -52
- data/test/data/users-guide/address_book.schema.yaml +0 -28
- data/test/data/users-guide/address_book.yaml +0 -27
- data/test/data/users-guide/answers-schema.yaml +0 -12
- data/test/data/users-guide/answers-validator.rb +0 -52
- data/test/data/users-guide/babel_genclass.result +0 -26
- data/test/data/users-guide/config.schema.yaml +0 -7
- data/test/data/users-guide/config.yaml +0 -4
- data/test/data/users-guide/document01a.yaml +0 -3
- data/test/data/users-guide/document01b.yaml +0 -3
- data/test/data/users-guide/document02a.yaml +0 -4
- data/test/data/users-guide/document02b.yaml +0 -4
- data/test/data/users-guide/document03a.yaml +0 -6
- data/test/data/users-guide/document03b.yaml +0 -6
- data/test/data/users-guide/document04a.yaml +0 -9
- data/test/data/users-guide/document04b.yaml +0 -9
- data/test/data/users-guide/document05a.yaml +0 -11
- data/test/data/users-guide/document05b.yaml +0 -12
- data/test/data/users-guide/document06a.yaml +0 -15
- data/test/data/users-guide/document06b.yaml +0 -16
- data/test/data/users-guide/document07a.yaml +0 -9
- data/test/data/users-guide/document07b.yaml +0 -7
- data/test/data/users-guide/document12a.json +0 -10
- data/test/data/users-guide/document12b.json +0 -6
- data/test/data/users-guide/document13a.yaml +0 -17
- data/test/data/users-guide/document14a.yaml +0 -3
- data/test/data/users-guide/document14b.yaml +0 -3
- data/test/data/users-guide/document15a.yaml +0 -6
- data/test/data/users-guide/document15b.yaml +0 -5
- data/test/data/users-guide/example_address_book.rb +0 -10
- data/test/data/users-guide/example_address_book_java.result +0 -32
- data/test/data/users-guide/example_address_book_ruby.result +0 -31
- data/test/data/users-guide/genclass_java.result +0 -4
- data/test/data/users-guide/howto-validation-with-parsing.rb +0 -28
- data/test/data/users-guide/howto-validation.rb +0 -25
- data/test/data/users-guide/howto3.rb +0 -6
- data/test/data/users-guide/howto3.result +0 -5
- data/test/data/users-guide/howto3.yaml +0 -8
- data/test/data/users-guide/howto5_databinding.result +0 -111
- data/test/data/users-guide/invalid01.result +0 -3
- data/test/data/users-guide/invalid02.result +0 -5
- data/test/data/users-guide/invalid03.result +0 -5
- data/test/data/users-guide/invalid04.result +0 -4
- data/test/data/users-guide/invalid05.result +0 -11
- data/test/data/users-guide/invalid06.result +0 -4
- data/test/data/users-guide/invalid07.result +0 -3
- data/test/data/users-guide/invalid08.result +0 -3
- data/test/data/users-guide/invalid12.json +0 -8
- data/test/data/users-guide/invalid14.result +0 -4
- data/test/data/users-guide/invalid15.result +0 -4
- data/test/data/users-guide/loadbabel.rb +0 -27
- data/test/data/users-guide/loadconfig.rb +0 -16
- data/test/data/users-guide/loadconfig.result +0 -6
- data/test/data/users-guide/models.rb +0 -22
- data/test/data/users-guide/option_ha.result +0 -6
- data/test/data/users-guide/option_ha_genclass_java.result +0 -7
- data/test/data/users-guide/schema01.yaml +0 -3
- data/test/data/users-guide/schema02.yaml +0 -12
- data/test/data/users-guide/schema03.yaml +0 -9
- data/test/data/users-guide/schema04.yaml +0 -20
- data/test/data/users-guide/schema05.yaml +0 -29
- data/test/data/users-guide/schema06.yaml +0 -11
- data/test/data/users-guide/schema12.json +0 -12
- data/test/data/users-guide/schema13.yaml +0 -13
- data/test/data/users-guide/schema14.yaml +0 -5
- data/test/data/users-guide/schema15.yaml +0 -21
- data/test/data/users-guide/valid01.result +0 -2
- data/test/data/users-guide/valid02.result +0 -2
- data/test/data/users-guide/valid03.result +0 -2
- data/test/data/users-guide/valid04.result +0 -2
- data/test/data/users-guide/valid05.result +0 -2
- data/test/data/users-guide/valid06.result +0 -2
- data/test/data/users-guide/valid07.result +0 -2
- data/test/data/users-guide/valid08.result +0 -2
- data/test/data/users-guide/valid12.result +0 -2
- data/test/data/users-guide/valid13.result +0 -2
- data/test/data/users-guide/valid14.result +0 -2
- data/test/data/users-guide/valid15.result +0 -2
- data/test/data/users-guide/validate08.rb +0 -37
- data/test/test-action.rb +0 -78
- data/test/test-action.yaml +0 -738
- data/test/test-databinding.rb +0 -83
- data/test/test-databinding.yaml +0 -339
- data/test/test-main.rb +0 -157
- data/test/test-main.yaml +0 -415
- data/test/test-metavalidator.rb +0 -80
- data/test/test-metavalidator.yaml +0 -1179
- data/test/test-parser-yaml.rb +0 -57
- data/test/test-parser-yaml.yaml +0 -1749
- data/test/test-rule.rb +0 -26
- data/test/test-rule.yaml +0 -317
- data/test/test-users-guide.rb +0 -75
- data/test/test-util.rb +0 -125
- data/test/test-validator.rb +0 -95
- data/test/test-validator.yaml +0 -986
- data/test/test-yaml-parser.rb +0 -47
- data/test/test-yaml-parser.yaml +0 -1226
- data/test/test.rb +0 -61
data/test/test-main.yaml
DELETED
@@ -1,415 +0,0 @@
|
|
1
|
-
##
|
2
|
-
## $Rev$
|
3
|
-
## $Release: 0.7.2 $
|
4
|
-
## copyright(c) 2005-2010 kuwata-lab all rights reserved.
|
5
|
-
##
|
6
|
-
---
|
7
|
-
- name: parseOptions1
|
8
|
-
desc: test Main#parseOptions()
|
9
|
-
method: parseOptions
|
10
|
-
args: [ -hvsmtlEDf, schema.yaml, -a, gemclass-ruby, -Ipath/to/dir, document.yaml, document2.yaml ]
|
11
|
-
expected: |
|
12
|
-
command: kwalify
|
13
|
-
options:
|
14
|
-
- action: gemclass-ruby
|
15
|
-
- debug: true
|
16
|
-
- emacs: true
|
17
|
-
- help: true
|
18
|
-
- linenum: true
|
19
|
-
- meta: true
|
20
|
-
- quiet: true
|
21
|
-
- schema: schema.yaml
|
22
|
-
- tpath: path/to/dir
|
23
|
-
- untabify: true
|
24
|
-
- version: true
|
25
|
-
properties:
|
26
|
-
filenames:
|
27
|
-
- document.yaml
|
28
|
-
- document2.yaml
|
29
|
-
##
|
30
|
-
- name: parseOptions2
|
31
|
-
desc: -ffilename
|
32
|
-
method: parseOptions
|
33
|
-
args: [ -lfschema.yaml, -hagenclass-ruby, -I/path/to/dir]
|
34
|
-
expected: |
|
35
|
-
command: kwalify
|
36
|
-
options:
|
37
|
-
- action: genclass-ruby
|
38
|
-
- help: true
|
39
|
-
- linenum: true
|
40
|
-
- schema: schema.yaml
|
41
|
-
- tpath: /path/to/dir
|
42
|
-
properties:
|
43
|
-
filenames:
|
44
|
-
##
|
45
|
-
- name: parseOptions3
|
46
|
-
desc: "'--help' is equal to '-h'"
|
47
|
-
method: parseOptions
|
48
|
-
args: [ --help, document.yaml ]
|
49
|
-
expected: |
|
50
|
-
command: kwalify
|
51
|
-
options:
|
52
|
-
- help: true
|
53
|
-
properties:
|
54
|
-
- help: true
|
55
|
-
filenames:
|
56
|
-
- document.yaml
|
57
|
-
##
|
58
|
-
- name: parseOptions4
|
59
|
-
desc: "'-E' turns on '-l'"
|
60
|
-
method: parseOptions
|
61
|
-
args: [ -E, document.yaml ]
|
62
|
-
expected: |
|
63
|
-
command: kwalify
|
64
|
-
options:
|
65
|
-
- emacs: true
|
66
|
-
- linenum: true
|
67
|
-
properties:
|
68
|
-
filenames:
|
69
|
-
- document.yaml
|
70
|
-
##
|
71
|
-
---
|
72
|
-
- name: optionError1
|
73
|
-
desc: invalid command-line option
|
74
|
-
method: parseOptions
|
75
|
-
args: [ -hvi ]
|
76
|
-
inspect: '*'
|
77
|
-
exception*:
|
78
|
-
ruby: CommandOptionError
|
79
|
-
java: CommandOptionException
|
80
|
-
message: "-i: invalid command option."
|
81
|
-
error_symbol*:
|
82
|
-
ruby: !ruby/sym :command_option_invalid
|
83
|
-
java: command.option.invalid
|
84
|
-
##
|
85
|
-
- name: optionError2
|
86
|
-
desc: no argument of '-f'
|
87
|
-
method: parseOptions
|
88
|
-
args: [ -f ]
|
89
|
-
inspect: '*'
|
90
|
-
exception*:
|
91
|
-
ruby: CommandOptionError
|
92
|
-
java: CommandOptionException
|
93
|
-
message: "-f: schema filename is required."
|
94
|
-
error_symbol*:
|
95
|
-
ruby: !ruby/sym :command_option_schema_required
|
96
|
-
java: command.option.noschema
|
97
|
-
####
|
98
|
-
##name: optionError3
|
99
|
-
##desc: invalid property
|
100
|
-
##method: parseOptions
|
101
|
-
##args: [ --foo@var ]
|
102
|
-
##inspect: '*'
|
103
|
-
##exception*:
|
104
|
-
## ruby: CommandOptionError
|
105
|
-
## #java: CommandOptionException
|
106
|
-
##message: "'--foo@var': invalid property."
|
107
|
-
##error_symbol*:
|
108
|
-
## ruby: !ruby/sym :command_property_invalid
|
109
|
-
## #java: command.property.invalid
|
110
|
-
#
|
111
|
-
|
112
|
-
##
|
113
|
-
- name: optionError4
|
114
|
-
desc: action required
|
115
|
-
method: execute
|
116
|
-
args: [ document.yaml ]
|
117
|
-
inspect: '*'
|
118
|
-
expected: |
|
119
|
-
exception*:
|
120
|
-
ruby: CommandOptionError
|
121
|
-
java: CommandOptionException
|
122
|
-
message: "command-line option '-f' or '-m' required."
|
123
|
-
error_symbol*:
|
124
|
-
ruby: !ruby/sym :command_option_noschema
|
125
|
-
java: command.option.noaction
|
126
|
-
##
|
127
|
-
---
|
128
|
-
- name: version # -v
|
129
|
-
desc: option '-v'
|
130
|
-
method: execute
|
131
|
-
args: [ -vt, document.yaml ]
|
132
|
-
expected: |
|
133
|
-
0.0.0
|
134
|
-
##
|
135
|
-
- name: help # -h
|
136
|
-
desc: option '-h'
|
137
|
-
method: execute
|
138
|
-
args: [ -hD, document.yaml ]
|
139
|
-
expected: |
|
140
|
-
kwalify - schema validator and data binding tool for YAML and JSON
|
141
|
-
## Usage1: validate yaml document
|
142
|
-
kwalify [..options..] -f schema.yaml doc.yaml [doc2.yaml ...]
|
143
|
-
## Usage2: validate schema definition
|
144
|
-
kwalify [..options..] -m schema.yaml [schema2.yaml ...]
|
145
|
-
## Usage3: do action
|
146
|
-
kwalify [..options..] -a action -f schema.yaml [schema2.yaml ...]
|
147
|
-
-h, --help : help
|
148
|
-
-v : version
|
149
|
-
-q : quiet
|
150
|
-
-s : silent (obsolete, use '-q' instead)
|
151
|
-
-f schema.yaml : schema definition file
|
152
|
-
-m : meta-validation mode
|
153
|
-
-t : expand tab characters
|
154
|
-
-l : show linenumber when errored (experimental)
|
155
|
-
-E : show errors in emacs-style (experimental, implies '-l')
|
156
|
-
-a action : action ('genclass-ruby', 'genclass-php', 'genclass-java')
|
157
|
-
(try '-ha genclass-ruby' for details)
|
158
|
-
-I path : template path (for '-a')
|
159
|
-
-P : allow preceding alias
|
160
|
-
##
|
161
|
-
- name: quiet1 # -q
|
162
|
-
desc: option '-q' (valid)
|
163
|
-
method: execute
|
164
|
-
args: [ -qf, quiet1.schema, quiet1.document ]
|
165
|
-
expected: |
|
166
|
-
schema: &quiet1_schema |
|
167
|
-
type: seq
|
168
|
-
sequence:
|
169
|
-
- type: str
|
170
|
-
document: &quiet1_document |
|
171
|
-
- foo
|
172
|
-
- bar
|
173
|
-
- baz
|
174
|
-
##
|
175
|
-
- name: quiet2 # -s
|
176
|
-
desc: option '-s' (invalid)
|
177
|
-
method: execute
|
178
|
-
args: [ -sf, quiet2.schema, quiet2.document ]
|
179
|
-
expected: |
|
180
|
-
quiet2.document#1: INVALID
|
181
|
-
- [/1] '123': not a string.
|
182
|
-
- [/2] 'true': not a string.
|
183
|
-
schema: &quiet2_schema |
|
184
|
-
type: seq
|
185
|
-
sequence:
|
186
|
-
- type: str
|
187
|
-
document: &quiet2_document |
|
188
|
-
- foo
|
189
|
-
- bar
|
190
|
-
- baz
|
191
|
-
---
|
192
|
-
- foo
|
193
|
-
- 123
|
194
|
-
- true
|
195
|
-
##
|
196
|
-
- name: silent1 # -s
|
197
|
-
desc: option '-s' (valid)
|
198
|
-
method: execute
|
199
|
-
args: [ -sf, silent1.schema, silent1.document ]
|
200
|
-
expected: |
|
201
|
-
schema: *quiet1_schema
|
202
|
-
document: *quiet1_document
|
203
|
-
##
|
204
|
-
- name: silent2 # -s
|
205
|
-
desc: option '-s' (invalid)
|
206
|
-
method: execute
|
207
|
-
args: [ -sf, silent2.schema, silent2.document ]
|
208
|
-
expected: |
|
209
|
-
silent2.document#1: INVALID
|
210
|
-
- [/1] '123': not a string.
|
211
|
-
- [/2] 'true': not a string.
|
212
|
-
schema: *quiet2_schema
|
213
|
-
document: *quiet2_document
|
214
|
-
##
|
215
|
-
- name: untabify # -t
|
216
|
-
desc: option '-t'
|
217
|
-
method: execute
|
218
|
-
args: [ -tf, untabify.schema, untabify.document ]
|
219
|
-
expected: |
|
220
|
-
untabify.document#0: valid.
|
221
|
-
schema: |
|
222
|
-
type: seq
|
223
|
-
sequence:
|
224
|
-
- type: map
|
225
|
-
mapping:
|
226
|
-
"key":
|
227
|
-
type: text
|
228
|
-
required: yes
|
229
|
-
"value":
|
230
|
-
type: any
|
231
|
-
required: yes
|
232
|
-
document: |
|
233
|
-
#
|
234
|
-
- key: foo
|
235
|
-
value: 123
|
236
|
-
- key: bar
|
237
|
-
value: [a, b, c]
|
238
|
-
##
|
239
|
-
- name: stream
|
240
|
-
desc: stream document
|
241
|
-
method: validation
|
242
|
-
schema: |
|
243
|
-
type: seq
|
244
|
-
sequence:
|
245
|
-
- type: str
|
246
|
-
valid: |
|
247
|
-
---
|
248
|
-
- foo
|
249
|
-
- bar
|
250
|
-
- baz
|
251
|
-
---
|
252
|
-
- aaa
|
253
|
-
- bbb
|
254
|
-
- ccc
|
255
|
-
valid_out: |
|
256
|
-
stream.valid#0: valid.
|
257
|
-
stream.valid#1: valid.
|
258
|
-
invalid: |
|
259
|
-
---
|
260
|
-
- foo
|
261
|
-
- 123
|
262
|
-
- baz
|
263
|
-
---
|
264
|
-
- aaa
|
265
|
-
- bbb
|
266
|
-
- true
|
267
|
-
invalid_out: |
|
268
|
-
stream.invalid#0: INVALID
|
269
|
-
- (line 3) [/1] '123': not a string.
|
270
|
-
stream.invalid#1: INVALID
|
271
|
-
- (line 8) [/2] 'true': not a string.
|
272
|
-
##
|
273
|
-
- name: meta1 # -m
|
274
|
-
desc: meta validation (valid)
|
275
|
-
method: execute
|
276
|
-
args: [ -m, meta1.schema ]
|
277
|
-
schema: &meta1_schema |
|
278
|
-
type: seq
|
279
|
-
sequence:
|
280
|
-
- type: str
|
281
|
-
document: |
|
282
|
-
expected: &meta1_expected |
|
283
|
-
meta1.schema#0: valid.
|
284
|
-
##
|
285
|
-
- name: meta2 # -m
|
286
|
-
desc: meta validation (invalid)
|
287
|
-
method: execute
|
288
|
-
args: [ -m, meta2.schema ]
|
289
|
-
schema: |
|
290
|
-
type: map
|
291
|
-
sequence:
|
292
|
-
- type: str
|
293
|
-
document: |
|
294
|
-
expected: |
|
295
|
-
meta2.schema#0: INVALID
|
296
|
-
- [/] type 'map' requires 'mapping:'.
|
297
|
-
- [/] 'sequence:': not available with mapping.
|
298
|
-
##
|
299
|
-
- name: emacs # -E
|
300
|
-
desc: show errors in emacs style
|
301
|
-
method: execute
|
302
|
-
args: [ -Ef, emacs.schema, emacs.document ]
|
303
|
-
schema: |
|
304
|
-
type: seq
|
305
|
-
sequence:
|
306
|
-
- type: map
|
307
|
-
mapping:
|
308
|
-
"key": { type: str, required: yes }
|
309
|
-
"value": { type: any }
|
310
|
-
document: |
|
311
|
-
- key: one
|
312
|
-
value: 1
|
313
|
-
- key: 2
|
314
|
-
val: two
|
315
|
-
- kye: three
|
316
|
-
value:
|
317
|
-
expected: |
|
318
|
-
emacs.document#0: INVALID
|
319
|
-
emacs.document:3:3 [/1/key] '2': not a string.
|
320
|
-
emacs.document:4:3 [/1/val] key 'val:' is undefined.
|
321
|
-
emacs.document:5:3 [/2] key 'key:' is required.
|
322
|
-
emacs.document:5:3 [/2/kye] key 'kye:' is undefined.
|
323
|
-
##
|
324
|
-
- name: preceding1 # -P
|
325
|
-
desc: preceding anchor
|
326
|
-
method: execute
|
327
|
-
args: [ -Pf, preceding1.schema, preceding1.document ]
|
328
|
-
schema: &preceding1_schema |
|
329
|
-
type: map
|
330
|
-
mapping:
|
331
|
-
"groups":
|
332
|
-
type: seq
|
333
|
-
sequence:
|
334
|
-
- &GROUP
|
335
|
-
type: map
|
336
|
-
mapping:
|
337
|
-
"name": { type: str, required: yes }
|
338
|
-
"owner": *USER
|
339
|
-
"users":
|
340
|
-
type: seq
|
341
|
-
sequence:
|
342
|
-
- &USER
|
343
|
-
type: map
|
344
|
-
mapping:
|
345
|
-
"name": { type: str, required: yes }
|
346
|
-
"mail": { type: str }
|
347
|
-
"group": *GROUP
|
348
|
-
document: &preceding1_document |
|
349
|
-
groups:
|
350
|
-
- &WHEEL
|
351
|
-
name: wheel
|
352
|
-
owner: *root
|
353
|
-
- &GUEST
|
354
|
-
name: guest
|
355
|
-
owner: *root
|
356
|
-
- &USERS
|
357
|
-
name: users
|
358
|
-
owner: *user1
|
359
|
-
users:
|
360
|
-
- &root
|
361
|
-
name: root
|
362
|
-
mail: root@localhost
|
363
|
-
group: *WHEEL
|
364
|
-
- &user1
|
365
|
-
name: user1
|
366
|
-
mail: user1@localhost
|
367
|
-
group: *USERS
|
368
|
-
expected: |
|
369
|
-
preceding1.document#0: valid.
|
370
|
-
##
|
371
|
-
- name: preceding2 # -P
|
372
|
-
desc: preceding anchor
|
373
|
-
method: execute
|
374
|
-
args: [ -lf, preceding2.schema, preceding2.document ]
|
375
|
-
schema: *preceding1_schema
|
376
|
-
document: *preceding1_document
|
377
|
-
exception*:
|
378
|
-
ruby: Kwalify::SyntaxError
|
379
|
-
#java: kwalify.YamlSyntaxException
|
380
|
-
errormsg*:
|
381
|
-
ruby: "file: preceding2.schema, line 10: *USER: anchor not found."
|
382
|
-
#java: "*USER: anchor not found."
|
383
|
-
expected: |
|
384
|
-
##
|
385
|
-
---
|
386
|
-
- name: empty1
|
387
|
-
desc: ignore first empty document
|
388
|
-
method: execute
|
389
|
-
args: [ -f, empty1.schema, empty1.document ]
|
390
|
-
schema: |
|
391
|
-
type: map
|
392
|
-
mapping:
|
393
|
-
"name": { type: str }
|
394
|
-
document: |
|
395
|
-
---
|
396
|
-
name: Foo
|
397
|
-
expected: |
|
398
|
-
empty1.document#0: valid.
|
399
|
-
|
400
|
-
- name: empty2
|
401
|
-
desc: report 'empty.' when document is empty
|
402
|
-
method: execute
|
403
|
-
args: [ -f, empty2.schema, empty2.document ]
|
404
|
-
schema: |
|
405
|
-
type: map
|
406
|
-
mapping:
|
407
|
-
"name": { type: str }
|
408
|
-
document: |
|
409
|
-
---
|
410
|
-
name: Foo
|
411
|
-
---
|
412
|
-
expected: |
|
413
|
-
empty2.document#0: valid.
|
414
|
-
empty2.document#1: empty.
|
415
|
-
|
data/test/test-metavalidator.rb
DELETED
@@ -1,80 +0,0 @@
|
|
1
|
-
###
|
2
|
-
### $Rev$
|
3
|
-
### $Release: 0.7.2 $
|
4
|
-
### copyright(c) 2005-2010 kuwata-lab all rights reserved.
|
5
|
-
###
|
6
|
-
|
7
|
-
require File.dirname(__FILE__) + '/test.rb'
|
8
|
-
|
9
|
-
|
10
|
-
class MetaValidatorTest < Test::Unit::TestCase
|
11
|
-
|
12
|
-
## define test methods
|
13
|
-
filename = __FILE__.sub(/\.rb$/, '.yaml')
|
14
|
-
load_yaml_documents(filename) do |ydoc|
|
15
|
-
name = ydoc['name']
|
16
|
-
ydoc.each do |key, val|
|
17
|
-
ydoc[$1] = val['ruby'] if key =~ /(.*)\*$/
|
18
|
-
end
|
19
|
-
s = <<-END
|
20
|
-
def test_meta_#{name}
|
21
|
-
@name = #{ydoc['name'].inspect}
|
22
|
-
@desc = #{ydoc['desc'].inspect}
|
23
|
-
@schema = #{ydoc['schema'].inspect}
|
24
|
-
@meta_msg = #{ydoc['meta-msg'].inspect}
|
25
|
-
# @rule_msg = #{ydoc['rule-msg'].inspect}
|
26
|
-
@test_type = :meta
|
27
|
-
_test
|
28
|
-
end
|
29
|
-
END
|
30
|
-
module_eval s if ydoc['meta-msg']
|
31
|
-
s = <<-END
|
32
|
-
def test_rule_#{name}
|
33
|
-
@name = #{ydoc['name'].inspect}
|
34
|
-
@desc = #{ydoc['desc'].inspect}
|
35
|
-
@schema = #{ydoc['schema'].inspect}
|
36
|
-
# @meta_msg = #{ydoc['meta-msg'].inspect}
|
37
|
-
@rule_msg = #{ydoc['rule-msg'].inspect}
|
38
|
-
@test_type = :rule
|
39
|
-
_test
|
40
|
-
end
|
41
|
-
END
|
42
|
-
module_eval s if ydoc['rule-msg']
|
43
|
-
end
|
44
|
-
|
45
|
-
|
46
|
-
## execute test
|
47
|
-
def _test()
|
48
|
-
return if $target && $target != @name
|
49
|
-
#schema = YAML.load(@schema)
|
50
|
-
parser = Kwalify::YamlParser.new(@schema)
|
51
|
-
schema = parser.parse()
|
52
|
-
case @test_type
|
53
|
-
when :meta
|
54
|
-
meta_validator = Kwalify::MetaValidator.instance()
|
55
|
-
errors = meta_validator.validate(schema)
|
56
|
-
parser.set_errors_linenum(errors)
|
57
|
-
errors.sort!
|
58
|
-
expected = @meta_msg
|
59
|
-
when :rule
|
60
|
-
errors = []
|
61
|
-
begin
|
62
|
-
rule = Kwalify::Validator.new(schema)
|
63
|
-
rescue Kwalify::KwalifyError => error
|
64
|
-
errors << error
|
65
|
-
end
|
66
|
-
expected = @rule_msg
|
67
|
-
end
|
68
|
-
actual = ''
|
69
|
-
errors.each do |error|
|
70
|
-
raise error if error.is_a?(Kwalify::AssertionError)
|
71
|
-
actual << "%-20s: [%s] %s\n" % [error.error_symbol.inspect, error.path, error.message]
|
72
|
-
end
|
73
|
-
if $print
|
74
|
-
print actual
|
75
|
-
else
|
76
|
-
assert_text_equal(expected, actual)
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
end
|