kwalify 0.5.1 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (109) hide show
  1. data/ChangeLog +24 -19
  2. data/README.txt +51 -51
  3. data/bin/kwalify +2 -2
  4. data/contrib/inline-require +151 -0
  5. data/contrib/kwalify +2850 -0
  6. data/doc-api/classes/CommandOptionError.html +184 -0
  7. data/doc-api/classes/CommandOptionParser.html +325 -0
  8. data/doc-api/classes/Kwalify.html +270 -0
  9. data/doc-api/classes/Kwalify/AssertionError.html +148 -0
  10. data/doc-api/classes/Kwalify/BaseError.html +296 -0
  11. data/doc-api/classes/Kwalify/CommandOptionError.html +168 -0
  12. data/doc-api/classes/Kwalify/ErrorHelper.html +218 -0
  13. data/doc-api/classes/Kwalify/HashInterface.html +240 -0
  14. data/doc-api/classes/Kwalify/KwalifyError.html +111 -0
  15. data/doc-api/classes/Kwalify/Main.html +336 -0
  16. data/doc-api/classes/Kwalify/MetaValidator.html +432 -0
  17. data/doc-api/classes/Kwalify/Parser.html +155 -0
  18. data/doc-api/classes/Kwalify/PlainYamlParser.html +520 -0
  19. data/doc-api/classes/Kwalify/PlainYamlParser/Alias.html +165 -0
  20. data/doc-api/classes/Kwalify/Rule.html +411 -0
  21. data/doc-api/classes/Kwalify/SchemaError.html +148 -0
  22. data/doc-api/classes/Kwalify/Types.html +301 -0
  23. data/doc-api/classes/Kwalify/ValidationError.html +148 -0
  24. data/doc-api/classes/Kwalify/Validator.html +311 -0
  25. data/doc-api/classes/Kwalify/YamlParser.html +535 -0
  26. data/doc-api/classes/Kwalify/YamlSyntaxError.html +168 -0
  27. data/doc-api/classes/Test.html +107 -0
  28. data/doc-api/classes/Test/Unit.html +101 -0
  29. data/doc-api/classes/YamlHelper.html +259 -0
  30. data/doc-api/created.rid +1 -0
  31. data/doc-api/files/__/README_txt.html +179 -0
  32. data/doc-api/files/kwalify/errors_rb.html +114 -0
  33. data/doc-api/files/kwalify/main_rb.html +117 -0
  34. data/doc-api/files/kwalify/messages_rb.html +107 -0
  35. data/doc-api/files/kwalify/meta-validator_rb.html +117 -0
  36. data/doc-api/files/kwalify/rule_rb.html +116 -0
  37. data/doc-api/files/kwalify/types_rb.html +114 -0
  38. data/doc-api/files/kwalify/util/assert-text-equal_rb.html +115 -0
  39. data/doc-api/files/kwalify/util/hash-interface_rb.html +107 -0
  40. data/doc-api/files/kwalify/util/option-parser_rb.html +107 -0
  41. data/doc-api/files/kwalify/util/testcase-helper_rb.html +115 -0
  42. data/doc-api/files/kwalify/util/yaml-helper_rb.html +114 -0
  43. data/doc-api/files/kwalify/validator_rb.html +117 -0
  44. data/doc-api/files/kwalify/yaml-parser_rb.html +117 -0
  45. data/doc-api/files/kwalify_rb.html +120 -0
  46. data/doc-api/fr_class_index.html +50 -0
  47. data/doc-api/fr_file_index.html +41 -0
  48. data/doc-api/fr_method_index.html +109 -0
  49. data/doc-api/index.html +24 -0
  50. data/doc-api/rdoc-style.css +208 -0
  51. data/doc/users-guide.html +693 -193
  52. data/examples/address-book/Makefile +5 -0
  53. data/examples/address-book/address-book.schema.yaml +2 -1
  54. data/examples/invoice/Makefile +5 -0
  55. data/examples/invoice/invoice.schema.yaml +3 -2
  56. data/examples/tapkit/Makefile +5 -0
  57. data/examples/tapkit/main.rb +7 -0
  58. data/examples/tapkit/tapkit.schema.yaml +6 -1
  59. data/lib/kwalify.rb +3 -3
  60. data/lib/kwalify/errors.rb +2 -2
  61. data/lib/kwalify/main.rb +161 -84
  62. data/lib/kwalify/messages.rb +17 -11
  63. data/lib/kwalify/meta-validator.rb +11 -2
  64. data/lib/kwalify/rule.rb +13 -3
  65. data/lib/kwalify/templates/genclass-java.eruby +195 -0
  66. data/lib/kwalify/templates/genclass-ruby.eruby +84 -0
  67. data/lib/kwalify/types.rb +18 -18
  68. data/lib/kwalify/util/assert-text-equal.rb +44 -0
  69. data/lib/kwalify/util/hash-interface.rb +37 -0
  70. data/lib/kwalify/util/option-parser.rb +2 -2
  71. data/lib/kwalify/util/testcase-helper.rb +112 -0
  72. data/lib/kwalify/util/yaml-helper.rb +2 -2
  73. data/lib/kwalify/validator.rb +2 -2
  74. data/lib/kwalify/yaml-parser.rb +12 -9
  75. data/test/test-main.rb +77 -78
  76. data/test/test-main.yaml +543 -769
  77. data/test/test-metavalidator.rb +27 -47
  78. data/test/test-metavalidator.yaml +21 -2
  79. data/test/test-rule.rb +6 -39
  80. data/test/test-rule.yaml +2 -2
  81. data/test/test-validator.rb +36 -869
  82. data/test/test-validator.yaml +28 -20
  83. data/test/test-yamlparser.rb +30 -1248
  84. data/test/test-yamlparser.yaml +138 -110
  85. data/test/test.rb +33 -13
  86. data/test/tmp.dir/Context.java +40 -0
  87. data/test/tmp.dir/Group.java +33 -0
  88. data/test/tmp.dir/User.java +43 -0
  89. data/test/tmp.dir/action1.document +18 -0
  90. data/test/tmp.dir/action1.schema +32 -0
  91. data/test/tmp.dir/action2.document +18 -0
  92. data/test/tmp.dir/action2.schema +32 -0
  93. data/test/tmp.dir/emacs.document +6 -0
  94. data/test/tmp.dir/emacs.schema +6 -0
  95. data/test/tmp.dir/meta1.document +0 -0
  96. data/test/tmp.dir/meta1.schema +3 -0
  97. data/test/tmp.dir/meta2.document +0 -0
  98. data/test/tmp.dir/meta2.schema +3 -0
  99. data/test/tmp.dir/silent1.document +3 -0
  100. data/test/tmp.dir/silent1.schema +3 -0
  101. data/test/tmp.dir/silent2.document +7 -0
  102. data/test/tmp.dir/silent2.schema +3 -0
  103. data/test/tmp.dir/stream.invalid +8 -0
  104. data/test/tmp.dir/stream.schema +3 -0
  105. data/test/tmp.dir/stream.valid +8 -0
  106. data/test/tmp.dir/untabify.document +5 -0
  107. data/test/tmp.dir/untabify.schema +10 -0
  108. metadata +98 -12
  109. data/lib/kwalify/util/assert-diff.rb +0 -44
@@ -1,118 +1,104 @@
1
1
  ##
2
- ## $Rev: 44 $
3
- ## $Release: 0.5.1 $
2
+ ## $Rev: 51 $
3
+ ## $Release: 0.6.0 $
4
4
  ## copyright(c) 2005 kuwata-lab all rights reserved.
5
5
  ##
6
6
  ---
7
- name: parseOptions1
8
- desc: test Main#parseOptions()
9
- method: parseOptions
10
- args: [ -hvsmtlEDf, schema.yaml, document.yaml, document2.yaml ]
11
- inspect: |
12
- command : kwalify
13
- flag_help : true
14
- flag_version : true
15
- flag_silent : true
16
- flag_meta : true
17
- flag_untabify : true
18
- flag_emacs : true
19
- flag_linenum : true
20
- flag_debug : true
21
- schema_filename : schema.yaml
22
- properties:
23
- filenames:
24
- - document.yaml
25
- - document2.yaml
26
- #
27
- ---
28
- name: parseOptions2
29
- desc: -ffilename
30
- method: parseOptions
31
- args: [ -lfschema.yaml]
32
- inspect: |
33
- command : kwalify
34
- flag_help : false
35
- flag_version : false
36
- flag_silent : false
37
- flag_meta : false
38
- flag_untabify : false
39
- flag_emacs : false
40
- flag_linenum : true
41
- flag_debug : false
42
- schema_filename : schema.yaml
43
- properties:
44
- filenames:
45
- #
46
- ---
47
- name: parseOptions3
48
- desc: "'--help' is equal to '-h'"
49
- method: parseOptions
50
- args: [ --help, document.yaml ]
51
- inspect: |
52
- command : kwalify
53
- flag_help : true
54
- flag_version : false
55
- flag_silent : false
56
- flag_meta : false
57
- flag_untabify : false
58
- flag_emacs : false
59
- flag_linenum : false
60
- flag_debug : false
61
- schema_filename : null
62
- properties:
63
- help: true
64
- filenames:
65
- - document.yaml
66
- #
67
- ---
68
- name: parseOptions4
69
- desc: "'-E' turns on '-l'"
70
- method: parseOptions
71
- args: [ -E, document.yaml ]
72
- inspect: |
73
- command : kwalify
74
- flag_help : false
75
- flag_version : false
76
- flag_silent : false
77
- flag_meta : false
78
- flag_untabify : false
79
- flag_emacs : true
80
- flag_linenum : true
81
- flag_debug : false
82
- schema_filename : null
83
- properties:
84
- filenames:
85
- - document.yaml
86
- #
87
- ---
88
- name: optionError1
89
- desc: invalid command-line option
90
- method: parseOptions
91
- args: [ -hvi ]
92
- inspect: '*'
93
- exception*:
94
- ruby: CommandOptionError
95
- java: CommandOptionException
96
- message: "-i: invalid command option."
97
- error_symbol*:
98
- ruby: !ruby/sym :command_option_invalid
99
- java: command.option.invalid
100
- #
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
+ - schema: schema.yaml
21
+ - silent: true
22
+ - tpath: path/to/dir
23
+ - untabify: true
24
+ - version: true
25
+ properties:
26
+ filenames:
27
+ - document.yaml
28
+ - document2.yaml
29
+
30
+ ##
31
+ - name: parseOptions2
32
+ desc: -ffilename
33
+ method: parseOptions
34
+ args: [ -lfschema.yaml, -hagenclass-ruby, -I/path/to/dir]
35
+ expected: |
36
+ command: kwalify
37
+ options:
38
+ - action: genclass-ruby
39
+ - help: true
40
+ - linenum: true
41
+ - schema: schema.yaml
42
+ - tpath: /path/to/dir
43
+ properties:
44
+ filenames:
45
+
46
+ ##
47
+ - name: parseOptions3
48
+ desc: "'--help' is equal to '-h'"
49
+ method: parseOptions
50
+ args: [ --help, document.yaml ]
51
+ expected: |
52
+ command: kwalify
53
+ options:
54
+ - help: true
55
+ properties:
56
+ - help: true
57
+ filenames:
58
+ - document.yaml
59
+
60
+ ##
61
+ - name: parseOptions4
62
+ desc: "'-E' turns on '-l'"
63
+ method: parseOptions
64
+ args: [ -E, document.yaml ]
65
+ expected: |
66
+ command: kwalify
67
+ options:
68
+ - emacs: true
69
+ - linenum: true
70
+ properties:
71
+ filenames:
72
+ - document.yaml
73
+
74
+ ##
101
75
  ---
102
- name: optionError2
103
- desc: no argument of '-f'
104
- method: parseOptions
105
- args: [ -f ]
106
- inspect: '*'
107
- exception*:
108
- ruby: CommandOptionError
109
- java: CommandOptionException
110
- message: "-f: schema filename is required."
111
- error_symbol*:
112
- ruby: !ruby/sym :command_option_noschema
113
- java: command.option.noschema
114
- #
115
- ##---
76
+ - name: optionError1
77
+ desc: invalid command-line option
78
+ method: parseOptions
79
+ args: [ -hvi ]
80
+ inspect: '*'
81
+ exception*:
82
+ ruby: CommandOptionError
83
+ java: CommandOptionException
84
+ message: "-i: invalid command option."
85
+ error_symbol*:
86
+ ruby: !ruby/sym :command_option_invalid
87
+ java: command.option.invalid
88
+ ##
89
+ - name: optionError2
90
+ desc: no argument of '-f'
91
+ method: parseOptions
92
+ args: [ -f ]
93
+ inspect: '*'
94
+ exception*:
95
+ ruby: CommandOptionError
96
+ java: CommandOptionException
97
+ message: "-f: schema filename is required."
98
+ error_symbol*:
99
+ ruby: !ruby/sym :command_option_noschema
100
+ java: command.option.noschema
101
+ ####
116
102
  ##name: optionError3
117
103
  ##desc: invalid property
118
104
  ##method: parseOptions
@@ -125,91 +111,96 @@ error_symbol*:
125
111
  ##error_symbol*:
126
112
  ## ruby: !ruby/sym :command_property_invalid
127
113
  ## #java: command.property.invalid
128
- ---
129
- name: optionError4
130
- desc: action required
131
- method: execute
132
- args: [ document.yaml ]
133
- inspect: '*'
134
- expected: |
135
- exception*:
136
- ruby: CommandOptionError
137
- java: CommandOptionException
138
- message: "command-line option '-f' or '-m' required."
139
- error_symbol*:
140
- ruby: !ruby/sym :command_option_noschema
141
- java: command.option.noaction
142
- #
143
- ---
144
- name: version
145
- desc: option '-v'
146
- method: execute
147
- args: [ -vt, document.yaml ]
148
- expected: |
149
- 0.0.0
150
- #
151
- ---
152
- name: help
153
- desc: option '-h'
154
- method: execute
155
- args: [ -hD, document.yaml ]
156
- expected: |
157
- Usage1: kwalify [-hvstlE] -f schema.yaml doc.yaml [doc2.yaml ...]
158
- Usage2: kwalify [-hvstlE] -m schema.yaml [schema2.yaml ...]
159
- -h, --help : help
160
- -v : version
161
- -s : silent
162
- -f schema.yaml : schema definition file
163
- -m : meta-validation mode
164
- -t : expand tab character automatically
165
- -l : show linenumber when errored (experimental)
166
- -E : show errors in emacs-style (implies '-l')
167
- #
168
- ---
169
- name: silent1
170
- desc: option '-s' (valid)
171
- method: execute
172
- args: [ -sf, silent1.schema, silent1.document ]
173
- expected: |
174
- schema: |
175
- type: seq
176
- sequence:
177
- - type: str
178
- document: |
179
- - foo
180
- - bar
181
- - baz
182
- #
183
- ---
184
- name: silent2
185
- desc: option '-s' (invalid)
186
- method: execute
187
- args: [ -sf, silent2.schema, silent2.document ]
188
- expected: |
189
- silent2.document#1: INVALID
190
- - [/1] '123': not a string.
191
- - [/2] 'true': not a string.
192
- schema: |
193
- type: seq
194
- sequence:
195
- - type: str
196
- document: |
197
- - foo
198
- - bar
199
- - baz
200
- ---
201
- - foo
202
- - 123
203
- - true
204
114
  #
115
+
116
+ ##
117
+ - name: optionError4
118
+ desc: action required
119
+ method: execute
120
+ args: [ document.yaml ]
121
+ inspect: '*'
122
+ expected: |
123
+ exception*:
124
+ ruby: CommandOptionError
125
+ java: CommandOptionException
126
+ message: "command-line option '-f' or '-m' required."
127
+ error_symbol*:
128
+ ruby: !ruby/sym :command_option_noschema
129
+ java: command.option.noaction
130
+ ##
205
131
  ---
206
- name: untabify
207
- desc: option '-t'
208
- method: execute
209
- args: [ -tf, untabify.schema, untabify.document ]
210
- expected: |
211
- untabify.document#0: valid.
212
- schema: |
132
+ - name: version
133
+ desc: option '-v'
134
+ method: execute
135
+ args: [ -vt, document.yaml ]
136
+ expected: |
137
+ 0.0.0
138
+
139
+ ##
140
+ - name: help
141
+ desc: option '-h'
142
+ method: execute
143
+ args: [ -hD, document.yaml ]
144
+ expected: |
145
+ kwalify - tiny schema validator for YAML and JSON
146
+ Usage1: kwalify [..options..] -f schema.yaml doc.yaml [doc2.yaml ...]
147
+ Usage2: kwalify [..options..] -m schema.yaml [schema2.yaml ...]
148
+ Usage3: kwalify [..options..] -a action -f schema.yaml [schema2.yaml ...]
149
+ -h, --help : help
150
+ -v : version
151
+ -s : silent
152
+ -f schema.yaml : schema definition file
153
+ -m : meta-validation mode
154
+ -t : expand tab characters
155
+ -l : show linenumber when errored (experimental)
156
+ -E : show errors in emacs-style (implies '-l')
157
+ -a action : action ('genclass-ruby' or 'genclass-java')
158
+ (use '-ha action' option to show action properites)
159
+ ##
160
+ - name: silent1
161
+ desc: option '-s' (valid)
162
+ method: execute
163
+ args: [ -sf, silent1.schema, silent1.document ]
164
+ expected: |
165
+ schema: |
166
+ type: seq
167
+ sequence:
168
+ - type: str
169
+ document: |
170
+ - foo
171
+ - bar
172
+ - baz
173
+
174
+ ##
175
+ - name: silent2
176
+ desc: option '-s' (invalid)
177
+ method: execute
178
+ args: [ -sf, silent2.schema, silent2.document ]
179
+ expected: |
180
+ silent2.document#1: INVALID
181
+ - [/1] '123': not a string.
182
+ - [/2] 'true': not a string.
183
+ schema: |
184
+ type: seq
185
+ sequence:
186
+ - type: str
187
+ document: |
188
+ - foo
189
+ - bar
190
+ - baz
191
+ ---
192
+ - foo
193
+ - 123
194
+ - true
195
+
196
+ ##
197
+ - name: untabify
198
+ desc: option '-t'
199
+ method: execute
200
+ args: [ -tf, untabify.schema, untabify.document ]
201
+ expected: |
202
+ untabify.document#0: valid.
203
+ schema: |
213
204
  type: seq
214
205
  sequence:
215
206
  - type: map
@@ -220,586 +211,369 @@ schema: |
220
211
  "value":
221
212
  type: any
222
213
  required: yes
223
- document: |
214
+ document: |
224
215
  #
225
216
  - key: foo
226
217
  value: 123
227
218
  - key: bar
228
219
  value: [a, b, c]
229
- #
230
- ---
231
- name: stream
232
- desc: stream document
233
- method: validation
234
- schema: |
235
- type: seq
236
- sequence:
237
- - type: str
238
- valid: |
239
- ---
240
- - foo
241
- - bar
242
- - baz
243
- ---
244
- - aaa
245
- - bbb
246
- - ccc
247
- valid-out: |
248
- stream.valid#0: valid.
249
- stream.valid#1: valid.
250
- invalid: |
251
- ---
252
- - foo
253
- - 123
254
- - baz
255
- ---
256
- - aaa
257
- - bbb
258
- - true
259
- invalid-out: |
260
- stream.invalid#0: INVALID
261
- - (line 3) [/1] '123': not a string.
262
- stream.invalid#1: INVALID
263
- - (line 8) [/2] 'true': not a string.
264
- #
265
- ---
266
- name: meta1
267
- desc: meta validation (valid)
268
- method: execute
269
- args: [ -m, meta1.schema ]
270
- schema: |
271
- type: seq
272
- sequence:
273
- - type: str
274
- document: |
275
- expected: |
276
- meta1.schema#0: valid.
277
- #
278
- ---
279
- name: meta2
280
- desc: meta validation (invalid)
281
- method: execute
282
- args: [ -m, meta2.schema ]
283
- schema: |
284
- type: map
285
- sequence:
286
- - type: str
287
- document: |
288
- expected: |
289
- meta2.schema#0: INVALID
290
- - [/] type 'map' requires 'mapping:'.
291
- - [/] 'sequence:': not available with mapping.
292
- #
293
- ---
294
- name: emacs
295
- desc: show errors in emacs style
296
- method: execute
297
- args: [ -Ef, emacs.schema, emacs.document ]
298
- schema: |
299
- type: seq
300
- sequence:
301
- - type: map
302
- mapping:
303
- "key": { type: str, required: yes }
304
- "value": { type: any }
305
- document: |
306
- - key: one
307
- value: 1
308
- - key: 2
309
- val: two
310
- - kye: three
311
- value:
312
- expected: |
313
- emacs.document#0: INVALID
314
- emacs.document:3: [/1/key] '2': not a string.
315
- emacs.document:4: [/1/val] key 'val:' is undefined.
316
- emacs.document:5: [/2] key 'key:' is required.
317
- emacs.document:5: [/2/kye] key 'kye:' is undefined.
318
- #
319
220
 
320
- ###
321
- ### user's guide
322
- ###
323
- ---
324
- name: validation01
325
- desc: basic validation
326
- method: validation
327
- schema: |
328
- type: seq
329
- sequence:
330
- - type: str
331
- valid: |
332
- - foo
333
- - bar
334
- - baz
335
- valid-out: |
336
- validation01.valid#0: valid.
337
- invalid: |
338
- - foo
339
- - 123
340
- - baz
341
- invalid-out: |
342
- validation01.invalid#0: INVALID
343
- - (line 2) [/1] '123': not a string.
344
- #
345
- ---
346
- name: validation02
347
- desc: basic validation
348
- method: validation
349
- schema: |
350
- type: map
351
- mapping:
352
- name:
353
- type: str
354
- required: yes
355
- email:
356
- type: str
357
- pattern: /@/
358
- age:
359
- type: int
360
- birth:
361
- type: date
362
- valid: |
363
- name: foo
364
- email: foo@mail.com
365
- age: 20
366
- birth: 1985-01-01
367
- valid-out: |
368
- validation02.valid#0: valid.
369
- invalid: |
370
- name: foo
371
- email: foo(at)mail.com
372
- age: twenty
373
- birth: Jun 01, 1985
374
- invalid-out: |
375
- validation02.invalid#0: INVALID
376
- - (line 2) [/email] 'foo(at)mail.com': not matched to pattern /@/.
377
- - (line 3) [/age] 'twenty': not a integer.
378
- - (line 4) [/birth] 'Jun 01, 1985': not a date.
379
- #
380
- ---
381
- name: validation03
382
- desc: sequence of mapping
383
- method: validation
384
- schema: |
385
- type: seq
386
- sequence:
387
- - type: map
388
- mapping:
389
- name:
390
- type: str
391
- required: true
392
- email:
393
- type: str
394
- valid: |
395
- - name: foo
396
- email: foo@mail.com
397
- - name: bar
398
- email: bar@mail.net
399
- - name: baz
400
- email: baz@mail.org
401
- valid-out: |
402
- validation03.valid#0: valid.
403
- invalid: |
404
- - name: foo
405
- email: foo@mail.com
406
- - naem: bar
407
- email: bar@mail.net
408
- - name: baz
409
- mail: baz@mail.org
410
- invalid-out: |
411
- validation03.invalid#0: INVALID
412
- - (line 3) [/1] key 'name:' is required.
413
- - (line 3) [/1/naem] key 'naem:' is undefined.
414
- - (line 6) [/2/mail] key 'mail:' is undefined.
415
- #
416
- ---
417
- name: validation04
418
- desc: mapping of sequence
419
- method: validation
420
- schema: |
421
- type: map
422
- mapping:
423
- company:
424
- type: str
425
- required: yes
426
- email:
427
- type: str
428
- employees:
429
- type: seq
430
- sequence:
431
- - type: map
432
- mapping:
433
- code:
434
- type: int
435
- required: yes
436
- name:
437
- type: str
438
- required: yes
439
- email:
440
- type: str
441
- valid: |
442
- company: Kuwata lab.
443
- email: webmaster@kuwata-lab.com
444
- employees:
445
- - code: 101
446
- name: foo
447
- email: foo@kuwata-lab.com
448
- - code: 102
449
- name: bar
450
- email: bar@kuwata-lab.com
451
- valid-out: |
452
- validation04.valid#0: valid.
453
- invalid: |
454
- company: Kuwata Lab.
455
- email: webmaster@kuwata-lab.com
456
- employees:
457
- - code: A101
458
- name: foo
459
- email: foo@kuwata-lab.com
460
- - code: 102
461
- name: bar
462
- mail: bar@kuwata-lab.com
463
- invalid-out: |
464
- validation04.invalid#0: INVALID
465
- - (line 4) [/employees/0/code] 'A101': not a integer.
466
- - (line 9) [/employees/1/mail] key 'mail:' is undefined.
467
- #
468
- ---
469
- name: validation05
470
- desc: rule and entry
471
- method: validation
472
- schema: |
473
- type: seq # new rule
474
- sequence:
475
- -
476
- type: map # new rule
477
- mapping:
478
- name:
479
- type: str # new rule
480
- required: yes
481
- email:
482
- type: str # new rule
483
- required: yes
484
- pattern: /@/
485
- password:
486
- type: str # new rule
487
- length: { max: 16, min: 8 }
488
- age:
489
- type: int # new rule
490
- range: { max: 30, min: 18 }
491
- # or assert: 18 <= val && val <= 30
492
- blood:
493
- type: str # new rule
494
- enum:
495
- - A
496
- - B
497
- - O
498
- - AB
499
- birth:
500
- type: date # new rule
501
- memo:
502
- type: any # new rule
503
- valid: |
504
- - name: foo
505
- email: foo@mail.com
506
- password: xxx123456
507
- age: 20
508
- blood: A
509
- birth: 1985-01-01
510
- - name: bar
511
- email: bar@mail.net
512
- age: 25
513
- blood: AB
514
- birth: 1980-01-01
515
- valid-out: |
516
- validation05.valid#0: valid.
517
- invalid: |
518
- - name: foo
519
- email: foo(at)mail.com
520
- password: xxx123
521
- age: twenty
522
- blood: a
523
- birth: 1985-01-01
524
- - given-name: bar
525
- family-name: Bar
526
- email: bar@mail.net
527
- age: 15
528
- blood: AB
529
- birth: 1980/01/01
530
- invalid-out*:
531
- ruby: |
532
- validation05.invalid#0: INVALID
533
- - (line 2) [/0/email] 'foo(at)mail.com': not matched to pattern /@/.
534
- - (line 3) [/0/password] 'xxx123': too short (length 6 < min 8).
535
- - (line 4) [/0/age] 'twenty': not a integer.
536
- - (line 5) [/0/blood] 'a': invalid blood value.
537
- - (line 7) [/1/given-name] key 'given-name:' is undefined.
538
- - (line 7) [/1] key 'name:' is required.
539
- - (line 8) [/1/family-name] key 'family-name:' is undefined.
540
- - (line 10) [/1/age] '15': too small (< min 18).
541
- - (line 12) [/1/birth] '1980/01/01': not a date.
542
- java: |
543
- validation05.invalid#0: INVALID
544
- - (line 2) [/0/email] 'foo(at)mail.com': not matched to pattern /@/.
545
- - (line 3) [/0/password] 'xxx123': too short (length 6 < min 8).
546
- - (line 4) [/0/age] 'twenty': not a integer.
547
- - (line 5) [/0/blood] 'a': invalid blood value.
548
- - (line 7) [/1] key 'name:' is required.
549
- - (line 7) [/1/given-name] key 'given-name:' is undefined.
550
- - (line 8) [/1/family-name] key 'family-name:' is undefined.
551
- - (line 10) [/1/age] '15': too small (< min 18).
552
- - (line 12) [/1/birth] '1980/01/01': not a date.
553
- #
554
- ---
555
- name: validation06
556
- desc: unique constraint
557
- method: validation
558
- schema: |
559
- type: seq
560
- sequence:
561
- - type: map
562
- required: yes
563
- mapping:
564
- name:
565
- type: str
566
- required: yes
567
- unique: yes
568
- email:
569
- type: str
570
- groups:
571
- type: seq
572
- sequence:
573
- - type: str
574
- unique: yes
575
- valid: |
576
- - name: foo
577
- email: admin@mail.com
578
- groups:
579
- - users
580
- - foo
581
- - admin
582
- - name: bar
583
- email: admin@mail.com
584
- groups:
585
- - users
586
- - admin
587
- - name: baz
588
- email: baz@mail.com
589
- groups:
590
- - users
591
- valid-out: |
592
- validation06.valid#0: valid.
593
- invalid: |
594
- - name: foo
595
- email: admin@mail.com
596
- groups:
597
- - foo
598
- - users
599
- - admin
600
- - foo
601
- - name: bar
602
- email: admin@mail.com
603
- groups:
604
- - admin
605
- - users
606
- - name: bar
607
- email: baz@mail.com
608
- groups:
609
- - users
610
- invalid-out: |
611
- validation06.invalid#0: INVALID
612
- - (line 7) [/0/groups/3] 'foo': is already used at '/0/groups/0'.
613
- - (line 13) [/2/name] 'bar': is already used at '/1/name'.
614
- #
615
- ---
616
- name: validation12
617
- desc: json
618
- method: validation
619
- schema: |
620
- { "type": "map",
621
- "required": true,
622
- "mapping": {
623
- "name": {
624
- "type": "str",
625
- "required": true
626
- },
627
- "email": {
628
- "type": "str"
629
- },
630
- "age": {
631
- "type": "int"
632
- },
633
- "gender": {
634
- "type": "str",
635
- "enum": ["M", "F"]
636
- },
637
- "favorite": {
638
- "type": "seq",
639
- "sequence": [
640
- { "type": "str" }
641
- ]
642
- }
643
- }
644
- }
645
- valid: |
646
- { "name": "Foo",
647
- "email": "foo@mail.com",
648
- "age": 20,
649
- "gender": "F",
650
- "favorite": [
651
- "football",
652
- "basketball",
653
- "baseball"
654
- ]
655
- }
656
- valid-out: |
657
- validation12.valid#0: valid.
658
- invalid: |
659
- {
660
- "mail": "foo@mail.com",
661
- "age": twenty,
662
- "gender": "X",
663
- "favorite": [ 123, 456 ]
664
- }
665
- invalid-out: |
666
- validation12.invalid#0: INVALID
667
- - (line 1) [/] key 'name:' is required.
668
- - (line 2) [/mail] key 'mail:' is undefined.
669
- - (line 3) [/age] 'twenty': not a integer.
670
- - (line 4) [/gender] 'X': invalid gender value.
671
- - (line 5) [/favorite/0] '123': not a string.
672
- - (line 5) [/favorite/1] '456': not a string.
673
- #
674
- ---
675
- name: validation13
676
- desc: anchor and alias
677
- method: validation
678
- schema: |
679
- type: seq
680
- sequence:
681
- - &employee
682
- type: map
683
- mapping:
684
- "given-name": &name
685
- type: str
686
- required: yes
687
- "family-name": *name
688
- "post":
689
- enum:
690
- - exective
691
- - manager
692
- - clerk
693
- "supervisor": *employee
694
- valid: |
695
- - &foo
696
- given-name: foo
697
- family-name: Foo
698
- post: exective
699
- - &bar
700
- given-name: bar
701
- family-name: Bar
702
- post: manager
703
- supervisor: *foo
704
- - given-name: baz
705
- family-name: Baz
706
- post: clerk
707
- supervisor: *bar
708
- - given-name: zak
709
- family-name: Zak
710
- post: clerk
711
- supervisor: *bar
712
- valid-out: |
713
- validation13.valid#0: valid.
714
- invalid: |
715
- - &foo
716
- #given-name: foo
717
- family-name: Foo
718
- post: exective
719
- - &bar
720
- given-name: bar
721
- family-name: Bar
722
- post: manager
723
- supervisor: *foo
724
- - given-name: baz
725
- family-name: Baz
726
- post: clerk
727
- supervisor: *bar
728
- - given-name: zak
729
- family-name: Zak
730
- post: clerk
731
- supervisor: *bar
732
- invalid-out: |
733
- validation13.invalid#0: INVALID
734
- - (line 1) [/0] key 'given-name:' is required.
735
- #
736
- ---
737
- name: validation14
738
- desc: anchor and alias
739
- method: validation
740
- schema: |
741
- type: map
742
- mapping:
743
- =: # default rule
744
- type: number
745
- range: { max: 1, min: -1 }
746
- valid: |
747
- value1: 0
748
- value2: 0.5
749
- value3: -0.9
750
- valid-out: |
751
- validation14.valid#0: valid.
752
- invalid: |
753
- value1: 0
754
- value2: 1.1
755
- value3: -2.0
756
- invalid-out: |
757
- validation14.invalid#0: INVALID
758
- - (line 2) [/value2] '1.1': too large (> max 1).
759
- - (line 3) [/value3] '-2.0': too small (< min -1).
760
- #
221
+ ##
222
+ - name: stream
223
+ desc: stream document
224
+ method: validation
225
+ schema: |
226
+ type: seq
227
+ sequence:
228
+ - type: str
229
+ valid: |
230
+ ---
231
+ - foo
232
+ - bar
233
+ - baz
234
+ ---
235
+ - aaa
236
+ - bbb
237
+ - ccc
238
+ valid_out: |
239
+ stream.valid#0: valid.
240
+ stream.valid#1: valid.
241
+ invalid: |
242
+ ---
243
+ - foo
244
+ - 123
245
+ - baz
246
+ ---
247
+ - aaa
248
+ - bbb
249
+ - true
250
+ invalid_out: |
251
+ stream.invalid#0: INVALID
252
+ - (line 3) [/1] '123': not a string.
253
+ stream.invalid#1: INVALID
254
+ - (line 8) [/2] 'true': not a string.
255
+
256
+ ##
257
+ - name: meta1
258
+ desc: meta validation (valid)
259
+ method: execute
260
+ args: [ -m, meta1.schema ]
261
+ schema: |
262
+ type: seq
263
+ sequence:
264
+ - type: str
265
+ document: |
266
+ expected: |
267
+ meta1.schema#0: valid.
268
+
269
+ ##
270
+ - name: meta2
271
+ desc: meta validation (invalid)
272
+ method: execute
273
+ args: [ -m, meta2.schema ]
274
+ schema: |
275
+ type: map
276
+ sequence:
277
+ - type: str
278
+ document: |
279
+ expected: |
280
+ meta2.schema#0: INVALID
281
+ - [/] type 'map' requires 'mapping:'.
282
+ - [/] 'sequence:': not available with mapping.
283
+ ##
284
+ - name: emacs
285
+ desc: show errors in emacs style
286
+ method: execute
287
+ args: [ -Ef, emacs.schema, emacs.document ]
288
+ schema: |
289
+ type: seq
290
+ sequence:
291
+ - type: map
292
+ mapping:
293
+ "key": { type: str, required: yes }
294
+ "value": { type: any }
295
+ document: |
296
+ - key: one
297
+ value: 1
298
+ - key: 2
299
+ val: two
300
+ - kye: three
301
+ value:
302
+ expected: |
303
+ emacs.document#0: INVALID
304
+ emacs.document:3: [/1/key] '2': not a string.
305
+ emacs.document:4: [/1/val] key 'val:' is undefined.
306
+ emacs.document:5: [/2] key 'key:' is required.
307
+ emacs.document:5: [/2/kye] key 'kye:' is undefined.
308
+
309
+ ##
761
310
  ---
762
- name: validation15
763
- desc: anchor and alias
764
- method: validation
765
- schema: |
766
- type: map
767
- mapping:
768
- "group":
769
- type: map
770
- mapping:
771
- "name": &name
772
- type: str
773
- required: yes
774
- "email": &email
775
- type: str
776
- pattern: /@/
777
- required: no
778
- "user":
779
- type: map
780
- mapping:
781
- "name":
782
- <<: *name # merge
783
- length: { max: 16 } # override
784
- "email":
785
- <<: *email # merge
786
- required: yes # add
787
- valid: |
788
- group:
789
- name: foo
790
- email: foo@mail.com
791
- user:
792
- name: bar
793
- email: bar@mail.com
794
- valid-out: |
795
- validation15.valid#0: valid.
796
- invalid: |
797
- group:
798
- name: foo
799
- email: foo@mail.com
800
- user:
801
- name: toooooo-looooong-name
802
- invalid-out: |
803
- validation15.invalid#0: INVALID
804
- - (line 4) [/user] key 'email:' is required.
805
- - (line 5) [/user/name] 'toooooo-looooong-name': too long (length 21 > max 16).
311
+ - name: action1
312
+ desc: action 'genclass-ruby'
313
+ action: genclass-ruby
314
+ method: action
315
+ args: [ -a, genclass-ruby, -tf, action1.schema ]
316
+ schema: &action1_schema |
317
+ type: map
318
+ classname: Context
319
+ mapping:
320
+ "groups":
321
+ type: seq
322
+ sequence:
323
+ - type: map
324
+ classname: Group
325
+ mapping:
326
+ "name":
327
+ type: str
328
+ required: yes
329
+ "desc":
330
+ type: str
331
+ "owner": &userschema
332
+ type: map
333
+ classname: User
334
+ mapping:
335
+ "name":
336
+ type: str
337
+ required: yes
338
+ "desc":
339
+ type: str
340
+ "gender":
341
+ type: bool
342
+ "mail":
343
+ type: str
344
+ "manager": *userschema
345
+ "users":
346
+ type: seq
347
+ sequence:
348
+ - *userschema
349
+ document: &action1_document |
350
+ groups:
351
+ - name: admin
352
+ desc: administrator group
353
+ owner: &root
354
+ name: root
355
+ desc: root user
356
+ - name: users
357
+ desc: user group
358
+ owner: &guest
359
+ name: guest
360
+ desc: guest user
361
+ users:
362
+ - *root
363
+ - *guest
364
+ - &user1
365
+ name: user1
366
+ - name: user2
367
+ manager: *user1
368
+ expected: |+
369
+ ##
370
+ class Context
371
+ def initialize(hash)
372
+ @groups = (v=hash['groups']) ? v.map!{|e| e.is_a?(Group) ? e : Group.new(e)} : v
373
+ @users = (v=hash['users']) ? v.map!{|e| e.is_a?(User) ? e : User.new(e)} : v
374
+ end
375
+ attr_accessor :groups # seq
376
+ attr_accessor :users # seq
377
+ end
378
+
379
+ ##
380
+ class Group
381
+ def initialize(hash)
382
+ @name = hash['name']
383
+ @desc = hash['desc']
384
+ @owner = (v=hash['owner']) && v.is_a?(Hash) ? User.new(v) : v
385
+ end
386
+ attr_accessor :name # str
387
+ attr_accessor :desc # str
388
+ attr_accessor :owner # map
389
+ end
390
+
391
+ ##
392
+ class User
393
+ def initialize(hash)
394
+ @name = hash['name']
395
+ @gender = hash['gender']
396
+ @mail = hash['mail']
397
+ @desc = hash['desc']
398
+ @manager = (v=hash['manager']) && v.is_a?(Hash) ? User.new(v) : v
399
+ end
400
+ attr_accessor :name # str
401
+ attr_accessor :gender # bool
402
+ attr_accessor :mail # str
403
+ attr_accessor :desc # str
404
+ attr_accessor :manager # map
405
+ end
406
+
407
+ ##
408
+ - name: action2
409
+ desc: action 'genclass-java'
410
+ action: genclass-java
411
+ method: action
412
+ args: [ -a, genclass-java, -tf, action2.schema ]
413
+ schema: *action1_schema
414
+ document: *action1_document
415
+ output_files: [ Context.java, Group.java, User.java ]
416
+ expected:
417
+ 'Context.java': |
418
+ // generated by kwalify from action2.schema
419
+
420
+ import java.util.*;
421
+
422
+ /**
423
+ *
424
+ */
425
+ public class Context {
426
+
427
+ private List _groups;
428
+ private List _users;
429
+
430
+ public Context() {}
431
+
432
+ public Context(Map map) {
433
+ List seq;
434
+ Object obj;
435
+ if ((seq = (List)map.get("groups")) != null) {
436
+ for (int i = 0; i < seq.size(); i++) {
437
+ if ((obj = seq.get(i)) instanceof Map) {
438
+ seq.set(i, new Group((Map)obj));
439
+ }
440
+ }
441
+ }
442
+ _groups = seq;
443
+ if ((seq = (List)map.get("users")) != null) {
444
+ for (int i = 0; i < seq.size(); i++) {
445
+ if ((obj = seq.get(i)) instanceof Map) {
446
+ seq.set(i, new User((Map)obj));
447
+ }
448
+ }
449
+ }
450
+ _users = seq;
451
+ }
452
+
453
+ public List getGroups() { return _groups; }
454
+ public void setGroups(List groups_) { _groups = groups_; }
455
+ public List getUsers() { return _users; }
456
+ public void setUsers(List users_) { _users = users_; }
457
+ }
458
+
459
+ 'Group.java': |
460
+ // generated by kwalify from action2.schema
461
+
462
+ import java.util.*;
463
+
464
+ /**
465
+ *
466
+ */
467
+ public class Group {
468
+
469
+ private String _name;
470
+ private String _desc;
471
+ private User _owner;
472
+
473
+ public Group() {}
474
+
475
+ public Group(Map map) {
476
+ _name = (String)map.get("name");
477
+ _desc = (String)map.get("desc");
478
+ Object obj;
479
+ if ((obj = map.get("owner")) != null && obj instanceof Map) {
480
+ _owner = new User((Map)obj);
481
+ } else {
482
+ _owner = (User)obj;
483
+ }
484
+ }
485
+
486
+ public String getName() { return _name; }
487
+ public void setName(String name_) { _name = name_; }
488
+ public String getDesc() { return _desc; }
489
+ public void setDesc(String desc_) { _desc = desc_; }
490
+ public User getOwner() { return _owner; }
491
+ public void setOwner(User owner_) { _owner = owner_; }
492
+ }
493
+
494
+ 'User.java': |
495
+ // generated by kwalify from action2.schema
496
+
497
+ import java.util.*;
498
+
499
+ /**
500
+ *
501
+ */
502
+ public class User {
503
+
504
+ private String _name;
505
+ private boolean _gender;
506
+ private String _mail;
507
+ private String _desc;
508
+ private User _manager;
509
+
510
+ public User() {}
511
+
512
+ public User(Map map) {
513
+ _name = (String)map.get("name");
514
+ if (map.get("gender") != null) {
515
+ _gender = ((Boolean)map.get("gender")).booleanValue();
516
+ }
517
+ _mail = (String)map.get("mail");
518
+ _desc = (String)map.get("desc");
519
+ Object obj;
520
+ if ((obj = map.get("manager")) != null && obj instanceof Map) {
521
+ _manager = new User((Map)obj);
522
+ } else {
523
+ _manager = (User)obj;
524
+ }
525
+ }
526
+
527
+ public String getName() { return _name; }
528
+ public void setName(String name_) { _name = name_; }
529
+ public boolean getGender() { return _gender; }
530
+ public void setGender(boolean gender_) { _gender = gender_; }
531
+ public String getMail() { return _mail; }
532
+ public void setMail(String mail_) { _mail = mail_; }
533
+ public String getDesc() { return _desc; }
534
+ public void setDesc(String desc_) { _desc = desc_; }
535
+ public User getManager() { return _manager; }
536
+ public void setManager(User manager_) { _manager = manager_; }
537
+ }
538
+
539
+ ## not used
540
+ main_file:
541
+ name: Example.java
542
+ content: |
543
+ import kwalify.*;
544
+ import java.util.*;
545
+
546
+ public class Example {
547
+ public static void main(String[] args) throws Exception {
548
+ String input = kwalify.Util.readFile("action2.document");
549
+ input = kwalify.Util.untabify(input);
550
+ YamlParser parser = new YamlParser(input);
551
+ Object ydoc = parser.parse();
552
+ //
553
+ Context context = new Context((Map)ydoc);
554
+ //
555
+ List groups = context.getGroups();
556
+ if (groups != null) {
557
+ for (Iterator it = groups.iterator(); it.hasNext(); ) {
558
+ Group g = (Group)it.next();
559
+ System.out.println("group.name = " + g.getName());
560
+ System.out.println("group.desc = " + g.getDesc());
561
+ System.out.println("group.owner.name = " + g.getOwner().getName());
562
+ System.out.println();
563
+ }
564
+ }
565
+ //
566
+ List users = context.getUsers();
567
+ if (users != null) {
568
+ for (Iterator it = users.iterator(); it.hasNext(); ) {
569
+ User u = (User)it.next();
570
+ System.out.println("user.name = " + u.getName());
571
+ System.out.println("user.desc = " + u.getDesc());
572
+ System.out.println("user.manager.name = " + (u.getManager() != null ? u.getManager().getName() : null));
573
+ System.out.println();
574
+ }
575
+ }
576
+ }
577
+ }
578
+
579
+ ##