psych 2.1.0-java → 2.1.1-java

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 (61) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +14 -0
  3. data/Gemfile +3 -0
  4. data/Mavenfile +7 -0
  5. data/bin/console +7 -0
  6. data/bin/setup +6 -0
  7. data/ext/java/PsychEmitter.java +345 -0
  8. data/ext/java/PsychLibrary.java +93 -0
  9. data/ext/java/PsychParser.java +399 -0
  10. data/ext/java/PsychToRuby.java +79 -0
  11. data/ext/java/PsychYamlTree.java +55 -0
  12. data/ext/psych/.gitignore +11 -0
  13. data/lib/psych.rb +2 -2
  14. data/lib/psych/visitors/to_ruby.rb +2 -2
  15. data/psych.gemspec +39 -0
  16. metadata +19 -53
  17. data/test/psych/handlers/test_recorder.rb +0 -26
  18. data/test/psych/helper.rb +0 -122
  19. data/test/psych/json/test_stream.rb +0 -110
  20. data/test/psych/nodes/test_enumerable.rb +0 -44
  21. data/test/psych/test_alias_and_anchor.rb +0 -97
  22. data/test/psych/test_array.rb +0 -58
  23. data/test/psych/test_boolean.rb +0 -37
  24. data/test/psych/test_class.rb +0 -37
  25. data/test/psych/test_coder.rb +0 -207
  26. data/test/psych/test_date_time.rb +0 -39
  27. data/test/psych/test_deprecated.rb +0 -215
  28. data/test/psych/test_document.rb +0 -47
  29. data/test/psych/test_emitter.rb +0 -112
  30. data/test/psych/test_encoding.rb +0 -269
  31. data/test/psych/test_exception.rb +0 -158
  32. data/test/psych/test_hash.rb +0 -95
  33. data/test/psych/test_json_tree.rb +0 -66
  34. data/test/psych/test_merge_keys.rb +0 -181
  35. data/test/psych/test_nil.rb +0 -19
  36. data/test/psych/test_null.rb +0 -20
  37. data/test/psych/test_numeric.rb +0 -46
  38. data/test/psych/test_object.rb +0 -45
  39. data/test/psych/test_object_references.rb +0 -72
  40. data/test/psych/test_omap.rb +0 -76
  41. data/test/psych/test_parser.rb +0 -340
  42. data/test/psych/test_psych.rb +0 -184
  43. data/test/psych/test_safe_load.rb +0 -98
  44. data/test/psych/test_scalar.rb +0 -12
  45. data/test/psych/test_scalar_scanner.rb +0 -111
  46. data/test/psych/test_serialize_subclasses.rb +0 -39
  47. data/test/psych/test_set.rb +0 -50
  48. data/test/psych/test_stream.rb +0 -94
  49. data/test/psych/test_string.rb +0 -231
  50. data/test/psych/test_struct.rb +0 -50
  51. data/test/psych/test_symbol.rb +0 -26
  52. data/test/psych/test_tainted.rb +0 -131
  53. data/test/psych/test_to_yaml_properties.rb +0 -64
  54. data/test/psych/test_tree_builder.rb +0 -80
  55. data/test/psych/test_yaml.rb +0 -1293
  56. data/test/psych/test_yamldbm.rb +0 -193
  57. data/test/psych/test_yamlstore.rb +0 -86
  58. data/test/psych/visitors/test_depth_first.rb +0 -50
  59. data/test/psych/visitors/test_emitter.rb +0 -145
  60. data/test/psych/visitors/test_to_ruby.rb +0 -332
  61. data/test/psych/visitors/test_yaml_tree.rb +0 -180
@@ -1,184 +0,0 @@
1
- # frozen_string_literal: false
2
- require_relative 'helper'
3
-
4
- require 'stringio'
5
- require 'tempfile'
6
-
7
- class TestPsych < Psych::TestCase
8
- def teardown
9
- Psych.domain_types.clear
10
- end
11
-
12
- def test_line_width_invalid
13
- assert_raises(ArgumentError) { Psych.dump('x', { :line_width => -2 }) }
14
- end
15
-
16
- def test_line_width_no_limit
17
- data = { 'a' => 'a b' * 50}
18
- expected = "---\na: #{'a b' * 50}\n"
19
- assert_equal(expected, Psych.dump(data, { :line_width => -1 }))
20
- end
21
-
22
- def test_line_width_limit
23
- yml = Psych.dump('123456 7', { :line_width => 5 })
24
- assert_match(/^\s*7/, yml)
25
- end
26
-
27
- def test_indent
28
- yml = Psych.dump({:a => {'b' => 'c'}}, {:indentation => 5})
29
- assert_match(/^[ ]{5}b/, yml)
30
- end
31
-
32
- def test_canonical
33
- yml = Psych.dump({:a => {'b' => 'c'}}, {:canonical => true})
34
- assert_match(/\? "b/, yml)
35
- end
36
-
37
- def test_header
38
- yml = Psych.dump({:a => {'b' => 'c'}}, {:header => true})
39
- assert_match(/YAML/, yml)
40
- end
41
-
42
- def test_version_array
43
- yml = Psych.dump({:a => {'b' => 'c'}}, {:version => [1,1]})
44
- assert_match(/1.1/, yml)
45
- end
46
-
47
- def test_version_string
48
- yml = Psych.dump({:a => {'b' => 'c'}}, {:version => '1.1'})
49
- assert_match(/1.1/, yml)
50
- end
51
-
52
- def test_version_bool
53
- yml = Psych.dump({:a => {'b' => 'c'}}, {:version => true})
54
- assert_match(/1.1/, yml)
55
- end
56
-
57
- def test_load_argument_error
58
- assert_raises(TypeError) do
59
- Psych.load nil
60
- end
61
- end
62
-
63
- def test_non_existing_class_on_deserialize
64
- e = assert_raises(ArgumentError) do
65
- Psych.load("--- !ruby/object:NonExistent\nfoo: 1")
66
- end
67
- assert_equal 'undefined class/module NonExistent', e.message
68
- end
69
-
70
- def test_dump_stream
71
- things = [22, "foo \n", {}]
72
- stream = Psych.dump_stream(*things)
73
- assert_equal things, Psych.load_stream(stream)
74
- end
75
-
76
- def test_dump_file
77
- hash = {'hello' => 'TGIF!'}
78
- Tempfile.create('fun.yml') do |io|
79
- assert_equal io, Psych.dump(hash, io)
80
- io.rewind
81
- assert_equal Psych.dump(hash), io.read
82
- end
83
- end
84
-
85
- def test_dump_io
86
- hash = {'hello' => 'TGIF!'}
87
- stringio = StringIO.new ''
88
- assert_equal stringio, Psych.dump(hash, stringio)
89
- assert_equal Psych.dump(hash), stringio.string
90
- end
91
-
92
- def test_simple
93
- assert_equal 'foo', Psych.load("--- foo\n")
94
- end
95
-
96
- def test_libyaml_version
97
- assert Psych.libyaml_version
98
- assert_equal Psych.libyaml_version.join('.'), Psych::LIBYAML_VERSION
99
- end
100
-
101
- def test_load_documents
102
- docs = Psych.load_documents("--- foo\n...\n--- bar\n...")
103
- assert_equal %w{ foo bar }, docs
104
- end
105
-
106
- def test_parse_stream
107
- docs = Psych.parse_stream("--- foo\n...\n--- bar\n...")
108
- assert_equal %w{ foo bar }, docs.children.map { |x| x.transform }
109
- end
110
-
111
- def test_add_builtin_type
112
- got = nil
113
- Psych.add_builtin_type 'omap' do |type, val|
114
- got = val
115
- end
116
- Psych.load('--- !!omap hello')
117
- assert_equal 'hello', got
118
- ensure
119
- Psych.remove_type 'omap'
120
- end
121
-
122
- def test_domain_types
123
- got = nil
124
- Psych.add_domain_type 'foo.bar,2002', 'foo' do |type, val|
125
- got = val
126
- end
127
-
128
- Psych.load('--- !foo.bar,2002/foo hello')
129
- assert_equal 'hello', got
130
-
131
- Psych.load("--- !foo.bar,2002/foo\n- hello\n- world")
132
- assert_equal %w{ hello world }, got
133
-
134
- Psych.load("--- !foo.bar,2002/foo\nhello: world")
135
- assert_equal({ 'hello' => 'world' }, got)
136
- end
137
-
138
- def test_load_file
139
- Tempfile.create(['yikes', 'yml']) {|t|
140
- t.binmode
141
- t.write('--- hello world')
142
- t.close
143
- assert_equal 'hello world', Psych.load_file(t.path)
144
- }
145
- end
146
-
147
- def test_load_file_with_fallback
148
- t = Tempfile.create(['empty', 'yml'])
149
- assert_equal Hash.new, Psych.load_file(t.path, Hash.new)
150
- end
151
-
152
- def test_parse_file
153
- Tempfile.create(['yikes', 'yml']) {|t|
154
- t.binmode
155
- t.write('--- hello world')
156
- t.close
157
- assert_equal 'hello world', Psych.parse_file(t.path).transform
158
- }
159
- end
160
-
161
- def test_degenerate_strings
162
- assert_equal false, Psych.load(' ')
163
- assert_equal false, Psych.parse(' ')
164
- assert_equal false, Psych.load('')
165
- assert_equal false, Psych.parse('')
166
- end
167
-
168
- def test_callbacks
169
- types = []
170
- appender = lambda { |*args| types << args }
171
-
172
- Psych.add_builtin_type('foo', &appender)
173
- Psych.add_domain_type('example.com,2002', 'foo', &appender)
174
- Psych.load <<-eoyml
175
- - !tag:yaml.org,2002:foo bar
176
- - !tag:example.com,2002:foo bar
177
- eoyml
178
-
179
- assert_equal [
180
- ["tag:yaml.org,2002:foo", "bar"],
181
- ["tag:example.com,2002:foo", "bar"]
182
- ], types
183
- end
184
- end
@@ -1,98 +0,0 @@
1
- # frozen_string_literal: false
2
- require 'psych/helper'
3
-
4
- module Psych
5
- class TestSafeLoad < TestCase
6
- class Foo; end
7
-
8
- [1, 2.2, {}, [], "foo"].each do |obj|
9
- define_method(:"test_basic_#{obj.class}") do
10
- assert_safe_cycle obj
11
- end
12
- end
13
-
14
- def test_no_recursion
15
- x = []
16
- x << x
17
- assert_raises(Psych::BadAlias) do
18
- Psych.safe_load Psych.dump(x)
19
- end
20
- end
21
-
22
- def test_explicit_recursion
23
- x = []
24
- x << x
25
- assert_equal(x, Psych.safe_load(Psych.dump(x), [], [], true))
26
- end
27
-
28
- def test_symbol_whitelist
29
- yml = Psych.dump :foo
30
- assert_raises(Psych::DisallowedClass) do
31
- Psych.safe_load yml
32
- end
33
- assert_equal(:foo, Psych.safe_load(yml, [Symbol], [:foo]))
34
- end
35
-
36
- def test_symbol
37
- assert_raises(Psych::DisallowedClass) do
38
- assert_safe_cycle :foo
39
- end
40
- assert_raises(Psych::DisallowedClass) do
41
- Psych.safe_load '--- !ruby/symbol foo', []
42
- end
43
- assert_safe_cycle :foo, [Symbol]
44
- assert_safe_cycle :foo, %w{ Symbol }
45
- assert_equal :foo, Psych.safe_load('--- !ruby/symbol foo', [Symbol])
46
- end
47
-
48
- def test_foo
49
- assert_raises(Psych::DisallowedClass) do
50
- Psych.safe_load '--- !ruby/object:Foo {}', [Foo]
51
- end
52
- assert_raises(Psych::DisallowedClass) do
53
- assert_safe_cycle Foo.new
54
- end
55
- assert_kind_of(Foo, Psych.safe_load(Psych.dump(Foo.new), [Foo]))
56
- end
57
-
58
- X = Struct.new(:x)
59
- def test_struct_depends_on_sym
60
- assert_safe_cycle(X.new, [X, Symbol])
61
- assert_raises(Psych::DisallowedClass) do
62
- cycle X.new, [X]
63
- end
64
- end
65
-
66
- def test_anon_struct
67
- assert Psych.safe_load(<<-eoyml, [Struct, Symbol])
68
- --- !ruby/struct
69
- foo: bar
70
- eoyml
71
-
72
- assert_raises(Psych::DisallowedClass) do
73
- Psych.safe_load(<<-eoyml, [Struct])
74
- --- !ruby/struct
75
- foo: bar
76
- eoyml
77
- end
78
-
79
- assert_raises(Psych::DisallowedClass) do
80
- Psych.safe_load(<<-eoyml, [Symbol])
81
- --- !ruby/struct
82
- foo: bar
83
- eoyml
84
- end
85
- end
86
-
87
- private
88
-
89
- def cycle object, whitelist = []
90
- Psych.safe_load(Psych.dump(object), whitelist)
91
- end
92
-
93
- def assert_safe_cycle object, whitelist = []
94
- other = cycle object, whitelist
95
- assert_equal object, other
96
- end
97
- end
98
- end
@@ -1,12 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- # frozen_string_literal: false
3
-
4
- require_relative 'helper'
5
-
6
- module Psych
7
- class TestScalar < TestCase
8
- def test_utf_8
9
- assert_equal "日本語", Psych.load("--- 日本語")
10
- end
11
- end
12
- end
@@ -1,111 +0,0 @@
1
- # frozen_string_literal: false
2
- require_relative 'helper'
3
- require 'date'
4
-
5
- module Psych
6
- class TestScalarScanner < TestCase
7
- attr_reader :ss
8
-
9
- def setup
10
- super
11
- @ss = Psych::ScalarScanner.new ClassLoader.new
12
- end
13
-
14
- def test_scan_time
15
- { '2001-12-15T02:59:43.1Z' => Time.utc(2001, 12, 15, 02, 59, 43, 100000),
16
- '2001-12-14t21:59:43.10-05:00' => Time.utc(2001, 12, 15, 02, 59, 43, 100000),
17
- '2001-12-14 21:59:43.10 -5' => Time.utc(2001, 12, 15, 02, 59, 43, 100000),
18
- '2001-12-15 2:59:43.10' => Time.utc(2001, 12, 15, 02, 59, 43, 100000),
19
- '2011-02-24 11:17:06 -0800' => Time.utc(2011, 02, 24, 19, 17, 06)
20
- }.each do |time_str, time|
21
- assert_equal time, @ss.tokenize(time_str)
22
- end
23
- end
24
-
25
- def test_scan_bad_time
26
- [ '2001-12-15T02:59:73.1Z',
27
- '2001-12-14t90:59:43.10-05:00',
28
- '2001-92-14 21:59:43.10 -5',
29
- '2001-12-15 92:59:43.10',
30
- '2011-02-24 81:17:06 -0800',
31
- ].each do |time_str|
32
- assert_equal time_str, @ss.tokenize(time_str)
33
- end
34
- end
35
-
36
- def test_scan_bad_dates
37
- x = '2000-15-01'
38
- assert_equal x, @ss.tokenize(x)
39
-
40
- x = '2000-10-51'
41
- assert_equal x, @ss.tokenize(x)
42
-
43
- x = '2000-10-32'
44
- assert_equal x, @ss.tokenize(x)
45
- end
46
-
47
- def test_scan_good_edge_date
48
- x = '2000-1-31'
49
- assert_equal Date.strptime(x, '%Y-%m-%d'), @ss.tokenize(x)
50
- end
51
-
52
- def test_scan_bad_edge_date
53
- x = '2000-11-31'
54
- assert_equal x, @ss.tokenize(x)
55
- end
56
-
57
- def test_scan_date
58
- date = '1980-12-16'
59
- token = @ss.tokenize date
60
- assert_equal 1980, token.year
61
- assert_equal 12, token.month
62
- assert_equal 16, token.day
63
- end
64
-
65
- def test_scan_inf
66
- assert_equal(1 / 0.0, ss.tokenize('.inf'))
67
- end
68
-
69
- def test_scan_minus_inf
70
- assert_equal(-1 / 0.0, ss.tokenize('-.inf'))
71
- end
72
-
73
- def test_scan_nan
74
- assert ss.tokenize('.nan').nan?
75
- end
76
-
77
- def test_scan_float_with_exponent_but_no_fraction
78
- assert_equal(0.0, ss.tokenize('0.E+0'))
79
- end
80
-
81
- def test_scan_null
82
- assert_equal nil, ss.tokenize('null')
83
- assert_equal nil, ss.tokenize('~')
84
- assert_equal nil, ss.tokenize('')
85
- end
86
-
87
- def test_scan_symbol
88
- assert_equal :foo, ss.tokenize(':foo')
89
- end
90
-
91
- def test_scan_sexagesimal_float
92
- assert_equal 685230.15, ss.tokenize('190:20:30.15')
93
- end
94
-
95
- def test_scan_sexagesimal_int
96
- assert_equal 685230, ss.tokenize('190:20:30')
97
- end
98
-
99
- def test_scan_float
100
- assert_equal 1.2, ss.tokenize('1.2')
101
- end
102
-
103
- def test_scan_true
104
- assert_equal true, ss.tokenize('true')
105
- end
106
-
107
- def test_scan_strings_starting_with_underscores
108
- assert_equal "_100", ss.tokenize('_100')
109
- end
110
- end
111
- end
@@ -1,39 +0,0 @@
1
- # frozen_string_literal: false
2
- require_relative 'helper'
3
-
4
- module Psych
5
- class TestSerializeSubclasses < TestCase
6
- class SomeObject
7
- def initialize one, two
8
- @one = one
9
- @two = two
10
- end
11
-
12
- def == other
13
- @one == other.instance_eval { @one } &&
14
- @two == other.instance_eval { @two }
15
- end
16
- end
17
-
18
- def test_some_object
19
- so = SomeObject.new('foo', [1,2,3])
20
- assert_equal so, Psych.load(Psych.dump(so))
21
- end
22
-
23
- class StructSubclass < Struct.new(:foo)
24
- def initialize foo, bar
25
- super(foo)
26
- @bar = bar
27
- end
28
-
29
- def == other
30
- super(other) && @bar == other.instance_eval{ @bar }
31
- end
32
- end
33
-
34
- def test_struct_subclass
35
- so = StructSubclass.new('foo', [1,2,3])
36
- assert_equal so, Psych.load(Psych.dump(so))
37
- end
38
- end
39
- end
@@ -1,50 +0,0 @@
1
- # frozen_string_literal: false
2
- require_relative 'helper'
3
-
4
- module Psych
5
- class TestSet < TestCase
6
- def setup
7
- super
8
- @set = Psych::Set.new
9
- @set['foo'] = 'bar'
10
- @set['bar'] = 'baz'
11
- end
12
-
13
- def test_dump
14
- assert_match(/!set/, Psych.dump(@set))
15
- end
16
-
17
- def test_roundtrip
18
- assert_cycle(@set)
19
- end
20
-
21
- ###
22
- # FIXME: Syck should also support !!set as shorthand
23
- def test_load_from_yaml
24
- loaded = Psych.load(<<-eoyml)
25
- --- !set
26
- foo: bar
27
- bar: baz
28
- eoyml
29
- assert_equal(@set, loaded)
30
- end
31
-
32
- def test_loaded_class
33
- assert_instance_of(Psych::Set, Psych.load(Psych.dump(@set)))
34
- end
35
-
36
- def test_set_shorthand
37
- loaded = Psych.load(<<-eoyml)
38
- --- !!set
39
- foo: bar
40
- bar: baz
41
- eoyml
42
- assert_instance_of(Psych::Set, loaded)
43
- end
44
-
45
- def test_set_self_reference
46
- @set['self'] = @set
47
- assert_cycle(@set)
48
- end
49
- end
50
- end