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
@@ -1,37 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require 'kwalify'
|
4
|
-
require 'yaml'
|
5
|
-
|
6
|
-
## load schema definition
|
7
|
-
schema = YAML.load_file('answers-schema.yaml')
|
8
|
-
|
9
|
-
## create validator for answers
|
10
|
-
validator = Kwalify::Validator.new(schema) { |value, rule, path, errors|
|
11
|
-
case rule.name
|
12
|
-
when 'Answer'
|
13
|
-
if value['answer'] == 'bad'
|
14
|
-
reason = value['reason']
|
15
|
-
if !reason || reason.empty?
|
16
|
-
msg = "reason is required when answer is 'bad'."
|
17
|
-
errors << Kwalify::ValidationError.new(msg, path)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
}
|
22
|
-
|
23
|
-
## load YAML document
|
24
|
-
input = ARGF.read()
|
25
|
-
document = YAML.load(input)
|
26
|
-
|
27
|
-
## validate
|
28
|
-
errors = validator.validate(document)
|
29
|
-
if errors.empty?
|
30
|
-
puts "Valid."
|
31
|
-
else
|
32
|
-
puts "*** INVALID!"
|
33
|
-
errors.each do |error|
|
34
|
-
# error.class == Kwalify::ValidationError
|
35
|
-
puts " - [#{error.path}] : #{error.message}"
|
36
|
-
end
|
37
|
-
end
|
data/test/test-action.rb
DELETED
@@ -1,78 +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/main'
|
10
|
-
|
11
|
-
|
12
|
-
module Kwalify
|
13
|
-
class Main
|
14
|
-
public :_parse_argv
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
|
19
|
-
class File
|
20
|
-
def self.move(filename, dirname)
|
21
|
-
File.rename(filename, "#{dirname}/#{filename}")
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
|
26
|
-
class ActionTest < Test::Unit::TestCase
|
27
|
-
|
28
|
-
## define test methods
|
29
|
-
filename = __FILE__.sub(/\.rb$/, ".yaml")
|
30
|
-
load_yaml_testdata(filename, :lang=>'ruby')
|
31
|
-
|
32
|
-
|
33
|
-
## temporary directory
|
34
|
-
@@tmpdir = "tmp.dir"
|
35
|
-
Dir.mkdir(@@tmpdir) unless test(?d, @@tmpdir)
|
36
|
-
|
37
|
-
|
38
|
-
def _test
|
39
|
-
if @exception
|
40
|
-
classname = @exception =~ /Kwalify::(.*)/ ? $1 : @exception
|
41
|
-
@exception_class = Kwalify.const_get(classname)
|
42
|
-
end
|
43
|
-
return if $target && $target != @name
|
44
|
-
raise "*** #{@name}: args is required." unless @args
|
45
|
-
raise "*** #{@name}: expected is require." unless @expected
|
46
|
-
#
|
47
|
-
File.open("#{@name}.schema", 'w') { |f| f.write(@schema) } if @schema
|
48
|
-
File.open("#{@name}.document", 'w') { |f| f.write(@document) } if @document
|
49
|
-
#
|
50
|
-
begin
|
51
|
-
main = Kwalify::Main.new("kwalify")
|
52
|
-
$stdout = StringWriter.new
|
53
|
-
main.execute(@args)
|
54
|
-
actual = $stdout; $stdout = STDOUT
|
55
|
-
if @output_files
|
56
|
-
if @output_message
|
57
|
-
assert_text_equal(@output_message, actual)
|
58
|
-
else
|
59
|
-
assert(actual.nil? || actual=='')
|
60
|
-
end
|
61
|
-
@output_files.each do |filename|
|
62
|
-
actual = File.read(filename)
|
63
|
-
assert_text_equal(@expected[filename], actual)
|
64
|
-
end
|
65
|
-
else
|
66
|
-
assert_text_equal(@expected, actual)
|
67
|
-
end
|
68
|
-
ensure
|
69
|
-
File.move("#{@name}.schema", @@tmpdir) if @schema
|
70
|
-
File.move("#{@name}.document", @@tmpdir) if @document
|
71
|
-
@output_files.each do |filename|
|
72
|
-
File.move(filename, @@tmpdir) if test(?f, filename)
|
73
|
-
end if @output_files
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
|
78
|
-
end
|