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
@@ -0,0 +1,80 @@
1
+ ###
2
+ ### $Rev: 93 $
3
+ ### $Release: 0.7.0 $
4
+ ### copyright(c) 2005-2008 kuwata-lab all rights reserved.
5
+ ###
6
+
7
+ require File.dirname(__FILE__) + '/test.rb'
8
+
9
+
10
+ class DataBindingTest < Test::Unit::TestCase
11
+
12
+
13
+ ## define test methods
14
+ filename = __FILE__.sub(/\.rb$/, '.yaml')
15
+ input = Kwalify::Util.untabify(File.read(filename))
16
+ TESTDATA1 = {}
17
+ YAML.load_documents(input) do |ydoc|
18
+ hash_list = ydoc
19
+ hash_list.each do |hash|
20
+ for key in hash.keys()
21
+ hash[key[0..-2]] = hash.delete(key)['ruby'] if key[-1] == ?*
22
+ end
23
+ name = hash['name'] or raise "name is not found."
24
+ TESTDATA1.key?(name) and raise "name '#{name}' is dupilcated."
25
+ TESTDATA1[name] = hash
26
+ #
27
+ s = ''
28
+ s << "def test_#{name}\n"
29
+ s << " @name = '#{name}'\n"
30
+ for key, val in hash
31
+ s << " @#{key} = TESTDATA1['#{name}']['#{key}']\n"
32
+ end
33
+ s << " _test\n"
34
+ s << "end\n"
35
+ eval s
36
+ end
37
+ end
38
+ load_yaml_testdata(filename, :lang=>'ruby')
39
+
40
+
41
+ def _test
42
+ ## schema
43
+ if @schema.is_a?(String)
44
+ @schema = Kwalify::Yaml::Parser.new.parse(@schema, :untabify=>true)
45
+ #@schema = YAML.load(Kwalify::Util.untabify(@schema))
46
+ end
47
+ ## data binding
48
+ eval @classdef if @classdef
49
+ validator = Kwalify::Validator.new(@schema)
50
+ parser = Kwalify::Yaml::Parser.new(validator, :data_binding=>true)
51
+ @testopts ||= {}
52
+ parser.preceding_alias = true if @testopts['preceding_alias']
53
+ ydoc = parser.parse(@data)
54
+ assert_equal(parser.errors, [])
55
+ ## pp
56
+ result = ''
57
+ def result.write(arg); self << arg.to_s; end
58
+ PP.pp(ydoc, result)
59
+ ## convert object-id to portable number
60
+ table = {}
61
+ counter = 0
62
+ result.gsub!(/:0x\w+/) {|m| ":0x%03d" % (table[m] ||= (counter+=1)) }
63
+ ## assert
64
+ #puts result
65
+ assert_text_equal(@expected, result)
66
+ ## path, linenum, column
67
+ if @locations
68
+ #t = parser.instance_variable_get("@location_table")
69
+ #require 'pp'
70
+ #pp t
71
+ @locations.each do |path, expected_linenum, expected_column|
72
+ linenum, column = parser.location(path)
73
+ assert_equal(expected_linenum, linenum)
74
+ assert_equal(expected_column, column)
75
+ end
76
+ end
77
+ end
78
+
79
+
80
+ end
@@ -0,0 +1,301 @@
1
+ ##
2
+ ## $Rev: 63 $
3
+ ## $Release: 0.7.0 $
4
+ ## copyright(c) 2005-2008 kuwata-lab all rights reserved.
5
+ ##
6
+ ---
7
+
8
+ - name: databind1
9
+ desc: sequence of mapping
10
+ schema: |
11
+ type: seq
12
+ sequence:
13
+ - type: map
14
+ class: My1::Address
15
+ mapping:
16
+ "name": { type: str, required: yes }
17
+ "tel": { type: str }
18
+ "email": { type: str }
19
+ "age": { type: int }
20
+ "birth": { type: date }
21
+ "blood": { type: str, enum: [A, B, O, AB] }
22
+ classdef*:
23
+ ruby: |
24
+ require 'kwalify/util/hashlike'
25
+ module ::My1
26
+ class Address
27
+ include Kwalify::Util::HashLike
28
+ attr_accessor :name, :tel, :email, :age, :birth, :blood
29
+ end
30
+ end
31
+
32
+ data: |
33
+ - name: Foo
34
+ tel: 012-345-7777
35
+ email: foo@mail.com
36
+ age: 15
37
+ birth: 1990-01-01
38
+ blood: A
39
+ - name: Bar
40
+ tel: 012-345-8889
41
+ email: bar@mail.org
42
+ age: 14
43
+ birth: 1991-01-02
44
+ - name: Foo
45
+ tel: 012-345-9999
46
+ email: baz@mail.net
47
+ age: 13
48
+ birth: 1992-01-03
49
+ blood: AB
50
+ expected*:
51
+ ruby: |
52
+ [#<My1::Address:0x001
53
+ @age=15,
54
+ @birth=#<Date: 4895785/2,0,2299161>,
55
+ @blood="A",
56
+ @email="foo@mail.com",
57
+ @name="Foo",
58
+ @tel="012-345-7777">,
59
+ #<My1::Address:0x002
60
+ @age=14,
61
+ @birth=#<Date: 4896517/2,0,2299161>,
62
+ @email="bar@mail.org",
63
+ @name="Bar",
64
+ @tel="012-345-8889">,
65
+ #<My1::Address:0x003
66
+ @age=13,
67
+ @birth=#<Date: 4897249/2,0,2299161>,
68
+ @blood="AB",
69
+ @email="baz@mail.net",
70
+ @name="Foo",
71
+ @tel="012-345-9999">]
72
+ locations:
73
+ - [ "/0", 1, 3 ]
74
+ - [ "/0/name", 1, 10 ]
75
+ - [ "/0/tel", 2, 10 ]
76
+ - [ "/0/email", 3, 10 ]
77
+ - [ "/0/age", 4, 10 ]
78
+ - [ "/0/birth", 5, 10 ]
79
+ - [ "/0/blood", 6, 10 ]
80
+ - [ "/1", 7, 3 ]
81
+ - [ "/1/name", 7, 10 ]
82
+ - [ "/1/tel", 8, 10 ]
83
+ - [ "/1/email", 9, 10 ]
84
+ - [ "/1/age", 10, 10 ]
85
+ - [ "/1/birth", 11, 10 ]
86
+ - [ "/2", 12, 3 ]
87
+ - [ "/2/name", 12, 10 ]
88
+ - [ "/2/tel", 13, 10 ]
89
+ - [ "/2/email", 14, 10 ]
90
+ - [ "/2/age", 15, 10 ]
91
+ - [ "/2/birth", 16, 10 ]
92
+
93
+
94
+ - name: databind2
95
+ desc: recursive binding
96
+ schema: &context_schema |
97
+ type: map
98
+ class: My2::Context
99
+ mapping:
100
+ "groups":
101
+ type: seq
102
+ sequence:
103
+ - type: map
104
+ class: My2::Group
105
+ mapping:
106
+ "name":
107
+ type: str
108
+ required: yes
109
+ "desc":
110
+ type: str
111
+ "owner": &userschema
112
+ type: map
113
+ class: My2::User
114
+ mapping:
115
+ "name":
116
+ type: str
117
+ required: yes
118
+ "desc":
119
+ type: str
120
+ "gender":
121
+ type: bool
122
+ "mail":
123
+ type: str
124
+ "manager": *userschema
125
+ "users":
126
+ type: seq
127
+ sequence:
128
+ - *userschema
129
+
130
+ classdef*: &context_classdef
131
+ ruby: |
132
+ require 'kwalify/util/hashlike'
133
+ module ::My2
134
+
135
+ class Context
136
+ include Kwalify::Util::HashLike
137
+ attr_accessor :groups # seq
138
+ attr_accessor :users # seq
139
+ end
140
+
141
+ class Group
142
+ include Kwalify::Util::HashLike
143
+ attr_accessor :name # str
144
+ attr_accessor :desc # str
145
+ attr_accessor :owner # map
146
+ end
147
+
148
+ class User
149
+ include Kwalify::Util::HashLike
150
+ attr_accessor :name # str
151
+ attr_accessor :gender # bool
152
+ attr_accessor :mail # str
153
+ attr_accessor :desc # str
154
+ attr_accessor :manager # map
155
+ end
156
+
157
+ end
158
+
159
+ data: |
160
+ groups:
161
+ - name: admin
162
+ desc: administrator group
163
+ owner: &root
164
+ name: root
165
+ desc: root user
166
+ - name: users
167
+ desc: user group
168
+ owner: &guest
169
+ name: guest
170
+ desc: guest user
171
+ users:
172
+ - *root
173
+ - *guest
174
+ - &user1
175
+ name: user1
176
+ - name: user2
177
+ manager: *user1
178
+
179
+ expected*:
180
+ ruby: |
181
+ #<My2::Context:0x001
182
+ @groups=
183
+ [#<My2::Group:0x002
184
+ @desc="administrator group",
185
+ @name="admin",
186
+ @owner=#<My2::User:0x003 @desc="root user", @name="root">>,
187
+ #<My2::Group:0x004
188
+ @desc="user group",
189
+ @name="users",
190
+ @owner=#<My2::User:0x005 @desc="guest user", @name="guest">>],
191
+ @users=
192
+ [#<My2::User:0x003 @desc="root user", @name="root">,
193
+ #<My2::User:0x005 @desc="guest user", @name="guest">,
194
+ #<My2::User:0x006 @name="user1">,
195
+ #<My2::User:0x007
196
+ @manager=#<My2::User:0x006 @name="user1">,
197
+ @name="user2">]>
198
+
199
+ locations:
200
+ - [ "/", 1, 1 ]
201
+ - [ "/groups", 2, 3 ]
202
+ - [ "/groups/0", 2, 5 ]
203
+ - [ "/groups/0/name", 2, 17 ]
204
+ - [ "/groups/0/desc", 3, 17 ]
205
+ - [ "/groups/0/owner", 4, 12 ]
206
+ - [ "/groups/0/owner/name", 5, 17 ]
207
+ - [ "/groups/0/owner/desc", 6, 17 ]
208
+ - [ "/groups/1", 7, 5 ]
209
+ - [ "/groups/1/name", 7, 17 ]
210
+ - [ "/groups/1/desc", 8, 17 ]
211
+ - [ "/groups/1/owner", 9, 12 ]
212
+ - [ "/groups/1/owner/name", 10, 17 ]
213
+ - [ "/groups/1/owner/desc", 11, 17 ]
214
+ - [ "/users", 13, 3 ]
215
+ - [ "/users/0", 13, 5 ]
216
+ - [ "/users/0/name", 5, 17 ]
217
+ - [ "/users/0/desc", 6, 17 ]
218
+ - [ "/users/1", 14, 5 ]
219
+ - [ "/users/1/name", 10, 17 ]
220
+ - [ "/users/1/desc", 11, 17 ]
221
+ - [ "/users/2", 15, 5 ]
222
+ - [ "/users/2/name", 16, 11 ]
223
+ - [ "/users/3", 17, 5 ]
224
+ - [ "/users/3/name", 17, 11 ]
225
+ - [ "/users/3/manager", 18, 14 ]
226
+ - [ "/users/3/manager/name", 16, 11 ]
227
+
228
+
229
+ - name: databind3
230
+ desc: preceding alias
231
+ testopts: { preceding_alias: yes }
232
+ schema: *context_schema
233
+ classdef*: *context_classdef
234
+ data: |
235
+ groups:
236
+ - name: admin
237
+ desc: administrator group
238
+ owner: *root
239
+ - name: users
240
+ desc: user group
241
+ owner: *guest
242
+ users:
243
+ - &root
244
+ name: root
245
+ desc: root user
246
+ - &guest
247
+ name: guest
248
+ desc: guest user
249
+ - name: user2
250
+ manager: *user1
251
+ - &user1
252
+ name: user1
253
+
254
+ expected*:
255
+ ruby: |
256
+ #<My2::Context:0x001
257
+ @groups=
258
+ [#<My2::Group:0x002
259
+ @desc="administrator group",
260
+ @name="admin",
261
+ @owner=#<My2::User:0x003 @desc="root user", @name="root">>,
262
+ #<My2::Group:0x004
263
+ @desc="user group",
264
+ @name="users",
265
+ @owner=#<My2::User:0x005 @desc="guest user", @name="guest">>],
266
+ @users=
267
+ [#<My2::User:0x003 @desc="root user", @name="root">,
268
+ #<My2::User:0x005 @desc="guest user", @name="guest">,
269
+ #<My2::User:0x006
270
+ @manager=#<My2::User:0x007 @name="user1">,
271
+ @name="user2">,
272
+ #<My2::User:0x007 @name="user1">]>
273
+
274
+ locations:
275
+ - [ "/", 1, 1 ]
276
+ - [ "/groups", 2, 3 ]
277
+ - [ "/groups/0", 2, 5 ]
278
+ - [ "/groups/0/name", 2, 17 ]
279
+ - [ "/groups/0/desc", 3, 17 ]
280
+ - [ "/groups/0/owner", 4, 17 ]
281
+ - [ "/groups/0/owner/name", 10, 17 ]
282
+ - [ "/groups/0/owner/desc", 11, 17 ]
283
+ - [ "/groups/1", 5, 5 ]
284
+ - [ "/groups/1/name", 5, 17 ]
285
+ - [ "/groups/1/desc", 6, 17 ]
286
+ - [ "/groups/1/owner", 7, 17 ]
287
+ - [ "/groups/1/owner/name", 13, 17 ]
288
+ - [ "/groups/1/owner/desc", 14, 17 ]
289
+ - [ "/users", 9, 3 ]
290
+ - [ "/users/0", 9, 5 ]
291
+ - [ "/users/0/name", 10, 17 ]
292
+ - [ "/users/0/desc", 11, 17 ]
293
+ - [ "/users/1", 12, 5 ]
294
+ - [ "/users/1/name", 13, 17 ]
295
+ - [ "/users/1/desc", 14, 17 ]
296
+ - [ "/users/2", 15, 5 ]
297
+ - [ "/users/2/name", 15, 17 ]
298
+ - [ "/users/2/manager", 16, 17 ]
299
+ - [ "/users/2/manager/name", 18, 17 ]
300
+ - [ "/users/3", 17, 5 ]
301
+ - [ "/users/3/name", 18, 17 ]
@@ -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: 90 $
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,169 +10,148 @@ require 'kwalify/main'
10
10
 
11
11
 
12
12
  module Kwalify
13
- class Main
14
- public :_parse_argv
15
- end
13
+ class Main
14
+ public :_parse_argv
15
+ end
16
16
  end
17
17
 
18
18
 
19
19
  class File
20
- def self.move(filename, dirname)
21
- File.rename(filename, "#{dirname}/#{filename}")
22
- end
20
+ def self.move(filename, dirname)
21
+ File.rename(filename, "#{dirname}/#{filename}")
22
+ end
23
23
  end
24
24
 
25
25
 
26
26
  class MainTest < Test::Unit::TestCase
27
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
- @exception_class = Kwalify.const_get(@exception)
41
- end
42
- case @method
43
- when 'parseOptions'
44
- _test_parse_options()
45
- when 'execute'
46
- _test_execute()
47
- when 'validation'
48
- raise "*** #{@name}: schema is not defined." unless @schema
49
- raise "*** #{@name}: valid is not defined." unless @valid
50
- raise "*** #{@name}: invalid is not defined." unless @invalid
51
- _test_validation()
52
- when 'action'
53
- _test_action()
54
- else
55
- raise "*** #{@method}: invalid method name."
56
- end
57
- end
58
-
59
-
60
- ## validation test
61
- def _test_validation()
62
- return if $target && $target != @name
63
- raise "*** schema is not defined." unless @schema
64
- raise "*** valid is not defined." unless @valid
65
- raise "*** invalid is not defined." unless @invalid
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
+ case @method
44
+ when 'parseOptions'
45
+ _test_parse_options()
46
+ when 'execute'
47
+ _test_execute()
48
+ when 'validation'
49
+ raise "*** #{@name}: schema is not defined." unless @schema
50
+ raise "*** #{@name}: valid is not defined." unless @valid
51
+ raise "*** #{@name}: invalid is not defined." unless @invalid
52
+ _test_validation()
53
+ #when 'action'
54
+ # _test_action()
55
+ else
56
+ raise "*** #{@method}: invalid method name."
57
+ end
58
+ end
59
+
60
+
61
+ ## validation test
62
+ def _test_validation()
63
+ return if $target && $target != @name
64
+ raise "*** schema is not defined." unless @schema
65
+ raise "*** valid is not defined." unless @valid
66
+ raise "*** invalid is not defined." unless @invalid
67
+ #
68
+ schema_filename = @name + ".schema"
69
+ valid_filename = @name + ".valid"
70
+ invalid_filename = @name + ".invalid"
71
+ #
72
+ begin
66
73
  #
67
- schema_filename = @name + ".schema"
68
- valid_filename = @name + ".valid"
69
- invalid_filename = @name + ".invalid"
74
+ File.open(schema_filename, 'w') { |f| f.write(@schema) }
75
+ File.open(valid_filename, 'w') { |f| f.write(@valid) }
76
+ File.open(invalid_filename, 'w') { |f| f.write(@invalid) }
70
77
  #
71
- begin
72
- #
73
- File.open(schema_filename, 'w') { |f| f.write(@schema) }
74
- File.open(valid_filename, 'w') { |f| f.write(@valid) }
75
- File.open(invalid_filename, 'w') { |f| f.write(@invalid) }
76
- #
77
- main = Kwalify::Main.new('kwalify')
78
- args = [ "-lf", schema_filename, valid_filename ]
79
- output = main.execute(args)
80
- assert_text_equal(@valid_out, output)
81
- #
82
- main = Kwalify::Main.new('kwalify')
83
- args = [ "-lf", schema_filename, invalid_filename ]
84
- output = main.execute(args)
85
- assert_text_equal(@invalid_out, output)
86
- #
87
- ensure
88
- File.move(schema_filename, @@tmpdir)
89
- File.move(valid_filename, @@tmpdir)
90
- File.move(invalid_filename, @@tmpdir)
91
- end
92
- end
93
-
94
-
95
- ## execute test
96
- def _test_execute()
97
- return if $target && $target != @name
98
- raise "*** #{@name}: args is required." unless @args
99
- raise "*** #{@name}: expected is require." unless @expected
78
+ $stdout = StringWriter.new
79
+ main = Kwalify::Main.new('kwalify')
80
+ args = [ "-lf", schema_filename, valid_filename ]
81
+ main.execute(args)
82
+ output = $stdout; $stdout = STDOUT
83
+ assert_text_equal(@valid_out, output)
100
84
  #
101
- File.open("#{@name}.schema", 'w') { |f| f.write(@schema) } if @schema
102
- File.open("#{@name}.document", 'w') { |f| f.write(@document) } if @document
85
+ $stdout = StringWriter.new
86
+ main = Kwalify::Main.new('kwalify')
87
+ args = [ "-lf", schema_filename, invalid_filename ]
88
+ main.execute(args)
89
+ output = $stdout; $stdout = STDOUT
90
+ assert_text_equal(@invalid_out, output)
103
91
  #
104
- begin
105
- main = Kwalify::Main.new("kwalify")
106
- if @exception_class
107
- assert_raise(@exception_class) do
108
- main.execute(@args)
109
- end
110
- else
111
- actual = main.execute(@args)
112
- assert_text_equal(@expected, actual)
113
- end
114
- ensure
115
- File.move("#{@name}.schema", @@tmpdir) if @schema
116
- File.move("#{@name}.document", @@tmpdir) if @document
117
- end
118
- end
119
-
120
-
121
- ## command option test
122
- def _test_parse_options()
123
- return if $target && $target != @name
92
+ ensure
93
+ File.move(schema_filename, @@tmpdir)
94
+ File.move(valid_filename, @@tmpdir)
95
+ File.move(invalid_filename, @@tmpdir)
96
+ end
97
+ end
98
+
99
+
100
+ ## execute test
101
+ def _test_execute()
102
+ return if $target && $target != @name
103
+ raise "*** #{@name}: args is required." unless @args
104
+ raise "*** #{@name}: expected is require." unless @expected
105
+ #
106
+ File.open("#{@name}.schema", 'w') { |f| f.write(@schema) } if @schema
107
+ File.open("#{@name}.document", 'w') { |f| f.write(@document) } if @document
108
+ #
109
+ begin
124
110
  main = Kwalify::Main.new("kwalify")
125
- begin
126
- filenames = main._parse_argv(@args)
127
- s = main._inspect()
128
- s << "filenames:\n"
129
- filenames.each do |filename|
130
- s << " - #{filename}\n"
131
- end
132
- actual = s
133
- assert_text_equal(@expected, actual)
134
- rescue => ex
135
- #klass = @exception
136
- if @exception_class && ex.class == @exception_class
137
- # OK
138
- assert_equal(@error_symbol, ex.error_symbol) if ex.respond_to?(:error_symbol)
139
- else
140
- # NG
141
- raise ex
142
- end
111
+ if @exception_class
112
+ $stdout = StringWriter.new
113
+ ex = assert_raise(@exception_class) do
114
+ main.execute(@args)
115
+ end
116
+ assert_text_equal(@errormsg, ex.message) if @errormsg
117
+ $stdout = STDOUT
118
+ else
119
+ $stdout = StringWriter.new
120
+ main.execute(@args)
121
+ actual = $stdout; $stdout = STDOUT
122
+ assert_text_equal(@expected, actual)
143
123
  end
144
- end
145
-
146
-
147
- ## execute test
148
- def _test_action()
149
- return if $target && $target != @name
150
- raise "*** #{@name}: args is required." unless @args
151
- raise "*** #{@name}: expected is require." unless @expected
152
- #
153
- File.open("#{@name}.schema", 'w') { |f| f.write(@schema) } if @schema
154
- File.open("#{@name}.document", 'w') { |f| f.write(@document) } if @document
155
- #
156
- begin
157
- main = Kwalify::Main.new("kwalify")
158
- actual = main.execute(@args)
159
- if @output_files
160
- assert(actual.nil? || actual=='')
161
- @output_files.each do |filename|
162
- actual = File.read(filename)
163
- assert_text_equal(@expected[filename], actual)
164
- end
165
- else
166
- assert_text_equal(@expected, actual)
167
- end
168
- ensure
169
- File.move("#{@name}.schema", @@tmpdir) if @schema
170
- File.move("#{@name}.document", @@tmpdir) if @document
171
- @output_files.each do |filename|
172
- File.move(filename, @@tmpdir) if @document
173
- end if @output_files
124
+ ensure
125
+ File.move("#{@name}.schema", @@tmpdir) if @schema
126
+ File.move("#{@name}.document", @@tmpdir) if @document
127
+ end
128
+ end
129
+
130
+
131
+ ## command option test
132
+ def _test_parse_options()
133
+ return if $target && $target != @name
134
+ main = Kwalify::Main.new("kwalify")
135
+ begin
136
+ filenames = main._parse_argv(@args)
137
+ s = main._inspect()
138
+ s << "filenames:\n"
139
+ filenames.each do |filename|
140
+ s << " - #{filename}\n"
141
+ end
142
+ actual = s
143
+ assert_text_equal(@expected, actual)
144
+ rescue => ex
145
+ #klass = @exception
146
+ if @exception_class && ex.class == @exception_class
147
+ # OK
148
+ assert_equal(@error_symbol, ex.error_symbol) if ex.respond_to?(:error_symbol)
149
+ else
150
+ # NG
151
+ raise ex
174
152
  end
175
- end
153
+ end
154
+ end
176
155
 
177
156
 
178
157
  end