kwalify 0.6.1 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (219) hide show
  1. data/CHANGES.txt +232 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.txt +16 -19
  4. data/bin/kwalify +3 -3
  5. data/contrib/inline-require +6 -4
  6. data/contrib/kwalify +3719 -2427
  7. data/doc-api/classes/CommandOptionError.html +17 -17
  8. data/doc-api/classes/CommandOptionParser.html +63 -63
  9. data/doc-api/classes/Kwalify.html +29 -7
  10. data/doc-api/classes/Kwalify/AssertionError.html +9 -9
  11. data/doc-api/classes/Kwalify/BaseError.html +72 -71
  12. data/doc-api/classes/Kwalify/BaseParser.html +461 -0
  13. data/doc-api/classes/Kwalify/CommandOptionError.html +11 -11
  14. data/doc-api/classes/Kwalify/ErrorHelper.html +51 -46
  15. data/doc-api/classes/Kwalify/HashInterface.html +13 -135
  16. data/doc-api/classes/Kwalify/Json.html +105 -0
  17. data/doc-api/classes/Kwalify/Main.html +129 -126
  18. data/doc-api/classes/Kwalify/MetaValidator.html +248 -232
  19. data/doc-api/classes/Kwalify/Parser.html +12 -12
  20. data/doc-api/classes/Kwalify/PlainYamlParser.html +166 -163
  21. data/doc-api/classes/Kwalify/PlainYamlParser/Alias.html +11 -11
  22. data/doc-api/classes/Kwalify/Rule.html +152 -130
  23. data/doc-api/classes/Kwalify/SchemaError.html +10 -10
  24. data/doc-api/classes/Kwalify/SyntaxError.html +185 -0
  25. data/doc-api/classes/Kwalify/Types.html +26 -25
  26. data/doc-api/classes/Kwalify/Util.html +389 -0
  27. data/doc-api/classes/Kwalify/Util/HashLike.html +246 -0
  28. data/doc-api/classes/Kwalify/Util/OrderedHash.html +330 -0
  29. data/doc-api/classes/Kwalify/ValidationError.html +10 -10
  30. data/doc-api/classes/Kwalify/Validator.html +153 -86
  31. data/doc-api/classes/Kwalify/Yaml.html +181 -0
  32. data/doc-api/classes/Kwalify/Yaml/Parser.html +1538 -0
  33. data/doc-api/classes/Kwalify/YamlParser.html +190 -183
  34. data/doc-api/classes/Kwalify/YamlSyntaxError.html +8 -57
  35. data/doc-api/created.rid +1 -1
  36. data/doc-api/files/__/README_txt.html +17 -22
  37. data/doc-api/files/kwalify/errors_rb.html +2 -2
  38. data/doc-api/files/kwalify/main_rb.html +4 -3
  39. data/doc-api/files/kwalify/messages_rb.html +2 -2
  40. data/doc-api/files/kwalify/meta-validator_rb.html +3 -3
  41. data/doc-api/files/kwalify/{util/yaml-helper_rb.html → parser/base_rb.html} +8 -6
  42. data/doc-api/files/kwalify/parser/yaml_rb.html +117 -0
  43. data/doc-api/files/kwalify/rule_rb.html +2 -2
  44. data/doc-api/files/kwalify/types_rb.html +2 -2
  45. data/doc-api/files/kwalify/util/assert-text-equal_rb.html +2 -2
  46. data/doc-api/files/kwalify/util/hash-interface_rb.html +9 -2
  47. data/doc-api/files/kwalify/util/hashlike_rb.html +107 -0
  48. data/doc-api/files/kwalify/util/option-parser_rb.html +2 -2
  49. data/doc-api/files/kwalify/util/ordered-hash_rb.html +107 -0
  50. data/doc-api/files/kwalify/util/testcase-helper_rb.html +2 -2
  51. data/doc-api/files/kwalify/util_rb.html +107 -0
  52. data/doc-api/files/kwalify/validator_rb.html +2 -2
  53. data/doc-api/files/kwalify/yaml-parser_rb.html +2 -2
  54. data/doc-api/files/kwalify_rb.html +3 -2
  55. data/doc-api/fr_class_index.html +8 -1
  56. data/doc-api/fr_file_index.html +5 -1
  57. data/doc-api/fr_method_index.html +128 -69
  58. data/doc/img/fig01.png +0 -0
  59. data/doc/users-guide.html +882 -717
  60. data/examples/address-book/address-book.schema.yaml +2 -2
  61. data/examples/data-binding/BABEL.data.yaml +63 -0
  62. data/examples/data-binding/BABEL.schema.yaml +31 -0
  63. data/examples/data-binding/Makefile +8 -0
  64. data/examples/data-binding/Rakefile +13 -0
  65. data/examples/data-binding/main.rb +27 -0
  66. data/examples/invoice/invoice.schema.yaml +3 -3
  67. data/examples/tapkit/tapkit.schema.yaml +2 -2
  68. data/lib/kwalify.rb +41 -4
  69. data/lib/kwalify/errors.rb +118 -96
  70. data/lib/kwalify/kwalify.schema.yaml +58 -0
  71. data/lib/kwalify/main.rb +384 -377
  72. data/lib/kwalify/messages.rb +41 -27
  73. data/lib/kwalify/meta-validator.rb +251 -331
  74. data/lib/kwalify/parser/base.rb +127 -0
  75. data/lib/kwalify/parser/yaml.rb +837 -0
  76. data/lib/kwalify/rule.rb +545 -487
  77. data/lib/kwalify/templates/genclass-java.eruby +189 -162
  78. data/lib/kwalify/templates/genclass-php.eruby +104 -0
  79. data/lib/kwalify/templates/genclass-ruby.eruby +95 -66
  80. data/lib/kwalify/types.rb +107 -106
  81. data/lib/kwalify/util.rb +157 -0
  82. data/lib/kwalify/util/assert-text-equal.rb +33 -31
  83. data/lib/kwalify/util/hash-interface.rb +11 -30
  84. data/lib/kwalify/util/hashlike.rb +51 -0
  85. data/lib/kwalify/util/option-parser.rb +144 -144
  86. data/lib/kwalify/util/ordered-hash.rb +57 -0
  87. data/lib/kwalify/util/testcase-helper.rb +3 -3
  88. data/lib/kwalify/validator.rb +267 -212
  89. data/lib/kwalify/yaml-parser.rb +822 -768
  90. data/setup.rb +861 -607
  91. data/test/Rookbook.yaml +10 -0
  92. data/test/{tmp.dir/Context.java → data/users-guide/AddressBook.java.expected} +11 -11
  93. data/test/data/users-guide/BABEL.data.yaml +24 -0
  94. data/test/data/users-guide/BABEL.schema.yaml +30 -0
  95. data/test/data/users-guide/ExampleAddressBook.java +47 -0
  96. data/test/{tmp.dir/Group.java → data/users-guide/Group.java.expected} +2 -11
  97. data/test/data/users-guide/Person.java.expected +44 -0
  98. data/test/data/users-guide/address_book.rb +52 -0
  99. data/test/data/users-guide/address_book.schema.yaml +28 -0
  100. data/test/data/users-guide/address_book.yaml +27 -0
  101. data/test/data/users-guide/answers-schema.yaml +12 -0
  102. data/test/data/users-guide/answers-validator.rb +52 -0
  103. data/test/data/users-guide/babel_genclass.result +26 -0
  104. data/test/data/users-guide/config.schema.yaml +7 -0
  105. data/test/data/users-guide/config.yaml +4 -0
  106. data/test/{tmp.dir/silent1.document → data/users-guide/document01a.yaml} +0 -0
  107. data/test/data/users-guide/document01b.yaml +3 -0
  108. data/test/data/users-guide/document02a.yaml +4 -0
  109. data/test/data/users-guide/document02b.yaml +4 -0
  110. data/test/data/users-guide/document03a.yaml +6 -0
  111. data/test/data/users-guide/document03b.yaml +6 -0
  112. data/test/data/users-guide/document04a.yaml +9 -0
  113. data/test/data/users-guide/document04b.yaml +9 -0
  114. data/test/data/users-guide/document05a.yaml +11 -0
  115. data/test/data/users-guide/document05b.yaml +12 -0
  116. data/test/data/users-guide/document06a.yaml +15 -0
  117. data/test/data/users-guide/document06b.yaml +16 -0
  118. data/test/data/users-guide/document07a.yaml +9 -0
  119. data/test/data/users-guide/document07b.yaml +7 -0
  120. data/test/data/users-guide/document12a.json +10 -0
  121. data/test/data/users-guide/document12b.json +6 -0
  122. data/test/data/users-guide/document13a.yaml +17 -0
  123. data/test/data/users-guide/document14a.yaml +3 -0
  124. data/test/data/users-guide/document14b.yaml +3 -0
  125. data/test/data/users-guide/document15a.yaml +6 -0
  126. data/test/data/users-guide/document15b.yaml +5 -0
  127. data/test/data/users-guide/example_address_book.rb +10 -0
  128. data/test/data/users-guide/example_address_book_java.result +32 -0
  129. data/test/data/users-guide/example_address_book_ruby.result +31 -0
  130. data/test/data/users-guide/genclass_java.result +4 -0
  131. data/test/data/users-guide/howto-validation-with-parsing.rb +28 -0
  132. data/test/data/users-guide/howto-validation.rb +25 -0
  133. data/test/data/users-guide/howto3.rb +6 -0
  134. data/test/data/users-guide/howto3.result +5 -0
  135. data/test/data/users-guide/howto3.yaml +8 -0
  136. data/test/data/users-guide/howto5_databinding.result +111 -0
  137. data/test/data/users-guide/invalid01.result +3 -0
  138. data/test/data/users-guide/invalid02.result +5 -0
  139. data/test/data/users-guide/invalid03.result +5 -0
  140. data/test/data/users-guide/invalid04.result +4 -0
  141. data/test/data/users-guide/invalid05.result +11 -0
  142. data/test/data/users-guide/invalid06.result +4 -0
  143. data/test/data/users-guide/invalid07.result +3 -0
  144. data/test/data/users-guide/invalid08.result +3 -0
  145. data/test/data/users-guide/invalid12.json +8 -0
  146. data/test/data/users-guide/invalid14.result +4 -0
  147. data/test/data/users-guide/invalid15.result +4 -0
  148. data/test/data/users-guide/loadbabel.rb +27 -0
  149. data/test/data/users-guide/loadconfig.rb +15 -0
  150. data/test/data/users-guide/loadconfig.result +2 -0
  151. data/test/data/users-guide/models.rb +22 -0
  152. data/test/data/users-guide/option_ha.result +6 -0
  153. data/test/data/users-guide/option_ha_genclass_java.result +7 -0
  154. data/test/{tmp.dir/meta1.schema → data/users-guide/schema01.yaml} +0 -0
  155. data/test/data/users-guide/schema02.yaml +12 -0
  156. data/test/data/users-guide/schema03.yaml +9 -0
  157. data/test/data/users-guide/schema04.yaml +20 -0
  158. data/test/data/users-guide/schema05.yaml +29 -0
  159. data/test/data/users-guide/schema06.yaml +11 -0
  160. data/test/data/users-guide/schema12.json +12 -0
  161. data/test/data/users-guide/schema13.yaml +13 -0
  162. data/test/data/users-guide/schema14.yaml +5 -0
  163. data/test/data/users-guide/schema15.yaml +21 -0
  164. data/test/data/users-guide/valid01.result +2 -0
  165. data/test/data/users-guide/valid02.result +2 -0
  166. data/test/data/users-guide/valid03.result +2 -0
  167. data/test/data/users-guide/valid04.result +2 -0
  168. data/test/data/users-guide/valid05.result +2 -0
  169. data/test/data/users-guide/valid06.result +2 -0
  170. data/test/data/users-guide/valid07.result +2 -0
  171. data/test/data/users-guide/valid08.result +2 -0
  172. data/test/data/users-guide/valid12.result +2 -0
  173. data/test/data/users-guide/valid13.result +2 -0
  174. data/test/data/users-guide/valid14.result +2 -0
  175. data/test/data/users-guide/valid15.result +2 -0
  176. data/test/data/users-guide/validate08.rb +37 -0
  177. data/test/test-action.rb +78 -0
  178. data/test/test-action.yaml +738 -0
  179. data/test/test-databinding.rb +80 -0
  180. data/test/test-databinding.yaml +301 -0
  181. data/test/test-main.rb +129 -150
  182. data/test/test-main.yaml +126 -321
  183. data/test/test-metavalidator.rb +47 -47
  184. data/test/test-metavalidator.yaml +77 -21
  185. data/test/test-parser-yaml.rb +57 -0
  186. data/test/test-parser-yaml.yaml +1749 -0
  187. data/test/test-rule.rb +14 -15
  188. data/test/test-rule.yaml +6 -3
  189. data/test/test-users-guide.rb +75 -0
  190. data/test/test-validator.rb +77 -52
  191. data/test/test-validator.yaml +168 -6
  192. data/test/test-yaml-parser.rb +47 -0
  193. data/test/{test-yamlparser.yaml → test-yaml-parser.yaml} +159 -52
  194. data/test/test.rb +37 -21
  195. metadata +136 -37
  196. data/COPYING +0 -340
  197. data/ChangeLog +0 -70
  198. data/doc-api/classes/YamlHelper.html +0 -259
  199. data/lib/kwalify/util/yaml-helper.rb +0 -82
  200. data/test/test-yamlparser.rb +0 -58
  201. data/test/tmp.dir/User.java +0 -43
  202. data/test/tmp.dir/action1.document +0 -18
  203. data/test/tmp.dir/action1.schema +0 -32
  204. data/test/tmp.dir/action2.document +0 -18
  205. data/test/tmp.dir/action2.schema +0 -32
  206. data/test/tmp.dir/emacs.document +0 -6
  207. data/test/tmp.dir/emacs.schema +0 -6
  208. data/test/tmp.dir/meta1.document +0 -0
  209. data/test/tmp.dir/meta2.document +0 -0
  210. data/test/tmp.dir/meta2.schema +0 -3
  211. data/test/tmp.dir/silent1.schema +0 -3
  212. data/test/tmp.dir/silent2.document +0 -7
  213. data/test/tmp.dir/silent2.schema +0 -3
  214. data/test/tmp.dir/stream.invalid +0 -8
  215. data/test/tmp.dir/stream.schema +0 -3
  216. data/test/tmp.dir/stream.valid +0 -8
  217. data/test/tmp.dir/untabify.document +0 -5
  218. data/test/tmp.dir/untabify.schema +0 -10
  219. data/todo.txt +0 -34
@@ -1,7 +1,7 @@
1
1
  ###
2
- ### $Rev: 51 $
3
- ### $Release: 0.6.1 $
4
- ### copyright(c) 2005 kuwata-lab all rights reserved.
2
+ ### $Rev: 83 $
3
+ ### $Release: 0.7.0 $
4
+ ### copyright(c) 2005-2008 kuwata-lab all rights reserved.
5
5
  ###
6
6
 
7
7
  require File.dirname(__FILE__) + '/test.rb'
@@ -9,19 +9,18 @@ require File.dirname(__FILE__) + '/test.rb'
9
9
 
10
10
  class RuleTest < Test::Unit::TestCase
11
11
 
12
- ## define test methods
13
- filename = __FILE__.sub(/\.rb$/, '.yaml')
14
- load_yaml_testdata(filename, :lang=>'ruby')
12
+ ## define test methods
13
+ filename = __FILE__.sub(/\.rb$/, '.yaml')
14
+ load_yaml_testdata(filename, :lang=>'ruby')
15
15
 
16
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
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
25
 
26
26
  end
27
-
@@ -1,7 +1,7 @@
1
1
  ##
2
- ## $Rev: 48 $
3
- ## $Release: 0.6.1 $
4
- ## copyright(c) 2005 kuwata-lab all rights reserved.
2
+ ## $Rev: 95 $
3
+ ## $Release: 0.7.0 $
4
+ ## copyright(c) 2005-2008 kuwata-lab all rights reserved.
5
5
  ##
6
6
  ---
7
7
  name: sequence1
@@ -122,6 +122,9 @@ input: |
122
122
  type: date
123
123
  "memo":
124
124
  type: any
125
+ "deleted"
126
+ type: bool
127
+ default: false
125
128
  #
126
129
  ---
127
130
  name: default1
@@ -0,0 +1,75 @@
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
@@ -1,7 +1,7 @@
1
1
  ###
2
- ### $Rev: 51 $
3
- ### $Release: 0.6.1 $
4
- ### copyright(c) 2005 kuwata-lab all rights reserved.
2
+ ### $Rev: 83 $
3
+ ### $Release: 0.7.0 $
4
+ ### copyright(c) 2005-2008 kuwata-lab all rights reserved.
5
5
  ###
6
6
 
7
7
  require File.dirname(__FILE__) + '/test.rb'
@@ -10,61 +10,86 @@ require File.dirname(__FILE__) + '/test.rb'
10
10
  class ValidatorTest < Test::Unit::TestCase
11
11
 
12
12
 
13
- ## define test methods
14
- filename = __FILE__.sub(/\.rb$/, '.yaml')
15
- load_yaml_testdata(filename, :lang=>'ruby')
13
+ ## define test methods
14
+ filename = __FILE__.sub(/\.rb$/, '.yaml')
15
+ load_yaml_testdata(filename, :lang=>'ruby')
16
16
 
17
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_parser(validator, @valid, '' )
31
- _test_by_kwalify_parser(validator, @invalid, @error)
32
- end
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
33
38
 
34
39
 
35
- def _test_by_kwalify_parser(validator, input, expected)
36
- parser = Kwalify::YamlParser.new(input)
37
- document = parser.parse()
38
- error_list = validator.validate(document)
39
- parser.set_errors_linenum(error_list)
40
- error_list.sort!
41
- actual = ''
42
- error_list.each do |error|
43
- e = error
44
- args = [e.error_symbol.inspect, e.linenum, e.path, e.message]
45
- actual << "%-20s: (line %d)[%s] %s\n" % args
46
- end
47
- if $print
48
- print actual
49
- else
50
- assert_text_equal(expected, actual)
51
- end
52
- end
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
53
58
 
54
59
 
55
- def _test_by_syck_parser(validator, input, expected)
56
- document = YAML.load(input)
57
- error_list = validator.validate(document)
58
- expected = expected.to_a.sort.join()
59
- actual = error_list.collect { |e|
60
- "%-20s: [%s] %s\n" % [e.error_symbol.inspect, e.path, e.message]
61
- }.sort.join()
62
- if $print
63
- print actual
64
- else
65
- assert_text_equal(expected, actual)
66
- end
67
- end
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
68
93
 
69
94
 
70
95
  end
@@ -1,7 +1,7 @@
1
1
  ##
2
- ## $Rev: 51 $
3
- ## $Release: 0.6.1 $
4
- ## copyright(c) 2005 kuwata-lab all rights reserved.
2
+ ## $Rev: 83 $
3
+ ## $Release: 0.7.0 $
4
+ ## copyright(c) 2005-2008 kuwata-lab all rights reserved.
5
5
  ##
6
6
  ---
7
7
  name: sequence1
@@ -30,6 +30,9 @@ invalid: |
30
30
  error: |
31
31
  :required_novalue : (line 3)[/2] value required but none.
32
32
  :type_unmatch : (line 5)[/4] '100': not a string.
33
+ error2: |
34
+ :required_novalue : 3:1:[/2] value required but none.
35
+ :type_unmatch : 5:1:[/4] '100': not a string.
33
36
  ##
34
37
  ---
35
38
  name: mapping1
@@ -80,6 +83,13 @@ error: |
80
83
  :type_unmatch : (line 3)[/age] 'twenty': not a integer.
81
84
  :enum_notexist : (line 4)[/blood] 'ab': invalid blood value.
82
85
  :type_unmatch : (line 5)[/birth] 'Jul 01, 1985': not a date.
86
+ error2: |
87
+ :required_nokey : 1:1:[/] key 'name:' is required.
88
+ :key_undefined : 1:1:[/nam] key 'nam:' is undefined.
89
+ :pattern_unmatch : 2:1:[/email] 'foo(at)mail.com': not matched to pattern /@/.
90
+ :type_unmatch : 3:1:[/age] 'twenty': not a integer.
91
+ :enum_notexist : 4:1:[/blood] 'ab': invalid blood value.
92
+ :type_unmatch : 5:1:[/birth] 'Jul 01, 1985': not a date.
83
93
  ##
84
94
  ---
85
95
  name: nested1
@@ -142,6 +152,13 @@ error: |
142
152
  :enum_notexist : (line 5)[/address-book/0/blood] 'ab': invalid blood value.
143
153
  :type_unmatch : (line 6)[/address-book/0/birth] '1985/01/01': not a date.
144
154
  :pattern_unmatch : (line 8)[/address-book/1/email] 'bar(at)mail.com': not matched to pattern /@/.
155
+ error2: |
156
+ :required_nokey : 2:5:[/address-book/0] key 'email:' is required.
157
+ :key_undefined : 3:5:[/address-book/0/mail] key 'mail:' is undefined.
158
+ :type_unmatch : 4:5:[/address-book/0/age] 'twenty': not a integer.
159
+ :enum_notexist : 5:5:[/address-book/0/blood] 'ab': invalid blood value.
160
+ :type_unmatch : 6:5:[/address-book/0/birth] '1985/01/01': not a date.
161
+ :pattern_unmatch : 8:5:[/address-book/1/email] 'bar(at)mail.com': not matched to pattern /@/.
145
162
  ##
146
163
  ---
147
164
  name: anchor1
@@ -176,6 +193,10 @@ error: |
176
193
  :required_nokey : (line 1)[/0] key 'family-name:' is required.
177
194
  :key_undefined : (line 2)[/0/last-name] key 'last-name:' is undefined.
178
195
  :type_unmatch : (line 4)[/1/family-name] '100': not a string.
196
+ error2: |
197
+ :required_nokey : 1:3:[/0] key 'family-name:' is required.
198
+ :key_undefined : 2:3:[/0/last-name] key 'last-name:' is undefined.
199
+ :type_unmatch : 4:3:[/1/family-name] '100': not a string.
179
200
  ##
180
201
  ---
181
202
  name: anchor2
@@ -220,6 +241,10 @@ error: |
220
241
  :type_unmatch : (line 3)[/address-book/0/name] '100': not a string.
221
242
  :required_nokey : (line 5)[/address-book/1] key 'name:' is required.
222
243
  :key_undefined : (line 5)[/address-book/1/first-name] key 'first-name:' is undefined.
244
+ error2: |
245
+ :type_unmatch : 3:5:[/address-book/0/name] '100': not a string.
246
+ :required_nokey : 5:5:[/address-book/1] key 'name:' is required.
247
+ :key_undefined : 5:5:[/address-book/1/first-name] key 'first-name:' is undefined.
223
248
  ##
224
249
  ---
225
250
  name: anchor3
@@ -272,6 +297,9 @@ invalid: |
272
297
  error: |
273
298
  :type_unmatch : (line 2)[/0/name] '100': not a string.
274
299
  :enum_notexist : (line 7)[/1/post] 'worker': invalid post value.
300
+ error2: |
301
+ :type_unmatch : 2:3:[/0/name] '100': not a string.
302
+ :enum_notexist : 7:3:[/1/post] 'worker': invalid post value.
275
303
  ##
276
304
  ---
277
305
  name: range1
@@ -335,6 +363,15 @@ error: |
335
363
  :range_toolarge : (line 9)[/max-and-min/1] '100.1': too large (> max 100.0).
336
364
  :range_toosmall : (line 10)[/max-and-min/2] '9': too small (< min 10.0).
337
365
  :range_toosmall : (line 11)[/max-and-min/3] '9.99': too small (< min 10.0).
366
+ error2: |
367
+ :range_toolarge : 2:3:[/max-only/0] '101': too large (> max 100).
368
+ :range_toolarge : 3:3:[/max-only/1] '100.1': too large (> max 100).
369
+ :range_toosmall : 5:3:[/min-only/0] '9': too small (< min 10.0).
370
+ :range_toosmall : 6:3:[/min-only/1] '9.99': too small (< min 10.0).
371
+ :range_toolarge : 8:3:[/max-and-min/0] '101': too large (> max 100.0).
372
+ :range_toolarge : 9:3:[/max-and-min/1] '100.1': too large (> max 100.0).
373
+ :range_toosmall : 10:3:[/max-and-min/2] '9': too small (< min 10.0).
374
+ :range_toosmall : 11:3:[/max-and-min/3] '9.99': too small (< min 10.0).
338
375
  ##
339
376
  ---
340
377
  name: range2
@@ -397,6 +434,15 @@ error: |
397
434
  :range_toolargeex : (line 9)[/max-ex-and-min-ex/1] '100.0': too large (>= max 100.0).
398
435
  :range_toosmallex : (line 10)[/max-ex-and-min-ex/2] '10': too small (<= min 10.0).
399
436
  :range_toosmallex : (line 11)[/max-ex-and-min-ex/3] '10.0': too small (<= min 10.0).
437
+ error2: |
438
+ :range_toolargeex : 2:3:[/max-ex-only/0] '100': too large (>= max 100).
439
+ :range_toolargeex : 3:3:[/max-ex-only/1] '100.0': too large (>= max 100).
440
+ :range_toosmallex : 5:3:[/min-ex-only/0] '10': too small (<= min 10.0).
441
+ :range_toosmallex : 6:3:[/min-ex-only/1] '10.0': too small (<= min 10.0).
442
+ :range_toolargeex : 8:3:[/max-ex-and-min-ex/0] '100': too large (>= max 100.0).
443
+ :range_toolargeex : 9:3:[/max-ex-and-min-ex/1] '100.0': too large (>= max 100.0).
444
+ :range_toosmallex : 10:3:[/max-ex-and-min-ex/2] '10': too small (<= min 10.0).
445
+ :range_toosmallex : 11:3:[/max-ex-and-min-ex/3] '10.0': too small (<= min 10.0).
400
446
  ##
401
447
  ---
402
448
  name: range3
@@ -439,6 +485,11 @@ error: |
439
485
  :range_toosmallex : (line 3)[/A/1] '10.0': too small (<= min 10.0).
440
486
  :range_toosmall : (line 5)[/B/0] '9.99999': too small (< min 10).
441
487
  :range_toolargeex : (line 6)[/B/1] '100.0': too large (>= max 100.0).
488
+ error2: |
489
+ :range_toolarge : 2:3:[/A/0] '100.00001': too large (> max 100).
490
+ :range_toosmallex : 3:3:[/A/1] '10.0': too small (<= min 10.0).
491
+ :range_toosmall : 5:3:[/B/0] '9.99999': too small (< min 10).
492
+ :range_toolargeex : 6:3:[/B/1] '100.0': too large (>= max 100.0).
442
493
  ##
443
494
  ---
444
495
  name: length1
@@ -490,6 +541,11 @@ error: |
490
541
  :length_tooshort : (line 4)[/min-only/0] 'foo': too short (length 3 < min 4).
491
542
  :length_toolong : (line 7)[/max-and-min/0] 'foobarbaz': too long (length 9 > max 8).
492
543
  :length_tooshort : (line 8)[/max-and-min/1] 'foo': too short (length 3 < min 4).
544
+ error2: |
545
+ :length_toolong : 2:3:[/max-only/0] 'hogehoge!': too long (length 9 > max 8).
546
+ :length_tooshort : 4:3:[/min-only/0] 'foo': too short (length 3 < min 4).
547
+ :length_toolong : 7:3:[/max-and-min/0] 'foobarbaz': too long (length 9 > max 8).
548
+ :length_tooshort : 8:3:[/max-and-min/1] 'foo': too short (length 3 < min 4).
493
549
  ##
494
550
  ---
495
551
  name: length2
@@ -540,6 +596,11 @@ error: |
540
596
  :length_tooshortex : (line 4)[/min-ex-only/0] 'foo!': too short (length 4 <= min 4).
541
597
  :length_toolongex : (line 7)[/max-ex-and-min-ex/0] 'foobarba': too long (length 8 >= max 8).
542
598
  :length_tooshortex : (line 8)[/max-ex-and-min-ex/1] 'foo!': too short (length 4 <= min 4).
599
+ error2: |
600
+ :length_toolongex : 2:3:[/max-ex-only/0] 'hogehoge': too long (length 8 >= max 8).
601
+ :length_tooshortex : 4:3:[/min-ex-only/0] 'foo!': too short (length 4 <= min 4).
602
+ :length_toolongex : 7:3:[/max-ex-and-min-ex/0] 'foobarba': too long (length 8 >= max 8).
603
+ :length_tooshortex : 8:3:[/max-ex-and-min-ex/1] 'foo!': too short (length 4 <= min 4).
543
604
  ##
544
605
  ---
545
606
  name: length3
@@ -580,6 +641,11 @@ error: |
580
641
  :length_tooshortex : (line 3)[/A/1] 'hoge': too short (length 4 <= min 4).
581
642
  :length_toolongex : (line 5)[/B/0] 'hogehoge': too long (length 8 >= max 8).
582
643
  :length_tooshort : (line 6)[/B/1] 'hog': too short (length 3 < min 4).
644
+ error2: |
645
+ :length_toolong : 2:3:[/A/0] 'hogehoge!': too long (length 9 > max 8).
646
+ :length_tooshortex : 3:3:[/A/1] 'hoge': too short (length 4 <= min 4).
647
+ :length_toolongex : 5:3:[/B/0] 'hogehoge': too long (length 8 >= max 8).
648
+ :length_tooshort : 6:3:[/B/1] 'hog': too short (length 3 < min 4).
583
649
  ##
584
650
  ---
585
651
  name: assert1
@@ -622,6 +688,11 @@ error: |
622
688
  :assert_failed : (line 2)[/1/more-than] '3': assertion expression failed (3 < val).
623
689
  :assert_failed : (line 3)[/2/between] '2.9': assertion expression failed (3 < val && val < 8).
624
690
  :assert_failed : (line 4)[/3/except] '3.1': assertion expression failed (val < 3 || 8 < val).
691
+ error2: |
692
+ :assert_failed : 1:3:[/0/less-than] '8': assertion expression failed (val < 8).
693
+ :assert_failed : 2:3:[/1/more-than] '3': assertion expression failed (3 < val).
694
+ :assert_failed : 3:3:[/2/between] '2.9': assertion expression failed (3 < val && val < 8).
695
+ :assert_failed : 4:3:[/3/except] '3.1': assertion expression failed (val < 3 || 8 < val).
625
696
  ##
626
697
  ---
627
698
  name: deftype1
@@ -658,6 +729,17 @@ error*:
658
729
  :type_unmatch : (line 2)[/0/email] 'true': not a string.
659
730
  :type_unmatch : (line 3)[/1/name] '3.14': not a string.
660
731
  :type_unmatch : (line 4)[/2/email] 'Sun Feb 01 00:00:00 JST 2004': not a string.
732
+ error2*:
733
+ ruby: |
734
+ :type_unmatch : 1:3:[/0/name] '123': not a string.
735
+ :type_unmatch : 2:3:[/0/email] 'true': not a string.
736
+ :type_unmatch : 3:3:[/1/name] '3.14': not a string.
737
+ :type_unmatch : 4:3:[/2/email] '2004-01-01': not a string.
738
+ java: |
739
+ :type_unmatch : 1:3:[/0/name] '123': not a string.
740
+ :type_unmatch : 2:3:[/0/email] 'true': not a string.
741
+ :type_unmatch : 3:3:[/1/name] '3.14': not a string.
742
+ :type_unmatch : 4:3:[/2/email] 'Sun Feb 01 00:00:00 JST 2004': not a string.
661
743
  ##
662
744
  ---
663
745
  name: ident1
@@ -691,6 +773,8 @@ invalid: |
691
773
  #
692
774
  error: |
693
775
  :value_notunique : (line 5)[/2/name] 'bar': is already used at '/1/name'.
776
+ error2: |
777
+ :value_notunique : 5:3:[/2/name] 'bar': is already used at '/1/name'.
694
778
  ##
695
779
  ---
696
780
  name: unique1
@@ -719,11 +803,13 @@ invalid: |
719
803
  age: 10
720
804
  - name: bar
721
805
  age: 10
722
- - name: bar
723
- age: 10
806
+ - age: 10
807
+ name: bar
724
808
  #
725
809
  error: |
726
- :value_notunique : (line 5)[/2/name] 'bar': is already used at '/1/name'.
810
+ :value_notunique : (line 6)[/2/name] 'bar': is already used at '/1/name'.
811
+ error2: |
812
+ :value_notunique : 6:3:[/2/name] 'bar': is already used at '/1/name'.
727
813
  ##
728
814
  ---
729
815
  name: unique2
@@ -751,6 +837,76 @@ invalid: |
751
837
  #
752
838
  error: |
753
839
  :value_notunique : (line 5)[/4] 'bar': is already used at '/2'.
840
+ error2: |
841
+ :value_notunique : 5:1:[/4] 'bar': is already used at '/2'.
842
+ ##
843
+ ---
844
+ name: unique3
845
+ desc: unique constraint and '<<' (merge)
846
+ #
847
+ schema: |
848
+ type: seq
849
+ sequence:
850
+ - type: map
851
+ mapping:
852
+ "name": { type: str, required: yes, unique: yes }
853
+ "value": { type: any, required: yes }
854
+ #
855
+ valid: |
856
+ # no sense
857
+ - name: x1
858
+ value: 10
859
+ - name: x2
860
+ value: 20
861
+ #
862
+ invalid: |
863
+ - &a1
864
+ name: x1
865
+ value: 10
866
+ - <<: *a1
867
+ - <<: *a1 # wrong validation error
868
+ name: x3
869
+ #
870
+ error: |
871
+ :value_notunique : (line 2)[/1/name] 'x1': is already used at '/0/name'.
872
+ error2: |
873
+ :value_notunique : 4:3:[/1/name] 'x1': is already used at '/0/name'.
874
+ :value_notunique : 5:3:[/2/name] 'x1': is already used at '/0/name'.
875
+ memo: |
876
+ * '(line 2)' is not expected line number.
877
+ ##
878
+ ---
879
+ name: unique4
880
+ desc: unique constrant and anchor
881
+ #
882
+ schema: |
883
+ type: seq
884
+ sequence:
885
+ - type: map
886
+ mapping:
887
+ "name": { type: str }
888
+ "value": { type: any }
889
+ #
890
+ valid: |
891
+ # no sense
892
+ - name: x1
893
+ value: 10
894
+ - name: x2
895
+ value: 20
896
+ #
897
+ invalid: |
898
+ - &a1
899
+ name: x1
900
+ value: 10
901
+ - name: x2
902
+ value: 20
903
+ - *a1
904
+ #
905
+ error: |
906
+ # :value_notunique : (line 6)[/2/name] 'x1': is already used at '/0/name'.
907
+ error2: |
908
+ memo: |
909
+ * validation error should be reported but not reported.
754
910
  ##
755
911
  ---
756
912
  name: default1
@@ -775,6 +931,9 @@ invalid: |
775
931
  error: |
776
932
  :range_toolarge : (line 2)[/value2] '20': too large (> max 10).
777
933
  :range_toosmall : (line 3)[/value3] '-20': too small (< min -10).
934
+ error2: |
935
+ :range_toolarge : 2:1:[/value2] '20': too large (> max 10).
936
+ :range_toosmall : 3:1:[/value3] '-20': too small (< min -10).
778
937
  ##
779
938
  ---
780
939
  name: merge1
@@ -821,4 +980,7 @@ invalid: |
821
980
  error: |
822
981
  :required_nokey : (line 4)[/user] key 'email:' is required.
823
982
  :length_toolong : (line 5)[/user/name] 'toooooo-looooong-naaaame': too long (length 24 > max 16).
983
+ error2: |
984
+ :required_nokey : 5:3:[/user] key 'email:' is required.
985
+ :length_toolong : 5:3:[/user/name] 'toooooo-looooong-naaaame': too long (length 24 > max 16).
824
986
  ##