psych 2.0.14-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (118) hide show
  1. checksums.yaml +7 -0
  2. data/.autotest +18 -0
  3. data/.gemtest +0 -0
  4. data/.travis.yml +16 -0
  5. data/CHANGELOG.rdoc +576 -0
  6. data/Manifest.txt +114 -0
  7. data/README.rdoc +71 -0
  8. data/Rakefile +123 -0
  9. data/ext/psych/depend +3 -0
  10. data/ext/psych/extconf.rb +38 -0
  11. data/ext/psych/psych.c +34 -0
  12. data/ext/psych/psych.h +20 -0
  13. data/ext/psych/psych_emitter.c +555 -0
  14. data/ext/psych/psych_emitter.h +8 -0
  15. data/ext/psych/psych_parser.c +597 -0
  16. data/ext/psych/psych_parser.h +6 -0
  17. data/ext/psych/psych_to_ruby.c +43 -0
  18. data/ext/psych/psych_to_ruby.h +8 -0
  19. data/ext/psych/psych_yaml_tree.c +24 -0
  20. data/ext/psych/psych_yaml_tree.h +8 -0
  21. data/ext/psych/yaml/LICENSE +19 -0
  22. data/ext/psych/yaml/api.c +1415 -0
  23. data/ext/psych/yaml/config.h +10 -0
  24. data/ext/psych/yaml/dumper.c +394 -0
  25. data/ext/psych/yaml/emitter.c +2329 -0
  26. data/ext/psych/yaml/loader.c +459 -0
  27. data/ext/psych/yaml/parser.c +1370 -0
  28. data/ext/psych/yaml/reader.c +469 -0
  29. data/ext/psych/yaml/scanner.c +3576 -0
  30. data/ext/psych/yaml/writer.c +141 -0
  31. data/ext/psych/yaml/yaml.h +1971 -0
  32. data/ext/psych/yaml/yaml_private.h +664 -0
  33. data/lib/psych.jar +0 -0
  34. data/lib/psych.rb +504 -0
  35. data/lib/psych/class_loader.rb +101 -0
  36. data/lib/psych/coder.rb +94 -0
  37. data/lib/psych/core_ext.rb +35 -0
  38. data/lib/psych/deprecated.rb +85 -0
  39. data/lib/psych/exception.rb +13 -0
  40. data/lib/psych/handler.rb +249 -0
  41. data/lib/psych/handlers/document_stream.rb +22 -0
  42. data/lib/psych/handlers/recorder.rb +39 -0
  43. data/lib/psych/json/ruby_events.rb +19 -0
  44. data/lib/psych/json/stream.rb +16 -0
  45. data/lib/psych/json/tree_builder.rb +12 -0
  46. data/lib/psych/json/yaml_events.rb +29 -0
  47. data/lib/psych/nodes.rb +77 -0
  48. data/lib/psych/nodes/alias.rb +18 -0
  49. data/lib/psych/nodes/document.rb +60 -0
  50. data/lib/psych/nodes/mapping.rb +56 -0
  51. data/lib/psych/nodes/node.rb +55 -0
  52. data/lib/psych/nodes/scalar.rb +67 -0
  53. data/lib/psych/nodes/sequence.rb +81 -0
  54. data/lib/psych/nodes/stream.rb +37 -0
  55. data/lib/psych/omap.rb +4 -0
  56. data/lib/psych/parser.rb +51 -0
  57. data/lib/psych/scalar_scanner.rb +149 -0
  58. data/lib/psych/set.rb +4 -0
  59. data/lib/psych/stream.rb +37 -0
  60. data/lib/psych/streaming.rb +27 -0
  61. data/lib/psych/syntax_error.rb +21 -0
  62. data/lib/psych/tree_builder.rb +96 -0
  63. data/lib/psych/versions.rb +3 -0
  64. data/lib/psych/visitors.rb +6 -0
  65. data/lib/psych/visitors/depth_first.rb +26 -0
  66. data/lib/psych/visitors/emitter.rb +51 -0
  67. data/lib/psych/visitors/json_tree.rb +24 -0
  68. data/lib/psych/visitors/to_ruby.rb +404 -0
  69. data/lib/psych/visitors/visitor.rb +19 -0
  70. data/lib/psych/visitors/yaml_tree.rb +605 -0
  71. data/lib/psych/y.rb +9 -0
  72. data/lib/psych_jars.rb +5 -0
  73. data/test/psych/handlers/test_recorder.rb +25 -0
  74. data/test/psych/helper.rb +121 -0
  75. data/test/psych/json/test_stream.rb +109 -0
  76. data/test/psych/nodes/test_enumerable.rb +43 -0
  77. data/test/psych/test_alias_and_anchor.rb +96 -0
  78. data/test/psych/test_array.rb +57 -0
  79. data/test/psych/test_boolean.rb +36 -0
  80. data/test/psych/test_class.rb +36 -0
  81. data/test/psych/test_coder.rb +206 -0
  82. data/test/psych/test_date_time.rb +38 -0
  83. data/test/psych/test_deprecated.rb +214 -0
  84. data/test/psych/test_document.rb +46 -0
  85. data/test/psych/test_emitter.rb +93 -0
  86. data/test/psych/test_encoding.rb +259 -0
  87. data/test/psych/test_exception.rb +157 -0
  88. data/test/psych/test_hash.rb +94 -0
  89. data/test/psych/test_json_tree.rb +65 -0
  90. data/test/psych/test_merge_keys.rb +180 -0
  91. data/test/psych/test_nil.rb +18 -0
  92. data/test/psych/test_null.rb +19 -0
  93. data/test/psych/test_numeric.rb +45 -0
  94. data/test/psych/test_object.rb +44 -0
  95. data/test/psych/test_object_references.rb +71 -0
  96. data/test/psych/test_omap.rb +75 -0
  97. data/test/psych/test_parser.rb +339 -0
  98. data/test/psych/test_psych.rb +168 -0
  99. data/test/psych/test_safe_load.rb +97 -0
  100. data/test/psych/test_scalar.rb +11 -0
  101. data/test/psych/test_scalar_scanner.rb +106 -0
  102. data/test/psych/test_serialize_subclasses.rb +38 -0
  103. data/test/psych/test_set.rb +49 -0
  104. data/test/psych/test_stream.rb +93 -0
  105. data/test/psych/test_string.rb +226 -0
  106. data/test/psych/test_struct.rb +49 -0
  107. data/test/psych/test_symbol.rb +25 -0
  108. data/test/psych/test_tainted.rb +130 -0
  109. data/test/psych/test_to_yaml_properties.rb +63 -0
  110. data/test/psych/test_tree_builder.rb +79 -0
  111. data/test/psych/test_yaml.rb +1292 -0
  112. data/test/psych/test_yamldbm.rb +193 -0
  113. data/test/psych/test_yamlstore.rb +85 -0
  114. data/test/psych/visitors/test_depth_first.rb +49 -0
  115. data/test/psych/visitors/test_emitter.rb +144 -0
  116. data/test/psych/visitors/test_to_ruby.rb +333 -0
  117. data/test/psych/visitors/test_yaml_tree.rb +173 -0
  118. metadata +240 -0
@@ -0,0 +1,193 @@
1
+ require_relative 'helper'
2
+ require 'tmpdir'
3
+
4
+ begin
5
+ require 'yaml/dbm'
6
+ rescue LoadError
7
+ end
8
+
9
+ module Psych
10
+ ::Psych::DBM = ::YAML::DBM unless defined?(::Psych::DBM)
11
+
12
+ class YAMLDBMTest < TestCase
13
+ def setup
14
+ @dir = Dir.mktmpdir("rubytest-file")
15
+ File.chown(-1, Process.gid, @dir)
16
+ @yamldbm_file = make_tmp_filename("yamldbm")
17
+ @yamldbm = YAML::DBM.new(@yamldbm_file)
18
+ end
19
+
20
+ def teardown
21
+ @yamldbm.clear
22
+ @yamldbm.close
23
+ FileUtils.remove_entry_secure @dir
24
+ end
25
+
26
+ def make_tmp_filename(prefix)
27
+ @dir + "/" + prefix + File.basename(__FILE__) + ".#{$$}.test"
28
+ end
29
+
30
+ def test_store
31
+ @yamldbm.store('a','b')
32
+ @yamldbm.store('c','d')
33
+ assert_equal 'b', @yamldbm['a']
34
+ assert_equal 'd', @yamldbm['c']
35
+ assert_nil @yamldbm['e']
36
+ end
37
+
38
+ def test_store_using_carret
39
+ @yamldbm['a'] = 'b'
40
+ @yamldbm['c'] = 'd'
41
+ assert_equal 'b', @yamldbm['a']
42
+ assert_equal 'd', @yamldbm['c']
43
+ assert_nil @yamldbm['e']
44
+ end
45
+
46
+ def test_to_a
47
+ @yamldbm['a'] = 'b'
48
+ @yamldbm['c'] = 'd'
49
+ assert_equal([['a','b'],['c','d']], @yamldbm.to_a.sort)
50
+ end
51
+
52
+ def test_to_hash
53
+ @yamldbm['a'] = 'b'
54
+ @yamldbm['c'] = 'd'
55
+ assert_equal({'a'=>'b','c'=>'d'}, @yamldbm.to_hash)
56
+ end
57
+
58
+ def test_has_value?
59
+ @yamldbm['a'] = 'b'
60
+ @yamldbm['c'] = 'd'
61
+ assert_equal true, @yamldbm.has_value?('b')
62
+ assert_equal true, @yamldbm.has_value?('d')
63
+ assert_equal false, @yamldbm.has_value?('f')
64
+ end
65
+
66
+ # Note:
67
+ # YAML::DBM#index makes warning from internal of ::DBM#index.
68
+ # It says 'DBM#index is deprecated; use DBM#key', but DBM#key
69
+ # behaves not same as DBM#index.
70
+ #
71
+ # def test_index
72
+ # @yamldbm['a'] = 'b'
73
+ # @yamldbm['c'] = 'd'
74
+ # assert_equal 'a', @yamldbm.index('b')
75
+ # assert_equal 'c', @yamldbm.index('d')
76
+ # assert_nil @yamldbm.index('f')
77
+ # end
78
+
79
+ def test_key
80
+ skip 'only on ruby 2.0.0' if RUBY_VERSION < '2.0.0'
81
+ @yamldbm['a'] = 'b'
82
+ @yamldbm['c'] = 'd'
83
+ assert_equal 'a', @yamldbm.key('b')
84
+ assert_equal 'c', @yamldbm.key('d')
85
+ assert_nil @yamldbm.key('f')
86
+ end
87
+
88
+ def test_fetch
89
+ assert_equal('bar', @yamldbm['foo']='bar')
90
+ assert_equal('bar', @yamldbm.fetch('foo'))
91
+ assert_nil @yamldbm.fetch('bar')
92
+ assert_equal('baz', @yamldbm.fetch('bar', 'baz'))
93
+ assert_equal('foobar', @yamldbm.fetch('bar') {|key| 'foo' + key })
94
+ end
95
+
96
+ def test_shift
97
+ @yamldbm['a'] = 'b'
98
+ @yamldbm['c'] = 'd'
99
+ assert_equal([['a','b'], ['c','d']],
100
+ [@yamldbm.shift, @yamldbm.shift].sort)
101
+ assert_nil @yamldbm.shift
102
+ end
103
+
104
+ def test_invert
105
+ @yamldbm['a'] = 'b'
106
+ @yamldbm['c'] = 'd'
107
+ assert_equal({'b'=>'a','d'=>'c'}, @yamldbm.invert)
108
+ end
109
+
110
+ def test_update
111
+ @yamldbm['a'] = 'b'
112
+ @yamldbm['c'] = 'd'
113
+ @yamldbm.update({'c'=>'d','e'=>'f'})
114
+ assert_equal 'b', @yamldbm['a']
115
+ assert_equal 'd', @yamldbm['c']
116
+ assert_equal 'f', @yamldbm['e']
117
+ end
118
+
119
+ def test_replace
120
+ @yamldbm['a'] = 'b'
121
+ @yamldbm['c'] = 'd'
122
+ @yamldbm.replace({'c'=>'d','e'=>'f'})
123
+ assert_nil @yamldbm['a']
124
+ assert_equal 'd', @yamldbm['c']
125
+ assert_equal 'f', @yamldbm['e']
126
+ end
127
+
128
+ def test_delete
129
+ @yamldbm['a'] = 'b'
130
+ @yamldbm['c'] = 'd'
131
+ assert_equal 'b', @yamldbm.delete('a')
132
+ assert_nil @yamldbm['a']
133
+ assert_equal 'd', @yamldbm['c']
134
+ assert_nil @yamldbm.delete('e')
135
+ end
136
+
137
+ def test_delete_if
138
+ @yamldbm['a'] = 'b'
139
+ @yamldbm['c'] = 'd'
140
+ @yamldbm['e'] = 'f'
141
+
142
+ @yamldbm.delete_if {|k,v| k == 'a'}
143
+ assert_nil @yamldbm['a']
144
+ assert_equal 'd', @yamldbm['c']
145
+ assert_equal 'f', @yamldbm['e']
146
+
147
+ @yamldbm.delete_if {|k,v| v == 'd'}
148
+ assert_nil @yamldbm['c']
149
+ assert_equal 'f', @yamldbm['e']
150
+
151
+ @yamldbm.delete_if {|k,v| false }
152
+ assert_equal 'f', @yamldbm['e']
153
+ end
154
+
155
+ def test_reject
156
+ @yamldbm['a'] = 'b'
157
+ @yamldbm['c'] = 'd'
158
+ @yamldbm['e'] = 'f'
159
+ assert_equal({'c'=>'d','e'=>'f'}, @yamldbm.reject {|k,v| k == 'a'})
160
+ assert_equal({'a'=>'b','e'=>'f'}, @yamldbm.reject {|k,v| v == 'd'})
161
+ assert_equal({'a'=>'b','c'=>'d','e'=>'f'}, @yamldbm.reject {false})
162
+ end
163
+
164
+ def test_values
165
+ assert_equal [], @yamldbm.values
166
+ @yamldbm['a'] = 'b'
167
+ @yamldbm['c'] = 'd'
168
+ assert_equal ['b','d'], @yamldbm.values.sort
169
+ end
170
+
171
+ def test_values_at
172
+ @yamldbm['a'] = 'b'
173
+ @yamldbm['c'] = 'd'
174
+ assert_equal ['b','d'], @yamldbm.values_at('a','c')
175
+ end
176
+
177
+ def test_selsct
178
+ @yamldbm['a'] = 'b'
179
+ @yamldbm['c'] = 'd'
180
+ @yamldbm['e'] = 'f'
181
+ assert_equal(['b','d'], @yamldbm.select('a','c'))
182
+ end
183
+
184
+ def test_selsct_with_block
185
+ @yamldbm['a'] = 'b'
186
+ @yamldbm['c'] = 'd'
187
+ @yamldbm['e'] = 'f'
188
+ assert_equal([['a','b']], @yamldbm.select {|k,v| k == 'a'})
189
+ assert_equal([['c','d']], @yamldbm.select {|k,v| v == 'd'})
190
+ assert_equal([], @yamldbm.select {false})
191
+ end
192
+ end
193
+ end if defined?(YAML::DBM) && defined?(Psych)
@@ -0,0 +1,85 @@
1
+ require_relative 'helper'
2
+ require 'yaml/store'
3
+ require 'tmpdir'
4
+
5
+ module Psych
6
+ Psych::Store = YAML::Store unless defined?(Psych::Store)
7
+
8
+ class YAMLStoreTest < TestCase
9
+ def setup
10
+ @dir = Dir.mktmpdir("rubytest-file")
11
+ File.chown(-1, Process.gid, @dir)
12
+ @yamlstore_file = make_tmp_filename("yamlstore")
13
+ @yamlstore = YAML::Store.new(@yamlstore_file)
14
+ end
15
+
16
+ def teardown
17
+ FileUtils.remove_entry_secure @dir
18
+ end
19
+
20
+ def make_tmp_filename(prefix)
21
+ @dir + "/" + prefix + File.basename(__FILE__) + ".#{$$}.test"
22
+ end
23
+
24
+ def test_opening_new_file_in_readonly_mode_should_result_in_empty_values
25
+ @yamlstore.transaction(true) do
26
+ assert_nil @yamlstore[:foo]
27
+ assert_nil @yamlstore[:bar]
28
+ end
29
+ end
30
+
31
+ def test_opening_new_file_in_readwrite_mode_should_result_in_empty_values
32
+ @yamlstore.transaction do
33
+ assert_nil @yamlstore[:foo]
34
+ assert_nil @yamlstore[:bar]
35
+ end
36
+ end
37
+
38
+ def test_data_should_be_loaded_correctly_when_in_readonly_mode
39
+ @yamlstore.transaction do
40
+ @yamlstore[:foo] = "bar"
41
+ end
42
+ @yamlstore.transaction(true) do
43
+ assert_equal "bar", @yamlstore[:foo]
44
+ end
45
+ end
46
+
47
+ def test_data_should_be_loaded_correctly_when_in_readwrite_mode
48
+ @yamlstore.transaction do
49
+ @yamlstore[:foo] = "bar"
50
+ end
51
+ @yamlstore.transaction do
52
+ assert_equal "bar", @yamlstore[:foo]
53
+ end
54
+ end
55
+
56
+ def test_changes_after_commit_are_discarded
57
+ @yamlstore.transaction do
58
+ @yamlstore[:foo] = "bar"
59
+ @yamlstore.commit
60
+ @yamlstore[:foo] = "baz"
61
+ end
62
+ @yamlstore.transaction(true) do
63
+ assert_equal "bar", @yamlstore[:foo]
64
+ end
65
+ end
66
+
67
+ def test_changes_are_not_written_on_abort
68
+ @yamlstore.transaction do
69
+ @yamlstore[:foo] = "bar"
70
+ @yamlstore.abort
71
+ end
72
+ @yamlstore.transaction(true) do
73
+ assert_nil @yamlstore[:foo]
74
+ end
75
+ end
76
+
77
+ def test_writing_inside_readonly_transaction_raises_error
78
+ assert_raises(PStore::Error) do
79
+ @yamlstore.transaction(true) do
80
+ @yamlstore[:foo] = "bar"
81
+ end
82
+ end
83
+ end
84
+ end
85
+ end if defined?(Psych)
@@ -0,0 +1,49 @@
1
+ require 'psych/helper'
2
+
3
+ module Psych
4
+ module Visitors
5
+ class TestDepthFirst < TestCase
6
+ class Collector < Struct.new(:calls)
7
+ def initialize(calls = [])
8
+ super
9
+ end
10
+
11
+ def call obj
12
+ calls << obj
13
+ end
14
+ end
15
+
16
+ def test_scalar
17
+ collector = Collector.new
18
+ visitor = Visitors::DepthFirst.new collector
19
+ visitor.accept Psych.parse_stream '--- hello'
20
+
21
+ assert_equal 3, collector.calls.length
22
+ end
23
+
24
+ def test_sequence
25
+ collector = Collector.new
26
+ visitor = Visitors::DepthFirst.new collector
27
+ visitor.accept Psych.parse_stream "---\n- hello"
28
+
29
+ assert_equal 4, collector.calls.length
30
+ end
31
+
32
+ def test_mapping
33
+ collector = Collector.new
34
+ visitor = Visitors::DepthFirst.new collector
35
+ visitor.accept Psych.parse_stream "---\nhello: world"
36
+
37
+ assert_equal 5, collector.calls.length
38
+ end
39
+
40
+ def test_alias
41
+ collector = Collector.new
42
+ visitor = Visitors::DepthFirst.new collector
43
+ visitor.accept Psych.parse_stream "--- &yay\n- foo\n- *yay\n"
44
+
45
+ assert_equal 5, collector.calls.length
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,144 @@
1
+ require 'psych/helper'
2
+
3
+ module Psych
4
+ module Visitors
5
+ class TestEmitter < TestCase
6
+ def setup
7
+ super
8
+ @io = StringIO.new
9
+ @visitor = Visitors::Emitter.new @io
10
+ end
11
+
12
+ def test_options
13
+ io = StringIO.new
14
+ visitor = Visitors::Emitter.new io, :indentation => 3
15
+
16
+ s = Nodes::Stream.new
17
+ doc = Nodes::Document.new
18
+ mapping = Nodes::Mapping.new
19
+ m2 = Nodes::Mapping.new
20
+ m2.children << Nodes::Scalar.new('a')
21
+ m2.children << Nodes::Scalar.new('b')
22
+
23
+ mapping.children << Nodes::Scalar.new('key')
24
+ mapping.children << m2
25
+ doc.children << mapping
26
+ s.children << doc
27
+
28
+ visitor.accept s
29
+ assert_match(/^[ ]{3}a/, io.string)
30
+ end
31
+
32
+ def test_stream
33
+ s = Nodes::Stream.new
34
+ @visitor.accept s
35
+ assert_equal '', @io.string
36
+ end
37
+
38
+ def test_document
39
+ s = Nodes::Stream.new
40
+ doc = Nodes::Document.new [1,1]
41
+ scalar = Nodes::Scalar.new 'hello world'
42
+
43
+ doc.children << scalar
44
+ s.children << doc
45
+
46
+ @visitor.accept s
47
+
48
+ assert_match(/1.1/, @io.string)
49
+ assert_equal @io.string, s.yaml
50
+ end
51
+
52
+ def test_document_implicit_end
53
+ s = Nodes::Stream.new
54
+ doc = Nodes::Document.new
55
+ mapping = Nodes::Mapping.new
56
+ mapping.children << Nodes::Scalar.new('key')
57
+ mapping.children << Nodes::Scalar.new('value')
58
+ doc.children << mapping
59
+ s.children << doc
60
+
61
+ @visitor.accept s
62
+
63
+ assert_match(/key: value/, @io.string)
64
+ assert_equal @io.string, s.yaml
65
+ assert(/\.\.\./ !~ s.yaml)
66
+ end
67
+
68
+ def test_scalar
69
+ s = Nodes::Stream.new
70
+ doc = Nodes::Document.new
71
+ scalar = Nodes::Scalar.new 'hello world'
72
+
73
+ doc.children << scalar
74
+ s.children << doc
75
+
76
+ @visitor.accept s
77
+
78
+ assert_match(/hello/, @io.string)
79
+ assert_equal @io.string, s.yaml
80
+ end
81
+
82
+ def test_scalar_with_tag
83
+ s = Nodes::Stream.new
84
+ doc = Nodes::Document.new
85
+ scalar = Nodes::Scalar.new 'hello world', nil, '!str', false, false, 5
86
+
87
+ doc.children << scalar
88
+ s.children << doc
89
+
90
+ @visitor.accept s
91
+
92
+ assert_match(/str/, @io.string)
93
+ assert_match(/hello/, @io.string)
94
+ assert_equal @io.string, s.yaml
95
+ end
96
+
97
+ def test_sequence
98
+ s = Nodes::Stream.new
99
+ doc = Nodes::Document.new
100
+ scalar = Nodes::Scalar.new 'hello world'
101
+ seq = Nodes::Sequence.new
102
+
103
+ seq.children << scalar
104
+ doc.children << seq
105
+ s.children << doc
106
+
107
+ @visitor.accept s
108
+
109
+ assert_match(/- hello/, @io.string)
110
+ assert_equal @io.string, s.yaml
111
+ end
112
+
113
+ def test_mapping
114
+ s = Nodes::Stream.new
115
+ doc = Nodes::Document.new
116
+ mapping = Nodes::Mapping.new
117
+ mapping.children << Nodes::Scalar.new('key')
118
+ mapping.children << Nodes::Scalar.new('value')
119
+ doc.children << mapping
120
+ s.children << doc
121
+
122
+ @visitor.accept s
123
+
124
+ assert_match(/key: value/, @io.string)
125
+ assert_equal @io.string, s.yaml
126
+ end
127
+
128
+ def test_alias
129
+ s = Nodes::Stream.new
130
+ doc = Nodes::Document.new
131
+ mapping = Nodes::Mapping.new
132
+ mapping.children << Nodes::Scalar.new('key', 'A')
133
+ mapping.children << Nodes::Alias.new('A')
134
+ doc.children << mapping
135
+ s.children << doc
136
+
137
+ @visitor.accept s
138
+
139
+ assert_match(/&A key: \*A/, @io.string)
140
+ assert_equal @io.string, s.yaml
141
+ end
142
+ end
143
+ end
144
+ end