psych 2.1.0 → 2.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +14 -0
  3. data/.travis.yml +1 -10
  4. data/Gemfile +3 -0
  5. data/Mavenfile +7 -0
  6. data/Rakefile +27 -119
  7. data/bin/console +7 -0
  8. data/bin/setup +6 -0
  9. data/ext/java/PsychEmitter.java +345 -0
  10. data/ext/java/PsychLibrary.java +93 -0
  11. data/ext/java/PsychParser.java +399 -0
  12. data/ext/java/PsychToRuby.java +79 -0
  13. data/ext/java/PsychYamlTree.java +55 -0
  14. data/ext/psych/.gitignore +11 -0
  15. data/lib/psych.rb +2 -2
  16. data/lib/psych/scalar_scanner.rb +1 -1
  17. data/lib/psych/visitors/to_ruby.rb +2 -2
  18. data/psych.gemspec +39 -0
  19. metadata +21 -84
  20. data/.autotest +0 -18
  21. data/Manifest.txt +0 -114
  22. data/test/psych/handlers/test_recorder.rb +0 -26
  23. data/test/psych/helper.rb +0 -122
  24. data/test/psych/json/test_stream.rb +0 -110
  25. data/test/psych/nodes/test_enumerable.rb +0 -44
  26. data/test/psych/test_alias_and_anchor.rb +0 -97
  27. data/test/psych/test_array.rb +0 -58
  28. data/test/psych/test_boolean.rb +0 -37
  29. data/test/psych/test_class.rb +0 -37
  30. data/test/psych/test_coder.rb +0 -207
  31. data/test/psych/test_date_time.rb +0 -39
  32. data/test/psych/test_deprecated.rb +0 -215
  33. data/test/psych/test_document.rb +0 -47
  34. data/test/psych/test_emitter.rb +0 -111
  35. data/test/psych/test_encoding.rb +0 -269
  36. data/test/psych/test_exception.rb +0 -158
  37. data/test/psych/test_hash.rb +0 -95
  38. data/test/psych/test_json_tree.rb +0 -66
  39. data/test/psych/test_merge_keys.rb +0 -181
  40. data/test/psych/test_nil.rb +0 -19
  41. data/test/psych/test_null.rb +0 -20
  42. data/test/psych/test_numeric.rb +0 -46
  43. data/test/psych/test_object.rb +0 -45
  44. data/test/psych/test_object_references.rb +0 -72
  45. data/test/psych/test_omap.rb +0 -76
  46. data/test/psych/test_parser.rb +0 -340
  47. data/test/psych/test_psych.rb +0 -184
  48. data/test/psych/test_safe_load.rb +0 -98
  49. data/test/psych/test_scalar.rb +0 -12
  50. data/test/psych/test_scalar_scanner.rb +0 -107
  51. data/test/psych/test_serialize_subclasses.rb +0 -39
  52. data/test/psych/test_set.rb +0 -50
  53. data/test/psych/test_stream.rb +0 -94
  54. data/test/psych/test_string.rb +0 -227
  55. data/test/psych/test_struct.rb +0 -50
  56. data/test/psych/test_symbol.rb +0 -26
  57. data/test/psych/test_tainted.rb +0 -131
  58. data/test/psych/test_to_yaml_properties.rb +0 -64
  59. data/test/psych/test_tree_builder.rb +0 -80
  60. data/test/psych/test_yaml.rb +0 -1293
  61. data/test/psych/test_yamldbm.rb +0 -193
  62. data/test/psych/test_yamlstore.rb +0 -86
  63. data/test/psych/visitors/test_depth_first.rb +0 -50
  64. data/test/psych/visitors/test_emitter.rb +0 -145
  65. data/test/psych/visitors/test_to_ruby.rb +0 -332
  66. data/test/psych/visitors/test_yaml_tree.rb +0 -180
@@ -1,193 +0,0 @@
1
- # frozen_string_literal: false
2
- require_relative 'helper'
3
- require 'tmpdir'
4
-
5
- begin
6
- require 'yaml/dbm'
7
- rescue LoadError
8
- end
9
-
10
- module Psych
11
- ::Psych::DBM = ::YAML::DBM unless defined?(::Psych::DBM)
12
-
13
- class YAMLDBMTest < TestCase
14
- def setup
15
- @dir = Dir.mktmpdir("rubytest-file")
16
- File.chown(-1, Process.gid, @dir)
17
- @yamldbm_file = make_tmp_filename("yamldbm")
18
- @yamldbm = YAML::DBM.new(@yamldbm_file)
19
- end
20
-
21
- def teardown
22
- @yamldbm.clear
23
- @yamldbm.close
24
- FileUtils.remove_entry_secure @dir
25
- end
26
-
27
- def make_tmp_filename(prefix)
28
- @dir + "/" + prefix + File.basename(__FILE__) + ".#{$$}.test"
29
- end
30
-
31
- def test_store
32
- @yamldbm.store('a','b')
33
- @yamldbm.store('c','d')
34
- assert_equal 'b', @yamldbm['a']
35
- assert_equal 'd', @yamldbm['c']
36
- assert_nil @yamldbm['e']
37
- end
38
-
39
- def test_store_using_carret
40
- @yamldbm['a'] = 'b'
41
- @yamldbm['c'] = 'd'
42
- assert_equal 'b', @yamldbm['a']
43
- assert_equal 'd', @yamldbm['c']
44
- assert_nil @yamldbm['e']
45
- end
46
-
47
- def test_to_a
48
- @yamldbm['a'] = 'b'
49
- @yamldbm['c'] = 'd'
50
- assert_equal([['a','b'],['c','d']], @yamldbm.to_a.sort)
51
- end
52
-
53
- def test_to_hash
54
- @yamldbm['a'] = 'b'
55
- @yamldbm['c'] = 'd'
56
- assert_equal({'a'=>'b','c'=>'d'}, @yamldbm.to_hash)
57
- end
58
-
59
- def test_has_value?
60
- @yamldbm['a'] = 'b'
61
- @yamldbm['c'] = 'd'
62
- assert_equal true, @yamldbm.has_value?('b')
63
- assert_equal true, @yamldbm.has_value?('d')
64
- assert_equal false, @yamldbm.has_value?('f')
65
- end
66
-
67
- # Note:
68
- # YAML::DBM#index makes warning from internal of ::DBM#index.
69
- # It says 'DBM#index is deprecated; use DBM#key', but DBM#key
70
- # behaves not same as DBM#index.
71
- #
72
- # def test_index
73
- # @yamldbm['a'] = 'b'
74
- # @yamldbm['c'] = 'd'
75
- # assert_equal 'a', @yamldbm.index('b')
76
- # assert_equal 'c', @yamldbm.index('d')
77
- # assert_nil @yamldbm.index('f')
78
- # end
79
-
80
- def test_key
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)
@@ -1,86 +0,0 @@
1
- # frozen_string_literal: false
2
- require_relative 'helper'
3
- require 'yaml/store'
4
- require 'tmpdir'
5
-
6
- module Psych
7
- Psych::Store = YAML::Store unless defined?(Psych::Store)
8
-
9
- class YAMLStoreTest < TestCase
10
- def setup
11
- @dir = Dir.mktmpdir("rubytest-file")
12
- File.chown(-1, Process.gid, @dir)
13
- @yamlstore_file = make_tmp_filename("yamlstore")
14
- @yamlstore = YAML::Store.new(@yamlstore_file)
15
- end
16
-
17
- def teardown
18
- FileUtils.remove_entry_secure @dir
19
- end
20
-
21
- def make_tmp_filename(prefix)
22
- @dir + "/" + prefix + File.basename(__FILE__) + ".#{$$}.test"
23
- end
24
-
25
- def test_opening_new_file_in_readonly_mode_should_result_in_empty_values
26
- @yamlstore.transaction(true) do
27
- assert_nil @yamlstore[:foo]
28
- assert_nil @yamlstore[:bar]
29
- end
30
- end
31
-
32
- def test_opening_new_file_in_readwrite_mode_should_result_in_empty_values
33
- @yamlstore.transaction do
34
- assert_nil @yamlstore[:foo]
35
- assert_nil @yamlstore[:bar]
36
- end
37
- end
38
-
39
- def test_data_should_be_loaded_correctly_when_in_readonly_mode
40
- @yamlstore.transaction do
41
- @yamlstore[:foo] = "bar"
42
- end
43
- @yamlstore.transaction(true) do
44
- assert_equal "bar", @yamlstore[:foo]
45
- end
46
- end
47
-
48
- def test_data_should_be_loaded_correctly_when_in_readwrite_mode
49
- @yamlstore.transaction do
50
- @yamlstore[:foo] = "bar"
51
- end
52
- @yamlstore.transaction do
53
- assert_equal "bar", @yamlstore[:foo]
54
- end
55
- end
56
-
57
- def test_changes_after_commit_are_discarded
58
- @yamlstore.transaction do
59
- @yamlstore[:foo] = "bar"
60
- @yamlstore.commit
61
- @yamlstore[:foo] = "baz"
62
- end
63
- @yamlstore.transaction(true) do
64
- assert_equal "bar", @yamlstore[:foo]
65
- end
66
- end
67
-
68
- def test_changes_are_not_written_on_abort
69
- @yamlstore.transaction do
70
- @yamlstore[:foo] = "bar"
71
- @yamlstore.abort
72
- end
73
- @yamlstore.transaction(true) do
74
- assert_nil @yamlstore[:foo]
75
- end
76
- end
77
-
78
- def test_writing_inside_readonly_transaction_raises_error
79
- assert_raises(PStore::Error) do
80
- @yamlstore.transaction(true) do
81
- @yamlstore[:foo] = "bar"
82
- end
83
- end
84
- end
85
- end
86
- end if defined?(Psych)
@@ -1,50 +0,0 @@
1
- # frozen_string_literal: false
2
- require 'psych/helper'
3
-
4
- module Psych
5
- module Visitors
6
- class TestDepthFirst < TestCase
7
- class Collector < Struct.new(:calls)
8
- def initialize(calls = [])
9
- super
10
- end
11
-
12
- def call obj
13
- calls << obj
14
- end
15
- end
16
-
17
- def test_scalar
18
- collector = Collector.new
19
- visitor = Visitors::DepthFirst.new collector
20
- visitor.accept Psych.parse_stream '--- hello'
21
-
22
- assert_equal 3, collector.calls.length
23
- end
24
-
25
- def test_sequence
26
- collector = Collector.new
27
- visitor = Visitors::DepthFirst.new collector
28
- visitor.accept Psych.parse_stream "---\n- hello"
29
-
30
- assert_equal 4, collector.calls.length
31
- end
32
-
33
- def test_mapping
34
- collector = Collector.new
35
- visitor = Visitors::DepthFirst.new collector
36
- visitor.accept Psych.parse_stream "---\nhello: world"
37
-
38
- assert_equal 5, collector.calls.length
39
- end
40
-
41
- def test_alias
42
- collector = Collector.new
43
- visitor = Visitors::DepthFirst.new collector
44
- visitor.accept Psych.parse_stream "--- &yay\n- foo\n- *yay\n"
45
-
46
- assert_equal 5, collector.calls.length
47
- end
48
- end
49
- end
50
- end
@@ -1,145 +0,0 @@
1
- # frozen_string_literal: false
2
- require 'psych/helper'
3
-
4
- module Psych
5
- module Visitors
6
- class TestEmitter < TestCase
7
- def setup
8
- super
9
- @io = StringIO.new
10
- @visitor = Visitors::Emitter.new @io
11
- end
12
-
13
- def test_options
14
- io = StringIO.new
15
- visitor = Visitors::Emitter.new io, :indentation => 3
16
-
17
- s = Nodes::Stream.new
18
- doc = Nodes::Document.new
19
- mapping = Nodes::Mapping.new
20
- m2 = Nodes::Mapping.new
21
- m2.children << Nodes::Scalar.new('a')
22
- m2.children << Nodes::Scalar.new('b')
23
-
24
- mapping.children << Nodes::Scalar.new('key')
25
- mapping.children << m2
26
- doc.children << mapping
27
- s.children << doc
28
-
29
- visitor.accept s
30
- assert_match(/^[ ]{3}a/, io.string)
31
- end
32
-
33
- def test_stream
34
- s = Nodes::Stream.new
35
- @visitor.accept s
36
- assert_equal '', @io.string
37
- end
38
-
39
- def test_document
40
- s = Nodes::Stream.new
41
- doc = Nodes::Document.new [1,1]
42
- scalar = Nodes::Scalar.new 'hello world'
43
-
44
- doc.children << scalar
45
- s.children << doc
46
-
47
- @visitor.accept s
48
-
49
- assert_match(/1.1/, @io.string)
50
- assert_equal @io.string, s.yaml
51
- end
52
-
53
- def test_document_implicit_end
54
- s = Nodes::Stream.new
55
- doc = Nodes::Document.new
56
- mapping = Nodes::Mapping.new
57
- mapping.children << Nodes::Scalar.new('key')
58
- mapping.children << Nodes::Scalar.new('value')
59
- doc.children << mapping
60
- s.children << doc
61
-
62
- @visitor.accept s
63
-
64
- assert_match(/key: value/, @io.string)
65
- assert_equal @io.string, s.yaml
66
- assert(/\.\.\./ !~ s.yaml)
67
- end
68
-
69
- def test_scalar
70
- s = Nodes::Stream.new
71
- doc = Nodes::Document.new
72
- scalar = Nodes::Scalar.new 'hello world'
73
-
74
- doc.children << scalar
75
- s.children << doc
76
-
77
- @visitor.accept s
78
-
79
- assert_match(/hello/, @io.string)
80
- assert_equal @io.string, s.yaml
81
- end
82
-
83
- def test_scalar_with_tag
84
- s = Nodes::Stream.new
85
- doc = Nodes::Document.new
86
- scalar = Nodes::Scalar.new 'hello world', nil, '!str', false, false, 5
87
-
88
- doc.children << scalar
89
- s.children << doc
90
-
91
- @visitor.accept s
92
-
93
- assert_match(/str/, @io.string)
94
- assert_match(/hello/, @io.string)
95
- assert_equal @io.string, s.yaml
96
- end
97
-
98
- def test_sequence
99
- s = Nodes::Stream.new
100
- doc = Nodes::Document.new
101
- scalar = Nodes::Scalar.new 'hello world'
102
- seq = Nodes::Sequence.new
103
-
104
- seq.children << scalar
105
- doc.children << seq
106
- s.children << doc
107
-
108
- @visitor.accept s
109
-
110
- assert_match(/- hello/, @io.string)
111
- assert_equal @io.string, s.yaml
112
- end
113
-
114
- def test_mapping
115
- s = Nodes::Stream.new
116
- doc = Nodes::Document.new
117
- mapping = Nodes::Mapping.new
118
- mapping.children << Nodes::Scalar.new('key')
119
- mapping.children << Nodes::Scalar.new('value')
120
- doc.children << mapping
121
- s.children << doc
122
-
123
- @visitor.accept s
124
-
125
- assert_match(/key: value/, @io.string)
126
- assert_equal @io.string, s.yaml
127
- end
128
-
129
- def test_alias
130
- s = Nodes::Stream.new
131
- doc = Nodes::Document.new
132
- mapping = Nodes::Mapping.new
133
- mapping.children << Nodes::Scalar.new('key', 'A')
134
- mapping.children << Nodes::Alias.new('A')
135
- doc.children << mapping
136
- s.children << doc
137
-
138
- @visitor.accept s
139
-
140
- assert_match(/&A key: \*A/, @io.string)
141
- assert_equal @io.string, s.yaml
142
- end
143
- end
144
- end
145
- end