kwalify 0.5.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +8 -3
- data/README.txt +1 -1
- data/bin/kwalify +1 -1
- data/doc/users-guide.html +11 -3
- data/examples/address-book/address-book.schema.yaml +1 -1
- data/examples/invoice/invoice.schema.yaml +1 -1
- data/examples/tapkit/tapkit.schema.yaml +1 -1
- data/lib/kwalify.rb +2 -2
- data/lib/kwalify/errors.rb +1 -1
- data/lib/kwalify/main.rb +125 -124
- data/lib/kwalify/messages.rb +23 -6
- data/lib/kwalify/meta-validator.rb +1 -1
- data/lib/kwalify/rule.rb +1 -1
- data/lib/kwalify/types.rb +1 -1
- 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 +1 -1
- data/lib/kwalify/validator.rb +1 -1
- data/lib/kwalify/yaml-parser.rb +3 -3
- data/test/test-main.rb +1 -1
- data/test/test-main.yaml +61 -12
- data/test/test-metavalidator.rb +1 -1
- data/test/test-metavalidator.yaml +2 -2
- data/test/test-rule.rb +1 -1
- data/test/test-rule.yaml +2 -2
- data/test/test-validator.rb +1 -1
- data/test/test-validator.yaml +2 -2
- data/test/test-yamlparser.rb +1 -1
- data/test/test-yamlparser.yaml +2 -2
- data/test/test.rb +1 -1
- metadata +2 -2
data/ChangeLog
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
.=title: ChangeLog
|
2
|
-
.?release: $Release: 0.5.
|
3
|
-
.?lastupdate: $Date: 2005-12-
|
4
|
-
.?version: $Rev:
|
2
|
+
.?release: $Release: 0.5.1 $
|
3
|
+
.?lastupdate: $Date: 2005-12-20 12:50:56 +0900 (Tue, 20 Dec 2005) $
|
4
|
+
.?version: $Rev: 44 $
|
5
|
+
|
6
|
+
|
7
|
+
.: 2005-12-20 (release 0.5.1)
|
8
|
+
.* Enhances:
|
9
|
+
.- add new command-line option '-E' which show errors in emacs-compatible style.
|
5
10
|
|
6
11
|
.: 2005-12-17 (release 0.5.0)
|
7
12
|
.* Enhances:
|
data/README.txt
CHANGED
data/bin/kwalify
CHANGED
data/doc/users-guide.html
CHANGED
@@ -15,7 +15,7 @@
|
|
15
15
|
<div align="left"><h1>Kwalify Users' Guide (for Ruby and Java)</h1></div>
|
16
16
|
<div align="left">
|
17
17
|
makoto kuwata <kwa(at)kuwata-lab.com><br>
|
18
|
-
last update: $Date: 2005-12-
|
18
|
+
last update: $Date: 2005-12-20 12:50:56 +0900 (Tue, 20 Dec 2005) $<br>
|
19
19
|
</div>
|
20
20
|
|
21
21
|
<a name="preface"></a>
|
@@ -173,9 +173,17 @@ $ java -classpath kwalify.jar kwalify.Main -m schema.yaml [schema2.yaml ...]
|
|
173
173
|
<dd class="dd3">
|
174
174
|
Show linenumber on which error found.
|
175
175
|
</dd>
|
176
|
+
<dt class="dt3"><strong>
|
177
|
+
<code>-E</code> </strong></dt>
|
178
|
+
<dd class="dd3">
|
179
|
+
Show errors in Emacs-compatible style (implies '-l' option).
|
180
|
+
</dd>
|
176
181
|
</dl>
|
177
182
|
<p>Notice that the command-line option <code>-l</code> is an experimental feature, for kwalify command use original YAML parser instead of Syck parser when this option is specified.
|
178
183
|
</p>
|
184
|
+
<p>If you are an Emacs user, try <code>-E</code> option that show errors in format which Emacs can parse and jump to errors.
|
185
|
+
You can use <code>C-x `</code> (next-error) to jump into errors.
|
186
|
+
</p>
|
179
187
|
<br>
|
180
188
|
|
181
189
|
|
@@ -195,7 +203,7 @@ validator = Kwalify::Validator.new(schema) # raises Kwalify::SchemaError if wro
|
|
195
203
|
document = YAML.load_file('document.yaml')
|
196
204
|
error_list = validator.validate(document)
|
197
205
|
unless error_list.empty?
|
198
|
-
error_list.each do |error| # error is Kwalify::ValidationError
|
206
|
+
error_list.each do |error| # error is instance of Kwalify::ValidationError
|
199
207
|
puts "[#{error.path}] #{error.message}"
|
200
208
|
end
|
201
209
|
end
|
@@ -596,7 +604,7 @@ sequence:
|
|
596
604
|
required: yes
|
597
605
|
pattern: /@/
|
598
606
|
password:
|
599
|
-
type: text
|
607
|
+
type: text # new rule
|
600
608
|
length: { max: 16, min: 8 }
|
601
609
|
age:
|
602
610
|
type: int # new rule
|
data/lib/kwalify.rb
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
###
|
2
2
|
### $Rev: 42 $
|
3
|
-
### $Release: 0.5.
|
3
|
+
### $Release: 0.5.1 $
|
4
4
|
### copyright(c) 2005 kuwata-lab all rights reserved.
|
5
5
|
###
|
6
6
|
|
7
7
|
|
8
8
|
module Kwalify
|
9
9
|
|
10
|
-
RELEASE = ("$Release: 0.5.
|
10
|
+
RELEASE = ("$Release: 0.5.1 $" =~ /[.\d]+/) && $&
|
11
11
|
|
12
12
|
end
|
13
13
|
|
data/lib/kwalify/errors.rb
CHANGED
data/lib/kwalify/main.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
###
|
2
|
-
### $Rev:
|
3
|
-
### $Release: 0.5.
|
2
|
+
### $Rev: 44 $
|
3
|
+
### $Release: 0.5.1 $
|
4
4
|
### copyright(c) 2005 kuwata-lab all rights reserved.
|
5
5
|
###
|
6
6
|
|
@@ -46,12 +46,19 @@ module Kwalify
|
|
46
46
|
@flag_silent = false
|
47
47
|
@flag_meta = false
|
48
48
|
@flag_untabify = false
|
49
|
+
@flag_emacs = false
|
49
50
|
@flag_linenum = false
|
50
51
|
@flag_debug = false
|
51
52
|
@schema_filename = nil
|
52
53
|
@properties = {}
|
53
54
|
end
|
54
55
|
|
56
|
+
|
57
|
+
def debug?
|
58
|
+
@flag_debug
|
59
|
+
end
|
60
|
+
|
61
|
+
|
55
62
|
def _inspect()
|
56
63
|
s = ""
|
57
64
|
s << "command : #{@command}\n"
|
@@ -60,6 +67,7 @@ module Kwalify
|
|
60
67
|
s << "flag_silent : #{@flag_silent}\n"
|
61
68
|
s << "flag_meta : #{@flag_meta}\n"
|
62
69
|
s << "flag_untabify : #{@flag_untabify}\n"
|
70
|
+
s << "flag_emacs : #{@flag_emacs}\n"
|
63
71
|
s << "flag_linenum : #{@flag_linenum}\n"
|
64
72
|
s << "flag_debug : #{@flag_debug}\n"
|
65
73
|
s << "schema_filename : #{@schema_filename != nil ? @schema_filename : 'null'}\n"
|
@@ -72,20 +80,25 @@ module Kwalify
|
|
72
80
|
|
73
81
|
|
74
82
|
def execute(argv=ARGV)
|
83
|
+
# parse command-line options
|
75
84
|
filenames = _parse_argv(argv)
|
76
85
|
|
86
|
+
# help or version
|
77
87
|
s = ''
|
78
88
|
s << _version() << "\n" if @flag_version
|
79
89
|
s << _usage() if @flag_help
|
80
90
|
return s unless s.empty?
|
81
91
|
|
82
|
-
|
92
|
+
# validation
|
93
|
+
if @flag_meta2
|
94
|
+
s = _quick_meta_validate(filenames)
|
95
|
+
elsif @flag_meta
|
83
96
|
s = _meta_validate(filenames)
|
84
97
|
elsif @schema_filename
|
85
98
|
if @flag_debug
|
86
|
-
s = _inspect_schema(@
|
99
|
+
s = _inspect_schema(@schema_filename)
|
87
100
|
else
|
88
|
-
s = _validate(filenames)
|
101
|
+
s = _validate(filenames, @schema_filename)
|
89
102
|
end
|
90
103
|
else
|
91
104
|
#* key=:command_option_noaction msg="command-line option '-f' or '-m' required."
|
@@ -107,8 +120,12 @@ module Kwalify
|
|
107
120
|
# $stderr.puts "ERROR: #{ex.message}"
|
108
121
|
# exit 1
|
109
122
|
rescue => ex
|
110
|
-
|
111
|
-
|
123
|
+
if main.debug?
|
124
|
+
raise ex
|
125
|
+
else
|
126
|
+
$stderr.puts ex.message
|
127
|
+
exit 1
|
128
|
+
end
|
112
129
|
end
|
113
130
|
end
|
114
131
|
|
@@ -122,161 +139,142 @@ module Kwalify
|
|
122
139
|
end
|
123
140
|
|
124
141
|
|
125
|
-
def
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
return
|
142
|
+
def _inspect_schema(schema_filename)
|
143
|
+
filename = schema_filename
|
144
|
+
str = File.open(schema_filename) { |f| f.read() }
|
145
|
+
str = YamlUtil.untabify(str) if @flag_untabify
|
146
|
+
schema = YAML.load(str)
|
147
|
+
return nil if schema == nil
|
148
|
+
validator = Kwalify::Validator.new(schema) # error raised when schema is wrong
|
149
|
+
s = validator._inspect()
|
150
|
+
s << "\n" unless s[-1] == ?\n
|
151
|
+
return s
|
135
152
|
end
|
136
153
|
|
137
154
|
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
end
|
155
|
+
#class QuickMetaValidator
|
156
|
+
# def validate(schema)
|
157
|
+
# errors = []
|
158
|
+
# begin
|
159
|
+
# validator = Kwalify::Validator.new(schema) # error raised when schema is wrong
|
160
|
+
# rescue Kwalify::SchemaError => ex
|
161
|
+
# errors << ex
|
162
|
+
# end
|
163
|
+
# return errors
|
164
|
+
# end
|
165
|
+
#end
|
148
166
|
|
149
167
|
|
150
|
-
def
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
if !schema || schema.empty?
|
155
|
-
#* key=:meta_empty msg="%s: empty.\n"
|
156
|
-
return Kwalify.msg(:meta_emtpy) % filename
|
157
|
-
end
|
158
|
-
errors = nil
|
159
|
-
if meta_validator
|
160
|
-
errors = meta_validator.validate(schema)
|
161
|
-
else
|
168
|
+
def _quick_meta_validate(filenames)
|
169
|
+
meta_validator = Object.new
|
170
|
+
def meta_validator.validate(schema)
|
171
|
+
errors = []
|
162
172
|
begin
|
163
|
-
validator = Kwalify::Validator.new(schema)
|
173
|
+
validator = Kwalify::Validator.new(schema) # error raised when schema is wrong
|
164
174
|
rescue Kwalify::SchemaError => ex
|
165
|
-
errors
|
175
|
+
errors << ex
|
166
176
|
end
|
177
|
+
return errors
|
167
178
|
end
|
168
|
-
s =
|
169
|
-
if !errors || errors.empty?
|
170
|
-
#* key=:meta_valid msg="%s: ok.\n"
|
171
|
-
s << (Kwalify.msg(:meta_valid) % filename) unless @flag_silent
|
172
|
-
else
|
173
|
-
#* key=:meta_invalid msg="%s: NG!\n"
|
174
|
-
s << (Kwalify.msg(:meta_invalid) % filename)
|
175
|
-
s << _errors_to_str(errors)
|
176
|
-
end
|
179
|
+
s = _validate_files(meta_validator, filenames)
|
177
180
|
return s
|
178
181
|
end
|
179
182
|
|
180
183
|
|
181
|
-
def
|
182
|
-
|
183
|
-
|
184
|
-
if flag_linenum
|
185
|
-
@parser.set_errors_linenum(errors)
|
186
|
-
errors = errors.sort
|
187
|
-
end
|
188
|
-
errors.each do |error|
|
189
|
-
if flag_linenum
|
190
|
-
s << " - (line #{error.linenum}) [#{error.path}] #{error.message}\n"
|
191
|
-
else
|
192
|
-
s << " - [#{error.path}] #{error.message}\n"
|
193
|
-
end
|
194
|
-
end
|
184
|
+
def _meta_validate(filenames)
|
185
|
+
meta_validator = Kwalify::MetaValidator.instance()
|
186
|
+
s = _validate_files(meta_validator, filenames)
|
195
187
|
return s
|
196
188
|
end
|
197
189
|
|
198
190
|
|
199
|
-
def _validate(filenames)
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
191
|
+
def _validate(filenames, schema_filename)
|
192
|
+
filename = schema_filename
|
193
|
+
str = File.open(filename) { |f| f.read() } # or File.read(filename) in ruby1.8
|
194
|
+
str = YamlHelper.untabify(str) if @flag_untabify
|
195
|
+
schema = YAML.load(str)
|
196
|
+
if schema
|
197
|
+
validator = Kwalify::Validator.new(schema)
|
198
|
+
s = _validate_files(validator, filenames)
|
199
|
+
else
|
200
|
+
#* key=:schema_empty msg="%s: empty schema.\n"
|
201
|
+
s = Kwalify.msg(:schema_emtpy) % filename
|
208
202
|
end
|
209
203
|
return s
|
210
204
|
end
|
211
205
|
|
212
206
|
|
213
|
-
def
|
214
|
-
str = filename ? File.open(filename) { |f| f.read() } : $stdin.read()
|
215
|
-
filename ||= "(stdin)"
|
207
|
+
def _validate_files(validator, filenames)
|
216
208
|
s = ''
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
209
|
+
filenames = [ nil ] if filenames.empty?
|
210
|
+
filenames.each do |filename|
|
211
|
+
if filename
|
212
|
+
str = File.open(filename) { |f| f.read() } # or File.read(filename) in ruby1.8
|
213
|
+
else
|
214
|
+
str = $stdin.read()
|
215
|
+
filename = '(stdin)'
|
224
216
|
end
|
225
|
-
|
226
|
-
if
|
227
|
-
|
228
|
-
|
217
|
+
str = YamlHelper.untabify(str) if @flag_untabify
|
218
|
+
if @flag_linenum
|
219
|
+
parser = Kwalify::YamlParser.new(str)
|
220
|
+
i = 0
|
221
|
+
while parser.has_next?
|
222
|
+
doc = parser.parse()
|
223
|
+
s << _validate_document(validator, doc, filename, i, parser)
|
224
|
+
i += 1
|
225
|
+
end
|
229
226
|
else
|
230
|
-
|
231
|
-
|
232
|
-
|
227
|
+
parser = nil
|
228
|
+
i = 0
|
229
|
+
YAML.load_documents(str) do |doc|
|
230
|
+
s << _validate_document(validator, doc, filename, i, nil)
|
231
|
+
i += 1
|
232
|
+
end
|
233
233
|
end
|
234
234
|
end
|
235
235
|
return s
|
236
236
|
end
|
237
237
|
|
238
238
|
|
239
|
-
def
|
240
|
-
|
241
|
-
if
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
239
|
+
def _validate_document(validator, doc, filename, i, parser=nil)
|
240
|
+
s = ''
|
241
|
+
if doc == nil
|
242
|
+
#* key=:validation_empty msg="%s#%d: empty.\n"
|
243
|
+
s << kwalify.msg(:validation_empty) % [filename, i]
|
244
|
+
return s
|
245
|
+
end
|
246
|
+
errors = validator.validate(doc)
|
247
|
+
if errors == nil || errors.empty?
|
248
|
+
#* key=:validation_valid msg="%s#%d: valid.\n"
|
249
|
+
s << Kwalify.msg(:validation_valid) % [filename, i] unless @flag_silent
|
247
250
|
else
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
+
#* key=:validation_invalid msg="%s#%d: INVALID\n"
|
252
|
+
s << Kwalify.msg(:validation_invalid) % [filename, i]
|
253
|
+
if @flag_linenum
|
254
|
+
#assert parser != nil
|
255
|
+
raise unless parser != nil
|
256
|
+
parser.set_errors_linenum(errors)
|
257
|
+
errors.sort!
|
258
|
+
end
|
259
|
+
errors.each do |error|
|
260
|
+
if @flag_emacs
|
261
|
+
#assert @flag_linenum
|
262
|
+
raise unless @flag_linenum
|
263
|
+
s << "#{filename}:#{error.linenum}: [#{error.path}] #{error.message}\n"
|
264
|
+
elsif @flag_linenum
|
265
|
+
s << " - (line #{error.linenum}) [#{error.path}] #{error.message}\n"
|
266
|
+
else
|
267
|
+
s << " - [#{error.path}] #{error.message}\n"
|
268
|
+
end
|
251
269
|
end
|
252
270
|
end
|
253
|
-
end
|
254
|
-
|
255
|
-
|
256
|
-
def _inspect_schema(schema_filename)
|
257
|
-
filename = schema_filename
|
258
|
-
str = filename ? File.open(filename) { |f| f.read() } : $stdin.read()
|
259
|
-
schema = _load_yaml(str)
|
260
|
-
return nil if !schema || schema.empty?
|
261
|
-
validator = Kwalify::Validator.new(schema) # error raised when schema is wrong
|
262
|
-
s = validator._inspect()
|
263
|
-
s << "\n" unless s[-1] == ?\n
|
264
271
|
return s
|
265
272
|
end
|
266
273
|
|
267
274
|
|
268
275
|
def _usage()
|
269
|
-
|
270
|
-
|
271
|
-
s << "Usage2: #{@command} [-hvstl] -m schema.yaml [schema2.yaml ...]\n"
|
272
|
-
s << " -h, --help : help\n"
|
273
|
-
s << " -v : version\n"
|
274
|
-
s << " -s : silent\n"
|
275
|
-
s << " -f schema.yaml : schema definition file\n"
|
276
|
-
s << " -m : meta-validation mode\n"
|
277
|
-
s << " -t : expand tab character automatically\n"
|
278
|
-
s << " -l : show linenumber when errored (experimental)\n"
|
279
|
-
return s
|
276
|
+
msg = Kwalify.msg(:command_help) % [@command, @command]
|
277
|
+
return msg
|
280
278
|
end
|
281
279
|
|
282
280
|
|
@@ -284,6 +282,7 @@ module Kwalify
|
|
284
282
|
return RELEASE
|
285
283
|
end
|
286
284
|
|
285
|
+
|
287
286
|
def _to_value(str)
|
288
287
|
case str
|
289
288
|
when nil, "null", "nil" ; return nil
|
@@ -297,6 +296,7 @@ module Kwalify
|
|
297
296
|
end
|
298
297
|
end
|
299
298
|
|
299
|
+
|
300
300
|
def _parse_argv(argv)
|
301
301
|
while argv[0] && argv[0][0] == ?-
|
302
302
|
optstr = argv.shift
|
@@ -321,9 +321,10 @@ module Kwalify
|
|
321
321
|
when ?v ; @flag_version = true
|
322
322
|
when ?s ; @flag_silent = true
|
323
323
|
when ?t ; @flag_untabify = true
|
324
|
-
when ?l ; @flag_linenum = true
|
325
324
|
when ?m ; @flag_meta = true
|
326
325
|
when ?M ; @flag_meta2 = true
|
326
|
+
when ?E ; @flag_emacs = true ; @flag_linenum = true
|
327
|
+
when ?l ; @flag_linenum = true
|
327
328
|
when ?D ; @flag_debug = true
|
328
329
|
when ?f ;
|
329
330
|
arg = optstr.empty? ? argv.shift : optstr
|
data/lib/kwalify/messages.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
###
|
2
|
-
### $Rev:
|
3
|
-
### $Release: 0.5.
|
2
|
+
### $Rev: 44 $
|
3
|
+
### $Release: 0.5.1 $
|
4
4
|
### copyright(c) 2005 kuwata-lab all rights reserved.
|
5
5
|
###
|
6
6
|
|
@@ -12,14 +12,31 @@ module Kwalify
|
|
12
12
|
return @@messages[key]
|
13
13
|
end
|
14
14
|
|
15
|
-
|
15
|
+
|
16
|
+
|
17
|
+
@@messages[:command_help] = <<END
|
18
|
+
Usage1: %s [-hvstlE] -f schema.yaml doc.yaml [doc2.yaml ...]
|
19
|
+
Usage2: %s [-hvstlE] -m schema.yaml [schema2.yaml ...]
|
20
|
+
-h, --help : help
|
21
|
+
-v : version
|
22
|
+
-s : silent
|
23
|
+
-f schema.yaml : schema definition file
|
24
|
+
-m : meta-validation mode
|
25
|
+
-t : expand tab character automatically
|
26
|
+
-l : show linenumber when errored (experimental)
|
27
|
+
-E : show errors in emacs-style (implies '-l')
|
28
|
+
END
|
29
|
+
|
30
|
+
|
31
|
+
|
16
32
|
##----- begin
|
17
33
|
# filename: lib/kwalify/main.rb
|
18
34
|
@@messages[:command_option_noaction] = "command-line option '-f' or '-m' required."
|
19
35
|
@@messages[:meta_empty] = "%s: empty.\n"
|
20
36
|
@@messages[:meta_valid] = "%s: ok.\n"
|
21
37
|
@@messages[:meta_invalid] = "%s: NG!\n"
|
22
|
-
@@messages[:schema_empty] = "%s#%d: empty.\n"
|
38
|
+
@@messages[:schema_empty] = "%s#%d: empty schema.\n"
|
39
|
+
@@messages[:validation_empty] = "%s#%d: empty.\n"
|
23
40
|
@@messages[:validation_valid] = "%s#%d: valid.\n"
|
24
41
|
@@messages[:validation_invalid] = "%s#%d: INVALID\n"
|
25
42
|
@@messages[:command_property_invalid] = "%s: invalid property."
|
@@ -122,11 +139,11 @@ module Kwalify
|
|
122
139
|
|
123
140
|
|
124
141
|
@@words = {}
|
125
|
-
|
142
|
+
|
126
143
|
def self.word(key)
|
127
144
|
return @@words[key] || key
|
128
145
|
end
|
129
|
-
|
146
|
+
|
130
147
|
@@words['str'] = 'string'
|
131
148
|
@@words['int'] = 'integer'
|
132
149
|
@@words['bool'] = 'boolean'
|
data/lib/kwalify/rule.rb
CHANGED
data/lib/kwalify/types.rb
CHANGED
data/lib/kwalify/validator.rb
CHANGED
data/lib/kwalify/yaml-parser.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
###
|
2
|
-
### $Rev:
|
3
|
-
### $Release: 0.5.
|
2
|
+
### $Rev: 44 $
|
3
|
+
### $Release: 0.5.1 $
|
4
4
|
### copyright(c) 2005 kuwata-lab all rights reserved.
|
5
5
|
###
|
6
6
|
|
@@ -50,7 +50,7 @@ module Kwalify
|
|
50
50
|
end
|
51
51
|
|
52
52
|
|
53
|
-
def has_next
|
53
|
+
def has_next?
|
54
54
|
return @end_flag != 'EOF'
|
55
55
|
end
|
56
56
|
|
data/test/test-main.rb
CHANGED
data/test/test-main.yaml
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
##
|
2
|
-
## $Rev:
|
3
|
-
## $Release: 0.5.
|
2
|
+
## $Rev: 44 $
|
3
|
+
## $Release: 0.5.1 $
|
4
4
|
## copyright(c) 2005 kuwata-lab all rights reserved.
|
5
5
|
##
|
6
6
|
---
|
7
7
|
name: parseOptions1
|
8
8
|
desc: test Main#parseOptions()
|
9
9
|
method: parseOptions
|
10
|
-
args: [ -
|
10
|
+
args: [ -hvsmtlEDf, schema.yaml, document.yaml, document2.yaml ]
|
11
11
|
inspect: |
|
12
12
|
command : kwalify
|
13
13
|
flag_help : true
|
@@ -15,6 +15,7 @@ inspect: |
|
|
15
15
|
flag_silent : true
|
16
16
|
flag_meta : true
|
17
17
|
flag_untabify : true
|
18
|
+
flag_emacs : true
|
18
19
|
flag_linenum : true
|
19
20
|
flag_debug : true
|
20
21
|
schema_filename : schema.yaml
|
@@ -35,6 +36,7 @@ inspect: |
|
|
35
36
|
flag_silent : false
|
36
37
|
flag_meta : false
|
37
38
|
flag_untabify : false
|
39
|
+
flag_emacs : false
|
38
40
|
flag_linenum : true
|
39
41
|
flag_debug : false
|
40
42
|
schema_filename : schema.yaml
|
@@ -53,6 +55,7 @@ inspect: |
|
|
53
55
|
flag_silent : false
|
54
56
|
flag_meta : false
|
55
57
|
flag_untabify : false
|
58
|
+
flag_emacs : false
|
56
59
|
flag_linenum : false
|
57
60
|
flag_debug : false
|
58
61
|
schema_filename : null
|
@@ -62,6 +65,26 @@ inspect: |
|
|
62
65
|
- document.yaml
|
63
66
|
#
|
64
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
|
+
---
|
65
88
|
name: optionError1
|
66
89
|
desc: invalid command-line option
|
67
90
|
method: parseOptions
|
@@ -116,7 +139,7 @@ message: "command-line option '-f' or '-m' required."
|
|
116
139
|
error_symbol*:
|
117
140
|
ruby: !ruby/sym :command_option_noschema
|
118
141
|
java: command.option.noaction
|
119
|
-
|
142
|
+
#
|
120
143
|
---
|
121
144
|
name: version
|
122
145
|
desc: option '-v'
|
@@ -131,8 +154,8 @@ desc: option '-h'
|
|
131
154
|
method: execute
|
132
155
|
args: [ -hD, document.yaml ]
|
133
156
|
expected: |
|
134
|
-
Usage1: kwalify [-
|
135
|
-
Usage2: kwalify [-
|
157
|
+
Usage1: kwalify [-hvstlE] -f schema.yaml doc.yaml [doc2.yaml ...]
|
158
|
+
Usage2: kwalify [-hvstlE] -m schema.yaml [schema2.yaml ...]
|
136
159
|
-h, --help : help
|
137
160
|
-v : version
|
138
161
|
-s : silent
|
@@ -140,6 +163,7 @@ expected: |
|
|
140
163
|
-m : meta-validation mode
|
141
164
|
-t : expand tab character automatically
|
142
165
|
-l : show linenumber when errored (experimental)
|
166
|
+
-E : show errors in emacs-style (implies '-l')
|
143
167
|
#
|
144
168
|
---
|
145
169
|
name: silent1
|
@@ -249,7 +273,7 @@ schema: |
|
|
249
273
|
- type: str
|
250
274
|
document: |
|
251
275
|
expected: |
|
252
|
-
meta1.schema:
|
276
|
+
meta1.schema#0: valid.
|
253
277
|
#
|
254
278
|
---
|
255
279
|
name: meta2
|
@@ -262,14 +286,40 @@ schema: |
|
|
262
286
|
- type: str
|
263
287
|
document: |
|
264
288
|
expected: |
|
265
|
-
meta2.schema:
|
289
|
+
meta2.schema#0: INVALID
|
266
290
|
- [/] type 'map' requires 'mapping:'.
|
267
291
|
- [/] 'sequence:': not available with mapping.
|
268
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
|
+
#
|
269
319
|
|
270
|
-
|
271
|
-
|
272
|
-
|
320
|
+
###
|
321
|
+
### user's guide
|
322
|
+
###
|
273
323
|
---
|
274
324
|
name: validation01
|
275
325
|
desc: basic validation
|
@@ -753,4 +803,3 @@ invalid-out: |
|
|
753
803
|
validation15.invalid#0: INVALID
|
754
804
|
- (line 4) [/user] key 'email:' is required.
|
755
805
|
- (line 5) [/user/name] 'toooooo-looooong-name': too long (length 21 > max 16).
|
756
|
-
#
|
data/test/test-metavalidator.rb
CHANGED
data/test/test-rule.rb
CHANGED
data/test/test-rule.yaml
CHANGED
data/test/test-validator.rb
CHANGED
data/test/test-validator.yaml
CHANGED
data/test/test-yamlparser.rb
CHANGED
data/test/test-yamlparser.yaml
CHANGED
data/test/test.rb
CHANGED
metadata
CHANGED