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 CHANGED
@@ -1,7 +1,12 @@
1
1
  .=title: ChangeLog
2
- .?release: $Release: 0.5.0 $
3
- .?lastupdate: $Date: 2005-12-17 13:49:16 +0900 (Sat, 17 Dec 2005) $
4
- .?version: $Rev: 42 $
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
@@ -1,7 +1,7 @@
1
1
  .=title: README
2
2
  .?version: $Rev: 41 $
3
3
  .?lastupdate: $Date: 2005-11-22 03:24:54 +0900 (Tue, 22 Nov 2005) $
4
- .?release: $Release: 0.5.0 $
4
+ .?release: $Release: 0.5.1 $
5
5
 
6
6
 
7
7
  .$ About Kwalify
data/bin/kwalify CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  ###
4
4
  ### $Rev: 42 $
5
- ### $Release: 0.5.0 $
5
+ ### $Release: 0.5.1 $
6
6
  ### copyright(c) 2005 kuwata-lab all rights reserved.
7
7
  ###
8
8
 
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 &lt;kwa(at)kuwata-lab.com&gt;<br>
18
- last update: $Date: 2005-12-17 13:49:16 +0900 (Sat, 17 Dec 2005) $<br>
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 # new rule
607
+ type: text # new rule
600
608
  length: { max: 16, min: 8 }
601
609
  age:
602
610
  type: int # new rule
@@ -1,7 +1,7 @@
1
1
  ##
2
2
  ## Kwalify schema example for address book
3
3
  ##
4
- ## $Release: 0.5.0 $
4
+ ## $Release: 0.5.1 $
5
5
  ## copyright(c) 2005 kuwata-lab all rights reserved.
6
6
  ##
7
7
  ##
@@ -2,7 +2,7 @@
2
2
  ### Kwalify schema example for invoice
3
3
  ###
4
4
  ### $Rev: 41 $
5
- ### $Release: 0.5.0 $
5
+ ### $Release: 0.5.1 $
6
6
  ### copyright(c) 2005 kuwata-lab all rights reserved.
7
7
  ###
8
8
 
@@ -1,7 +1,7 @@
1
1
  ##
2
2
  ## Kwalify schema example for TapKit
3
3
  ##
4
- ## $Release: 0.5.0 $
4
+ ## $Release: 0.5.1 $
5
5
  ## copyright(c) 2005 kuwata-lab all rights reserved.
6
6
  ##
7
7
 
data/lib/kwalify.rb CHANGED
@@ -1,13 +1,13 @@
1
1
  ###
2
2
  ### $Rev: 42 $
3
- ### $Release: 0.5.0 $
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.0 $" =~ /[.\d]+/) && $&
10
+ RELEASE = ("$Release: 0.5.1 $" =~ /[.\d]+/) && $&
11
11
 
12
12
  end
13
13
 
@@ -1,6 +1,6 @@
1
1
  ###
2
2
  ### $Rev: 42 $
3
- ### $Release: 0.5.0 $
3
+ ### $Release: 0.5.1 $
4
4
  ### copyright(c) 2005 kuwata-lab all rights reserved.
5
5
  ###
6
6
 
data/lib/kwalify/main.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  ###
2
- ### $Rev: 42 $
3
- ### $Release: 0.5.0 $
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
- if @flag_meta || @flag_meta2
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(@flag_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
- $stderr.puts ex.message
111
- exit 1
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 _load_yaml(str)
126
- str = YamlHelper.untabify(str) if @flag_untabify
127
- if @flag_linenum
128
- @parser = Kwalify::YamlParser.new(str)
129
- doc = @parser.parse()
130
- else
131
- doc = YAML.load(str)
132
- doc = doc.value if _domain_type?(doc)
133
- end
134
- return doc
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
- def _meta_validate(filenames)
139
- filenames = [ nil ] if filenames.empty?
140
- meta_validator = @flag_meta2 ? nil : Kwalify::MetaValidator.instance()
141
- flag_no_validate = @flag_meta2 == true
142
- s = ''
143
- filenames.each do |filename|
144
- s << __meta_validate(meta_validator, filename)
145
- end
146
- return s
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 __meta_validate(meta_validator, filename=nil)
151
- str = filename ? File.open(filename) { |f| f.read() } : $stdin.read()
152
- schema = _load_yaml(str)
153
- filename ||= "(stdin)"
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) # error raised when schema is wrong
173
+ validator = Kwalify::Validator.new(schema) # error raised when schema is wrong
164
174
  rescue Kwalify::SchemaError => ex
165
- errors = [ ex ]
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 _errors_to_str(errors)
182
- s = ''
183
- flag_linenum = @flag_linenum
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
- str = File.open(@schema_filename) { |f| f.read() }
201
- schema = _load_yaml(str)
202
- validator = Kwalify::Validator.new(schema)
203
- #
204
- filenames = [ nil ] if filenames.empty?
205
- s = ''
206
- filenames.each do |filename|
207
- s << __validate(validator, filename)
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 __validate(validator, filename=nil)
214
- str = filename ? File.open(filename) { |f| f.read() } : $stdin.read()
215
- filename ||= "(stdin)"
207
+ def _validate_files(validator, filenames)
216
208
  s = ''
217
- i = -1
218
- _each_yaml_documents(str) do |document|
219
- i += 1
220
- if !document || document.empty?
221
- #* key=:schema_empty msg="%s#%d: empty.\n"
222
- s << (Kwalify.msg(:schema_empty) % i)
223
- next
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
- errors = validator.validate(document)
226
- if errors.empty?
227
- #* key=:validation_valid msg="%s#%d: valid.\n"
228
- s << (Kwalify.msg(:validation_valid) % [filename, i]) unless @flag_silent
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
- #* key=:validation_invalid msg="%s#%d: INVALID\n"
231
- s << (Kwalify.msg(:validation_invalid) % [filename, i])
232
- s << _errors_to_str(errors)
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 _each_yaml_documents(str, &block)
240
- str = YamlHelper.untabify(str) if @flag_untabify
241
- if @flag_linenum
242
- @parser = Kwalify::YamlParser.new(str)
243
- while @parser.has_next()
244
- doc = @parser.parse()
245
- yield(doc)
246
- end
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
- YAML::load_documents(str) do |doc|
249
- doc = doc.value if _domain_type?(doc)
250
- yield(doc)
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
- s = ''
270
- s << "Usage1: #{@command} [-hvstl] -f schema.yaml document.yaml [document2.yaml ...]\n"
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
@@ -1,6 +1,6 @@
1
1
  ###
2
- ### $Rev: 42 $
3
- ### $Release: 0.5.0 $
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'
@@ -1,6 +1,6 @@
1
1
  ###
2
2
  ### $Rev: 42 $
3
- ### $Release: 0.5.0 $
3
+ ### $Release: 0.5.1 $
4
4
  ### copyright(c) 2005 kuwata-lab all rights reserved.
5
5
  ###
6
6
 
data/lib/kwalify/rule.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  ###
2
2
  ### $Rev: 42 $
3
- ### $Release: 0.5.0 $
3
+ ### $Release: 0.5.1 $
4
4
  ### copyright(c) 2005 kuwata-lab all rights reserved.
5
5
  ###
6
6
 
data/lib/kwalify/types.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  ###
2
2
  ### $Rev: 42 $
3
- ### $Release: 0.5.0 $
3
+ ### $Release: 0.5.1 $
4
4
  ### copyright(c) 2005 kuwata-lab all rights reserved.
5
5
  ###
6
6
 
@@ -1,6 +1,6 @@
1
1
  ###
2
2
  ### $Rev: 41 $
3
- ### $Release: 0.5.0 $
3
+ ### $Release: 0.5.1 $
4
4
  ### copyright(c) 2005 kuwata-lab all rights reserved.
5
5
  ###
6
6
 
@@ -1,6 +1,6 @@
1
1
  ###
2
2
  ### $Rev: 41 $
3
- ### $Release: 0.5.0 $
3
+ ### $Release: 0.5.1 $
4
4
  ### copyright(c) 2005 kuwata-lab all rights reserved.
5
5
  ###
6
6
 
@@ -1,6 +1,6 @@
1
1
  ###
2
2
  ### $Rev: 41 $
3
- ### $Release: 0.5.0 $
3
+ ### $Release: 0.5.1 $
4
4
  ### copyright(c) 2005 kuwata-lab all rights reserved.
5
5
  ###
6
6
 
@@ -1,6 +1,6 @@
1
1
  ###
2
2
  ### $Rev: 42 $
3
- ### $Release: 0.5.0 $
3
+ ### $Release: 0.5.1 $
4
4
  ### copyright(c) 2005 kuwata-lab all rights reserved.
5
5
  ###
6
6
 
@@ -1,6 +1,6 @@
1
1
  ###
2
- ### $Rev: 42 $
3
- ### $Release: 0.5.0 $
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
@@ -1,6 +1,6 @@
1
1
  ###
2
2
  ### $Rev: 42 $
3
- ### $Release: 0.5.0 $
3
+ ### $Release: 0.5.1 $
4
4
  ### copyright(c) 2005 kuwata-lab all rights reserved.
5
5
  ###
6
6
 
data/test/test-main.yaml CHANGED
@@ -1,13 +1,13 @@
1
1
  ##
2
- ## $Rev: 42 $
3
- ## $Release: 0.5.0 $
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: [ -hvsmtlDf, schema.yaml, document.yaml, document2.yaml ]
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 [-hvstl] -f schema.yaml document.yaml [document2.yaml ...]
135
- Usage2: kwalify [-hvstl] -m schema.yaml [schema2.yaml ...]
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: ok.
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: NG!
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
- #### user's guide
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
- #
@@ -1,6 +1,6 @@
1
1
  ###
2
2
  ### $Rev: 42 $
3
- ### $Release: 0.5.0 $
3
+ ### $Release: 0.5.1 $
4
4
  ### copyright(c) 2005 kuwata-lab all rights reserved.
5
5
  ###
6
6
 
@@ -1,6 +1,6 @@
1
1
  ##
2
- ## $Rev: 42 $
3
- ## $Release: 0.5.0 $
2
+ ## $Rev: 2 $
3
+ ## $Release: 0.5.1 $
4
4
  ## copyright(c) 2005 kuwata-lab all rights reserved.
5
5
  ##
6
6
  ---
data/test/test-rule.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  ###
2
2
  ### $Rev: 42 $
3
- ### $Release: 0.5.0 $
3
+ ### $Release: 0.5.1 $
4
4
  ### copyright(c) 2005 kuwata-lab all rights reserved.
5
5
  ###
6
6
 
data/test/test-rule.yaml CHANGED
@@ -1,6 +1,6 @@
1
1
  ##
2
- ## $Rev: 42 $
3
- ## $Release: 0.5.0 $
2
+ ## $Rev: 2 $
3
+ ## $Release: 0.5.1 $
4
4
  ## copyright(c) 2005 kuwata-lab all rights reserved.
5
5
  ##
6
6
  ---
@@ -1,6 +1,6 @@
1
1
  ###
2
2
  ### $Rev: 42 $
3
- ### $Release: 0.5.0 $
3
+ ### $Release: 0.5.1 $
4
4
  ### copyright(c) 2005 kuwata-lab all rights reserved.
5
5
  ###
6
6
 
@@ -1,6 +1,6 @@
1
1
  ##
2
- ## $Rev: 42 $
3
- ## $Release: 0.5.0 $
2
+ ## $Rev: 2 $
3
+ ## $Release: 0.5.1 $
4
4
  ## copyright(c) 2005 kuwata-lab all rights reserved.
5
5
  ##
6
6
  ---
@@ -1,6 +1,6 @@
1
1
  ###
2
2
  ### $Rev: 42 $
3
- ### $Release: 0.5.0 $
3
+ ### $Release: 0.5.1 $
4
4
  ### copyright(c) 2005 kuwata-lab all rights reserved.
5
5
  ###
6
6
 
@@ -1,6 +1,6 @@
1
1
  ##
2
- ## $Rev: 42 $
3
- ## $Release: 0.5.0 $
2
+ ## $Rev: 2 $
3
+ ## $Release: 0.5.1 $
4
4
  ## copyright(c) 2005 kuwata-lab all rights reserved.
5
5
  ##
6
6
  ---
data/test/test.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  ###
2
2
  ### $Rev: 42 $
3
- ### $Release: 0.5.0 $
3
+ ### $Release: 0.5.1 $
4
4
  ### copyright(c) 2005 kuwata-lab all rights reserved.
5
5
  ###
6
6
 
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.5.0
7
- date: 2005-12-18
6
+ version: 0.5.1
7
+ date: 2005-12-20
8
8
  summary: a tiny schema validator for YAML document.
9
9
  require_paths:
10
10
  - lib