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-rule.rb
DELETED
@@ -1,26 +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 RuleTest < Test::Unit::TestCase
|
11
|
-
|
12
|
-
## define test methods
|
13
|
-
filename = __FILE__.sub(/\.rb$/, '.yaml')
|
14
|
-
load_yaml_testdata(filename, :lang=>'ruby')
|
15
|
-
|
16
|
-
|
17
|
-
## execute test
|
18
|
-
def _test()
|
19
|
-
assert_nothing_raised do
|
20
|
-
return if $target && $target != @name
|
21
|
-
schema = @schema
|
22
|
-
rule = Kwalify::Rule.new(schema)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
end
|
data/test/test-rule.yaml
DELETED
@@ -1,317 +0,0 @@
|
|
1
|
-
##
|
2
|
-
## $Rev$
|
3
|
-
## $Release: 0.7.2 $
|
4
|
-
## copyright(c) 2005-2010 kuwata-lab all rights reserved.
|
5
|
-
##
|
6
|
-
---
|
7
|
-
name: sequence1
|
8
|
-
desc: basic sequence
|
9
|
-
input: |
|
10
|
-
type: seq
|
11
|
-
sequence:
|
12
|
-
- type: str
|
13
|
-
#
|
14
|
-
---
|
15
|
-
name: mapping1
|
16
|
-
desc: basic mapping
|
17
|
-
input: |
|
18
|
-
type: map
|
19
|
-
mapping:
|
20
|
-
"name":
|
21
|
-
type: str
|
22
|
-
required: yes
|
23
|
-
"email":
|
24
|
-
type: str
|
25
|
-
pattern: /@/
|
26
|
-
"age":
|
27
|
-
type: int
|
28
|
-
"birth":
|
29
|
-
type: date
|
30
|
-
#
|
31
|
-
---
|
32
|
-
name: seqmap1
|
33
|
-
desc: mapping of sequence
|
34
|
-
input: |
|
35
|
-
type: seq
|
36
|
-
sequence:
|
37
|
-
- type: map
|
38
|
-
mapping:
|
39
|
-
"name":
|
40
|
-
type: str
|
41
|
-
required: true
|
42
|
-
"email":
|
43
|
-
type: str
|
44
|
-
#
|
45
|
-
---
|
46
|
-
name: mapseq1
|
47
|
-
desc: mapping of sequence
|
48
|
-
input: |
|
49
|
-
type: map
|
50
|
-
mapping:
|
51
|
-
"company":
|
52
|
-
type: str
|
53
|
-
required: yes
|
54
|
-
"email":
|
55
|
-
type: str
|
56
|
-
"employees":
|
57
|
-
type: seq
|
58
|
-
sequence:
|
59
|
-
- type: map
|
60
|
-
mapping:
|
61
|
-
"code":
|
62
|
-
type: int
|
63
|
-
required: yes
|
64
|
-
"name":
|
65
|
-
type: str
|
66
|
-
required: yes
|
67
|
-
"email":
|
68
|
-
type: str
|
69
|
-
#
|
70
|
-
---
|
71
|
-
name: unique1
|
72
|
-
desc: unique constraint
|
73
|
-
input: |
|
74
|
-
type: seq
|
75
|
-
sequence:
|
76
|
-
- type: map
|
77
|
-
required: yes
|
78
|
-
mapping:
|
79
|
-
"name":
|
80
|
-
type: str
|
81
|
-
required: yes
|
82
|
-
unique: yes
|
83
|
-
"email":
|
84
|
-
type: str
|
85
|
-
"groups":
|
86
|
-
type: seq
|
87
|
-
sequence:
|
88
|
-
- type: str
|
89
|
-
unique: yes
|
90
|
-
---
|
91
|
-
name: constraints1
|
92
|
-
desc: some constraints
|
93
|
-
input: |
|
94
|
-
name: address-book
|
95
|
-
desc: Address book
|
96
|
-
type: seq
|
97
|
-
sequence:
|
98
|
-
- type: map
|
99
|
-
mapping:
|
100
|
-
"name":
|
101
|
-
type: str
|
102
|
-
required: yes
|
103
|
-
"email":
|
104
|
-
type: str
|
105
|
-
required: yes
|
106
|
-
pattern: /@/
|
107
|
-
"password":
|
108
|
-
type: str
|
109
|
-
length: { max: 16, min: 8 }
|
110
|
-
"age":
|
111
|
-
type: int
|
112
|
-
range: { max: 30, min: 18 }
|
113
|
-
# or assert: 18 <= val && val <= 30
|
114
|
-
"blood":
|
115
|
-
type: str
|
116
|
-
enum:
|
117
|
-
- A
|
118
|
-
- B
|
119
|
-
- O
|
120
|
-
- AB
|
121
|
-
"birth":
|
122
|
-
type: date
|
123
|
-
"memo":
|
124
|
-
type: any
|
125
|
-
"deleted"
|
126
|
-
type: bool
|
127
|
-
default: false
|
128
|
-
#
|
129
|
-
---
|
130
|
-
name: default1
|
131
|
-
desc: default rule
|
132
|
-
input: |
|
133
|
-
type: map
|
134
|
-
mapping:
|
135
|
-
"properties":
|
136
|
-
type: map
|
137
|
-
mapping:
|
138
|
-
=:
|
139
|
-
type: any
|
140
|
-
#
|
141
|
-
---
|
142
|
-
name: default2
|
143
|
-
desc: default rule #2
|
144
|
-
input: |
|
145
|
-
type: seq
|
146
|
-
sequence:
|
147
|
-
- type: map
|
148
|
-
mapping:
|
149
|
-
"name":
|
150
|
-
type: str
|
151
|
-
required: yes
|
152
|
-
"email":
|
153
|
-
type: str
|
154
|
-
"birth":
|
155
|
-
type: date
|
156
|
-
=:
|
157
|
-
type: any
|
158
|
-
#
|
159
|
-
---
|
160
|
-
name: merge1
|
161
|
-
desc: merge rule
|
162
|
-
input: |
|
163
|
-
type: map
|
164
|
-
mapping:
|
165
|
-
"group":
|
166
|
-
type: map
|
167
|
-
mapping:
|
168
|
-
"name": &name
|
169
|
-
type: str
|
170
|
-
required: yes
|
171
|
-
"email": &email
|
172
|
-
type: str
|
173
|
-
pattern: /@/
|
174
|
-
required: no
|
175
|
-
"user":
|
176
|
-
type: map
|
177
|
-
mapping:
|
178
|
-
"name":
|
179
|
-
<<: *name # merge
|
180
|
-
length: { max: 16 } # append
|
181
|
-
"email":
|
182
|
-
<<: *email # merge
|
183
|
-
required: yes # overwrite
|
184
|
-
#
|
185
|
-
---
|
186
|
-
name: anchor1
|
187
|
-
desc: sharing rule with anchor and alias
|
188
|
-
input: |
|
189
|
-
desc: Bookshelf
|
190
|
-
type: seq
|
191
|
-
sequence:
|
192
|
-
- type: map
|
193
|
-
mapping:
|
194
|
-
"title":
|
195
|
-
type: str
|
196
|
-
required: yes
|
197
|
-
"author": &persons # anchor
|
198
|
-
type: seq
|
199
|
-
sequence:
|
200
|
-
- type: str
|
201
|
-
"translator": *persons # alias
|
202
|
-
"publisher":
|
203
|
-
type: str
|
204
|
-
"year":
|
205
|
-
type: int
|
206
|
-
#
|
207
|
-
---
|
208
|
-
name: anchor2
|
209
|
-
desc: recursive definition of rule
|
210
|
-
input: |
|
211
|
-
&task # anchor
|
212
|
-
desc: WBS
|
213
|
-
type: map
|
214
|
-
mapping:
|
215
|
-
"name": { type: str, required: yes }
|
216
|
-
"assigned": { type: str }
|
217
|
-
"deadline": { type: date }
|
218
|
-
"subtasks":
|
219
|
-
type: seq
|
220
|
-
sequence:
|
221
|
-
- *task # alias
|
222
|
-
---
|
223
|
-
name: meta_schema
|
224
|
-
desc: schema for meta-validator
|
225
|
-
#
|
226
|
-
input: |
|
227
|
-
name: MAIN
|
228
|
-
type: map
|
229
|
-
required: yes
|
230
|
-
mapping: &main-rule
|
231
|
-
"name":
|
232
|
-
type: str
|
233
|
-
"desc":
|
234
|
-
type: str
|
235
|
-
"type":
|
236
|
-
type: str
|
237
|
-
#required: yes
|
238
|
-
enum:
|
239
|
-
- seq
|
240
|
-
#- sequence
|
241
|
-
#- list
|
242
|
-
- map
|
243
|
-
#- mapping
|
244
|
-
#- hash
|
245
|
-
- str
|
246
|
-
#- string
|
247
|
-
- int
|
248
|
-
#- integer
|
249
|
-
- float
|
250
|
-
- number
|
251
|
-
#- numeric
|
252
|
-
- bool
|
253
|
-
#- boolean
|
254
|
-
- text
|
255
|
-
- date
|
256
|
-
- time
|
257
|
-
- timestamp
|
258
|
-
#- object
|
259
|
-
- any
|
260
|
-
- scalar
|
261
|
-
#- collection
|
262
|
-
"required":
|
263
|
-
type: bool
|
264
|
-
"enum":
|
265
|
-
type: seq
|
266
|
-
sequence:
|
267
|
-
- type: scalar
|
268
|
-
unique: yes
|
269
|
-
"pattern":
|
270
|
-
type: str
|
271
|
-
"assert":
|
272
|
-
type: str
|
273
|
-
pattern: /\bval\b/
|
274
|
-
"range":
|
275
|
-
type: map
|
276
|
-
mapping:
|
277
|
-
"max":
|
278
|
-
type: scalar
|
279
|
-
"min":
|
280
|
-
type: scalar
|
281
|
-
"max-ex":
|
282
|
-
type: scalar
|
283
|
-
"min-ex":
|
284
|
-
type: scalar
|
285
|
-
"length":
|
286
|
-
type: map
|
287
|
-
mapping:
|
288
|
-
"max":
|
289
|
-
type: int
|
290
|
-
"min":
|
291
|
-
type: int
|
292
|
-
"max-ex":
|
293
|
-
type: int
|
294
|
-
"min-ex":
|
295
|
-
type: int
|
296
|
-
"ident":
|
297
|
-
type: bool
|
298
|
-
"unique":
|
299
|
-
type: bool
|
300
|
-
"sequence":
|
301
|
-
name: SEQUENCE
|
302
|
-
type: seq
|
303
|
-
sequence:
|
304
|
-
- type: map
|
305
|
-
mapping: *main-rule
|
306
|
-
name: MAIN
|
307
|
-
#required: yes
|
308
|
-
"mapping":
|
309
|
-
name: MAPPING
|
310
|
-
type: map
|
311
|
-
mapping:
|
312
|
-
=:
|
313
|
-
type: map
|
314
|
-
mapping: *main-rule
|
315
|
-
name: MAIN
|
316
|
-
#required: yes
|
317
|
-
|
data/test/test-users-guide.rb
DELETED
@@ -1,75 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/../test/test.rb')
|
2
|
-
|
3
|
-
class UsersGuideTest < Test::Unit::TestCase
|
4
|
-
|
5
|
-
DATA_DIR = 'data/users-guide'
|
6
|
-
CURR_DIR = Dir.pwd
|
7
|
-
for item in Dir.glob("#{DATA_DIR}/*.result").sort()
|
8
|
-
filename = File.basename(item)
|
9
|
-
name = (filename =~ /(.*)\.\w+$/) && $1.gsub(/[^\w]/, '_')
|
10
|
-
s = <<-END
|
11
|
-
def test_#{name}
|
12
|
-
@name = #{name.inspect}
|
13
|
-
@filename = #{filename.inspect}
|
14
|
-
_test()
|
15
|
-
end
|
16
|
-
END
|
17
|
-
eval s
|
18
|
-
end
|
19
|
-
|
20
|
-
### BEGIN
|
21
|
-
def test_address_book_ruby
|
22
|
-
@command = 'kwalify -a genclass-ruby -tf address_book.schema.yaml'
|
23
|
-
@result = File.read('address_book.rb')
|
24
|
-
_test()
|
25
|
-
end
|
26
|
-
def test_example_address_book_ruby
|
27
|
-
@command = 'ruby example_address_book.rb'
|
28
|
-
@result = File.read('example_address_book_ruby.result')
|
29
|
-
@testopts = { 'delete_object_id' => true }
|
30
|
-
_test()
|
31
|
-
end
|
32
|
-
### END
|
33
|
-
|
34
|
-
def setup
|
35
|
-
Dir.chdir DATA_DIR
|
36
|
-
end
|
37
|
-
|
38
|
-
def teardown
|
39
|
-
Dir.chdir CURR_DIR
|
40
|
-
end
|
41
|
-
|
42
|
-
def _test
|
43
|
-
#@name ||= (caller()[0] =~ /in `test_(.*?)'/) && $1
|
44
|
-
@name = (self.name =~ /\Atest_(.*)\(.*\)\z/) && $1
|
45
|
-
return if @name =~ /\_java$/
|
46
|
-
@filename ||= @name + '.result'
|
47
|
-
|
48
|
-
result = @result || File.read(@filename)
|
49
|
-
tuples = result.split(/^(?=\$ )/).collect do |s|
|
50
|
-
if s.sub!(/\A\$ (.*)\n/, '')
|
51
|
-
command = $1
|
52
|
-
while command =~ /\\\z/
|
53
|
-
command.chop!
|
54
|
-
s.sub!(/\A(.*)\n/, '')
|
55
|
-
command << $1
|
56
|
-
end
|
57
|
-
[@command || command, @expected || s]
|
58
|
-
else
|
59
|
-
[@command, @expected || s]
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
tuples.each do |command, expected|
|
64
|
-
actual = @actual || `#{command}`
|
65
|
-
#if @testopts && @testops['delete_object_id']
|
66
|
-
rexp = /(\#<\w+(::\w+)*:)0x[0-9a-f]+/
|
67
|
-
actual.gsub!(rexp, '\1')
|
68
|
-
expected.gsub!(rexp, '\1')
|
69
|
-
#end
|
70
|
-
assert_text_equal(expected, actual)
|
71
|
-
end
|
72
|
-
|
73
|
-
end
|
74
|
-
|
75
|
-
end
|
data/test/test-util.rb
DELETED
@@ -1,125 +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
|
-
require 'kwalify/util'
|
10
|
-
|
11
|
-
|
12
|
-
class UtilTest < Test::Unit::TestCase
|
13
|
-
|
14
|
-
def spec(detail)
|
15
|
-
yield
|
16
|
-
end
|
17
|
-
|
18
|
-
def test_untabify
|
19
|
-
spec "converts tab characters to spaces" do
|
20
|
-
input = "123\t999"
|
21
|
-
expected = "123 999"
|
22
|
-
assert_text_equal expected, Kwalify::Util.untabify(input)
|
23
|
-
end
|
24
|
-
spec "able to specify column width" do
|
25
|
-
input = "12\t999"
|
26
|
-
expected = "12 999"
|
27
|
-
assert_text_equal expected, Kwalify::Util.untabify(input, 4)
|
28
|
-
end
|
29
|
-
spec "able to handle multiline string" do
|
30
|
-
input = "123\n\t456\n789\t0"
|
31
|
-
expected = "123\n 456\n789 0"
|
32
|
-
assert_text_equal expected, Kwalify::Util.untabify(input)
|
33
|
-
end
|
34
|
-
spec "returns nil if argument is nil" do
|
35
|
-
assert_nil Kwalify::Util.untabify(nil)
|
36
|
-
end
|
37
|
-
spec "don't remove tailing spaces" do # bugfix
|
38
|
-
input = "abc\t\t"
|
39
|
-
expected = "abc "
|
40
|
-
assert_text_equal expected, Kwalify::Util.untabify(input)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
SCHEMA1 = <<END
|
45
|
-
type: seq
|
46
|
-
sequence:
|
47
|
-
- type: map
|
48
|
-
class: Member
|
49
|
-
mapping:
|
50
|
-
"name": { type: str, required: true }
|
51
|
-
"age": { type: int, required: false }
|
52
|
-
END
|
53
|
-
|
54
|
-
def test_traverse
|
55
|
-
spec "traverse schema structure" do
|
56
|
-
schema = YAML.load(SCHEMA1)
|
57
|
-
assert_equal "Member", schema["sequence"][0]["class"]
|
58
|
-
Kwalify::Util.traverse_schema(schema) do |rulehash|
|
59
|
-
## add module prefix to class name
|
60
|
-
if rulehash['class']
|
61
|
-
rulehash['class'] = 'MyModule::' + rulehash['class']
|
62
|
-
end
|
63
|
-
end
|
64
|
-
assert_equal "MyModule::Member", schema["sequence"][0]["class"]
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
def test_traverse_rule
|
69
|
-
spec "traverse rule" do
|
70
|
-
schema = YAML.load(SCHEMA1)
|
71
|
-
validator = Kwalify::Validator.new(schema)
|
72
|
-
rules = []
|
73
|
-
Kwalify::Util.traverse_rule(validator) do |rule|
|
74
|
-
rules << rule
|
75
|
-
end
|
76
|
-
assert_equal 4, rules.length
|
77
|
-
assert_text_equal <<'END', rules[0].send(:_inspect)
|
78
|
-
type: seq
|
79
|
-
klass: Array
|
80
|
-
-
|
81
|
-
type: map
|
82
|
-
klass: Hash
|
83
|
-
"name":
|
84
|
-
type: str
|
85
|
-
klass: String
|
86
|
-
required: true
|
87
|
-
"age":
|
88
|
-
type: int
|
89
|
-
klass: Integer
|
90
|
-
required: false
|
91
|
-
END
|
92
|
-
assert_text_equal <<'END', rules[1].send(:_inspect)
|
93
|
-
type: map
|
94
|
-
klass: Hash
|
95
|
-
"name":
|
96
|
-
type: str
|
97
|
-
klass: String
|
98
|
-
required: true
|
99
|
-
"age":
|
100
|
-
type: int
|
101
|
-
klass: Integer
|
102
|
-
required: false
|
103
|
-
END
|
104
|
-
assert_text_equal <<'END', rules[2].send(:_inspect)
|
105
|
-
type: str
|
106
|
-
klass: String
|
107
|
-
required: true
|
108
|
-
END
|
109
|
-
assert_text_equal <<'END', rules[3].send(:_inspect)
|
110
|
-
type: int
|
111
|
-
klass: Integer
|
112
|
-
required: false
|
113
|
-
END
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
def test_get_value
|
118
|
-
schema = YAML.load(SCHEMA1)
|
119
|
-
path = ['sequence', 0, 'mapping', 'name', 'type']
|
120
|
-
assert_equal 'str', Kwalify::Util.get_value(schema, path)
|
121
|
-
path = ['sequence', 1, 'mapping', 'name', 'type']
|
122
|
-
assert_equal nil, Kwalify::Util.get_value(schema, path)
|
123
|
-
end
|
124
|
-
|
125
|
-
end
|
data/test/test-validator.rb
DELETED
@@ -1,95 +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 ValidatorTest < Test::Unit::TestCase
|
11
|
-
|
12
|
-
|
13
|
-
## define test methods
|
14
|
-
filename = __FILE__.sub(/\.rb$/, '.yaml')
|
15
|
-
load_yaml_testdata(filename, :lang=>'ruby')
|
16
|
-
|
17
|
-
|
18
|
-
## execute test
|
19
|
-
def _test()
|
20
|
-
return if $target && $target != @name
|
21
|
-
## Syck parser
|
22
|
-
schema = YAML.load(@schema)
|
23
|
-
validator = Kwalify::Validator.new(schema)
|
24
|
-
error2 = @error.gsub(/\(line \d+\)/, '')
|
25
|
-
_test_by_syck_parser(validator, @valid, '' )
|
26
|
-
_test_by_syck_parser(validator, @invalid, error2)
|
27
|
-
## Kwalify::YamlParser
|
28
|
-
schema = Kwalify::YamlParser.new(@schema).parse()
|
29
|
-
validator = Kwalify::Validator.new(schema)
|
30
|
-
_test_by_kwalify_yamlparser(validator, @valid, '' )
|
31
|
-
_test_by_kwalify_yamlparser(validator, @invalid, @error)
|
32
|
-
## Kwalify::Yaml::Parser
|
33
|
-
schema = Kwalify::Yaml::Parser.new().parse(@schema)
|
34
|
-
validator = Kwalify::Validator.new(schema)
|
35
|
-
_test_by_kwalify_yaml_parser(validator, @valid, '' )
|
36
|
-
_test_by_kwalify_yaml_parser(validator, @invalid, @error2 || @error)
|
37
|
-
end
|
38
|
-
|
39
|
-
|
40
|
-
def _test_by_kwalify_yamlparser(validator, input, expected)
|
41
|
-
parser = Kwalify::YamlParser.new(input)
|
42
|
-
document = parser.parse()
|
43
|
-
error_list = validator.validate(document)
|
44
|
-
parser.set_errors_linenum(error_list)
|
45
|
-
error_list.sort!
|
46
|
-
actual = ''
|
47
|
-
error_list.each do |error|
|
48
|
-
e = error
|
49
|
-
args = [e.error_symbol.inspect, e.linenum, e.path, e.message]
|
50
|
-
actual << "%-20s: (line %d)[%s] %s\n" % args
|
51
|
-
end
|
52
|
-
if $print
|
53
|
-
print actual
|
54
|
-
else
|
55
|
-
assert_text_equal(expected, actual)
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
|
60
|
-
def _test_by_kwalify_yaml_parser(validator, input, expected)
|
61
|
-
parser = Kwalify::Yaml::Parser.new(validator)
|
62
|
-
document = parser.parse(input)
|
63
|
-
error_list = parser.errors()
|
64
|
-
error_list.sort!
|
65
|
-
actual = ''
|
66
|
-
error_list.each do |error|
|
67
|
-
e = error
|
68
|
-
args = [e.error_symbol.inspect, e.linenum, e.column, e.path, e.message]
|
69
|
-
#actual << "%-20s: (line %d)[%s] %s\n" % args
|
70
|
-
actual << "%-20s: %d:%d:[%s] %s\n" % args
|
71
|
-
end
|
72
|
-
if $print
|
73
|
-
print actual
|
74
|
-
else
|
75
|
-
assert_text_equal(expected, actual)
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
|
80
|
-
def _test_by_syck_parser(validator, input, expected)
|
81
|
-
document = YAML.load(input)
|
82
|
-
error_list = validator.validate(document)
|
83
|
-
expected = expected.to_a.sort.join()
|
84
|
-
actual = error_list.collect { |e|
|
85
|
-
"%-20s: [%s] %s\n" % [e.error_symbol.inspect, e.path, e.message]
|
86
|
-
}.sort.join()
|
87
|
-
if $print
|
88
|
-
print actual
|
89
|
-
else
|
90
|
-
assert_text_equal(expected, actual)
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
|
95
|
-
end
|