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