kwalify 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/ChangeLog +29 -62
- data/README.txt +39 -11
- data/bin/kwalify +16 -177
- data/doc/users-guide.html +279 -145
- data/examples/address-book/Makefile +1 -0
- data/examples/address-book/address-book.schema.yaml +10 -10
- data/examples/invoice/Makefile +1 -0
- data/examples/invoice/invoice.schema.yaml +17 -34
- data/examples/tapkit/Makefile +5 -0
- data/examples/tapkit/tapkit.schema.yaml +137 -0
- data/examples/tapkit/tapkit.yaml +85 -0
- data/lib/kwalify.rb +12 -3
- data/lib/kwalify/errors.rb +36 -60
- data/lib/kwalify/main-program.rb +214 -0
- data/lib/kwalify/messages.rb +91 -0
- data/lib/kwalify/meta-validator.rb +199 -76
- data/lib/kwalify/rule.rb +326 -0
- data/lib/kwalify/types.rb +86 -20
- data/lib/kwalify/util/assert-diff.rb +1 -1
- data/lib/kwalify/util/option-parser.rb +1 -1
- data/lib/kwalify/util/yaml-helper.rb +6 -6
- data/lib/kwalify/validator.rb +111 -218
- data/test/test-metavalidator.rb +608 -0
- data/test/test-metavalidator.rb.error +490 -0
- data/test/test-validator.rb +526 -0
- data/test/test.rb +12 -351
- data/todo.txt +14 -4
- metadata +12 -3
- data/lib/kwalify/error-msg.rb +0 -41
data/test/test.rb
CHANGED
@@ -1,364 +1,25 @@
|
|
1
1
|
###
|
2
|
-
### $Rev:
|
3
|
-
### $Release: 0.
|
2
|
+
### $Rev: 15 $
|
3
|
+
### $Release: 0.2.0 $
|
4
4
|
### copyright(c) 2005 kuwata-lab all rights reserved.
|
5
5
|
###
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
7
|
+
testdir = File.dirname(__FILE__)
|
8
|
+
libdir = File.dirname(testdir) + "/lib"
|
9
|
+
$LOAD_PATH << libdir << testdir
|
11
10
|
require 'test/unit'
|
12
11
|
require 'test/unit/ui/console/testrunner'
|
13
|
-
|
14
12
|
require 'kwalify'
|
15
13
|
require 'kwalify/util/assert-diff'
|
16
|
-
|
17
14
|
require 'yaml'
|
18
|
-
require 'pp'
|
19
|
-
|
20
|
-
class ValidatorTest < Test::Unit::TestCase
|
21
|
-
|
22
|
-
def _test(flag_print=false)
|
23
|
-
schema = YAML.load(@schema.gsub(/^\t/, ''))
|
24
|
-
document = YAML.load(@data.gsub(/^\t/, ''))
|
25
|
-
validator = Kwalify::Validator.new(schema)
|
26
|
-
error_list = validator.validate(document)
|
27
|
-
actual = ""
|
28
|
-
error_list.each do |error|
|
29
|
-
actual << "%-20s: %s\n" % [error.error_symbol.inspect, error.message]
|
30
|
-
end
|
31
|
-
if flag_print
|
32
|
-
print actual
|
33
|
-
else
|
34
|
-
assert_equal_with_diff(@expected.gsub(/^\t/, ''), actual)
|
35
|
-
end
|
36
|
-
return error_list
|
37
|
-
end
|
38
|
-
|
39
|
-
|
40
|
-
def test_validate01
|
41
|
-
@schema = <<-'END'
|
42
|
-
type: map
|
43
|
-
required: true
|
44
|
-
mapping:
|
45
|
-
name:
|
46
|
-
type: string
|
47
|
-
required: true
|
48
|
-
email:
|
49
|
-
type: string
|
50
|
-
pattern: /@/
|
51
|
-
required: yes
|
52
|
-
age:
|
53
|
-
type: integer
|
54
|
-
blood:
|
55
|
-
type: string
|
56
|
-
enum:
|
57
|
-
- A
|
58
|
-
- B
|
59
|
-
- O
|
60
|
-
- AB
|
61
|
-
birth:
|
62
|
-
type: date
|
63
|
-
END
|
64
|
-
## correct data
|
65
|
-
@data = <<-'END'
|
66
|
-
name: foo
|
67
|
-
email: foo@mail.com
|
68
|
-
age: 20
|
69
|
-
blood: AB
|
70
|
-
birth: 1985-01-01
|
71
|
-
END
|
72
|
-
@expected = ""
|
73
|
-
errors = _test()
|
74
|
-
## incorrect data
|
75
|
-
@data = <<-'END'
|
76
|
-
nam: foo
|
77
|
-
email: foo(at)mail.com
|
78
|
-
age: twenty
|
79
|
-
blood: ab
|
80
|
-
birth: Jul 01, 1985
|
81
|
-
END
|
82
|
-
@expected = <<-'END'
|
83
|
-
:missing_key : [/] key 'name' required but not found.
|
84
|
-
:invalid_key : [/] key 'nam' is not expected.
|
85
|
-
:invalid_enum : [/blood] 'ab' is invalid enum value.
|
86
|
-
:invalid_type : [/birth] date type expected but got String.
|
87
|
-
:invalid_type : [/age] integer type expected but got String.
|
88
|
-
:invalid_pattern : [/email] 'foo(at)mail.com' is not matched to pattern /@/.
|
89
|
-
END
|
90
|
-
errors = _test()
|
91
|
-
end
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
def test_validate02
|
96
|
-
@schema = <<-'END'
|
97
|
-
type: seq
|
98
|
-
required: true
|
99
|
-
sequence:
|
100
|
-
- type: string
|
101
|
-
required: true
|
102
|
-
END
|
103
|
-
## correct data
|
104
|
-
@data = <<-'END'
|
105
|
-
- foo
|
106
|
-
- bar
|
107
|
-
- baz
|
108
|
-
END
|
109
|
-
@expected = ''
|
110
|
-
_test()
|
111
|
-
## incorrect data
|
112
|
-
@data = <<-'END'
|
113
|
-
- foo
|
114
|
-
- bar
|
115
|
-
-
|
116
|
-
- baz
|
117
|
-
- 100
|
118
|
-
END
|
119
|
-
@expected = <<-'END'
|
120
|
-
:missing_value : [/3] value required but not found.
|
121
|
-
:invalid_type : [/5] string type expected but got Fixnum.
|
122
|
-
END
|
123
|
-
errors = _test()
|
124
|
-
end
|
125
|
-
|
126
|
-
|
127
|
-
def test_validate03
|
128
|
-
@schema = <<-'END'
|
129
|
-
type: map
|
130
|
-
required: true
|
131
|
-
mapping:
|
132
|
-
address-book:
|
133
|
-
type: seq
|
134
|
-
required: true
|
135
|
-
sequence:
|
136
|
-
- type: map
|
137
|
-
mapping:
|
138
|
-
name:
|
139
|
-
type: string
|
140
|
-
required: yes
|
141
|
-
email:
|
142
|
-
type: string
|
143
|
-
pattern: /@/
|
144
|
-
required: yes
|
145
|
-
age:
|
146
|
-
type: integer
|
147
|
-
blood:
|
148
|
-
type: string
|
149
|
-
enum:
|
150
|
-
- A
|
151
|
-
- B
|
152
|
-
- O
|
153
|
-
- AB
|
154
|
-
birth:
|
155
|
-
type: date
|
156
|
-
END
|
157
|
-
## correct data
|
158
|
-
@data = <<-'END'
|
159
|
-
address-book:
|
160
|
-
- name: foo
|
161
|
-
email: foo@mail.com
|
162
|
-
age: 20
|
163
|
-
blood: AB
|
164
|
-
birth: 1985-01-01
|
165
|
-
- name: bar
|
166
|
-
email: foo@mail.com
|
167
|
-
END
|
168
|
-
@expected = <<-'END'
|
169
|
-
END
|
170
|
-
errors = _test()
|
171
|
-
## incorrect data
|
172
|
-
@data = <<-'END'
|
173
|
-
address-book:
|
174
|
-
- name: foo
|
175
|
-
mail: foo@mail.com
|
176
|
-
age: twenty
|
177
|
-
blood: ab
|
178
|
-
birth: 1985/01/01
|
179
|
-
- name: bar
|
180
|
-
email: bar(at)mail.com
|
181
|
-
END
|
182
|
-
@expected = <<-'END'
|
183
|
-
:missing_key : [/address-book/1] key 'email' required but not found.
|
184
|
-
:invalid_key : [/address-book/1] key 'mail' is not expected.
|
185
|
-
:invalid_enum : [/address-book/1/blood] 'ab' is invalid enum value.
|
186
|
-
:invalid_type : [/address-book/1/birth] date type expected but got String.
|
187
|
-
:invalid_type : [/address-book/1/age] integer type expected but got String.
|
188
|
-
:invalid_pattern : [/address-book/2/email] 'bar(at)mail.com' is not matched to pattern /@/.
|
189
|
-
END
|
190
|
-
errors = _test()
|
191
|
-
end
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
def test_validate11
|
196
|
-
@schema = <<-'END'
|
197
|
-
type: seq
|
198
|
-
required: true
|
199
|
-
sequence:
|
200
|
-
- type: map
|
201
|
-
required: true
|
202
|
-
mapping:
|
203
|
-
first-name: &name
|
204
|
-
type: string
|
205
|
-
required: yes
|
206
|
-
family-name: *name
|
207
|
-
END
|
208
|
-
## correct data
|
209
|
-
@data = <<-'END'
|
210
|
-
- first-name: foo
|
211
|
-
family-name: Foo
|
212
|
-
- first-name: bar
|
213
|
-
family-name: Bar
|
214
|
-
END
|
215
|
-
@expected = <<-'END'
|
216
|
-
END
|
217
|
-
errors = _test()
|
218
|
-
## incorrect data
|
219
|
-
@data = <<-'END'
|
220
|
-
- first-name: foo
|
221
|
-
last-name: Foo
|
222
|
-
- first-name: bar
|
223
|
-
family-name: 100
|
224
|
-
END
|
225
|
-
@expected = <<-'END'
|
226
|
-
:missing_key : [/1] key 'family-name' required but not found.
|
227
|
-
:invalid_key : [/1] key 'last-name' is not expected.
|
228
|
-
:invalid_type : [/2/family-name] string type expected but got Fixnum.
|
229
|
-
END
|
230
|
-
errors = _test()
|
231
|
-
end
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
def test_validate12
|
236
|
-
@schema = <<-'END'
|
237
|
-
type: map
|
238
|
-
required: true
|
239
|
-
mapping:
|
240
|
-
title: &name
|
241
|
-
type: string
|
242
|
-
required: true
|
243
|
-
address-book:
|
244
|
-
type: seq
|
245
|
-
required: true
|
246
|
-
sequence:
|
247
|
-
- type: map
|
248
|
-
mapping:
|
249
|
-
name: *name
|
250
|
-
email:
|
251
|
-
type: string
|
252
|
-
required: yes
|
253
|
-
END
|
254
|
-
## correct data
|
255
|
-
@data = <<-'END'
|
256
|
-
title: my friends
|
257
|
-
address-book:
|
258
|
-
- name: foo
|
259
|
-
email: foo@mail.com
|
260
|
-
- name: bar
|
261
|
-
email: bar@mail.com
|
262
|
-
END
|
263
|
-
@expected = ""
|
264
|
-
errors = _test()
|
265
|
-
## incorrect data
|
266
|
-
@data = <<-'END'
|
267
|
-
title: my friends
|
268
|
-
address-book:
|
269
|
-
- name: 100
|
270
|
-
email: foo@mail.com
|
271
|
-
- first-name: bar
|
272
|
-
email: bar@mail.com
|
273
|
-
END
|
274
|
-
@expected = <<-'END'
|
275
|
-
:invalid_type : [/address-book/1/name] string type expected but got Fixnum.
|
276
|
-
:missing_key : [/address-book/2] key 'name' required but not found.
|
277
|
-
:invalid_key : [/address-book/2] key 'first-name' is not expected.
|
278
|
-
END
|
279
|
-
errors = _test()
|
280
|
-
end
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
def test_validate13
|
285
|
-
@schema = <<-'END'
|
286
|
-
type: seq
|
287
|
-
sequence:
|
288
|
-
- &employee
|
289
|
-
type: map
|
290
|
-
mapping:
|
291
|
-
name:
|
292
|
-
type: string
|
293
|
-
post:
|
294
|
-
enum:
|
295
|
-
- exective
|
296
|
-
- manager
|
297
|
-
- clerk
|
298
|
-
supervisor: *employee
|
299
|
-
END
|
300
|
-
## correct data
|
301
|
-
@data = <<-'END'
|
302
|
-
- &foo
|
303
|
-
name: foo
|
304
|
-
post: exective
|
305
|
-
- &bar
|
306
|
-
name: bar
|
307
|
-
post: manager
|
308
|
-
supervisor: *foo
|
309
|
-
- &baz
|
310
|
-
name: baz
|
311
|
-
post: clerk
|
312
|
-
supervisor: *bar
|
313
|
-
- &zak
|
314
|
-
name: zak
|
315
|
-
post: clerk
|
316
|
-
supervisor: *bar
|
317
|
-
END
|
318
|
-
@expected = ""
|
319
|
-
errors = _test()
|
320
|
-
## incorrect data
|
321
|
-
@data = <<-'END'
|
322
|
-
- &foo
|
323
|
-
name: 100
|
324
|
-
post: exective
|
325
|
-
supervisor: *foo
|
326
|
-
- &bar
|
327
|
-
name: foo
|
328
|
-
post: worker
|
329
|
-
supervisor: *foo
|
330
|
-
END
|
331
|
-
@expected = <<-'END'
|
332
|
-
:invalid_type : [/1/name] string type expected but got Fixnum.
|
333
|
-
:invalid_enum : [/2/post] 'worker' is invalid enum value.
|
334
|
-
END
|
335
|
-
errors = _test()
|
336
|
-
end
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
# def test_validateXX
|
341
|
-
# @schema = <<-'END'
|
342
|
-
# END
|
343
|
-
# ## correct data
|
344
|
-
# @data = <<-'END'
|
345
|
-
# END
|
346
|
-
# @expected = <<-'END'
|
347
|
-
# END
|
348
|
-
# errors = _test()
|
349
|
-
# ## incorrect data
|
350
|
-
# @data = <<-'END'
|
351
|
-
# END
|
352
|
-
# @expected = <<-'END'
|
353
|
-
# END
|
354
|
-
# errors = _test()
|
355
|
-
# end
|
356
15
|
|
16
|
+
require 'test-validator.rb'
|
17
|
+
require 'test-metavalidator.rb'
|
357
18
|
|
19
|
+
if $0 == __FILE__
|
20
|
+
suite = Test::Unit::TestSuite.new()
|
21
|
+
suite << ValidatorTest.suite()
|
22
|
+
suite << MetaValidatorTest.suite()
|
23
|
+
Test::Unit::UI::Console::TestRunner.run(suite)
|
358
24
|
end
|
359
25
|
|
360
|
-
|
361
|
-
suite = Test::Unit::TestSuite.new()
|
362
|
-
suite << ValidatorTest.suite()
|
363
|
-
Test::Unit::UI::Console::TestRunner.run(suite)
|
364
|
-
|
data/todo.txt
CHANGED
@@ -8,9 +8,9 @@
|
|
8
8
|
.- [v] examples
|
9
9
|
.- [v] gemspec
|
10
10
|
.- [_] 'unique-keys:'
|
11
|
-
.- [
|
12
|
-
.- [
|
13
|
-
.- [
|
11
|
+
.- [-] 'not-null:'
|
12
|
+
.- [-] 'primary-key:'
|
13
|
+
.- [-] 'constraints:'
|
14
14
|
.- [v] meta-validation
|
15
15
|
.- [v] use 'sequence'/'mapping' or 'hash-elems'/'list-elems' instead of 'elements'
|
16
16
|
.- [X] 'default:'
|
@@ -18,4 +18,14 @@
|
|
18
18
|
.- [v] type 'Object'
|
19
19
|
.- [_] check RelaxNG
|
20
20
|
.- [_] check XML Schema type
|
21
|
-
.- [
|
21
|
+
.- [v] separate test script
|
22
|
+
.- [v] 'range:' or 'value:'
|
23
|
+
.- [v] 'length:' or 'width:'
|
24
|
+
.- [_] range 'max-ex' and 'min-ex' (or 'ceiling' and 'floor')
|
25
|
+
.- [_] range 'noteq'
|
26
|
+
.- [_] range 'reverse'
|
27
|
+
.- [v] type 'scalar'
|
28
|
+
.- [_] type 'collection'
|
29
|
+
.- [_] 'multiple: yes'
|
30
|
+
.- [v] support validator hook method
|
31
|
+
.- [_] test for kwalify command
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.10
|
|
3
3
|
specification_version: 1
|
4
4
|
name: kwalify
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.
|
7
|
-
date: 2005-
|
6
|
+
version: 0.2.0
|
7
|
+
date: 2005-09-25
|
8
8
|
summary: a tiny schema validator for YAML document.
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -29,11 +29,13 @@ authors:
|
|
29
29
|
files:
|
30
30
|
- lib/kwalify.rb
|
31
31
|
- lib/kwalify
|
32
|
-
- lib/kwalify/
|
32
|
+
- lib/kwalify/main-program.rb
|
33
|
+
- lib/kwalify/rule.rb
|
33
34
|
- lib/kwalify/types.rb
|
34
35
|
- lib/kwalify/validator.rb
|
35
36
|
- lib/kwalify/errors.rb
|
36
37
|
- lib/kwalify/meta-validator.rb
|
38
|
+
- lib/kwalify/messages.rb
|
37
39
|
- lib/kwalify/util
|
38
40
|
- lib/kwalify/util/yaml-helper.rb
|
39
41
|
- lib/kwalify/util/option-parser.rb
|
@@ -41,13 +43,20 @@ files:
|
|
41
43
|
- bin/kwalify
|
42
44
|
- examples/invoice
|
43
45
|
- examples/address-book
|
46
|
+
- examples/tapkit
|
44
47
|
- examples/invoice/invoice.schema.yaml
|
45
48
|
- examples/invoice/invoice.yaml
|
46
49
|
- examples/invoice/Makefile
|
47
50
|
- examples/address-book/Makefile
|
48
51
|
- examples/address-book/address-book.schema.yaml
|
49
52
|
- examples/address-book/address-book.yaml
|
53
|
+
- examples/tapkit/tapkit.schema.yaml
|
54
|
+
- examples/tapkit/tapkit.yaml
|
55
|
+
- examples/tapkit/Makefile
|
50
56
|
- test/test.rb
|
57
|
+
- test/test-metavalidator.rb
|
58
|
+
- test/test-validator.rb
|
59
|
+
- test/test-metavalidator.rb.error
|
51
60
|
- doc/users-guide.html
|
52
61
|
- doc/docstyle.css
|
53
62
|
- README.txt
|