psych-shopifork 2.0.5 → 2.0.13

Sign up to get free protection for your applications and to get access to all the features.
@@ -16,6 +16,12 @@ module Psych
16
16
  @wups = Wups.new
17
17
  end
18
18
 
19
+ def test_naming_exception
20
+ err = String.xxx rescue $!
21
+ new_err = Psych.load(Psych.dump(err))
22
+ assert_equal err.message, new_err.message
23
+ end
24
+
19
25
  def test_load_takes_file
20
26
  ex = assert_raises(Psych::SyntaxError) do
21
27
  Psych.load '--- `'
@@ -5,11 +5,61 @@ module Psych
5
5
  class X < Hash
6
6
  end
7
7
 
8
+ class HashWithCustomInit < Hash
9
+ attr_reader :obj
10
+ def initialize(obj)
11
+ @obj = obj
12
+ end
13
+ end
14
+
15
+ class HashWithCustomInitNoIvar < Hash
16
+ def initialize(obj)
17
+ # *shrug*
18
+ end
19
+ end
20
+
8
21
  def setup
9
22
  super
10
23
  @hash = { :a => 'b' }
11
24
  end
12
25
 
26
+ def test_referenced_hash_with_ivar
27
+ a = [1,2,3,4,5]
28
+ t1 = [HashWithCustomInit.new(a)]
29
+ t1 << t1.first
30
+ assert_cycle t1
31
+ end
32
+
33
+ def test_custom_initialized
34
+ a = [1,2,3,4,5]
35
+ t1 = HashWithCustomInit.new(a)
36
+ t2 = Psych.load(Psych.dump(t1))
37
+ assert_equal t1, t2
38
+ assert_cycle t1
39
+ end
40
+
41
+ def test_custom_initialize_no_ivar
42
+ t1 = HashWithCustomInitNoIvar.new(nil)
43
+ t2 = Psych.load(Psych.dump(t1))
44
+ assert_equal t1, t2
45
+ assert_cycle t1
46
+ end
47
+
48
+ def test_hash_subclass_with_ivars
49
+ x = X.new
50
+ x[:a] = 'b'
51
+ x.instance_variable_set :@foo, 'bar'
52
+ dup = Psych.load Psych.dump x
53
+ assert_cycle x
54
+ assert_equal 'bar', dup.instance_variable_get(:@foo)
55
+ assert_equal X, dup.class
56
+ end
57
+
58
+ def test_load_with_class_syck_compatibility
59
+ hash = Psych.load "--- !ruby/object:Hash\n:user_id: 7\n:username: Lucas\n"
60
+ assert_equal({ user_id: 7, username: 'Lucas'}, hash)
61
+ end
62
+
13
63
  def test_empty_subclass
14
64
  assert_match "!ruby/hash:#{X}", Psych.dump(X.new)
15
65
  x = Psych.load Psych.dump X.new
@@ -45,7 +45,7 @@ module Psych
45
45
  def test_list_to_json
46
46
  list = %w{ one two }
47
47
  json = Psych.to_json(list)
48
- assert_match(/]$/, json)
48
+ assert_match(/\]$/, json)
49
49
  assert_match(/^\[/, json)
50
50
  assert_match(/"one"/, json)
51
51
  assert_match(/"two"/, json)
@@ -6,6 +6,36 @@ module Psych
6
6
  attr_reader :bar
7
7
  end
8
8
 
9
+ def test_merge_key_with_bare_hash
10
+ doc = Psych.load <<-eodoc
11
+ map:
12
+ <<:
13
+ hello: world
14
+ eodoc
15
+ hash = { "map" => { "hello" => "world" } }
16
+ assert_equal hash, doc
17
+ end
18
+
19
+ def test_roundtrip_with_chevron_key
20
+ h = {}
21
+ v = { 'a' => h, '<<' => h }
22
+ assert_cycle v
23
+ end
24
+
25
+ def test_explicit_string
26
+ doc = Psych.load <<-eoyml
27
+ a: &me { hello: world }
28
+ b: { !!str '<<': *me }
29
+ eoyml
30
+ expected = {
31
+ "a" => { "hello" => "world" },
32
+ "b" => {
33
+ "<<" => { "hello" => "world" }
34
+ }
35
+ }
36
+ assert_equal expected, doc
37
+ end
38
+
9
39
  def test_mergekey_with_object
10
40
  s = <<-eoyml
11
41
  foo: &foo
@@ -1,3 +1,4 @@
1
+ # encoding: UTF-8
1
2
  require_relative 'helper'
2
3
 
3
4
  module Psych
@@ -15,13 +16,76 @@ module Psych
15
16
  end
16
17
  end
17
18
 
19
+ def test_string_with_newline
20
+ assert_equal "1\n2", Psych.load("--- ! '1\n\n 2'\n")
21
+ end
22
+
18
23
  def test_no_doublequotes_with_special_characters
19
24
  assert_equal 2, Psych.dump(%Q{<%= ENV["PATH"] %>}).count('"')
20
25
  end
21
26
 
27
+ def test_no_quotes_when_start_with_non_ascii_character
28
+ yaml = Psych.dump 'Český non-ASCII'.encode(Encoding::UTF_8)
29
+ assert_match(/---\s*[^"'!]+$/, yaml)
30
+ end
31
+
22
32
  def test_doublequotes_when_there_is_a_single
23
- yaml = Psych.dump "@123'abc"
24
- assert_match(/---\s*"/, yaml)
33
+ str = "@123'abc"
34
+ yaml = Psych.dump str
35
+ assert_match /---\s*"/, yaml
36
+ assert_equal str, Psych.load(yaml)
37
+ end
38
+
39
+ def test_plain_when_shorten_than_line_width_and_no_final_line_break
40
+ str = "Lorem ipsum"
41
+ yaml = Psych.dump str, line_width: 12
42
+ assert_match /---\s*[^>|]+\n/, yaml
43
+ assert_equal str, Psych.load(yaml)
44
+ end
45
+
46
+ def test_plain_when_shorten_than_line_width_and_with_final_line_break
47
+ str = "Lorem ipsum\n"
48
+ yaml = Psych.dump str, line_width: 12
49
+ assert_match /---\s*[^>|]+\n/, yaml
50
+ assert_equal str, Psych.load(yaml)
51
+ end
52
+
53
+ def test_folded_when_longer_than_line_width_and_with_final_line_break
54
+ str = "Lorem ipsum dolor sit\n"
55
+ yaml = Psych.dump str, line_width: 12
56
+ assert_match /---\s*>\n(.*\n){2}\Z/, yaml
57
+ assert_equal str, Psych.load(yaml)
58
+ end
59
+
60
+ # http://yaml.org/spec/1.2/2009-07-21/spec.html#id2593651
61
+ def test_folded_strip_when_longer_than_line_width_and_no_newlines
62
+ str = "Lorem ipsum dolor sit amet, consectetur"
63
+ yaml = Psych.dump str, line_width: 12
64
+ assert_match /---\s*>-\n(.*\n){3}\Z/, yaml
65
+ assert_equal str, Psych.load(yaml)
66
+ end
67
+
68
+ def test_literal_when_inner_and_final_line_break
69
+ [
70
+ "Lorem ipsum\ndolor\n",
71
+ "Lorem ipsum\nZolor\n",
72
+ ].each do |str|
73
+ yaml = Psych.dump str, line_width: 12
74
+ assert_match /---\s*\|\n(.*\n){2}\Z/, yaml
75
+ assert_equal str, Psych.load(yaml)
76
+ end
77
+ end
78
+
79
+ # http://yaml.org/spec/1.2/2009-07-21/spec.html#id2593651
80
+ def test_literal_strip_when_inner_line_break_and_no_final_line_break
81
+ [
82
+ "Lorem ipsum\ndolor",
83
+ "Lorem ipsum\nZolor",
84
+ ].each do |str|
85
+ yaml = Psych.dump str, line_width: 12
86
+ assert_match /---\s*\|-\n(.*\n){2}\Z/, yaml
87
+ assert_equal str, Psych.load(yaml)
88
+ end
25
89
  end
26
90
 
27
91
  def test_cycle_x
@@ -2,6 +2,14 @@ require_relative 'helper'
2
2
 
3
3
  module Psych
4
4
  class TestSymbol < TestCase
5
+ def test_cycle_empty
6
+ assert_cycle :''
7
+ end
8
+
9
+ def test_cycle_colon
10
+ assert_cycle :':'
11
+ end
12
+
5
13
  def test_cycle
6
14
  assert_cycle :a
7
15
  end
@@ -1,7 +1,7 @@
1
1
  require_relative 'helper'
2
2
 
3
3
  module Psych
4
- class TestToYamlProperties < MiniTest::Unit::TestCase
4
+ class TestToYamlProperties < Psych::TestCase
5
5
  class Foo
6
6
  attr_accessor :a, :b, :c
7
7
  def initialize
@@ -27,6 +27,10 @@ class Psych_Unit_Tests < Psych::TestCase
27
27
  assert_match "2010-10-10 00:00:00.000000000 Z", yaml
28
28
  end
29
29
 
30
+ def test_multiline_regexp
31
+ assert_cycle(Regexp.new("foo\nbar"))
32
+ end
33
+
30
34
  # [ruby-core:34969]
31
35
  def test_regexp_with_n
32
36
  assert_cycle(Regexp.new('',0,'n'))
@@ -1,5 +1,3 @@
1
- # -*- coding: UTF-8 -*-
2
-
3
1
  require_relative 'helper'
4
2
  require 'tmpdir'
5
3
 
@@ -13,7 +11,6 @@ module Psych
13
11
 
14
12
  class YAMLDBMTest < TestCase
15
13
  def setup
16
- @engine, YAML::ENGINE.yamler = YAML::ENGINE.yamler, 'psych'
17
14
  @dir = Dir.mktmpdir("rubytest-file")
18
15
  File.chown(-1, Process.gid, @dir)
19
16
  @yamldbm_file = make_tmp_filename("yamldbm")
@@ -21,7 +18,6 @@ module Psych
21
18
  end
22
19
 
23
20
  def teardown
24
- YAML::ENGINE.yamler = @engine
25
21
  @yamldbm.clear
26
22
  @yamldbm.close
27
23
  FileUtils.remove_entry_secure @dir
@@ -7,7 +7,6 @@ module Psych
7
7
 
8
8
  class YAMLStoreTest < TestCase
9
9
  def setup
10
- @engine, YAML::ENGINE.yamler = YAML::ENGINE.yamler, 'psych'
11
10
  @dir = Dir.mktmpdir("rubytest-file")
12
11
  File.chown(-1, Process.gid, @dir)
13
12
  @yamlstore_file = make_tmp_filename("yamlstore")
@@ -15,7 +14,6 @@ module Psych
15
14
  end
16
15
 
17
16
  def teardown
18
- YAML::ENGINE.yamler = @engine
19
17
  FileUtils.remove_entry_secure @dir
20
18
  end
21
19
 
@@ -321,6 +321,13 @@ description:
321
321
  assert_equal %w{ foo foo }, list
322
322
  assert_equal list[0].object_id, list[1].object_id
323
323
  end
324
+
325
+ def test_mapping_with_str_tag
326
+ mapping = Nodes::Mapping.new(nil, '!strawberry')
327
+ mapping.children << Nodes::Scalar.new('foo')
328
+ mapping.children << Nodes::Scalar.new('bar')
329
+ assert_equal({'foo' => 'bar'}, mapping.to_ruby)
330
+ end
324
331
  end
325
332
  end
326
333
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: psych-shopifork
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.5
4
+ version: 2.0.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Patterson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-29 00:00:00.000000000 Z
11
+ date: 2015-08-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rdoc
@@ -38,20 +38,34 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: 0.4.1
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: hoe
43
57
  requirement: !ruby/object:Gem::Requirement
44
58
  requirements:
45
59
  - - "~>"
46
60
  - !ruby/object:Gem::Version
47
- version: '3.10'
61
+ version: '3.13'
48
62
  type: :development
49
63
  prerelease: false
50
64
  version_requirements: !ruby/object:Gem::Requirement
51
65
  requirements:
52
66
  - - "~>"
53
67
  - !ruby/object:Gem::Version
54
- version: '3.10'
68
+ version: '3.13'
55
69
  description: |-
56
70
  Psych is a YAML parser and emitter. Psych leverages libyaml[http://pyyaml.org/wiki/LibYAML]
57
71
  for its YAML parsing and emitting capabilities. In addition to wrapping
@@ -149,7 +163,6 @@ files:
149
163
  - test/psych/test_document.rb
150
164
  - test/psych/test_emitter.rb
151
165
  - test/psych/test_encoding.rb
152
- - test/psych/test_engine_manager.rb
153
166
  - test/psych/test_exception.rb
154
167
  - test/psych/test_hash.rb
155
168
  - test/psych/test_json_tree.rb
@@ -203,53 +216,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
203
216
  version: '0'
204
217
  requirements: []
205
218
  rubyforge_project:
206
- rubygems_version: 2.2.0
219
+ rubygems_version: 2.4.6
207
220
  signing_key:
208
221
  specification_version: 4
209
222
  summary: Psych is a YAML parser and emitter
210
- test_files:
211
- - test/psych/handlers/test_recorder.rb
212
- - test/psych/json/test_stream.rb
213
- - test/psych/nodes/test_enumerable.rb
214
- - test/psych/test_alias_and_anchor.rb
215
- - test/psych/test_array.rb
216
- - test/psych/test_boolean.rb
217
- - test/psych/test_class.rb
218
- - test/psych/test_coder.rb
219
- - test/psych/test_date_time.rb
220
- - test/psych/test_deprecated.rb
221
- - test/psych/test_document.rb
222
- - test/psych/test_emitter.rb
223
- - test/psych/test_encoding.rb
224
- - test/psych/test_engine_manager.rb
225
- - test/psych/test_exception.rb
226
- - test/psych/test_hash.rb
227
- - test/psych/test_json_tree.rb
228
- - test/psych/test_merge_keys.rb
229
- - test/psych/test_nil.rb
230
- - test/psych/test_null.rb
231
- - test/psych/test_numeric.rb
232
- - test/psych/test_object.rb
233
- - test/psych/test_object_references.rb
234
- - test/psych/test_omap.rb
235
- - test/psych/test_parser.rb
236
- - test/psych/test_psych.rb
237
- - test/psych/test_safe_load.rb
238
- - test/psych/test_scalar.rb
239
- - test/psych/test_scalar_scanner.rb
240
- - test/psych/test_serialize_subclasses.rb
241
- - test/psych/test_set.rb
242
- - test/psych/test_stream.rb
243
- - test/psych/test_string.rb
244
- - test/psych/test_struct.rb
245
- - test/psych/test_symbol.rb
246
- - test/psych/test_tainted.rb
247
- - test/psych/test_to_yaml_properties.rb
248
- - test/psych/test_tree_builder.rb
249
- - test/psych/test_yaml.rb
250
- - test/psych/test_yamldbm.rb
251
- - test/psych/test_yamlstore.rb
252
- - test/psych/visitors/test_depth_first.rb
253
- - test/psych/visitors/test_emitter.rb
254
- - test/psych/visitors/test_to_ruby.rb
255
- - test/psych/visitors/test_yaml_tree.rb
223
+ test_files: []
@@ -1,47 +0,0 @@
1
- require_relative 'helper'
2
- require 'yaml'
3
-
4
- module Psych
5
- class TestEngineManager < TestCase
6
- def test_bad_engine
7
- assert_raises(ArgumentError) do
8
- YAML::ENGINE.yamler = 'foooo'
9
- end
10
- end
11
-
12
- def test_set_psych
13
- YAML::ENGINE.yamler = 'psych'
14
- assert_equal Psych, YAML
15
- assert_equal 'psych', YAML::ENGINE.yamler
16
- end
17
-
18
- A = Struct.new(:name)
19
-
20
- def test_dump_types
21
- YAML::ENGINE.yamler = 'psych'
22
-
23
- assert_to_yaml ::Object.new
24
- assert_to_yaml Time.now
25
- assert_to_yaml Date.today
26
- assert_to_yaml('a' => 'b')
27
- assert_to_yaml A.new('foo')
28
- assert_to_yaml %w{a b}
29
- assert_to_yaml Exception.new('foo')
30
- assert_to_yaml "hello!"
31
- assert_to_yaml :fooo
32
- assert_to_yaml(1..10)
33
- assert_to_yaml(/hello!~/)
34
- assert_to_yaml 1
35
- assert_to_yaml 1.2
36
- assert_to_yaml Rational(1, 2)
37
- assert_to_yaml Complex(1, 2)
38
- assert_to_yaml true
39
- assert_to_yaml false
40
- assert_to_yaml nil
41
- end
42
-
43
- def assert_to_yaml obj
44
- assert obj.to_yaml, "#{obj.class} to_yaml works"
45
- end
46
- end
47
- end