kwalify 0.5.1 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (109) hide show
  1. data/ChangeLog +24 -19
  2. data/README.txt +51 -51
  3. data/bin/kwalify +2 -2
  4. data/contrib/inline-require +151 -0
  5. data/contrib/kwalify +2850 -0
  6. data/doc-api/classes/CommandOptionError.html +184 -0
  7. data/doc-api/classes/CommandOptionParser.html +325 -0
  8. data/doc-api/classes/Kwalify.html +270 -0
  9. data/doc-api/classes/Kwalify/AssertionError.html +148 -0
  10. data/doc-api/classes/Kwalify/BaseError.html +296 -0
  11. data/doc-api/classes/Kwalify/CommandOptionError.html +168 -0
  12. data/doc-api/classes/Kwalify/ErrorHelper.html +218 -0
  13. data/doc-api/classes/Kwalify/HashInterface.html +240 -0
  14. data/doc-api/classes/Kwalify/KwalifyError.html +111 -0
  15. data/doc-api/classes/Kwalify/Main.html +336 -0
  16. data/doc-api/classes/Kwalify/MetaValidator.html +432 -0
  17. data/doc-api/classes/Kwalify/Parser.html +155 -0
  18. data/doc-api/classes/Kwalify/PlainYamlParser.html +520 -0
  19. data/doc-api/classes/Kwalify/PlainYamlParser/Alias.html +165 -0
  20. data/doc-api/classes/Kwalify/Rule.html +411 -0
  21. data/doc-api/classes/Kwalify/SchemaError.html +148 -0
  22. data/doc-api/classes/Kwalify/Types.html +301 -0
  23. data/doc-api/classes/Kwalify/ValidationError.html +148 -0
  24. data/doc-api/classes/Kwalify/Validator.html +311 -0
  25. data/doc-api/classes/Kwalify/YamlParser.html +535 -0
  26. data/doc-api/classes/Kwalify/YamlSyntaxError.html +168 -0
  27. data/doc-api/classes/Test.html +107 -0
  28. data/doc-api/classes/Test/Unit.html +101 -0
  29. data/doc-api/classes/YamlHelper.html +259 -0
  30. data/doc-api/created.rid +1 -0
  31. data/doc-api/files/__/README_txt.html +179 -0
  32. data/doc-api/files/kwalify/errors_rb.html +114 -0
  33. data/doc-api/files/kwalify/main_rb.html +117 -0
  34. data/doc-api/files/kwalify/messages_rb.html +107 -0
  35. data/doc-api/files/kwalify/meta-validator_rb.html +117 -0
  36. data/doc-api/files/kwalify/rule_rb.html +116 -0
  37. data/doc-api/files/kwalify/types_rb.html +114 -0
  38. data/doc-api/files/kwalify/util/assert-text-equal_rb.html +115 -0
  39. data/doc-api/files/kwalify/util/hash-interface_rb.html +107 -0
  40. data/doc-api/files/kwalify/util/option-parser_rb.html +107 -0
  41. data/doc-api/files/kwalify/util/testcase-helper_rb.html +115 -0
  42. data/doc-api/files/kwalify/util/yaml-helper_rb.html +114 -0
  43. data/doc-api/files/kwalify/validator_rb.html +117 -0
  44. data/doc-api/files/kwalify/yaml-parser_rb.html +117 -0
  45. data/doc-api/files/kwalify_rb.html +120 -0
  46. data/doc-api/fr_class_index.html +50 -0
  47. data/doc-api/fr_file_index.html +41 -0
  48. data/doc-api/fr_method_index.html +109 -0
  49. data/doc-api/index.html +24 -0
  50. data/doc-api/rdoc-style.css +208 -0
  51. data/doc/users-guide.html +693 -193
  52. data/examples/address-book/Makefile +5 -0
  53. data/examples/address-book/address-book.schema.yaml +2 -1
  54. data/examples/invoice/Makefile +5 -0
  55. data/examples/invoice/invoice.schema.yaml +3 -2
  56. data/examples/tapkit/Makefile +5 -0
  57. data/examples/tapkit/main.rb +7 -0
  58. data/examples/tapkit/tapkit.schema.yaml +6 -1
  59. data/lib/kwalify.rb +3 -3
  60. data/lib/kwalify/errors.rb +2 -2
  61. data/lib/kwalify/main.rb +161 -84
  62. data/lib/kwalify/messages.rb +17 -11
  63. data/lib/kwalify/meta-validator.rb +11 -2
  64. data/lib/kwalify/rule.rb +13 -3
  65. data/lib/kwalify/templates/genclass-java.eruby +195 -0
  66. data/lib/kwalify/templates/genclass-ruby.eruby +84 -0
  67. data/lib/kwalify/types.rb +18 -18
  68. data/lib/kwalify/util/assert-text-equal.rb +44 -0
  69. data/lib/kwalify/util/hash-interface.rb +37 -0
  70. data/lib/kwalify/util/option-parser.rb +2 -2
  71. data/lib/kwalify/util/testcase-helper.rb +112 -0
  72. data/lib/kwalify/util/yaml-helper.rb +2 -2
  73. data/lib/kwalify/validator.rb +2 -2
  74. data/lib/kwalify/yaml-parser.rb +12 -9
  75. data/test/test-main.rb +77 -78
  76. data/test/test-main.yaml +543 -769
  77. data/test/test-metavalidator.rb +27 -47
  78. data/test/test-metavalidator.yaml +21 -2
  79. data/test/test-rule.rb +6 -39
  80. data/test/test-rule.yaml +2 -2
  81. data/test/test-validator.rb +36 -869
  82. data/test/test-validator.yaml +28 -20
  83. data/test/test-yamlparser.rb +30 -1248
  84. data/test/test-yamlparser.yaml +138 -110
  85. data/test/test.rb +33 -13
  86. data/test/tmp.dir/Context.java +40 -0
  87. data/test/tmp.dir/Group.java +33 -0
  88. data/test/tmp.dir/User.java +43 -0
  89. data/test/tmp.dir/action1.document +18 -0
  90. data/test/tmp.dir/action1.schema +32 -0
  91. data/test/tmp.dir/action2.document +18 -0
  92. data/test/tmp.dir/action2.schema +32 -0
  93. data/test/tmp.dir/emacs.document +6 -0
  94. data/test/tmp.dir/emacs.schema +6 -0
  95. data/test/tmp.dir/meta1.document +0 -0
  96. data/test/tmp.dir/meta1.schema +3 -0
  97. data/test/tmp.dir/meta2.document +0 -0
  98. data/test/tmp.dir/meta2.schema +3 -0
  99. data/test/tmp.dir/silent1.document +3 -0
  100. data/test/tmp.dir/silent1.schema +3 -0
  101. data/test/tmp.dir/silent2.document +7 -0
  102. data/test/tmp.dir/silent2.schema +3 -0
  103. data/test/tmp.dir/stream.invalid +8 -0
  104. data/test/tmp.dir/stream.schema +3 -0
  105. data/test/tmp.dir/stream.valid +8 -0
  106. data/test/tmp.dir/untabify.document +5 -0
  107. data/test/tmp.dir/untabify.schema +10 -0
  108. metadata +98 -12
  109. data/lib/kwalify/util/assert-diff.rb +0 -44
@@ -1,11 +1,12 @@
1
1
  ##
2
- ## $Rev: 2 $
3
- ## $Release: 0.5.1 $
2
+ ## $Rev: 51 $
3
+ ## $Release: 0.6.0 $
4
4
  ## copyright(c) 2005 kuwata-lab all rights reserved.
5
5
  ##
6
6
  ---
7
7
  name: sequence1
8
8
  desc: sequence test
9
+ checked: yes
9
10
  #
10
11
  schema: |
11
12
  type: seq
@@ -29,10 +30,11 @@ invalid: |
29
30
  error: |
30
31
  :required_novalue : (line 3)[/2] value required but none.
31
32
  :type_unmatch : (line 5)[/4] '100': not a string.
32
- #
33
+ ##
33
34
  ---
34
35
  name: mapping1
35
36
  desc: mapping test
37
+ checked: yes
36
38
  #
37
39
  schema: |
38
40
  type: map
@@ -78,10 +80,11 @@ error: |
78
80
  :type_unmatch : (line 3)[/age] 'twenty': not a integer.
79
81
  :enum_notexist : (line 4)[/blood] 'ab': invalid blood value.
80
82
  :type_unmatch : (line 5)[/birth] 'Jul 01, 1985': not a date.
81
- #
83
+ ##
82
84
  ---
83
85
  name: nested1
84
86
  desc: nest of seq and map
87
+ checked: yes
85
88
  #
86
89
  schema: |
87
90
  type: map
@@ -139,10 +142,11 @@ error: |
139
142
  :enum_notexist : (line 5)[/address-book/0/blood] 'ab': invalid blood value.
140
143
  :type_unmatch : (line 6)[/address-book/0/birth] '1985/01/01': not a date.
141
144
  :pattern_unmatch : (line 8)[/address-book/1/email] 'bar(at)mail.com': not matched to pattern /@/.
142
- #
145
+ ##
143
146
  ---
144
147
  name: anchor1
145
148
  desc: schema with anchor
149
+ checked: yes
146
150
  #
147
151
  schema: |
148
152
  type: seq
@@ -172,10 +176,11 @@ error: |
172
176
  :required_nokey : (line 1)[/0] key 'family-name:' is required.
173
177
  :key_undefined : (line 2)[/0/last-name] key 'last-name:' is undefined.
174
178
  :type_unmatch : (line 4)[/1/family-name] '100': not a string.
175
- #
179
+ ##
176
180
  ---
177
181
  name: anchor2
178
182
  desc: schema with anchor 2
183
+ checked: yes
179
184
  #
180
185
  schema: |
181
186
  type: map
@@ -215,10 +220,11 @@ error: |
215
220
  :type_unmatch : (line 3)[/address-book/0/name] '100': not a string.
216
221
  :required_nokey : (line 5)[/address-book/1] key 'name:' is required.
217
222
  :key_undefined : (line 5)[/address-book/1/first-name] key 'first-name:' is undefined.
218
- #
223
+ ##
219
224
  ---
220
225
  name: anchor3
221
226
  desc: document with anchor
227
+ checked: yes
222
228
  #
223
229
  schema: |
224
230
  type: seq
@@ -266,10 +272,11 @@ invalid: |
266
272
  error: |
267
273
  :type_unmatch : (line 2)[/0/name] '100': not a string.
268
274
  :enum_notexist : (line 7)[/1/post] 'worker': invalid post value.
269
- #
275
+ ##
270
276
  ---
271
277
  name: range1
272
278
  desc: range test && bug#?????
279
+ checked: yes
273
280
  #
274
281
  schema: |
275
282
  type: map
@@ -328,7 +335,7 @@ error: |
328
335
  :range_toolarge : (line 9)[/max-and-min/1] '100.1': too large (> max 100.0).
329
336
  :range_toosmall : (line 10)[/max-and-min/2] '9': too small (< min 10.0).
330
337
  :range_toosmall : (line 11)[/max-and-min/3] '9.99': too small (< min 10.0).
331
- #
338
+ ##
332
339
  ---
333
340
  name: range2
334
341
  desc: range test (with max-ex and min-ex)
@@ -390,7 +397,7 @@ error: |
390
397
  :range_toolargeex : (line 9)[/max-ex-and-min-ex/1] '100.0': too large (>= max 100.0).
391
398
  :range_toosmallex : (line 10)[/max-ex-and-min-ex/2] '10': too small (<= min 10.0).
392
399
  :range_toosmallex : (line 11)[/max-ex-and-min-ex/3] '10.0': too small (<= min 10.0).
393
- #
400
+ ##
394
401
  ---
395
402
  name: range3
396
403
  desc: range test (with max, min, max-ex and min-ex)
@@ -432,7 +439,7 @@ error: |
432
439
  :range_toosmallex : (line 3)[/A/1] '10.0': too small (<= min 10.0).
433
440
  :range_toosmall : (line 5)[/B/0] '9.99999': too small (< min 10).
434
441
  :range_toolargeex : (line 6)[/B/1] '100.0': too large (>= max 100.0).
435
- #
442
+ ##
436
443
  ---
437
444
  name: length1
438
445
  desc: length test
@@ -483,7 +490,7 @@ error: |
483
490
  :length_tooshort : (line 4)[/min-only/0] 'foo': too short (length 3 < min 4).
484
491
  :length_toolong : (line 7)[/max-and-min/0] 'foobarbaz': too long (length 9 > max 8).
485
492
  :length_tooshort : (line 8)[/max-and-min/1] 'foo': too short (length 3 < min 4).
486
- #
493
+ ##
487
494
  ---
488
495
  name: length2
489
496
  desc: length test (with max-ex and min-ex)
@@ -533,7 +540,7 @@ error: |
533
540
  :length_tooshortex : (line 4)[/min-ex-only/0] 'foo!': too short (length 4 <= min 4).
534
541
  :length_toolongex : (line 7)[/max-ex-and-min-ex/0] 'foobarba': too long (length 8 >= max 8).
535
542
  :length_tooshortex : (line 8)[/max-ex-and-min-ex/1] 'foo!': too short (length 4 <= min 4).
536
- #
543
+ ##
537
544
  ---
538
545
  name: length3
539
546
  desc: length test (with min, max, max-ex and min-ex)
@@ -573,7 +580,7 @@ error: |
573
580
  :length_tooshortex : (line 3)[/A/1] 'hoge': too short (length 4 <= min 4).
574
581
  :length_toolongex : (line 5)[/B/0] 'hogehoge': too long (length 8 >= max 8).
575
582
  :length_tooshort : (line 6)[/B/1] 'hog': too short (length 3 < min 4).
576
- #
583
+ ##
577
584
  ---
578
585
  name: assert1
579
586
  desc: assert test
@@ -615,7 +622,7 @@ error: |
615
622
  :assert_failed : (line 2)[/1/more-than] '3': assertion expression failed (3 < val).
616
623
  :assert_failed : (line 3)[/2/between] '2.9': assertion expression failed (3 < val && val < 8).
617
624
  :assert_failed : (line 4)[/3/except] '3.1': assertion expression failed (val < 3 || 8 < val).
618
- #
625
+ ##
619
626
  ---
620
627
  name: deftype1
621
628
  desc: default type test
@@ -651,7 +658,7 @@ error*:
651
658
  :type_unmatch : (line 2)[/0/email] 'true': not a string.
652
659
  :type_unmatch : (line 3)[/1/name] '3.14': not a string.
653
660
  :type_unmatch : (line 4)[/2/email] 'Sun Feb 01 00:00:00 JST 2004': not a string.
654
- #
661
+ ##
655
662
  ---
656
663
  name: ident1
657
664
  desc: ident constraint test
@@ -684,7 +691,7 @@ invalid: |
684
691
  #
685
692
  error: |
686
693
  :value_notunique : (line 5)[/2/name] 'bar': is already used at '/1/name'.
687
- #
694
+ ##
688
695
  ---
689
696
  name: unique1
690
697
  desc: unique constraint test with map
@@ -717,7 +724,7 @@ invalid: |
717
724
  #
718
725
  error: |
719
726
  :value_notunique : (line 5)[/2/name] 'bar': is already used at '/1/name'.
720
- #
727
+ ##
721
728
  ---
722
729
  name: unique2
723
730
  desc: unique constraint test with seq
@@ -744,7 +751,7 @@ invalid: |
744
751
  #
745
752
  error: |
746
753
  :value_notunique : (line 5)[/4] 'bar': is already used at '/2'.
747
- #
754
+ ##
748
755
  ---
749
756
  name: default1
750
757
  desc: default value of map
@@ -768,6 +775,7 @@ invalid: |
768
775
  error: |
769
776
  :range_toolarge : (line 2)[/value2] '20': too large (> max 10).
770
777
  :range_toosmall : (line 3)[/value3] '-20': too small (< min -10).
778
+ ##
771
779
  ---
772
780
  name: merge1
773
781
  desc: merge maps
@@ -813,4 +821,4 @@ invalid: |
813
821
  error: |
814
822
  :required_nokey : (line 4)[/user] key 'email:' is required.
815
823
  :length_toolong : (line 5)[/user/name] 'toooooo-looooong-naaaame': too long (length 24 > max 16).
816
- #
824
+ ##
@@ -1,26 +1,34 @@
1
1
  ###
2
- ### $Rev: 42 $
3
- ### $Release: 0.5.1 $
2
+ ### $Rev: 51 $
3
+ ### $Release: 0.6.0 $
4
4
  ### copyright(c) 2005 kuwata-lab all rights reserved.
5
5
  ###
6
6
 
7
- unless defined?(TESTDIR)
8
- TESTDIR = File.dirname(__FILE__)
9
- libdir = File.dirname(TESTDIR) + "/lib"
10
- $LOAD_PATH << libdir << TESTDIR
11
- end
7
+ require File.dirname(__FILE__) + '/test.rb'
8
+
9
+
10
+ class Hash
11
+
12
+ def inspect
13
+ buf = [ '{' ]
14
+ self.keys.sort_by { |k| k.to_s }.each_with_index do |key, i|
15
+ buf << ', ' if i > 0
16
+ buf << key.inspect << '=>' << self[key].inspect
17
+ end
18
+ buf << '}'
19
+ return buf.join
20
+ end
12
21
 
13
- require 'test/unit'
14
- require 'test/unit/ui/console/testrunner'
15
- require 'kwalify'
16
- require 'kwalify/util/assert-diff'
17
- require 'yaml'
18
- require 'pp'
19
- require 'stringio'
22
+ end
20
23
 
21
24
 
22
25
  class YamlParserTest < Test::Unit::TestCase
26
+
27
+ filename = __FILE__.sub(/\.rb$/, '.yaml')
28
+ load_yaml_testdata(filename, :lang=>'ruby')
29
+
23
30
  def _test()
31
+ @error_class = Kwalify.const_get(@exception) if @exception
24
32
  parser = Kwalify::YamlParser.new(@input)
25
33
  if @error_class
26
34
  assert_raise(@error_class) do
@@ -28,9 +36,13 @@ class YamlParserTest < Test::Unit::TestCase
28
36
  end
29
37
  else
30
38
  doc = parser.parse()
31
- sio = StringIO.new
32
- PP.pp(doc, sio)
33
- actual = sio.string
39
+ if @recursive || @pp
40
+ s = StringWriter.new
41
+ PP.pp(doc, s)
42
+ actual = s
43
+ else
44
+ actual = doc.inspect + "\n"
45
+ end
34
46
  if $log
35
47
  File.open("#{@name}.expected", 'w') { |f| f.write(@expected) }
36
48
  File.open("#{@name}.actual", 'w') { |f| f.write(actual) }
@@ -38,1239 +50,9 @@ class YamlParserTest < Test::Unit::TestCase
38
50
  if $print
39
51
  print actual
40
52
  else
41
- assert_equal_with_diff(@expected, actual)
53
+ assert_text_equal(@expected, actual)
42
54
  end
43
55
  end
44
56
  end
45
57
 
46
- #str = DATA.read() # doesn't work when required by other script
47
- str = File.read(__FILE__)
48
- str.gsub!(/.*^__END__$/m, '')
49
- doc_table = {}
50
- YAML.load_documents(str) do |doc|
51
- name = doc['name']
52
- raise "name '#{name}' is duplicated." if doc_table[name]
53
- doc_table[name] = doc
54
- next if $target && $target != doc['name']
55
- #if $target && $show
56
- # puts doc.to_yaml
57
- # exit
58
- #end
59
- s = <<-END
60
- def test_#{name}
61
- @name = #{doc['name'].dump}
62
- @input = #{doc['input'].dump}
63
- @expected = #{doc['expected'].dump}
64
- @error_class = #{doc['error'] ? doc['error'] : 'nil'}
65
- @option = #{doc['option'] ? doc['option'].dump : 'nil'}
66
- _test()
67
- end
68
- END
69
- if $target && $show
70
- puts s
71
- exit
72
- end
73
- eval s
74
- end
75
58
  end
76
-
77
- #if $0 == __FILE__
78
- # Test::Unit::UI::Console::TestRunner.run(YamlParserTest)
79
- #end
80
-
81
- __END__
82
- ---
83
- name: parse01
84
- desc: basic
85
- #flag: print
86
- #
87
- input: |
88
- - AAA
89
- - BBB
90
- - CCC
91
- #
92
- expected: |
93
- ["AAA", "BBB", "CCC"]
94
- #
95
- ---
96
- name: parse02
97
- desc: scalar
98
- #
99
- input: |
100
- - abc
101
- - 123
102
- - 3.14
103
- - true
104
- - false
105
- - yes
106
- - no
107
- - ~
108
- - null
109
- - "123"
110
- - '456'
111
- - 2005-01-01
112
- - :sym
113
- #
114
- expected: |
115
- ["abc",
116
- 123,
117
- 3.14,
118
- true,
119
- false,
120
- true,
121
- false,
122
- nil,
123
- nil,
124
- "123",
125
- "456",
126
- #<Date: 4906743/2,0,2299161>,
127
- :sym]
128
- # ["abc", 123, true, false, true, false, nil, nil, "123", "456", #<Date: 4906743/2,0,2299161>, :sym]
129
- #
130
- ---
131
- name: parse03
132
- desc: nested sequence
133
- #
134
- input: |
135
- - AAA
136
- -
137
- - BBB1
138
- - BBB2
139
- - CCC
140
- #
141
- expected: |
142
- ["AAA", ["BBB1", "BBB2"], "CCC"]
143
- #
144
- ---
145
- name: parse04
146
- desc: nested sequence #2
147
- #
148
- input: |
149
- - A
150
- -
151
- - B1
152
- -
153
- - B1-1
154
- - B1-2
155
- - C
156
- #
157
- expected: |
158
- ["A", ["B1", ["B1-1", "B1-2"]], "C"]
159
- #
160
- ---
161
- name: parse05
162
- desc: null item of sequence
163
- #
164
- input: |
165
- - A
166
- -
167
- - C
168
- -
169
- -
170
- -
171
- - G
172
- #
173
- expected: |
174
- ["A", nil, "C", nil, nil, nil, "G"]
175
- #
176
- ---
177
- name: parse06
178
- desc: null item of nested sequence
179
- #
180
- input: |
181
- -
182
- -
183
- -
184
- -
185
- -
186
- -
187
- #
188
- expected: |
189
- [[[nil, nil, nil]], nil]
190
- #
191
- ---
192
- name: parse07
193
- desc: sequence with empty lines
194
- #
195
- input: |
196
-
197
- - A
198
-
199
- -
200
-
201
-
202
- - B
203
-
204
-
205
- -
206
- #
207
- expected: |
208
- ["A", ["B"], nil]
209
- #
210
- ---
211
- name: parse08
212
- desc: syntax error - invalid indent of sequence.
213
- error: Kwalify::YamlSyntaxError
214
- #
215
- input: |
216
- - AAA
217
- - BBB1
218
- - BBB2
219
- - CCC
220
- #
221
- expected: |
222
- #
223
- ---
224
- name: parse09
225
- desc: syntax error - sequence item is exepcted.
226
- error: Kwalify::YamlSyntaxError
227
- #
228
- input: |
229
- -
230
- - a1
231
- - a2
232
- a3
233
- -
234
- - b1
235
- - b2
236
- b3
237
- #
238
- expected: |
239
- #
240
- ---
241
- name: parse11
242
- desc: mapping
243
- #
244
- input: |
245
- A: foo
246
- B: bar
247
- C : baz
248
- #
249
- expected: |
250
- {"A"=>"foo", "B"=>"bar", "C"=>"baz"}
251
- ---
252
- name: parse12
253
- desc: mapping of scalar
254
- #
255
- input: |
256
- abc: ABC
257
- 123: 1.23
258
- 3.14: 314
259
- #
260
- expected: |
261
- {"abc"=>"ABC", 3.14=>314, 123=>1.23}
262
- ---
263
- name: parse12b
264
- desc: mapping of scalar
265
- #
266
- input: |
267
- true: yes
268
- false: no
269
- #
270
- expected: |
271
- {false=>false, true=>true}
272
- #
273
- ---
274
- name: parse12c
275
- desc: mapping of scalar
276
- #
277
- input: |
278
- :sym: :symbol
279
- --: -10
280
- #
281
- expected: |
282
- {"--"=>-10, :sym=>:symbol}
283
- #
284
- ---
285
- name: parse13
286
- desc: nested mapping
287
- #
288
- input: |
289
- A: 10
290
- B:
291
- B1: 21
292
- B2: 22
293
- C: 30
294
- #
295
- expected: |
296
- {"A"=>10, "B"=>{"B1"=>21, "B2"=>22}, "C"=>30}
297
- #
298
- ---
299
- name: parse14
300
- desc: nested mapping #2
301
- #
302
- input: |
303
- A: 10
304
- B:
305
- B1:
306
- B1-1: 21
307
- B1-2: 22
308
- B1-3: 23
309
- C: 30
310
- #
311
- expected: |
312
- {"A"=>10, "B"=>{"B1"=>{"B1-1"=>21, "B1-2"=>22, "B1-3"=>23}}, "C"=>30}
313
- #
314
- ---
315
- name: parse15
316
- desc: null item in mapping
317
- #
318
- input: |
319
- A:
320
- B:
321
- C:
322
- D:
323
- #
324
- expected: |
325
- {"A"=>nil, "B"=>nil, "C"=>nil, "D"=>nil}
326
- #
327
- ---
328
- name: parse16
329
- desc: null mapping
330
- #
331
- input: |
332
- A:
333
- B:
334
- B1:
335
- B1-2:
336
- C:
337
- #
338
- expected: |
339
- {"A"=>nil, "B"=>{"B1"=>{"B1-2"=>nil}}, "C"=>nil}
340
- #
341
- ---
342
- name: parse17
343
- desc: mapping with empty lines
344
- #
345
- input: |
346
-
347
- A: 1
348
-
349
- B:
350
-
351
-
352
- B1:
353
-
354
-
355
-
356
- B1a: 2
357
- C: 3
358
-
359
- #
360
- expected: |
361
- {"A"=>1, "B"=>{"B1"=>{"B1a"=>2}}, "C"=>3}
362
- #
363
- ---
364
- name: parse18
365
- desc: parse error - invalid indent of mapping.
366
- error: Kwalify::YamlSyntaxError
367
- #
368
- input: |
369
- A: 10
370
- B: 20
371
- B1: 21
372
- B2: 22
373
- C: 30
374
- #
375
- expected: |
376
-
377
- #
378
- ---
379
- name: parse19
380
- desc: parse error - mapping item is expected.
381
- error: Kwalify::YamlSyntaxError
382
- #
383
- input: |
384
- A:
385
- a1: 1
386
- a2: 2
387
- a3 3
388
- B:
389
- b1: 1
390
- b2: 2
391
- b3 3
392
- expected: |
393
- #
394
- ---
395
- name: parse21
396
- desc: seq of mapping
397
- #
398
- input: |
399
- -
400
- x: 10
401
- y: 20
402
- -
403
- x: 15
404
- y: 25
405
- #
406
- expected: |
407
- [{"x"=>10, "y"=>20}, {"x"=>15, "y"=>25}]
408
- ---
409
- name: parse22
410
- desc: seq of mapping (inline)
411
- #
412
- input: |
413
- - x: 10
414
- y: 20
415
- - x: 15
416
- y: 25
417
- #
418
- expected: |
419
- [{"x"=>10, "y"=>20}, {"x"=>15, "y"=>25}]
420
- ---
421
- name: parse23
422
- desc: seq of seq of seq (inline)
423
- #
424
- input: |
425
- - - - a
426
- - b
427
- - - - c
428
- - d
429
- #
430
- expected: |
431
- [[["a", "b"]], [["c", "d"]]]
432
- ---
433
- name: parse24
434
- desc: map of sequence
435
- #
436
- input: |
437
- foo:
438
- - 1
439
- - 2
440
- - 3
441
- bar:
442
- - 4
443
- - 5
444
- - 6
445
- #
446
- expected: |
447
- {"foo"=>[1, 2, 3], "bar"=>[4, 5, 6]}
448
- ---
449
- name: parse25
450
- desc: map of sequence (inline)
451
- #
452
- input: |
453
- foo: - 1
454
- - 2
455
- - 3
456
- bar: - 4
457
- - 5
458
- - 6
459
- #
460
- expected: |
461
- {"foo"=>[1, 2, 3], "bar"=>[4, 5, 6]}
462
- ---
463
- name: parse26
464
- desc: map of map of map (inline)
465
- #
466
- input: |
467
- A: a: 1: 100
468
- 2: 200
469
- B: b: 3: 300
470
- 4: 400
471
- #
472
- expected: |
473
- {"A"=>{"a"=>{1=>100, 2=>200}}, "B"=>{"b"=>{3=>300, 4=>400}}}
474
- ---
475
- name: comment1
476
- desc: line comment
477
- #
478
- input: |
479
- # comment
480
- - A
481
- - B
482
- # comment
483
- -
484
- # comment
485
- - C
486
- #
487
- expected: |
488
- ["A", "B", ["C"]]
489
- ---
490
- name: comment2
491
- desc: escape line comment
492
- #
493
- input: |
494
- # comment
495
- - A
496
- - B:
497
- "# comment"
498
- -
499
- '# comment'
500
- #
501
- expected: |
502
- ["A", {"B"=>"# comment"}, "# comment"]
503
- ---
504
- name: comment3
505
- desc: line comment with seq and map
506
- #
507
- input: |
508
- - A # comment
509
- - B: # comment
510
- C: foo # comment
511
- D: "bar#bar" #comment
512
- #
513
- expected: |
514
- ["A", {"B"=>{"C"=>"foo", "D"=>"bar#bar"}}]
515
- ---
516
- name: comment4
517
- desc: line comment with anchor and alias
518
- #
519
- input: |
520
- - &a1 # comment
521
- foo
522
- - *a1 # comment
523
- #
524
- expected: |
525
- ["foo", "foo"]
526
- ---
527
- name: flowseq1
528
- desc: flow style seq
529
- #
530
- input: |
531
- - [ 10, 20 ]
532
- - [15,25,35]
533
- #
534
- expected: |
535
- [[10, 20], [15, 25, 35]]
536
- #
537
- ---
538
- name: flowseq2
539
- desc: nested flow style seq
540
- #
541
- input: |
542
- 1: [ A, [B1, B2]]
543
- 2: [[[X]]]
544
- 3: [[x1,y1],[x2,"y2"],['x3',y3]]
545
- #
546
- expected: |
547
- {1=>["A", ["B1", "B2"]],
548
- 2=>[[["X"]]],
549
- 3=>[["x1", "y1"], ["x2", "y2"], ["x3", "y3"]]}
550
- #
551
- ---
552
- name: flowseq3
553
- desc: flow style seq with some lines
554
- #
555
- input: |
556
- A: [ [10,20],
557
- [11,21],
558
- [12,22]]
559
- B: [
560
- [1.1,
561
- 1.2,
562
- 1.3
563
- ]
564
- ]
565
- #
566
- expected: |
567
- {"A"=>[[10, 20], [11, 21], [12, 22]], "B"=>[[1.1, 1.2, 1.3]]}
568
- #
569
- ---
570
- name: flowseq4
571
- desc: invalid flow style seq (sequence item required (or last comma is extra).)
572
- mesg: sequence item required (or last comma is extra).
573
- error: Kwalify::YamlSyntaxError
574
- #
575
- input: |
576
- A: [ [10,20], ]
577
- #
578
- expected: |
579
- #
580
- ---
581
- name: flowseq5
582
- desc: invalid flow style seq (flow style sequence requires ']').
583
- mesg: flow style sequence requires ']'
584
- error: Kwalify::YamlSyntaxError
585
- #
586
- input: |
587
- A: [ [10,20]
588
- B: [ [30, 40]]
589
- #
590
- expected: |
591
- #
592
- ---
593
- name: flowseq6
594
- desc: invalid flow style seq (flow style sequence requires ']').
595
- mesg: flow style sequence is closed but got ']'.
596
- error: Kwalify::YamlSyntaxError
597
- #
598
- input: |
599
- [ 10 ]]
600
- #
601
- expected: |
602
- #
603
- ---
604
- name: flowmap1
605
- desc: flow style map
606
- #
607
- input: |
608
- - { A1: 10, A2: 20 }
609
- - {B1: 15, 'B2': 25, "B3": 35}
610
- #
611
- expected: |
612
- [{"A1"=>10, "A2"=>20}, {"B1"=>15, "B2"=>25, "B3"=>35}]
613
- #
614
- ---
615
- name: flowmap2
616
- desc: flow style map nested
617
- #
618
- input: |
619
- A: { x: {y: {z: 10}}}
620
- B: { a: 1, b:{c: 2, d: 3, e:{f: 4}}, g: 5}
621
- #
622
- expected: |
623
- {"A"=>{"x"=>{"y"=>{"z"=>10}}},
624
- "B"=>{"a"=>1, "b"=>{"c"=>2, "d"=>3, "e"=>{"f"=>4}}, "g"=>5}}
625
- #
626
- ---
627
- name: flowmap3
628
- desc: flow style map with some lines
629
- #
630
- input: |
631
- A: { x:
632
- {y:
633
- {z: 10}
634
- }
635
- }
636
- B: {
637
- a: 1,
638
- b: {
639
- c: 2,
640
- d: 3,
641
- e: {
642
- f: 4
643
- }
644
- },
645
- g: 5
646
- }
647
- #
648
- expected: |
649
- {"A"=>{"x"=>{"y"=>{"z"=>10}}},
650
- "B"=>{"a"=>1, "b"=>{"c"=>2, "d"=>3, "e"=>{"f"=>4}}, "g"=>5}}
651
- #
652
- ---
653
- name: flowmap4
654
- desc: invalid flow style map (mapping item required (or last comma is extra).)
655
- mesg: mapping item required (or last comma is extra).
656
- error: Kwalify::YamlSyntaxError
657
- #
658
- input: |
659
- - {A: 10, B: 20, }
660
- #
661
- expected: |
662
- #
663
- ---
664
- name: flowmap5
665
- desc: invalid flow style map (flow style mapping requires '}').
666
- mesg: flow style mapping requires '}'
667
- error: Kwalify::YamlSyntaxError
668
- #
669
- input: |
670
- - {A: { x: 10, y: 20 }
671
- - {A: { x: 11, y: 21 }}
672
- #
673
- expected: |
674
- #
675
- ---
676
- name: flowmap6
677
- desc: invalid flow style map (flow style mapping requires ']').
678
- mesg: flow style mapping is closed but got '}'.
679
- error: Kwalify::YamlSyntaxError
680
- #
681
- input: |
682
- { x: 10 }}
683
- #
684
- expected: |
685
- #
686
- ---
687
- name: parse61
688
- desc: combination of flow style seq and map
689
- #
690
- input: |
691
- [
692
- {name: ' foo ',
693
- e-mail: foo@mail.com},
694
- {name: ba z,
695
- e-mail: ba__z@mail.com }
696
- ]
697
- #
698
- expected: |
699
- [{"name"=>" foo ", "e-mail"=>"foo@mail.com"},
700
- {"name"=>"ba z", "e-mail"=>"ba__z@mail.com"}]
701
- #
702
- ---
703
- name: block_text1
704
- desc: parse_block_text
705
- #
706
- input: |
707
- - text1: |
708
- foo
709
- bar
710
- baz
711
- - text2: |
712
- aaa
713
- bbb
714
- ccc
715
- - |
716
- foo
717
- bar
718
- baz
719
- - |
720
- aaa
721
- bbb
722
- ccc
723
- #
724
- expected: |
725
- [{"text1"=>"foo\nbar\nbaz\n"},
726
- {"text2"=>" aaa\nbbb\n ccc\n"},
727
- "foo\nbar\nbaz\n",
728
- " aaa\nbbb\n ccc\n"]
729
- #
730
- ---
731
- name: block_text2
732
- desc: block text with '|+' or '|-'
733
- #
734
- input: |
735
- - text1: |
736
- A
737
-
738
- B
739
- C
740
-
741
-
742
- - text2: |+
743
- A
744
-
745
- B
746
- C
747
-
748
-
749
- - text3: |-
750
- A
751
-
752
- B
753
- C
754
-
755
-
756
- #
757
- expected: |
758
- [{"text1"=>"A\n\nB\nC\n"},
759
- {"text2"=>"A\n\nB\nC\n\n\n"},
760
- {"text3"=>"A\n\nB\nC"}]
761
- #
762
- ---
763
- name: block_text3
764
- desc: block text with '| foo'
765
- #
766
- input: |
767
- - text1: | foo
768
- A
769
-
770
- B
771
- C
772
-
773
- - | foo
774
- A
775
- B
776
- C
777
- #
778
- expected: |
779
- [{"text1"=>"foo A\n\nB\nC\n"}, "fooA\n B\n C\n"]
780
- #
781
- ---
782
- name: block_text4
783
- desc: block text with '#' (comment)
784
- #
785
- input: |
786
- #
787
- - text1: |
788
- A
789
- #
790
- B
791
- #
792
- text2: |
793
- #
794
- #
795
- #
796
- - |
797
- A
798
- #
799
- B
800
- #
801
- - |
802
- #
803
- #
804
- #
805
- - x
806
-
807
- #
808
- expected: |
809
- [{"text1"=>"A\n#\nB\n", "text2"=>"#\n#\n"}, "A\n#\nB\n", "#\n#\n", "x"]
810
- #
811
- ---
812
- name: block_text6
813
- desc: parse_block_text (>)
814
- #
815
- input: |
816
- - text1: >
817
- foo
818
- bar
819
- baz
820
- - text2: >
821
- aaa
822
- bbb
823
- ccc
824
- - >
825
- foo
826
- bar
827
- baz
828
- - >
829
- aaa
830
- bbb
831
- ccc
832
- #
833
- expected: |
834
- [{"text1"=>"foo bar baz\n"},
835
- {"text2"=>" aaa bbb ccc\n"},
836
- "foo bar baz\n",
837
- " aaa bbb ccc\n"]
838
- #
839
- ---
840
- name: block_text7
841
- desc: block text with '>+' or '>-'
842
- #
843
- input: |
844
- - text1: >
845
- A
846
-
847
- B
848
- C
849
-
850
-
851
- - text2: >+
852
- A
853
-
854
- B
855
- C
856
-
857
-
858
- - text3: >-
859
- A
860
-
861
- B
862
- C
863
-
864
-
865
- #
866
- expected: |
867
- [{"text1"=>"A\nB C\n"}, {"text2"=>"A\nB C\n\n"}, {"text3"=>"A\nB C"}]
868
- #
869
- ---
870
- name: block_text8
871
- desc: block text with '> foo'
872
- #
873
- input: |
874
- - text1: > foo
875
- A
876
-
877
- B
878
- C
879
-
880
- - > foo
881
- A
882
- B
883
- C
884
- #
885
- expected: |
886
- [{"text1"=>"foo A\nB C\n"}, "fooA B C\n"]
887
- #
888
- ---
889
- name: block_text9
890
- desc: block text with '#' (comment)
891
- #
892
- input: |
893
- #
894
- - text1: >
895
- AA
896
- ##
897
- BB
898
- #
899
- text2: >
900
- #
901
- #
902
- #
903
- - >
904
- AA
905
- ##
906
- BB
907
- #
908
- - >
909
- #
910
- #
911
- #
912
- - x
913
-
914
- #
915
- expected: |
916
- [{"text1"=>"AA ## BB\n", "text2"=>"# #\n"}, "AA ## BB\n", "# #\n", "x"]
917
- #
918
- ---
919
- name: anchor1
920
- desc: parse_anchor, parse_alias
921
- #
922
- input: |
923
- - &a1 foo
924
- - &a2
925
- bar
926
- - *a1
927
- - *a2
928
- #
929
- expected: |
930
- ["foo", "bar", "foo", "bar"]
931
- #
932
- ---
933
- name: anchor2
934
- desc: parse_anchor, parse_alias
935
- #
936
- input: |
937
- - A: &a1
938
- x: 10
939
- y: 20
940
- - B: bar
941
- - C: *a1
942
- #
943
- expected: |
944
- [{"A"=>{"x"=>10, "y"=>20}}, {"B"=>"bar"}, {"C"=>{"x"=>10, "y"=>20}}]
945
- #
946
- ---
947
- name: anchor3
948
- desc: anchor on child node
949
- #
950
- input: |
951
- - A: &a1
952
- x: 10
953
- y: 20
954
- z: *a1
955
- #
956
- expected: |
957
- [{"A"=>{"x"=>10, "y"=>20, "z"=>{...}}}]
958
- #
959
- ---
960
- name: anchor4
961
- desc: backward anchor
962
- #
963
- input: |
964
- - *a1
965
- - *a1
966
- - foo
967
- - &a1 bar
968
- #
969
- expected: |
970
- ["bar", "bar", "foo", "bar"]
971
- #
972
- ---
973
- name: anchor5
974
- desc: anchor not found
975
- error: Kwalify::YamlSyntaxError
976
- mesg: anchor 'a2' not found (Kwalify::YamlSyntaxError)
977
- #
978
- input: |
979
- - &a1 foo
980
- - bar
981
- - *a2
982
- #
983
- expected: |
984
- #
985
- ---
986
- name: anchor6
987
- desc: anchor on child node
988
- #
989
- input: |
990
- type: seq
991
- sequence:
992
- - &employee
993
- type: map
994
- mapping:
995
- name:
996
- type: str
997
- post:
998
- type: str
999
- enum:
1000
- - exective
1001
- - manager
1002
- - clerk
1003
- supervisor: *employee
1004
- #
1005
- expected: |
1006
- {"sequence"=>
1007
- [{"type"=>"map",
1008
- "mapping"=>
1009
- {"name"=>{"type"=>"str"},
1010
- "post"=>{"type"=>"str", "enum"=>["exective", "manager", "clerk"]},
1011
- "supervisor"=>{...}}}],
1012
- "type"=>"seq"}
1013
- #
1014
- ---
1015
- name: tag1
1016
- desc: tag
1017
- #
1018
- input: |
1019
- - !str 123
1020
- - foo: !text 123
1021
- #
1022
- expected: |
1023
- [123, {"foo"=>123}]
1024
- #
1025
- ---
1026
- name: docend1
1027
- desc: ... (document end)
1028
- #
1029
- input: |
1030
- - aaa
1031
- - bbb
1032
- ...
1033
- - ccc
1034
- #
1035
- expected: |
1036
- ["aaa", "bbb"]
1037
- #
1038
- ---
1039
- name: docend2
1040
- desc: ... (document end) in block text
1041
- #
1042
- input: |
1043
- - |
1044
- foo
1045
- ...
1046
- bar
1047
- #
1048
- expected: |
1049
- ["foo\n...\nbar\n"]
1050
- #
1051
- ---
1052
- name: docstart1
1053
- desc: --- (document start)
1054
- #
1055
- input: |
1056
- # comment
1057
- ---
1058
- - foo
1059
- - bar
1060
- #
1061
- expected: |
1062
- ["foo", "bar"]
1063
- #
1064
- ---
1065
- name: docstart2
1066
- desc: --- (document start) with tag
1067
- #
1068
- input: |
1069
- # comment
1070
- --- %YAML !seq
1071
- - foo
1072
- - bar
1073
- #
1074
- expected: |
1075
- ["foo", "bar"]
1076
- #
1077
- ---
1078
- name: docstart3
1079
- desc: --- (document start) with tag
1080
- #
1081
- input: |
1082
- - |
1083
- foo
1084
- ---
1085
- bar
1086
- ---
1087
- baz
1088
- #
1089
- expected: |
1090
- ["foo\n---\nbar\n---\nbaz\n"]
1091
- #
1092
- ---
1093
- name: default1
1094
- desc: map default value
1095
- #
1096
- input: |
1097
- A: 10
1098
- B: 20
1099
- =: 0
1100
- #
1101
- expected: |
1102
- {"A"=>10, "B"=>20}
1103
- #
1104
- ---
1105
- name: merge1
1106
- desc: merge key '<<'
1107
- #
1108
- input: |
1109
- - &a1
1110
- A: 10
1111
- B: 20
1112
- - C: 30
1113
- <<: *a1
1114
- A: ~
1115
- #
1116
- expected: |
1117
- [{"A"=>10, "B"=>20}, {"A"=>nil, "B"=>20, "C"=>30}]
1118
- ---
1119
- name: example1
1120
- desc: complex combination of seq and map
1121
- #
1122
- input: |
1123
- columns:
1124
- - name: id
1125
- type: integer
1126
- primary-key: yes
1127
- sequence: yes
1128
-
1129
- - name: name
1130
- type: string
1131
- not-null: yes
1132
- width: 63
1133
-
1134
- - name: desc
1135
- type: string
1136
-
1137
- - name: email
1138
- type: string
1139
- width: 63
1140
-
1141
- - name: birth
1142
- type: date
1143
-
1144
- - name: age
1145
- type: integer
1146
-
1147
- - name: last_update
1148
- type: timestamp
1149
-
1150
- - name: gender
1151
- type: string
1152
- values:
1153
- - M
1154
- - F
1155
-
1156
- tables:
1157
- - name: groups
1158
- class: Group
1159
- desc: Group master table
1160
- columns:
1161
- - name: id
1162
- - name: name
1163
- - name: desc
1164
-
1165
- - name: users
1166
- class: User
1167
- desc: User master table
1168
- columns:
1169
- - name: id
1170
- - name: name
1171
- - name: desc
1172
- - name: email
1173
- - name: group_id
1174
- type: ref
1175
- ref: groups.id
1176
- - name: account
1177
- type: string
1178
- maxlength: 31
1179
- not-null: yes
1180
- - name: password
1181
- not-null: yes
1182
- #
1183
- expected: |
1184
- {"columns"=>
1185
- [{"name"=>"id", "sequence"=>true, "type"=>"integer", "primary-key"=>true},
1186
- {"name"=>"name", "not-null"=>true, "type"=>"string", "width"=>63},
1187
- {"name"=>"desc", "type"=>"string"},
1188
- {"name"=>"email", "type"=>"string", "width"=>63},
1189
- {"name"=>"birth", "type"=>"date"},
1190
- {"name"=>"age", "type"=>"integer"},
1191
- {"name"=>"last_update", "type"=>"timestamp"},
1192
- {"name"=>"gender", "type"=>"string", "values"=>["M", "F"]}],
1193
- "tables"=>
1194
- [{"columns"=>[{"name"=>"id"}, {"name"=>"name"}, {"name"=>"desc"}],
1195
- "name"=>"groups",
1196
- "class"=>"Group",
1197
- "desc"=>"Group master table"},
1198
- {"columns"=>
1199
- [{"name"=>"id"},
1200
- {"name"=>"name"},
1201
- {"name"=>"desc"},
1202
- {"name"=>"email"},
1203
- {"name"=>"group_id", "type"=>"ref", "ref"=>"groups.id"},
1204
- {"name"=>"account", "not-null"=>true, "type"=>"string", "maxlength"=>31},
1205
- {"name"=>"password", "not-null"=>true}],
1206
- "name"=>"users",
1207
- "class"=>"User",
1208
- "desc"=>"User master table"}]}
1209
- #
1210
- ---
1211
- name: example2
1212
- desc: invoice
1213
- #
1214
- input: |
1215
- invoice: 34843
1216
- date : 2001-01-23
1217
- bill-to: &id001
1218
- given : Chris
1219
- family : Dumars
1220
- address:
1221
- lines: |
1222
- 458 Walkman Dr.
1223
- Suite #292
1224
- city : Royal Oak
1225
- state : MI
1226
- postal : 48046
1227
- ship-to: *id001
1228
- product:
1229
- - sku : BL394D
1230
- quantity : 4
1231
- description : Basketball
1232
- price : 450.00
1233
- - sku : BL4438H
1234
- quantity : 1
1235
- description : Super Hoop
1236
- price : 2392.00
1237
- tax : 251.42
1238
- total: 4443.52
1239
- comments: >
1240
- Late afternoon is best.
1241
- Backup contact is Nancy
1242
- Billsmer @ 338-4338.
1243
- #
1244
- expected: |
1245
- {"tax"=>251.42,
1246
- "bill-to"=>
1247
- {"given"=>"Chris",
1248
- "family"=>"Dumars",
1249
- "address"=>
1250
- {"postal"=>48046,
1251
- "city"=>"Royal Oak",
1252
- "lines"=>"458 Walkman Dr.\nSuite #292\n",
1253
- "state"=>"MI"}},
1254
- "comments"=>
1255
- "Late afternoon is best. Backup contact is Nancy Billsmer @ 338-4338.\n",
1256
- "invoice"=>34843,
1257
- "date"=>#<Date: 4903865/2,0,2299161>,
1258
- "total"=>4443.52,
1259
- "product"=>
1260
- [{"price"=>450.0,
1261
- "quantity"=>4,
1262
- "description"=>"Basketball",
1263
- "sku"=>"BL394D"},
1264
- {"price"=>2392.0,
1265
- "quantity"=>1,
1266
- "description"=>"Super Hoop",
1267
- "sku"=>"BL4438H"}],
1268
- "ship-to"=>
1269
- {"given"=>"Chris",
1270
- "family"=>"Dumars",
1271
- "address"=>
1272
- {"postal"=>48046,
1273
- "city"=>"Royal Oak",
1274
- "lines"=>"458 Walkman Dr.\nSuite #292\n",
1275
- "state"=>"MI"}}}
1276
- #