mirror of
https://github.com/ruby/ruby.git
synced 2025-09-18 01:54:00 +02:00

* ext/psych/lib/psych.rb: updating version to match gem * ext/psych/psych.gemspec: ditto * ext/psych/lib/psych/visitors/to_ruby.rb: fixing deprecation warning * ext/psych/lib/psych.rb: define a new BadAlias error class. * ext/psych/lib/psych/visitors/to_ruby.rb: raise an exception when deserializing an alias that does not exist. * test/psych/test_merge_keys.rb: corresponding test. * ext/psych/lib/psych.rb (load, parse): stop parsing or loading after the first document has been parsed. * test/psych/test_stream.rb: pertinent tests. * ext/psych/lib/psych.rb (parse_stream, load_stream): if a block is given, documents will be yielded to the block as they are parsed. [ruby-core:42404] [Bug #5978] * ext/psych/lib/psych/handlers/document_stream.rb: add a handler that yields documents as they are parsed * test/psych/test_stream.rb: corresponding tests. * ext/psych/lib/psych/core_ext.rb: only extend Kernel if IRB is loaded in order to stop method pollution. * ext/psych/lib/psych.rb: default open YAML files with utf8 external encoding. [ruby-core:42967] * test/psych/test_tainted.rb: ditto * ext/psych/parser.c: prevent a memory leak by protecting calls to handler callbacks. * test/psych/test_parser.rb: test to demonstrate leak. * ext/psych/parser.c: set parser encoding based on the YAML input rather than user configuration. * test/psych/test_encoding.rb: corresponding tests. * test/psych/test_parser.rb: ditto * test/psych/test_tainted.rb: ditto * ext/psych/parser.c: removed external encoding setter, allow parser to be reused. * ext/psych/lib/psych/parser.rb: added external encoding setter. * test/psych/test_parser.rb: test parser reuse * ext/psych/lib/psych/visitors/to_ruby.rb: Added support for loading subclasses of String with ivars * ext/psych/lib/psych/visitors/yaml_tree.rb: Added support for dumping subclasses of String with ivars * test/psych/test_string.rb: corresponding tests * ext/psych/lib/psych/visitors/to_ruby.rb: Added ability to load array subclasses with ivars. * ext/psych/lib/psych/visitors/yaml_tree.rb: Added ability to dump array subclasses with ivars. * test/psych/test_array.rb: corresponding tests * ext/psych/emitter.c: fixing clang warnings. Thanks Joey! * ext/psych/lib/psych/visitors/to_ruby.rb: BigDecimals can be restored from YAML. * ext/psych/lib/psych/visitors/yaml_tree.rb: BigDecimals can be dumped to YAML. * test/psych/test_numeric.rb: tests for BigDecimal serialization * ext/psych/lib/psych/scalar_scanner.rb: Strings that look like dates should be treated as strings and not dates. * test/psych/test_scalar_scanner.rb: corresponding tests. * ext/psych/lib/psych.rb (module Psych): parse and load methods take an optional file name that is used when raising Psych::SyntaxError exceptions * ext/psych/lib/psych/syntax_error.rb (module Psych): allow nil file names and handle nil file names in the exception message * test/psych/test_exception.rb (module Psych): Tests for changes. * ext/psych/parser.c (parse): parse method can take an option file name for use in exception messages. * test/psych/test_parser.rb: corresponding tests. * ext/psych/lib/psych.rb: remove autoload from psych * ext/psych/lib/psych/json.rb: ditto * ext/psych/lib/psych/tree_builder.rb: dump complex numbers, rationals, etc with reference ids. * ext/psych/lib/psych/visitors/yaml_tree.rb: ditto * ext/psych/lib/psych/visitors/to_ruby.rb: loading complex numbers, rationals, etc with reference ids. * test/psych/test_object_references.rb: corresponding tests * ext/psych/lib/psych/scalar_scanner.rb: make sure strings that look like base 60 numbers are serialized as quoted strings. * test/psych/test_string.rb: test for change. * ext/psych/parser.c: remove unused variable. * ext/psych/lib/psych/syntax_error.rb: Add file, line, offset, and message attributes during parse failure. * ext/psych/parser.c: Update parser to raise exception with correct values. * test/psych/test_exception.rb: corresponding tests. * ext/psych/parser.c (parse): Use context_mark for indicating error line and column. * ext/psych/lib/psych/scalar_scanner.rb: use normal begin / rescue since postfix rescue cannot receive the exception class. Thanks nagachika! git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_3@35165 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
88 lines
2.1 KiB
Ruby
88 lines
2.1 KiB
Ruby
require 'psych/helper'
|
|
|
|
module Psych
|
|
class TestString < TestCase
|
|
class X < String
|
|
end
|
|
|
|
class Y < String
|
|
attr_accessor :val
|
|
end
|
|
|
|
def test_backwards_with_syck
|
|
x = Psych.load "--- !str:#{X.name} foo\n\n"
|
|
assert_equal X, x.class
|
|
assert_equal 'foo', x
|
|
end
|
|
|
|
def test_empty_subclass
|
|
assert_match "!ruby/string:#{X}", Psych.dump(X.new)
|
|
x = Psych.load Psych.dump X.new
|
|
assert_equal X, x.class
|
|
end
|
|
|
|
def test_subclass_with_attributes
|
|
y = Psych.load Psych.dump Y.new.tap {|y| y.val = 1}
|
|
assert_equal Y, y.class
|
|
assert_equal 1, y.val
|
|
end
|
|
|
|
def test_string_with_base_60
|
|
yaml = Psych.dump '01:03:05'
|
|
assert_match "'01:03:05'", yaml
|
|
assert_equal '01:03:05', Psych.load(yaml)
|
|
end
|
|
|
|
def test_tagged_binary_should_be_dumped_as_binary
|
|
string = "hello world!"
|
|
string.force_encoding 'ascii-8bit'
|
|
yml = Psych.dump string
|
|
assert_match(/binary/, yml)
|
|
assert_equal string, Psych.load(yml)
|
|
end
|
|
|
|
def test_binary_string_null
|
|
string = "\x00"
|
|
yml = Psych.dump string
|
|
assert_match(/binary/, yml)
|
|
assert_equal string, Psych.load(yml)
|
|
end
|
|
|
|
def test_binary_string
|
|
string = binary_string
|
|
yml = Psych.dump string
|
|
assert_match(/binary/, yml)
|
|
assert_equal string, Psych.load(yml)
|
|
end
|
|
|
|
def test_non_binary_string
|
|
string = binary_string(0.29)
|
|
yml = Psych.dump string
|
|
refute_match(/binary/, yml)
|
|
assert_equal string, Psych.load(yml)
|
|
end
|
|
|
|
def test_string_with_ivars
|
|
food = "is delicious"
|
|
ivar = "on rock and roll"
|
|
food.instance_variable_set(:@we_built_this_city, ivar)
|
|
|
|
str = Psych.load Psych.dump food
|
|
assert_equal ivar, food.instance_variable_get(:@we_built_this_city)
|
|
end
|
|
|
|
def test_binary
|
|
string = [0, 123,22, 44, 9, 32, 34, 39].pack('C*')
|
|
assert_cycle string
|
|
end
|
|
|
|
def binary_string percentage = 0.31, length = 100
|
|
string = ''
|
|
(percentage * length).to_i.times do |i|
|
|
string << "\b"
|
|
end
|
|
string << 'a' * (length - string.length)
|
|
string
|
|
end
|
|
end
|
|
end
|