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,26 +0,0 @@
1
- # frozen_string_literal: false
2
- require 'psych/helper'
3
- require 'psych/handlers/recorder'
4
-
5
- module Psych
6
- module Handlers
7
- class TestRecorder < TestCase
8
- def test_replay
9
- yaml = "--- foo\n...\n"
10
- output = StringIO.new
11
-
12
- recorder = Psych::Handlers::Recorder.new
13
- parser = Psych::Parser.new recorder
14
- parser.parse yaml
15
-
16
- assert_equal 5, recorder.events.length
17
-
18
- emitter = Psych::Emitter.new output
19
- recorder.events.each do |m, args|
20
- emitter.send m, *args
21
- end
22
- assert_equal yaml, output.string
23
- end
24
- end
25
- end
26
- end
@@ -1,122 +0,0 @@
1
- # frozen_string_literal: false
2
- require 'minitest/autorun'
3
- require 'stringio'
4
- require 'tempfile'
5
- require 'date'
6
-
7
- require 'psych'
8
-
9
- module Psych
10
- superclass = if defined?(Minitest::Test)
11
- Minitest::Test
12
- else
13
- MiniTest::Unit::TestCase
14
- end
15
-
16
- class TestCase < superclass
17
- def self.suppress_warning
18
- verbose, $VERBOSE = $VERBOSE, nil
19
- yield
20
- ensure
21
- $VERBOSE = verbose
22
- end
23
-
24
- def with_default_external(enc)
25
- verbose, $VERBOSE = $VERBOSE, nil
26
- origenc, Encoding.default_external = Encoding.default_external, enc
27
- $VERBOSE = verbose
28
- yield
29
- ensure
30
- verbose, $VERBOSE = $VERBOSE, nil
31
- Encoding.default_external = origenc
32
- $VERBOSE = verbose
33
- end
34
-
35
- def with_default_internal(enc)
36
- verbose, $VERBOSE = $VERBOSE, nil
37
- origenc, Encoding.default_internal = Encoding.default_internal, enc
38
- $VERBOSE = verbose
39
- yield
40
- ensure
41
- verbose, $VERBOSE = $VERBOSE, nil
42
- Encoding.default_internal = origenc
43
- $VERBOSE = verbose
44
- end
45
-
46
- #
47
- # Convert between Psych and the object to verify correct parsing and
48
- # emitting
49
- #
50
- def assert_to_yaml( obj, yaml )
51
- assert_equal( obj, Psych::load( yaml ) )
52
- assert_equal( obj, Psych::parse( yaml ).transform )
53
- assert_equal( obj, Psych::load( obj.psych_to_yaml ) )
54
- assert_equal( obj, Psych::parse( obj.psych_to_yaml ).transform )
55
- assert_equal( obj, Psych::load(
56
- obj.psych_to_yaml(
57
- :UseVersion => true, :UseHeader => true, :SortKeys => true
58
- )
59
- ))
60
- end
61
-
62
- #
63
- # Test parser only
64
- #
65
- def assert_parse_only( obj, yaml )
66
- assert_equal( obj, Psych::load( yaml ) )
67
- assert_equal( obj, Psych::parse( yaml ).transform )
68
- end
69
-
70
- def assert_cycle( obj )
71
- v = Visitors::YAMLTree.create
72
- v << obj
73
- assert_equal(obj, Psych.load(v.tree.yaml))
74
- assert_equal( obj, Psych::load(Psych.dump(obj)))
75
- assert_equal( obj, Psych::load( obj.psych_to_yaml ) )
76
- end
77
-
78
- #
79
- # Make a time with the time zone
80
- #
81
- def mktime( year, mon, day, hour, min, sec, usec, zone = "Z" )
82
- usec = Rational(usec.to_s) * 1000000
83
- val = Time::utc( year.to_i, mon.to_i, day.to_i, hour.to_i, min.to_i, sec.to_i, usec )
84
- if zone != "Z"
85
- hour = zone[0,3].to_i * 3600
86
- min = zone[3,2].to_i * 60
87
- ofs = (hour + min)
88
- val = Time.at( val.tv_sec - ofs, val.tv_nsec / 1000.0 )
89
- end
90
- return val
91
- end
92
- end
93
- end
94
-
95
- # backport so that tests will run on 2.0.0
96
- unless Tempfile.respond_to? :create
97
- def Tempfile.create(basename, *rest)
98
- tmpfile = nil
99
- Dir::Tmpname.create(basename, *rest) do |tmpname, n, opts|
100
- mode = File::RDWR|File::CREAT|File::EXCL
101
- perm = 0600
102
- if opts
103
- mode |= opts.delete(:mode) || 0
104
- opts[:perm] = perm
105
- perm = nil
106
- else
107
- opts = perm
108
- end
109
- tmpfile = File.open(tmpname, mode, opts)
110
- end
111
- if block_given?
112
- begin
113
- yield tmpfile
114
- ensure
115
- tmpfile.close if !tmpfile.closed?
116
- File.unlink tmpfile
117
- end
118
- else
119
- tmpfile
120
- end
121
- end
122
- end
@@ -1,110 +0,0 @@
1
- # frozen_string_literal: false
2
- require 'psych/helper'
3
-
4
- module Psych
5
- module JSON
6
- class TestStream < TestCase
7
- def setup
8
- @io = StringIO.new
9
- @stream = Psych::JSON::Stream.new(@io)
10
- @stream.start
11
- end
12
-
13
- def test_explicit_documents
14
- @io = StringIO.new
15
- @stream = Psych::JSON::Stream.new(@io)
16
- @stream.start
17
-
18
- @stream.push({ 'foo' => 'bar' })
19
-
20
- assert !@stream.finished?, 'stream not finished'
21
- @stream.finish
22
- assert @stream.finished?, 'stream finished'
23
-
24
- assert_match(/^---/, @io.string)
25
- assert_match(/\.\.\.$/, @io.string)
26
- end
27
-
28
- def test_null
29
- @stream.push(nil)
30
- assert_match(/^--- null/, @io.string)
31
- end
32
-
33
- def test_string
34
- @stream.push "foo"
35
- assert_match(/(["])foo\1/, @io.string)
36
- end
37
-
38
- def test_symbol
39
- @stream.push :foo
40
- assert_match(/(["])foo\1/, @io.string)
41
- end
42
-
43
- def test_int
44
- @stream.push 10
45
- assert_match(/^--- 10/, @io.string)
46
- end
47
-
48
- def test_float
49
- @stream.push 1.2
50
- assert_match(/^--- 1.2/, @io.string)
51
- end
52
-
53
- def test_hash
54
- hash = { 'one' => 'two' }
55
- @stream.push hash
56
-
57
- json = @io.string
58
- assert_match(/}$/, json)
59
- assert_match(/^--- \{/, json)
60
- assert_match(/["]one['"]/, json)
61
- assert_match(/["]two['"]/, json)
62
- end
63
-
64
- def test_list_to_json
65
- list = %w{ one two }
66
- @stream.push list
67
-
68
- json = @io.string
69
- assert_match(/\]$/, json)
70
- assert_match(/^--- \[/, json)
71
- assert_match(/["]one["]/, json)
72
- assert_match(/["]two["]/, json)
73
- end
74
-
75
- class Foo; end
76
-
77
- def test_json_dump_exclude_tag
78
- @stream << Foo.new
79
- json = @io.string
80
- refute_match('Foo', json)
81
- end
82
-
83
- class Bar
84
- def encode_with coder
85
- coder.represent_seq 'omg', %w{ a b c }
86
- end
87
- end
88
-
89
- def test_json_list_dump_exclude_tag
90
- @stream << Bar.new
91
- json = @io.string
92
- refute_match('omg', json)
93
- end
94
-
95
- def test_time
96
- time = Time.utc(2010, 10, 10)
97
- @stream.push({'a' => time })
98
- json = @io.string
99
- assert_match "{\"a\": \"2010-10-10 00:00:00.000000000 Z\"}\n", json
100
- end
101
-
102
- def test_datetime
103
- time = Time.new(2010, 10, 10).to_datetime
104
- @stream.push({'a' => time })
105
- json = @io.string
106
- assert_match "{\"a\": \"#{time.strftime("%Y-%m-%d %H:%M:%S.%9N %:z")}\"}\n", json
107
- end
108
- end
109
- end
110
- end
@@ -1,44 +0,0 @@
1
- # frozen_string_literal: false
2
- require 'psych/helper'
3
-
4
- module Psych
5
- module Nodes
6
- class TestEnumerable < TestCase
7
- def test_includes_enumerable
8
- yaml = '--- hello'
9
- assert_equal 3, Psych.parse_stream(yaml).to_a.length
10
- end
11
-
12
- def test_returns_enumerator
13
- yaml = '--- hello'
14
- assert_equal 3, Psych.parse_stream(yaml).each.map { |x| x }.length
15
- end
16
-
17
- def test_scalar
18
- assert_equal 3, calls('--- hello').length
19
- end
20
-
21
- def test_sequence
22
- assert_equal 4, calls("---\n- hello").length
23
- end
24
-
25
- def test_mapping
26
- assert_equal 5, calls("---\nhello: world").length
27
- end
28
-
29
- def test_alias
30
- assert_equal 5, calls("--- &yay\n- foo\n- *yay\n").length
31
- end
32
-
33
- private
34
-
35
- def calls yaml
36
- calls = []
37
- Psych.parse_stream(yaml).each do |node|
38
- calls << node
39
- end
40
- calls
41
- end
42
- end
43
- end
44
- end
@@ -1,97 +0,0 @@
1
- # frozen_string_literal: false
2
- require_relative 'helper'
3
-
4
- class ObjectWithInstanceVariables
5
- attr_accessor :var1, :var2
6
- end
7
-
8
- class SubStringWithInstanceVariables < String
9
- attr_accessor :var1
10
- end
11
-
12
- module Psych
13
- class TestAliasAndAnchor < TestCase
14
- def test_mri_compatibility
15
- yaml = <<EOYAML
16
- ---
17
- - &id001 !ruby/object {}
18
-
19
- - *id001
20
- - *id001
21
- EOYAML
22
- result = Psych.load yaml
23
- result.each {|el| assert_same(result[0], el) }
24
- end
25
-
26
- def test_mri_compatibility_object_with_ivars
27
- yaml = <<EOYAML
28
- ---
29
- - &id001 !ruby/object:ObjectWithInstanceVariables
30
- var1: test1
31
- var2: test2
32
- - *id001
33
- - *id001
34
- EOYAML
35
-
36
- result = Psych.load yaml
37
- result.each do |el|
38
- assert_same(result[0], el)
39
- assert_equal('test1', el.var1)
40
- assert_equal('test2', el.var2)
41
- end
42
- end
43
-
44
- def test_mri_compatibility_substring_with_ivars
45
- yaml = <<EOYAML
46
- ---
47
- - &id001 !str:SubStringWithInstanceVariables
48
- str: test
49
- "@var1": test
50
- - *id001
51
- - *id001
52
- EOYAML
53
- result = Psych.load yaml
54
- result.each do |el|
55
- assert_same(result[0], el)
56
- assert_equal('test', el.var1)
57
- end
58
- end
59
-
60
- def test_anchor_alias_round_trip
61
- o = Object.new
62
- original = [o,o,o]
63
-
64
- yaml = Psych.dump original
65
- result = Psych.load yaml
66
- result.each {|el| assert_same(result[0], el) }
67
- end
68
-
69
- def test_anchor_alias_round_trip_object_with_ivars
70
- o = ObjectWithInstanceVariables.new
71
- o.var1 = 'test1'
72
- o.var2 = 'test2'
73
- original = [o,o,o]
74
-
75
- yaml = Psych.dump original
76
- result = Psych.load yaml
77
- result.each do |el|
78
- assert_same(result[0], el)
79
- assert_equal('test1', el.var1)
80
- assert_equal('test2', el.var2)
81
- end
82
- end
83
-
84
- def test_anchor_alias_round_trip_substring_with_ivars
85
- o = SubStringWithInstanceVariables.new
86
- o.var1 = 'test'
87
- original = [o,o,o]
88
-
89
- yaml = Psych.dump original
90
- result = Psych.load yaml
91
- result.each do |el|
92
- assert_same(result[0], el)
93
- assert_equal('test', el.var1)
94
- end
95
- end
96
- end
97
- end
@@ -1,58 +0,0 @@
1
- # frozen_string_literal: false
2
- require_relative 'helper'
3
-
4
- module Psych
5
- class TestArray < TestCase
6
- class X < Array
7
- end
8
-
9
- class Y < Array
10
- attr_accessor :val
11
- end
12
-
13
- def setup
14
- super
15
- @list = [{ :a => 'b' }, 'foo']
16
- end
17
-
18
- def test_another_subclass_with_attributes
19
- y = Y.new.tap {|y| y.val = 1}
20
- y << "foo" << "bar"
21
- y = Psych.load Psych.dump y
22
-
23
- assert_equal %w{foo bar}, y
24
- assert_equal Y, y.class
25
- assert_equal 1, y.val
26
- end
27
-
28
- def test_subclass
29
- yaml = Psych.dump X.new
30
- assert_match X.name, yaml
31
-
32
- list = X.new
33
- list << 1
34
- assert_equal X, list.class
35
- assert_equal 1, list.first
36
- end
37
-
38
- def test_subclass_with_attributes
39
- y = Psych.load Psych.dump Y.new.tap {|y| y.val = 1}
40
- assert_equal Y, y.class
41
- assert_equal 1, y.val
42
- end
43
-
44
- def test_backwards_with_syck
45
- x = Psych.load "--- !seq:#{X.name} []\n\n"
46
- assert_equal X, x.class
47
- end
48
-
49
- def test_self_referential
50
- @list << @list
51
- assert_cycle(@list)
52
- end
53
-
54
- def test_cycle
55
- assert_cycle(@list)
56
- end
57
- end
58
- end