kwalify 0.6.1 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES.txt +232 -0
- data/MIT-LICENSE +20 -0
- data/README.txt +16 -19
- data/bin/kwalify +3 -3
- data/contrib/inline-require +6 -4
- data/contrib/kwalify +3719 -2427
- data/doc-api/classes/CommandOptionError.html +17 -17
- data/doc-api/classes/CommandOptionParser.html +63 -63
- data/doc-api/classes/Kwalify.html +29 -7
- data/doc-api/classes/Kwalify/AssertionError.html +9 -9
- data/doc-api/classes/Kwalify/BaseError.html +72 -71
- data/doc-api/classes/Kwalify/BaseParser.html +461 -0
- data/doc-api/classes/Kwalify/CommandOptionError.html +11 -11
- data/doc-api/classes/Kwalify/ErrorHelper.html +51 -46
- data/doc-api/classes/Kwalify/HashInterface.html +13 -135
- data/doc-api/classes/Kwalify/Json.html +105 -0
- data/doc-api/classes/Kwalify/Main.html +129 -126
- data/doc-api/classes/Kwalify/MetaValidator.html +248 -232
- data/doc-api/classes/Kwalify/Parser.html +12 -12
- data/doc-api/classes/Kwalify/PlainYamlParser.html +166 -163
- data/doc-api/classes/Kwalify/PlainYamlParser/Alias.html +11 -11
- data/doc-api/classes/Kwalify/Rule.html +152 -130
- data/doc-api/classes/Kwalify/SchemaError.html +10 -10
- data/doc-api/classes/Kwalify/SyntaxError.html +185 -0
- data/doc-api/classes/Kwalify/Types.html +26 -25
- data/doc-api/classes/Kwalify/Util.html +389 -0
- data/doc-api/classes/Kwalify/Util/HashLike.html +246 -0
- data/doc-api/classes/Kwalify/Util/OrderedHash.html +330 -0
- data/doc-api/classes/Kwalify/ValidationError.html +10 -10
- data/doc-api/classes/Kwalify/Validator.html +153 -86
- data/doc-api/classes/Kwalify/Yaml.html +181 -0
- data/doc-api/classes/Kwalify/Yaml/Parser.html +1538 -0
- data/doc-api/classes/Kwalify/YamlParser.html +190 -183
- data/doc-api/classes/Kwalify/YamlSyntaxError.html +8 -57
- data/doc-api/created.rid +1 -1
- data/doc-api/files/__/README_txt.html +17 -22
- data/doc-api/files/kwalify/errors_rb.html +2 -2
- data/doc-api/files/kwalify/main_rb.html +4 -3
- data/doc-api/files/kwalify/messages_rb.html +2 -2
- data/doc-api/files/kwalify/meta-validator_rb.html +3 -3
- data/doc-api/files/kwalify/{util/yaml-helper_rb.html → parser/base_rb.html} +8 -6
- data/doc-api/files/kwalify/parser/yaml_rb.html +117 -0
- data/doc-api/files/kwalify/rule_rb.html +2 -2
- data/doc-api/files/kwalify/types_rb.html +2 -2
- data/doc-api/files/kwalify/util/assert-text-equal_rb.html +2 -2
- data/doc-api/files/kwalify/util/hash-interface_rb.html +9 -2
- data/doc-api/files/kwalify/util/hashlike_rb.html +107 -0
- data/doc-api/files/kwalify/util/option-parser_rb.html +2 -2
- data/doc-api/files/kwalify/util/ordered-hash_rb.html +107 -0
- data/doc-api/files/kwalify/util/testcase-helper_rb.html +2 -2
- data/doc-api/files/kwalify/util_rb.html +107 -0
- data/doc-api/files/kwalify/validator_rb.html +2 -2
- data/doc-api/files/kwalify/yaml-parser_rb.html +2 -2
- data/doc-api/files/kwalify_rb.html +3 -2
- data/doc-api/fr_class_index.html +8 -1
- data/doc-api/fr_file_index.html +5 -1
- data/doc-api/fr_method_index.html +128 -69
- data/doc/img/fig01.png +0 -0
- data/doc/users-guide.html +882 -717
- data/examples/address-book/address-book.schema.yaml +2 -2
- data/examples/data-binding/BABEL.data.yaml +63 -0
- data/examples/data-binding/BABEL.schema.yaml +31 -0
- data/examples/data-binding/Makefile +8 -0
- data/examples/data-binding/Rakefile +13 -0
- data/examples/data-binding/main.rb +27 -0
- data/examples/invoice/invoice.schema.yaml +3 -3
- data/examples/tapkit/tapkit.schema.yaml +2 -2
- data/lib/kwalify.rb +41 -4
- data/lib/kwalify/errors.rb +118 -96
- data/lib/kwalify/kwalify.schema.yaml +58 -0
- data/lib/kwalify/main.rb +384 -377
- data/lib/kwalify/messages.rb +41 -27
- data/lib/kwalify/meta-validator.rb +251 -331
- data/lib/kwalify/parser/base.rb +127 -0
- data/lib/kwalify/parser/yaml.rb +837 -0
- data/lib/kwalify/rule.rb +545 -487
- data/lib/kwalify/templates/genclass-java.eruby +189 -162
- data/lib/kwalify/templates/genclass-php.eruby +104 -0
- data/lib/kwalify/templates/genclass-ruby.eruby +95 -66
- data/lib/kwalify/types.rb +107 -106
- data/lib/kwalify/util.rb +157 -0
- data/lib/kwalify/util/assert-text-equal.rb +33 -31
- data/lib/kwalify/util/hash-interface.rb +11 -30
- data/lib/kwalify/util/hashlike.rb +51 -0
- data/lib/kwalify/util/option-parser.rb +144 -144
- data/lib/kwalify/util/ordered-hash.rb +57 -0
- data/lib/kwalify/util/testcase-helper.rb +3 -3
- data/lib/kwalify/validator.rb +267 -212
- data/lib/kwalify/yaml-parser.rb +822 -768
- data/setup.rb +861 -607
- data/test/Rookbook.yaml +10 -0
- data/test/{tmp.dir/Context.java → data/users-guide/AddressBook.java.expected} +11 -11
- data/test/data/users-guide/BABEL.data.yaml +24 -0
- data/test/data/users-guide/BABEL.schema.yaml +30 -0
- data/test/data/users-guide/ExampleAddressBook.java +47 -0
- data/test/{tmp.dir/Group.java → data/users-guide/Group.java.expected} +2 -11
- data/test/data/users-guide/Person.java.expected +44 -0
- data/test/data/users-guide/address_book.rb +52 -0
- data/test/data/users-guide/address_book.schema.yaml +28 -0
- data/test/data/users-guide/address_book.yaml +27 -0
- data/test/data/users-guide/answers-schema.yaml +12 -0
- data/test/data/users-guide/answers-validator.rb +52 -0
- data/test/data/users-guide/babel_genclass.result +26 -0
- data/test/data/users-guide/config.schema.yaml +7 -0
- data/test/data/users-guide/config.yaml +4 -0
- data/test/{tmp.dir/silent1.document → data/users-guide/document01a.yaml} +0 -0
- data/test/data/users-guide/document01b.yaml +3 -0
- data/test/data/users-guide/document02a.yaml +4 -0
- data/test/data/users-guide/document02b.yaml +4 -0
- data/test/data/users-guide/document03a.yaml +6 -0
- data/test/data/users-guide/document03b.yaml +6 -0
- data/test/data/users-guide/document04a.yaml +9 -0
- data/test/data/users-guide/document04b.yaml +9 -0
- data/test/data/users-guide/document05a.yaml +11 -0
- data/test/data/users-guide/document05b.yaml +12 -0
- data/test/data/users-guide/document06a.yaml +15 -0
- data/test/data/users-guide/document06b.yaml +16 -0
- data/test/data/users-guide/document07a.yaml +9 -0
- data/test/data/users-guide/document07b.yaml +7 -0
- data/test/data/users-guide/document12a.json +10 -0
- data/test/data/users-guide/document12b.json +6 -0
- data/test/data/users-guide/document13a.yaml +17 -0
- data/test/data/users-guide/document14a.yaml +3 -0
- data/test/data/users-guide/document14b.yaml +3 -0
- data/test/data/users-guide/document15a.yaml +6 -0
- data/test/data/users-guide/document15b.yaml +5 -0
- data/test/data/users-guide/example_address_book.rb +10 -0
- data/test/data/users-guide/example_address_book_java.result +32 -0
- data/test/data/users-guide/example_address_book_ruby.result +31 -0
- data/test/data/users-guide/genclass_java.result +4 -0
- data/test/data/users-guide/howto-validation-with-parsing.rb +28 -0
- data/test/data/users-guide/howto-validation.rb +25 -0
- data/test/data/users-guide/howto3.rb +6 -0
- data/test/data/users-guide/howto3.result +5 -0
- data/test/data/users-guide/howto3.yaml +8 -0
- data/test/data/users-guide/howto5_databinding.result +111 -0
- data/test/data/users-guide/invalid01.result +3 -0
- data/test/data/users-guide/invalid02.result +5 -0
- data/test/data/users-guide/invalid03.result +5 -0
- data/test/data/users-guide/invalid04.result +4 -0
- data/test/data/users-guide/invalid05.result +11 -0
- data/test/data/users-guide/invalid06.result +4 -0
- data/test/data/users-guide/invalid07.result +3 -0
- data/test/data/users-guide/invalid08.result +3 -0
- data/test/data/users-guide/invalid12.json +8 -0
- data/test/data/users-guide/invalid14.result +4 -0
- data/test/data/users-guide/invalid15.result +4 -0
- data/test/data/users-guide/loadbabel.rb +27 -0
- data/test/data/users-guide/loadconfig.rb +15 -0
- data/test/data/users-guide/loadconfig.result +2 -0
- data/test/data/users-guide/models.rb +22 -0
- data/test/data/users-guide/option_ha.result +6 -0
- data/test/data/users-guide/option_ha_genclass_java.result +7 -0
- data/test/{tmp.dir/meta1.schema → data/users-guide/schema01.yaml} +0 -0
- data/test/data/users-guide/schema02.yaml +12 -0
- data/test/data/users-guide/schema03.yaml +9 -0
- data/test/data/users-guide/schema04.yaml +20 -0
- data/test/data/users-guide/schema05.yaml +29 -0
- data/test/data/users-guide/schema06.yaml +11 -0
- data/test/data/users-guide/schema12.json +12 -0
- data/test/data/users-guide/schema13.yaml +13 -0
- data/test/data/users-guide/schema14.yaml +5 -0
- data/test/data/users-guide/schema15.yaml +21 -0
- data/test/data/users-guide/valid01.result +2 -0
- data/test/data/users-guide/valid02.result +2 -0
- data/test/data/users-guide/valid03.result +2 -0
- data/test/data/users-guide/valid04.result +2 -0
- data/test/data/users-guide/valid05.result +2 -0
- data/test/data/users-guide/valid06.result +2 -0
- data/test/data/users-guide/valid07.result +2 -0
- data/test/data/users-guide/valid08.result +2 -0
- data/test/data/users-guide/valid12.result +2 -0
- data/test/data/users-guide/valid13.result +2 -0
- data/test/data/users-guide/valid14.result +2 -0
- data/test/data/users-guide/valid15.result +2 -0
- data/test/data/users-guide/validate08.rb +37 -0
- data/test/test-action.rb +78 -0
- data/test/test-action.yaml +738 -0
- data/test/test-databinding.rb +80 -0
- data/test/test-databinding.yaml +301 -0
- data/test/test-main.rb +129 -150
- data/test/test-main.yaml +126 -321
- data/test/test-metavalidator.rb +47 -47
- data/test/test-metavalidator.yaml +77 -21
- data/test/test-parser-yaml.rb +57 -0
- data/test/test-parser-yaml.yaml +1749 -0
- data/test/test-rule.rb +14 -15
- data/test/test-rule.yaml +6 -3
- data/test/test-users-guide.rb +75 -0
- data/test/test-validator.rb +77 -52
- data/test/test-validator.yaml +168 -6
- data/test/test-yaml-parser.rb +47 -0
- data/test/{test-yamlparser.yaml → test-yaml-parser.yaml} +159 -52
- data/test/test.rb +37 -21
- metadata +136 -37
- data/COPYING +0 -340
- data/ChangeLog +0 -70
- data/doc-api/classes/YamlHelper.html +0 -259
- data/lib/kwalify/util/yaml-helper.rb +0 -82
- data/test/test-yamlparser.rb +0 -58
- data/test/tmp.dir/User.java +0 -43
- data/test/tmp.dir/action1.document +0 -18
- data/test/tmp.dir/action1.schema +0 -32
- data/test/tmp.dir/action2.document +0 -18
- data/test/tmp.dir/action2.schema +0 -32
- data/test/tmp.dir/emacs.document +0 -6
- data/test/tmp.dir/emacs.schema +0 -6
- data/test/tmp.dir/meta1.document +0 -0
- data/test/tmp.dir/meta2.document +0 -0
- data/test/tmp.dir/meta2.schema +0 -3
- data/test/tmp.dir/silent1.schema +0 -3
- data/test/tmp.dir/silent2.document +0 -7
- data/test/tmp.dir/silent2.schema +0 -3
- data/test/tmp.dir/stream.invalid +0 -8
- data/test/tmp.dir/stream.schema +0 -3
- data/test/tmp.dir/stream.valid +0 -8
- data/test/tmp.dir/untabify.document +0 -5
- data/test/tmp.dir/untabify.schema +0 -10
- data/todo.txt +0 -34
data/test/test-main.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
##
|
2
|
-
## $Rev:
|
3
|
-
## $Release: 0.
|
4
|
-
## copyright(c) 2005 kuwata-lab all rights reserved.
|
2
|
+
## $Rev: 93 $
|
3
|
+
## $Release: 0.7.0 $
|
4
|
+
## copyright(c) 2005-2008 kuwata-lab all rights reserved.
|
5
5
|
##
|
6
6
|
---
|
7
7
|
- name: parseOptions1
|
@@ -17,8 +17,8 @@
|
|
17
17
|
- help: true
|
18
18
|
- linenum: true
|
19
19
|
- meta: true
|
20
|
+
- quiet: true
|
20
21
|
- schema: schema.yaml
|
21
|
-
- silent: true
|
22
22
|
- tpath: path/to/dir
|
23
23
|
- untabify: true
|
24
24
|
- version: true
|
@@ -26,7 +26,6 @@
|
|
26
26
|
filenames:
|
27
27
|
- document.yaml
|
28
28
|
- document2.yaml
|
29
|
-
|
30
29
|
##
|
31
30
|
- name: parseOptions2
|
32
31
|
desc: -ffilename
|
@@ -42,7 +41,6 @@
|
|
42
41
|
- tpath: /path/to/dir
|
43
42
|
properties:
|
44
43
|
filenames:
|
45
|
-
|
46
44
|
##
|
47
45
|
- name: parseOptions3
|
48
46
|
desc: "'--help' is equal to '-h'"
|
@@ -56,7 +54,6 @@
|
|
56
54
|
- help: true
|
57
55
|
filenames:
|
58
56
|
- document.yaml
|
59
|
-
|
60
57
|
##
|
61
58
|
- name: parseOptions4
|
62
59
|
desc: "'-E' turns on '-l'"
|
@@ -70,7 +67,6 @@
|
|
70
67
|
properties:
|
71
68
|
filenames:
|
72
69
|
- document.yaml
|
73
|
-
|
74
70
|
##
|
75
71
|
---
|
76
72
|
- name: optionError1
|
@@ -96,7 +92,7 @@
|
|
96
92
|
java: CommandOptionException
|
97
93
|
message: "-f: schema filename is required."
|
98
94
|
error_symbol*:
|
99
|
-
ruby: !ruby/sym :
|
95
|
+
ruby: !ruby/sym :command_option_schema_required
|
100
96
|
java: command.option.noschema
|
101
97
|
####
|
102
98
|
##name: optionError3
|
@@ -129,62 +125,66 @@
|
|
129
125
|
java: command.option.noaction
|
130
126
|
##
|
131
127
|
---
|
132
|
-
- name: version
|
128
|
+
- name: version # -v
|
133
129
|
desc: option '-v'
|
134
130
|
method: execute
|
135
131
|
args: [ -vt, document.yaml ]
|
136
132
|
expected: |
|
137
133
|
0.0.0
|
138
|
-
|
139
134
|
##
|
140
|
-
- name: help
|
135
|
+
- name: help # -h
|
141
136
|
desc: option '-h'
|
142
137
|
method: execute
|
143
138
|
args: [ -hD, document.yaml ]
|
144
139
|
expected: |
|
145
|
-
kwalify -
|
146
|
-
Usage1:
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
-
|
153
|
-
-
|
154
|
-
-
|
155
|
-
-
|
156
|
-
-
|
157
|
-
-
|
158
|
-
|
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
|
159
160
|
##
|
160
|
-
- name:
|
161
|
-
desc: option '-
|
161
|
+
- name: quiet1 # -q
|
162
|
+
desc: option '-q' (valid)
|
162
163
|
method: execute
|
163
|
-
args: [ -
|
164
|
+
args: [ -qf, quiet1.schema, quiet1.document ]
|
164
165
|
expected: |
|
165
|
-
schema: |
|
166
|
+
schema: &quiet1_schema |
|
166
167
|
type: seq
|
167
168
|
sequence:
|
168
169
|
- type: str
|
169
|
-
document: |
|
170
|
+
document: &quiet1_document |
|
170
171
|
- foo
|
171
172
|
- bar
|
172
173
|
- baz
|
173
|
-
|
174
174
|
##
|
175
|
-
- name:
|
175
|
+
- name: quiet2 # -s
|
176
176
|
desc: option '-s' (invalid)
|
177
177
|
method: execute
|
178
|
-
args: [ -sf,
|
178
|
+
args: [ -sf, quiet2.schema, quiet2.document ]
|
179
179
|
expected: |
|
180
|
-
|
180
|
+
quiet2.document#1: INVALID
|
181
181
|
- [/1] '123': not a string.
|
182
182
|
- [/2] 'true': not a string.
|
183
|
-
schema: |
|
183
|
+
schema: &quiet2_schema |
|
184
184
|
type: seq
|
185
185
|
sequence:
|
186
186
|
- type: str
|
187
|
-
document: |
|
187
|
+
document: &quiet2_document |
|
188
188
|
- foo
|
189
189
|
- bar
|
190
190
|
- baz
|
@@ -192,9 +192,27 @@
|
|
192
192
|
- foo
|
193
193
|
- 123
|
194
194
|
- true
|
195
|
-
|
196
195
|
##
|
197
|
-
- name:
|
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
|
198
216
|
desc: option '-t'
|
199
217
|
method: execute
|
200
218
|
args: [ -tf, untabify.schema, untabify.document ]
|
@@ -217,7 +235,6 @@
|
|
217
235
|
value: 123
|
218
236
|
- key: bar
|
219
237
|
value: [a, b, c]
|
220
|
-
|
221
238
|
##
|
222
239
|
- name: stream
|
223
240
|
desc: stream document
|
@@ -252,22 +269,20 @@
|
|
252
269
|
- (line 3) [/1] '123': not a string.
|
253
270
|
stream.invalid#1: INVALID
|
254
271
|
- (line 8) [/2] 'true': not a string.
|
255
|
-
|
256
272
|
##
|
257
|
-
- name: meta1
|
273
|
+
- name: meta1 # -m
|
258
274
|
desc: meta validation (valid)
|
259
275
|
method: execute
|
260
276
|
args: [ -m, meta1.schema ]
|
261
|
-
schema: |
|
277
|
+
schema: &meta1_schema |
|
262
278
|
type: seq
|
263
279
|
sequence:
|
264
280
|
- type: str
|
265
281
|
document: |
|
266
|
-
expected: |
|
282
|
+
expected: &meta1_expected |
|
267
283
|
meta1.schema#0: valid.
|
268
|
-
|
269
284
|
##
|
270
|
-
- name: meta2
|
285
|
+
- name: meta2 # -m
|
271
286
|
desc: meta validation (invalid)
|
272
287
|
method: execute
|
273
288
|
args: [ -m, meta2.schema ]
|
@@ -281,7 +296,7 @@
|
|
281
296
|
- [/] type 'map' requires 'mapping:'.
|
282
297
|
- [/] 'sequence:': not available with mapping.
|
283
298
|
##
|
284
|
-
- name: emacs
|
299
|
+
- name: emacs # -E
|
285
300
|
desc: show errors in emacs style
|
286
301
|
method: execute
|
287
302
|
args: [ -Ef, emacs.schema, emacs.document ]
|
@@ -301,279 +316,69 @@
|
|
301
316
|
value:
|
302
317
|
expected: |
|
303
318
|
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
|
-
|
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.
|
309
323
|
##
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
type:
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
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
|
-
|
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: |
|
579
384
|
##
|