diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2015-03-03 10:04:43 -0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2015-03-03 10:04:43 -0800 |
commit | 22589e504eb32388b23dd9c22ed7e95cd11c845a (patch) | |
tree | 439c22e59620927a5d7646d8966c9bede5dbe037 /test/psych | |
parent | b2dab9e80c62776138b4b63aa0b197e99033f239 (diff) | |
parent | 24ff7855ca2f62e59fc951fa30b225f42369c2a2 (diff) | |
download | psych-22589e504eb32388b23dd9c22ed7e95cd11c845a.tar.gz |
Merge branch 'master' into jruby
* master:
Adding Rubinius as an Allowed Failure
bump version
Fix CVE-2014-9130
Adding RVM listing for Rubinius
fix minitest warnings
* ext/psych/lib/psych/visitors/yaml_tree.rb: register nodes when dumping objects with custom coders. [ruby-core:66215] [Bug #10496]
* ext/psych/lib/psych/visitors/to_ruby.rb: fix support for regular expressions with newlines. tenderlove/psych#222
* ext/psych/lib/psych/visitors/to_ruby.rb: fix parsing hashes with instance variables when it is referenced multiple times. * ext/psych/lib/psych.rb: bump version * ext/psych/psych.gemspec: bump version * test/psych/test_hash.rb: test for fix
bump version
Fix anchor
Fix assertion regexps
bump version
Only dump ivars for subclasses of String, not for String. With cf0dd2b93f1552a3c452a0bfa0e996f441d5e27e, fixes #217.
Only dump ivars for subclasses of Hash, not for Hash. Fixes #216. Fixes part of #217.
Fix block chomping and add more tests
Preset @line_width in YAMLTree#initialize for better performance
Use appropriate style for serialized strings
Remove unnnecessary 'str' variable in YAMLTree#visit_String
Diffstat (limited to 'test/psych')
-rw-r--r-- | test/psych/helper.rb | 8 | ||||
-rw-r--r-- | test/psych/test_coder.rb | 22 | ||||
-rw-r--r-- | test/psych/test_hash.rb | 13 | ||||
-rw-r--r-- | test/psych/test_string.rb | 58 | ||||
-rw-r--r-- | test/psych/test_to_yaml_properties.rb | 2 | ||||
-rw-r--r-- | test/psych/test_yaml.rb | 4 |
6 files changed, 97 insertions, 10 deletions
diff --git a/test/psych/helper.rb b/test/psych/helper.rb index 468beac..f28ac0f 100644 --- a/test/psych/helper.rb +++ b/test/psych/helper.rb @@ -6,7 +6,13 @@ require 'date' require 'psych' module Psych - class TestCase < MiniTest::Unit::TestCase + superclass = if defined?(Minitest::Test) + Minitest::Test + else + MiniTest::Unit::TestCase + end + + class TestCase < superclass def self.suppress_warning verbose, $VERBOSE = $VERBOSE, nil yield diff --git a/test/psych/test_coder.rb b/test/psych/test_coder.rb index 7571e89..e3213e2 100644 --- a/test/psych/test_coder.rb +++ b/test/psych/test_coder.rb @@ -95,6 +95,28 @@ module Psych end end + class Referential + attr_reader :a + + def initialize + @a = self + end + + def encode_with(c) + c['a'] = @a + end + + def init_with(c) + @a = c['a'] + end + end + + def test_self_referential + x = Referential.new + copy = Psych.load Psych.dump x + assert_equal copy, copy.a + end + def test_represent_with_object thing = Psych.load(Psych.dump(RepresentWithObject.new)) assert_equal 20, thing diff --git a/test/psych/test_hash.rb b/test/psych/test_hash.rb index 066df66..e2a3129 100644 --- a/test/psych/test_hash.rb +++ b/test/psych/test_hash.rb @@ -23,6 +23,13 @@ module Psych @hash = { :a => 'b' } end + def test_referenced_hash_with_ivar + a = [1,2,3,4,5] + t1 = [HashWithCustomInit.new(a)] + t1 << t1.first + assert_cycle t1 + end + def test_custom_initialized a = [1,2,3,4,5] t1 = HashWithCustomInit.new(a) @@ -38,12 +45,6 @@ module Psych assert_cycle t1 end - def test_hash_with_ivars - @hash.instance_variable_set :@foo, 'bar' - dup = Psych.load Psych.dump @hash - assert_equal 'bar', dup.instance_variable_get(:@foo) - end - def test_hash_subclass_with_ivars x = X.new x[:a] = 'b' diff --git a/test/psych/test_string.rb b/test/psych/test_string.rb index 26a4e20..a8ae55c 100644 --- a/test/psych/test_string.rb +++ b/test/psych/test_string.rb @@ -30,8 +30,62 @@ module Psych end def test_doublequotes_when_there_is_a_single - yaml = Psych.dump "@123'abc" - assert_match(/---\s*"/, yaml) + str = "@123'abc" + yaml = Psych.dump str + assert_match /---\s*"/, yaml + assert_equal str, Psych.load(yaml) + end + + def test_plain_when_shorten_than_line_width_and_no_final_line_break + str = "Lorem ipsum" + yaml = Psych.dump str, line_width: 12 + assert_match /---\s*[^>|]+\n/, yaml + assert_equal str, Psych.load(yaml) + end + + def test_plain_when_shorten_than_line_width_and_with_final_line_break + str = "Lorem ipsum\n" + yaml = Psych.dump str, line_width: 12 + assert_match /---\s*[^>|]+\n/, yaml + assert_equal str, Psych.load(yaml) + end + + def test_folded_when_longer_than_line_width_and_with_final_line_break + str = "Lorem ipsum dolor sit\n" + yaml = Psych.dump str, line_width: 12 + assert_match /---\s*>\n(.*\n){2}\Z/, yaml + assert_equal str, Psych.load(yaml) + end + + # http://yaml.org/spec/1.2/2009-07-21/spec.html#id2593651 + def test_folded_strip_when_longer_than_line_width_and_no_newlines + str = "Lorem ipsum dolor sit amet, consectetur" + yaml = Psych.dump str, line_width: 12 + assert_match /---\s*>-\n(.*\n){3}\Z/, yaml + assert_equal str, Psych.load(yaml) + end + + def test_literal_when_inner_and_final_line_break + [ + "Lorem ipsum\ndolor\n", + "Lorem ipsum\nZolor\n", + ].each do |str| + yaml = Psych.dump str, line_width: 12 + assert_match /---\s*\|\n(.*\n){2}\Z/, yaml + assert_equal str, Psych.load(yaml) + end + end + + # http://yaml.org/spec/1.2/2009-07-21/spec.html#id2593651 + def test_literal_strip_when_inner_line_break_and_no_final_line_break + [ + "Lorem ipsum\ndolor", + "Lorem ipsum\nZolor", + ].each do |str| + yaml = Psych.dump str, line_width: 12 + assert_match /---\s*\|-\n(.*\n){2}\Z/, yaml + assert_equal str, Psych.load(yaml) + end end def test_cycle_x diff --git a/test/psych/test_to_yaml_properties.rb b/test/psych/test_to_yaml_properties.rb index 5b4860c..724aab4 100644 --- a/test/psych/test_to_yaml_properties.rb +++ b/test/psych/test_to_yaml_properties.rb @@ -1,7 +1,7 @@ require_relative 'helper' module Psych - class TestToYamlProperties < MiniTest::Unit::TestCase + class TestToYamlProperties < Psych::TestCase class Foo attr_accessor :a, :b, :c def initialize diff --git a/test/psych/test_yaml.rb b/test/psych/test_yaml.rb index cd3e8ee..e628175 100644 --- a/test/psych/test_yaml.rb +++ b/test/psych/test_yaml.rb @@ -27,6 +27,10 @@ class Psych_Unit_Tests < Psych::TestCase assert_match "2010-10-10 00:00:00.000000000 Z", yaml end + def test_multiline_regexp + assert_cycle(Regexp.new("foo\nbar")) + end + # [ruby-core:34969] def test_regexp_with_n assert_cycle(Regexp.new('',0,'n')) |