Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

porting all constants to use Syck

  • Loading branch information...
commit 0fe4b21c4df53a436cbbff2f0c7b878540bf05c0 1 parent a201054
@tenderlove authored
View
4 lib/syck.rb
@@ -436,9 +436,9 @@ module Kernel
def y( object, *objects )
objects.unshift object
puts( if objects.length == 1
- YAML.dump( *objects )
+ Syck.dump( *objects )
else
- YAML.dump_stream( *objects )
+ Syck.dump_stream( *objects )
end )
end
private :y
View
83 lib/syck/rubytypes.rb
@@ -13,7 +13,7 @@ def to_yaml_style; end
undef to_yaml_properties rescue nil
def to_yaml_properties; instance_variables.sort; end
def to_yaml( opts = {} )
- YAML::quick_emit( self, opts ) do |out|
+ Syck::quick_emit( self, opts ) do |out|
out.map( taguri, to_yaml_style ) do |map|
to_yaml_properties.each do |m|
map.add( m[1..-1], instance_variable_get( m ) )
@@ -33,12 +33,11 @@ def yaml_initialize( tag, val )
elsif Hash === val
update val
else
- raise YAML::TypeError, "Invalid map explicitly tagged #{ tag }: " + val.inspect
+ raise Syck::TypeError, "Invalid map explicitly tagged #{ tag }: " + val.inspect
end
end
def to_yaml( opts = {} )
- return super unless YAML::ENGINE.syck?
- YAML::quick_emit( self, opts ) do |out|
+ Syck::quick_emit( self, opts ) do |out|
out.map( taguri, to_yaml_style ) do |map|
each do |k, v|
map.add( k, v )
@@ -62,7 +61,7 @@ def self.yaml_new( klass, tag, val )
props = {}
val.delete_if { |k,v| props[k] = v if k =~ /^@/ }
begin
- struct_type = YAML.read_type_class( tag, Struct ).last
+ struct_type = Syck.read_type_class( tag, Struct ).last
rescue NameError
end
if not struct_type
@@ -73,7 +72,7 @@ def self.yaml_new( klass, tag, val )
#
# Set the Struct properties
#
- st = YAML::object_maker( struct_type, {} )
+ st = Syck::object_maker( struct_type, {} )
st.members.each do |m|
st.send( "#{m}=", val[m.to_s] )
end
@@ -82,12 +81,11 @@ def self.yaml_new( klass, tag, val )
end
st
else
- raise YAML::TypeError, "Invalid Ruby Struct: " + val.inspect
+ raise Syck::TypeError, "Invalid Ruby Struct: " + val.inspect
end
end
def to_yaml( opts = {} )
- return super unless YAML::ENGINE.syck?
- YAML::quick_emit( self, opts ) do |out|
+ Syck::quick_emit( self, opts ) do |out|
#
# Basic struct is passed as a YAML map
#
@@ -108,8 +106,7 @@ class Array
yaml_as "tag:yaml.org,2002:seq"
def yaml_initialize( tag, val ); concat( val.to_a ); end
def to_yaml( opts = {} )
- return super unless YAML::ENGINE.syck?
- YAML::quick_emit( self, opts ) do |out|
+ Syck::quick_emit( self, opts ) do |out|
out.seq( taguri, to_yaml_style ) do |seq|
each do |x|
seq.add( x )
@@ -130,8 +127,7 @@ def Exception.yaml_new( klass, tag, val )
o
end
def to_yaml( opts = {} )
- return super unless YAML::ENGINE.syck?
- YAML::quick_emit( self, opts ) do |out|
+ Syck::quick_emit( self, opts ) do |out|
out.map( taguri, to_yaml_style ) do |map|
map.add( 'message', message )
to_yaml_properties.each do |m|
@@ -164,12 +160,11 @@ def String.yaml_new( klass, tag, val )
val.each { |k,v| s.instance_variable_set( k, v ) }
s
else
- raise YAML::TypeError, "Invalid String: " + val.inspect
+ raise Syck::TypeError, "Invalid String: " + val.inspect
end
end
def to_yaml( opts = {} )
- return super unless YAML::ENGINE.syck?
- YAML::quick_emit( is_complex_yaml? ? self : nil, opts ) do |out|
+ Syck::quick_emit( is_complex_yaml? ? self : nil, opts ) do |out|
if is_binary_data?
out.scalar( "tag:yaml.org,2002:binary", [self].pack("m"), :literal )
elsif to_yaml_properties.empty?
@@ -191,15 +186,14 @@ class Symbol
yaml_as "tag:ruby.yaml.org,2002:sym"
def Symbol.yaml_new( klass, tag, val )
if String === val
- val = YAML::load( val ) if val =~ /\A(["']).*\1\z/
+ val = Syck::load( val ) if val =~ /\A(["']).*\1\z/
val.intern
else
- raise YAML::TypeError, "Invalid Symbol: " + val.inspect
+ raise Syck::TypeError, "Invalid Symbol: " + val.inspect
end
end
def to_yaml( opts = {} )
- return super unless YAML::ENGINE.syck?
- YAML::quick_emit( nil, opts ) do |out|
+ Syck::quick_emit( nil, opts ) do |out|
out.scalar( "tag:yaml.org,2002:str", self.inspect, :plain )
end
end
@@ -213,8 +207,8 @@ def Range.yaml_new( klass, tag, val )
if String === val and val =~ /^#{inr}(\.{2,3})#{inr}$/o
r1, rdots, r2 = $1, $2, $3
opts = {
- 'begin' => YAML.load( "--- #{r1}" ),
- 'end' => YAML.load( "--- #{r2}" ),
+ 'begin' => Syck.load( "--- #{r1}" ),
+ 'end' => Syck.load( "--- #{r2}" ),
'excl' => rdots.length == 3
}
val = {}
@@ -224,7 +218,7 @@ def Range.yaml_new( klass, tag, val )
opts['excl'] = val.delete('excl')
end
if Hash === opts
- r = YAML::object_maker( klass, {} )
+ r = Syck::object_maker( klass, {} )
# Thank you, NaHi
Range.instance_method(:initialize).
bind(r).
@@ -232,12 +226,11 @@ def Range.yaml_new( klass, tag, val )
val.each { |k,v| r.instance_variable_set( k, v ) }
r
else
- raise YAML::TypeError, "Invalid Range: " + val.inspect
+ raise Syck::TypeError, "Invalid Range: " + val.inspect
end
end
def to_yaml( opts = {} )
- return super unless YAML::ENGINE.syck?
- YAML::quick_emit( self, opts ) do |out|
+ Syck::quick_emit( self, opts ) do |out|
# if self.begin.is_complex_yaml? or self.begin.respond_to? :to_str or
# self.end.is_complex_yaml? or self.end.respond_to? :to_str or
# not to_yaml_properties.empty?
@@ -276,19 +269,18 @@ def Regexp.yaml_new( klass, tag, val )
mods |= Regexp::NOENCODING if val['mods'].include?( 'n' )
end
val.delete( 'mods' )
- r = YAML::object_maker( klass, {} )
+ r = Syck::object_maker( klass, {} )
Regexp.instance_method(:initialize).
bind(r).
call( val.delete( 'regexp' ), mods )
val.each { |k,v| r.instance_variable_set( k, v ) }
r
else
- raise YAML::TypeError, "Invalid Regular expression: " + val.inspect
+ raise Syck::TypeError, "Invalid Regular expression: " + val.inspect
end
end
def to_yaml( opts = {} )
- return super unless YAML::ENGINE.syck?
- YAML::quick_emit( nil, opts ) do |out|
+ Syck::quick_emit( nil, opts ) do |out|
if to_yaml_properties.empty?
out.scalar( taguri, self.inspect, :plain )
else
@@ -298,7 +290,7 @@ def to_yaml( opts = {} )
map.add( 'regexp', $1 )
map.add( 'mods', $2 )
else
- raise YAML::TypeError, "Invalid Regular expression: " + src
+ raise Syck::TypeError, "Invalid Regular expression: " + src
end
to_yaml_properties.each do |m|
map.add( m, instance_variable_get( m ) )
@@ -318,12 +310,11 @@ def Time.yaml_new( klass, tag, val )
val.each { |k,v| t.instance_variable_set( k, v ) }
t
else
- raise YAML::TypeError, "Invalid Time: " + val.inspect
+ raise Syck::TypeError, "Invalid Time: " + val.inspect
end
end
def to_yaml( opts = {} )
- return super unless YAML::ENGINE.syck?
- YAML::quick_emit( self, opts ) do |out|
+ Syck::quick_emit( self, opts ) do |out|
tz = "Z"
# from the tidy Tobias Peters <t-peters@gmx.de> Thanks!
unless self.utc?
@@ -360,8 +351,7 @@ def to_yaml( opts = {} )
class Date
yaml_as "tag:yaml.org,2002:timestamp#ymd"
def to_yaml( opts = {} )
- return super unless YAML::ENGINE.syck?
- YAML::quick_emit( self, opts ) do |out|
+ Syck::quick_emit( self, opts ) do |out|
out.scalar( "tag:yaml.org,2002:timestamp", self.to_s, :plain )
end
end
@@ -370,8 +360,7 @@ def to_yaml( opts = {} )
class Integer
yaml_as "tag:yaml.org,2002:int"
def to_yaml( opts = {} )
- return super unless YAML::ENGINE.syck?
- YAML::quick_emit( nil, opts ) do |out|
+ Syck::quick_emit( nil, opts ) do |out|
out.scalar( "tag:yaml.org,2002:int", self.to_s, :plain )
end
end
@@ -380,8 +369,7 @@ def to_yaml( opts = {} )
class Float
yaml_as "tag:yaml.org,2002:float"
def to_yaml( opts = {} )
- return super unless YAML::ENGINE.syck?
- YAML::quick_emit( nil, opts ) do |out|
+ Syck::quick_emit( nil, opts ) do |out|
str = self.to_s
if str == "Infinity"
str = ".Inf"
@@ -405,8 +393,7 @@ def Rational.yaml_new( klass, tag, val )
end
end
def to_yaml( opts = {} )
- return super unless YAML::ENGINE.syck?
- YAML::quick_emit( self, opts ) do |out|
+ Syck::quick_emit( self, opts ) do |out|
out.map( taguri, nil ) do |map|
map.add( 'denominator', denominator )
map.add( 'numerator', numerator )
@@ -425,8 +412,7 @@ def Complex.yaml_new( klass, tag, val )
end
end
def to_yaml( opts = {} )
- return super unless YAML::ENGINE.syck?
- YAML::quick_emit( self, opts ) do |out|
+ Syck::quick_emit( self, opts ) do |out|
out.map( taguri, nil ) do |map|
map.add( 'image', imaginary )
map.add( 'real', real )
@@ -438,8 +424,7 @@ def to_yaml( opts = {} )
class TrueClass
yaml_as "tag:yaml.org,2002:bool#yes"
def to_yaml( opts = {} )
- return super unless YAML::ENGINE.syck?
- YAML::quick_emit( nil, opts ) do |out|
+ Syck::quick_emit( nil, opts ) do |out|
out.scalar( taguri, "true", :plain )
end
end
@@ -448,8 +433,7 @@ def to_yaml( opts = {} )
class FalseClass
yaml_as "tag:yaml.org,2002:bool#no"
def to_yaml( opts = {} )
- return super unless YAML::ENGINE.syck?
- YAML::quick_emit( nil, opts ) do |out|
+ Syck::quick_emit( nil, opts ) do |out|
out.scalar( taguri, "false", :plain )
end
end
@@ -458,8 +442,7 @@ def to_yaml( opts = {} )
class NilClass
yaml_as "tag:yaml.org,2002:null"
def to_yaml( opts = {} )
- return super unless YAML::ENGINE.syck?
- YAML::quick_emit( nil, opts ) do |out|
+ Syck::quick_emit( nil, opts ) do |out|
out.scalar( taguri, "", :plain )
end
end
View
15 test/test_array.rb
@@ -1,24 +1,13 @@
-require 'test/unit'
-require 'yaml'
+require 'helper'
module Syck
class TestArray < Test::Unit::TestCase
def setup
- @current_engine = YAML::ENGINE.yamler
- YAML::ENGINE.yamler = 'syck'
@list = [{ :a => 'b' }, 'foo']
end
- def teardown
- YAML::ENGINE.yamler = @current_engine
- end
-
- def test_to_yaml
- assert_equal @list, YAML.load(@list.to_yaml)
- end
-
def test_dump
- assert_equal @list, YAML.load(YAML.dump(@list))
+ assert_equal @list, Syck.load(Syck.dump(@list))
end
end
end
View
15 test/test_boolean.rb
@@ -1,5 +1,4 @@
-require 'test/unit'
-require 'yaml'
+require 'helper'
module Syck
###
@@ -8,13 +7,13 @@ module Syck
class TestBoolean < Test::Unit::TestCase
%w{ yes Yes YES true True TRUE on On ON }.each do |truth|
define_method(:"test_#{truth}") do
- assert_equal true, YAML.load("--- #{truth}")
+ assert_equal true, Syck.load("--- #{truth}")
end
end
%w{ no No NO false False FALSE off Off OFF }.each do |truth|
define_method(:"test_#{truth}") do
- assert_equal false, YAML.load("--- #{truth}")
+ assert_equal false, Syck.load("--- #{truth}")
end
end
@@ -22,16 +21,16 @@ class TestBoolean < Test::Unit::TestCase
# YAML spec says "y" and "Y" may be used as true, but Syck treats them
# as literal strings
def test_y
- assert_equal "y", YAML.load("--- y")
- assert_equal "Y", YAML.load("--- Y")
+ assert_equal "y", Syck.load("--- y")
+ assert_equal "Y", Syck.load("--- Y")
end
###
# YAML spec says "n" and "N" may be used as false, but Syck treats them
# as literal strings
def test_n
- assert_equal "n", YAML.load("--- n")
- assert_equal "N", YAML.load("--- N")
+ assert_equal "n", Syck.load("--- n")
+ assert_equal "N", Syck.load("--- N")
end
end
end
View
20 test/test_class.rb
@@ -1,26 +1,10 @@
-require 'test/unit'
-require 'yaml'
+require 'helper'
module Syck
class TestClass < Test::Unit::TestCase
- def setup
- @engine = YAML::ENGINE.yamler
- YAML::ENGINE.yamler = 'syck'
- end
-
- def teardown
- YAML::ENGINE.yamler = @engine
- end
-
- def test_to_yaml
- assert_raises(::TypeError) do
- TestClass.to_yaml
- end
- end
-
def test_dump
assert_raises(::TypeError) do
- YAML.dump TestClass
+ Syck.dump TestClass
end
end
end
View
3  test/test_engine_manager.rb
@@ -1,3 +0,0 @@
-require 'test/unit'
-require 'yaml'
-
View
9 test/test_exception.rb
@@ -1,5 +1,4 @@
-require 'test/unit'
-require 'yaml'
+require 'helper'
module Syck
class TestException < Test::Unit::TestCase
@@ -17,14 +16,14 @@ def setup
end
def test_to_yaml
- w = YAML.load(@wups.to_yaml)
+ w = Syck.load(Syck.dump(@wups))
assert_equal @wups, w
assert_equal 1, w.foo
assert_equal 2, w.bar
end
def test_dump
- w = YAML.load(@wups.to_yaml)
+ w = Syck.load(Syck.dump(@wups))
assert_equal @wups, w
assert_equal 1, w.foo
assert_equal 2, w.bar
@@ -37,7 +36,7 @@ def to_yaml_properties
end
end
- w = YAML.load(YAML.dump(@wups))
+ w = Syck.load(Syck.dump(@wups))
assert_equal @wups, w
assert_equal 1, w.foo
assert_nil w.bar
View
11 test/test_hash.rb
@@ -1,5 +1,4 @@
-require 'test/unit'
-require 'yaml'
+require 'helper'
module Syck
class TestHash < Test::Unit::TestCase
@@ -7,16 +6,12 @@ def setup
@hash = { :a => 'b' }
end
- def test_to_yaml
- assert_equal @hash, YAML.load(@hash.to_yaml)
- end
-
def test_dump
- assert_equal @hash, YAML.load(YAML.dump(@hash))
+ assert_equal @hash, Syck.load(Syck.dump(@hash))
end
def test_ref_append
- hash = YAML.load(<<-eoyml)
+ hash = Syck.load(<<-eoyml)
---
foo: &foo
hello: world
View
5 test/test_null.rb
@@ -1,5 +1,4 @@
-require 'test/unit'
-require 'yaml'
+require 'helper'
module Syck
###
@@ -7,7 +6,7 @@ module Syck
# http://yaml.org/type/null.html
class TestNull < Test::Unit::TestCase
def test_null_list
- assert_equal [nil] * 5, YAML.load(<<-eoyml)
+ assert_equal [nil] * 5, Syck.load(<<-eoyml)
---
- ~
- null
View
17 test/test_omap.rb
@@ -1,16 +1,15 @@
-require 'test/unit'
-require 'yaml'
+require 'helper'
module Syck
class TestOmap < Test::Unit::TestCase
def test_keys
- map = YAML::Omap.new
+ map = Syck::Omap.new
map['foo'] = 'bar'
assert_equal 'bar', map['foo']
end
def test_order
- map = YAML::Omap.new
+ map = Syck::Omap.new
map['a'] = 'b'
map['b'] = 'c'
assert_equal [%w{a b}, %w{b c}], map.to_a
@@ -18,14 +17,14 @@ def test_order
def test_square
list = [["a", "b"], ["b", "c"]]
- map = YAML::Omap[*list.flatten]
+ map = Syck::Omap[*list.flatten]
assert_equal list, map.to_a
assert_equal 'b', map['a']
assert_equal 'c', map['b']
end
def test_to_yaml
- map = YAML::Omap['a', 'b', 'c', 'd']
+ map = Syck::Omap['a', 'b', 'c', 'd']
yaml = map.to_yaml
assert_match('!omap', yaml)
assert_match('- a: b', yaml)
@@ -34,8 +33,8 @@ def test_to_yaml
def test_round_trip
list = [["a", "b"], ["b", "c"]]
- map = YAML::Omap[*list.flatten]
- loaded = YAML.load(YAML.dump(map))
+ map = Syck::Omap[*list.flatten]
+ loaded = Syck.load(Syck.dump(map))
assert_equal map, loaded
assert_equal list, loaded.to_a
@@ -45,7 +44,7 @@ def test_round_trip
# FIXME: Syck should also support !!omap as shorthand
def test_load
list = [["a", "b"], ["c", "d"]]
- map = YAML.load(<<-eoyml)
+ map = Syck.load(<<-eoyml)
--- !omap
- a: b
- c: d
View
9 test/test_set.rb
@@ -1,10 +1,9 @@
-require 'test/unit'
-require 'yaml'
+require 'helper'
module Syck
class TestSet < Test::Unit::TestCase
def setup
- @set = YAML::Set.new
+ @set = Syck::Set.new
@set['foo'] = 'bar'
@set['bar'] = 'baz'
end
@@ -14,13 +13,13 @@ def test_to_yaml
end
def test_roundtrip
- assert_equal(@set, YAML.load(YAML.dump(@set)))
+ assert_equal(@set, Syck.load(Syck.dump(@set)))
end
###
# FIXME: Syck should also support !!set as shorthand
def test_load_from_yaml
- loaded = YAML.load(<<-eoyml)
+ loaded = Syck.load(<<-eoyml)
--- !set
foo: bar
bar: baz
View
17 test/test_string.rb
@@ -1,27 +1,26 @@
-require 'test/unit'
-require 'yaml'
+require 'helper'
module Syck
class TestString < Test::Unit::TestCase
def test_binary_string_null
string = "\x00"
- yml = YAML.dump string
+ yml = Syck.dump string
assert_match(/binary/, yml)
- assert_equal string, YAML.load(yml)
+ assert_equal string, Syck.load(yml)
end
def test_binary_string
string = binary_string
- yml = YAML.dump string
+ yml = Syck.dump string
assert_match(/binary/, yml)
- assert_equal string, YAML.load(yml)
+ assert_equal string, Syck.load(yml)
end
def test_non_binary_string
string = binary_string(0.29)
- yml = YAML.dump string
+ yml = Syck.dump string
assert_not_match(/binary/, yml)
- assert_equal string, YAML.load(yml)
+ assert_equal string, Syck.load(yml)
end
def test_string_with_ivars
@@ -29,7 +28,7 @@ def test_string_with_ivars
ivar = "on rock and roll"
food.instance_variable_set(:@we_built_this_city, ivar)
- str = YAML.load YAML.dump food
+ str = Syck.load Syck.dump food
assert_equal ivar, food.instance_variable_get(:@we_built_this_city)
end
View
16 test/test_struct.rb
@@ -1,5 +1,4 @@
-require 'test/unit'
-require 'yaml'
+require 'helper'
class StructWithIvar < Struct.new(:foo)
attr_reader :bar
@@ -11,25 +10,16 @@ def initialize *args
module Syck
class TestStruct < MiniTest::Unit::TestCase
- def setup
- @current_engine = YAML::ENGINE.yamler
- YAML::ENGINE.yamler = 'syck'
- end
-
- def teardown
- YAML::ENGINE.yamler = @current_engine
- end
-
def test_roundtrip
thing = StructWithIvar.new('bar')
- struct = YAML.load(YAML.dump(thing))
+ struct = Syck.load(Syck.dump(thing))
assert_equal 'hello', struct.bar
assert_equal 'bar', struct.foo
end
def test_load
- obj = YAML.load(<<-eoyml)
+ obj = Syck.load(<<-eoyml)
--- !ruby/struct:StructWithIvar
foo: bar
@bar: hello
View
8 test/test_syck.rb
@@ -1,8 +0,0 @@
-require 'minitest/autorun'
-require 'syck'
-
-class TestSyck < MiniTest::Unit::TestCase
- def test_sanity
- flunk "write tests or I will kneecap you"
- end
-end
View
11 test/test_symbol.rb
@@ -1,22 +1,21 @@
-require 'test/unit'
-require 'yaml'
+require 'helper'
module Syck
class TestSymbol < Test::Unit::TestCase
def test_to_yaml
- assert_equal :a, YAML.load(:a.to_yaml)
+ assert_equal :a, Syck.load(:a.to_yaml)
end
def test_dump
- assert_equal :a, YAML.load(YAML.dump(:a))
+ assert_equal :a, Syck.load(Syck.dump(:a))
end
def test_stringy
- assert_equal :"1", YAML.load(YAML.dump(:"1"))
+ assert_equal :"1", Syck.load(Syck.dump(:"1"))
end
def test_load_quoted
- assert_equal :"1", YAML.load("--- :'1'\n")
+ assert_equal :"1", Syck.load("--- :'1'\n")
end
end
end
View
11 test/test_time.rb
@@ -1,24 +1,23 @@
-require 'test/unit'
-require 'yaml'
+require 'helper'
module Syck
class TestString < Test::Unit::TestCase
def test_usec_long
bug4571 = '[ruby-core:35713]'
- assert_equal(34, YAML.load("2011-03-22t23:32:11.0000342222+01:00").usec, bug4571)
+ assert_equal(34, Syck.load("2011-03-22t23:32:11.0000342222+01:00").usec, bug4571)
end
def test_usec_very_long
t = "2011-03-22t23:32:11.0000342"+"0"*1000+"1+01:00"
- assert_equal(34, YAML.load(t).usec)
+ assert_equal(34, Syck.load(t).usec)
end
def test_usec_full
- assert_equal(342222, YAML.load("2011-03-22t23:32:11.342222+01:00").usec)
+ assert_equal(342222, Syck.load("2011-03-22t23:32:11.342222+01:00").usec)
end
def test_usec_short
- assert_equal(330000, YAML.load("2011-03-22t23:32:11.33+01:00").usec)
+ assert_equal(330000, Syck.load("2011-03-22t23:32:11.33+01:00").usec)
end
end
end
View
79 test/test_yaml.rb
@@ -2,9 +2,7 @@
# vim:sw=4:ts=4
# $Id$
#
-require 'test/unit'
-require 'syck'
-require 'yaml'
+require 'helper'
require 'syck/ypath'
# [ruby-core:01946]
@@ -14,15 +12,6 @@ module YAML_Tests
module Syck
class YAML_Unit_Tests < Test::Unit::TestCase
- def setup
- @current_engine = YAML::ENGINE.yamler
- YAML::ENGINE.yamler = 'syck'
- end
-
- def teardown
- YAML::ENGINE.yamler = @current_engine
- end
-
# [ruby-core:34969]
def test_regexp_with_n
assert_cycle(Regexp.new('',0,'n'))
@@ -33,11 +22,11 @@ def test_regexp_with_n
# emitting
#
def assert_to_yaml( obj, yaml, msg = nil )
- assert_equal( obj, YAML::load( yaml ), msg )
- assert_equal( obj, YAML::parse( yaml ).transform, msg )
- assert_equal( obj, YAML::load( obj.to_yaml ), msg )
- assert_equal( obj, YAML::parse( obj.to_yaml ).transform, msg )
- assert_equal( obj, YAML::load(
+ assert_equal( obj, Syck::load( yaml ), msg )
+ assert_equal( obj, Syck::parse( yaml ).transform, msg )
+ assert_equal( obj, Syck::load( obj.to_yaml ), msg )
+ assert_equal( obj, Syck::parse( obj.to_yaml ).transform, msg )
+ assert_equal( obj, Syck::load(
obj.to_yaml( :UseVersion => true, :UseHeader => true, :SortKeys => true )
), msg )
end
@@ -46,16 +35,16 @@ def assert_to_yaml( obj, yaml, msg = nil )
# Test parser only
#
def assert_parse_only( obj, yaml, msg = nil )
- assert_equal( obj, YAML::load( yaml ), msg )
- assert_equal( obj, YAML::parse( yaml ).transform, msg )
+ assert_equal( obj, Syck::load( yaml ), msg )
+ assert_equal( obj, Syck::parse( yaml ).transform, msg )
end
def assert_cycle( obj, msg = nil )
- assert_equal( obj, YAML::load( obj.to_yaml ), msg )
+ assert_equal( obj, Syck::load( obj.to_yaml ), msg )
end
def assert_path_segments( path, segments, msg = nil )
- YAML::YPath.each_path( path ) { |choice|
+ Syck::YPath.each_path( path ) { |choice|
assert_equal( choice.segments, segments.shift, msg )
}
assert_equal( segments.length, 0, "Some segments leftover: #{ segments.inspect }" )
@@ -566,7 +555,7 @@ def test_spec_type_float
fixed: 1,230.15
negative infinity: -.inf
EOY
- nan = YAML::load( <<EOY )
+ nan = Syck::load( <<EOY )
not a number: .NaN
EOY
assert( nan['not a number'].nan? )
@@ -632,7 +621,7 @@ def test_spec_complex_invoice
def test_spec_log_file
doc_ct = 0
- YAML::load_documents( <<EOY
+ Syck::load_documents( <<EOY
---
Time: 2001-11-23 15:01:42 -05:00
User: ed
@@ -681,7 +670,7 @@ def test_spec_log_file
end
def test_spec_root_fold
- y = YAML::load( <<EOY
+ y = Syck::load( <<EOY
--- >
This YAML stream contains a single text value.
The next stream is a log file - a sequence of
@@ -693,7 +682,7 @@ def test_spec_root_fold
end
def test_spec_root_mapping
- y = YAML::load( <<EOY
+ y = Syck::load( <<EOY
# This stream is an example of a top-level mapping.
invoice : 34843
date : 2001-01-23
@@ -705,7 +694,7 @@ def test_spec_root_mapping
def test_spec_oneline_docs
doc_ct = 0
- YAML::load_documents( <<EOY
+ Syck::load_documents( <<EOY
# The following is a sequence of three documents.
# The first contains an empty mapping, the second
# an empty sequence, and the last an empty string.
@@ -737,8 +726,8 @@ def test_spec_domain_prefix
raise ArgumentError, "Not a Hash in domain.tld,2002/invoice: " + val.inspect
end
}
- YAML.add_domain_type( "domain.tld,2002", 'invoice', &customer_proc )
- YAML.add_domain_type( "domain.tld,2002", 'customer', &customer_proc )
+ Syck.add_domain_type( "domain.tld,2002", 'invoice', &customer_proc )
+ Syck.add_domain_type( "domain.tld,2002", 'customer', &customer_proc )
assert_parse_only( { "invoice"=> { "customers"=> [ { "given"=>"Chris", "type"=>"domain customer", "family"=>"Dumars" } ], "type"=>"domain invoice" } }, <<EOY
# 'http://domain.tld,2002/invoice' is some type family.
invoice: !domain.tld,2002/^invoice
@@ -785,7 +774,7 @@ def test_spec_force_implicit
def test_spec_private_types
doc_ct = 0
- YAML::parse_documents( <<EOY
+ Syck::parse_documents( <<EOY
# Private types are per-document.
---
pool: !!ball
@@ -810,10 +799,10 @@ def test_spec_private_types
end
def test_spec_url_escaping
- YAML.add_domain_type( "domain.tld,2002", "type0" ) { |type, val|
+ Syck.add_domain_type( "domain.tld,2002", "type0" ) { |type, val|
"ONE: #{val}"
}
- YAML.add_domain_type( "domain.tld,2002", "type%30" ) { |type, val|
+ Syck.add_domain_type( "domain.tld,2002", "type%30" ) { |type, val|
"TWO: #{val}"
}
assert_parse_only(
@@ -842,7 +831,7 @@ def test_spec_override_anchor
end
def test_spec_explicit_families
- YAML.add_domain_type( "somewhere.com,2002", 'type' ) { |type, val|
+ Syck.add_domain_type( "somewhere.com,2002", 'type' ) { |type, val|
"SOMEWHERE: #{val}"
}
assert_parse_only(
@@ -863,7 +852,7 @@ def test_spec_explicit_families
def test_spec_application_family
# Testing the clarkevans.com graphs
- YAML.add_domain_type( "clarkevans.com,2002", 'graph/shape' ) { |type, val|
+ Syck.add_domain_type( "clarkevans.com,2002", 'graph/shape' ) { |type, val|
if Array === val
val << "Shape Container"
val
@@ -880,9 +869,9 @@ def test_spec_application_family
raise ArgumentError, "Invalid graph of type #{val.class}: " + val.inspect
end
}
- YAML.add_domain_type( "clarkevans.com,2002", 'graph/circle', &one_shape_proc )
- YAML.add_domain_type( "clarkevans.com,2002", 'graph/line', &one_shape_proc )
- YAML.add_domain_type( "clarkevans.com,2002", 'graph/text', &one_shape_proc )
+ Syck.add_domain_type( "clarkevans.com,2002", 'graph/circle', &one_shape_proc )
+ Syck.add_domain_type( "clarkevans.com,2002", 'graph/line', &one_shape_proc )
+ Syck.add_domain_type( "clarkevans.com,2002", 'graph/text', &one_shape_proc )
assert_parse_only(
[[{"radius"=>7, "center"=>{"x"=>73, "y"=>129}, "TYPE"=>"Shape: graph/circle"}, {"finish"=>{"x"=>89, "y"=>102}, "TYPE"=>"Shape: graph/line", "start"=>{"x"=>73, "y"=>129}}, {"TYPE"=>"Shape: graph/text", "value"=>"Pretty vector drawing.", "start"=>{"x"=>73, "y"=>129}, "color"=>16772795}, "Shape Container"]], <<EOY
- !clarkevans.com,2002/graph/^shape
@@ -1212,7 +1201,7 @@ def test_ruby_rational
# Read YAML dumped by the ruby 1.8.3.
assert_to_yaml( Rational(1, 2), "!ruby/object:Rational 1/2\n" )
- assert_raise( ArgumentError ) { YAML.load("!ruby/object:Rational INVALID/RATIONAL\n") }
+ assert_raise( ArgumentError ) { Syck.load("!ruby/object:Rational INVALID/RATIONAL\n") }
end
def test_ruby_complex
@@ -1224,7 +1213,7 @@ def test_ruby_complex
# Read YAML dumped by the ruby 1.8.3.
assert_to_yaml( Complex(3, 4), "!ruby/object:Complex 3+4i\n" )
- assert_raise( ArgumentError ) { YAML.load("!ruby/object:Complex INVALID+COMPLEXi\n") }
+ assert_raise( ArgumentError ) { Syck.load("!ruby/object:Complex INVALID+COMPLEXi\n") }
end
def test_emitting_indicators
@@ -1238,7 +1227,7 @@ def test_emitting_indicators
# Test the YAML::Stream class -- INACTIVE at the moment
#
def test_document
- y = YAML::Stream.new( :Indent => 2, :UseVersion => 0 )
+ y = Syck::Stream.new( :Indent => 2, :UseVersion => 0 )
y.add(
{ 'hi' => 'hello', 'map' =>
{ 'good' => 'two' },
@@ -1344,7 +1333,7 @@ def test_range_cycle
def test_circular_references
a = []; a[0] = a; a[1] = a
inspect_str = "[[...], [...]]"
- assert_equal( inspect_str, YAML::load( a.to_yaml ).inspect )
+ assert_equal( inspect_str, Syck::load( a.to_yaml ).inspect )
end
#
@@ -1381,14 +1370,14 @@ def test_empty_map_key
#
# empty seq as key
#
- o = YAML.load({[]=>""}.to_yaml)
+ o = Syck.load({[]=>""}.to_yaml)
assert_equal(Hash, o.class)
assert_equal([[]], o.keys)
#
# empty map as key
#
- o = YAML.load({{}=>""}.to_yaml)
+ o = Syck.load({{}=>""}.to_yaml)
assert_equal(Hash, o.class)
assert_equal([{}], o.keys)
end
@@ -1397,17 +1386,17 @@ def test_empty_map_key
# contributed by riley lynch [ruby-Bugs-8548]
#
def test_object_id_collision
- omap = YAML::Omap.new
+ omap = Syck::Omap.new
1000.times { |i| omap["key_#{i}"] = { "value" => i } }
raise "id collision in ordered map" if omap.to_yaml =~ /id\d+/
end
def test_date_out_of_range
- assert_nothing_raised{YAML::load('1900-01-01T00:00:00+00:00')}
+ assert_nothing_raised{Syck::load('1900-01-01T00:00:00+00:00')}
end
def test_normal_exit
- YAML.load("2000-01-01 00:00:00.#{"0"*1000} +00:00\n")
+ Syck.load("2000-01-01 00:00:00.#{"0"*1000} +00:00\n")
# '[ruby-core:13735]'
end
end
View
11 test/test_yaml_properties.rb
@@ -1,5 +1,4 @@
-require 'test/unit'
-require 'yaml'
+require 'helper'
module Syck
class TestYamlProperties < Test::Unit::TestCase
@@ -17,7 +16,7 @@ def to_yaml_properties
end
def test_object_dump_yaml_properties
- foo = YAML.load(YAML.dump(Foo.new))
+ foo = Syck.load(Syck.dump(Foo.new))
assert_equal 1, foo.a
assert_equal 2, foo.b
assert_nil foo.c
@@ -36,7 +35,7 @@ def to_yaml_properties
end
def test_struct_dump_yaml_properties
- bar = YAML.load(YAML.dump(Bar.new('a', 'b')))
+ bar = Syck.load(Syck.dump(Bar.new('a', 'b')))
assert_equal 'a', bar.foo
assert_equal 'b', bar.bar
assert_nil bar.baz
@@ -51,12 +50,12 @@ def to_yaml_properties
end
string.instance_variable_set(:@tastes, 'delicious')
- v = YAML.load YAML.dump string
+ v = Syck.load Syck.dump string
assert_equal 'delicious', v.instance_variable_get(:@tastes)
end
def test_string_load
- str = YAML.load("--- !str \nstr: okonomiyaki\n:@tastes: delicious\n")
+ str = Syck.load("--- !str \nstr: okonomiyaki\n:@tastes: delicious\n")
assert_equal 'okonomiyaki', str
assert_equal 'delicious', str.instance_variable_get(:@tastes)
end
View
194 test/test_yamldbm.rb
@@ -1,194 +0,0 @@
-# -*- coding: UTF-8 -*-
-begin
- require 'test/unit'
- require 'yaml/dbm'
- require 'tmpdir'
-rescue LoadError
-end
-
-module Syck
- ::Syck::DBM = ::YAML::DBM unless defined?(::Syck::DBM)
-
- class YAMLDBMTest < Test::Unit::TestCase
- def setup
- @engine, YAML::ENGINE.yamler = YAML::ENGINE.yamler, 'syck'
- @dir = Dir.mktmpdir("rubytest-file")
- File.chown(-1, Process.gid, @dir)
- @yamldbm_file = make_tmp_filename("yamldbm")
- @yamldbm = YAML::DBM.new(@yamldbm_file)
- end
-
- def teardown
- YAML::ENGINE.yamler = @engine
- @yamldbm.clear
- @yamldbm.close
- FileUtils.remove_entry_secure @dir
- end
-
- def make_tmp_filename(prefix)
- @dir + "/" + prefix + File.basename(__FILE__) + ".#{$$}.test"
- end
-
- def test_store
- @yamldbm.store('a','b')
- @yamldbm.store('c','d')
- assert_equal 'b', @yamldbm['a']
- assert_equal 'd', @yamldbm['c']
- assert_nil @yamldbm['e']
- end
-
- def test_store_using_carret
- @yamldbm['a'] = 'b'
- @yamldbm['c'] = 'd'
- assert_equal 'b', @yamldbm['a']
- assert_equal 'd', @yamldbm['c']
- assert_nil @yamldbm['e']
- end
-
- def test_to_a
- @yamldbm['a'] = 'b'
- @yamldbm['c'] = 'd'
- assert_equal([['a','b'],['c','d']], @yamldbm.to_a.sort)
- end
-
- def test_to_hash
- @yamldbm['a'] = 'b'
- @yamldbm['c'] = 'd'
- assert_equal({'a'=>'b','c'=>'d'}, @yamldbm.to_hash)
- end
-
- def test_has_value?
- @yamldbm['a'] = 'b'
- @yamldbm['c'] = 'd'
- assert_equal true, @yamldbm.has_value?('b')
- assert_equal true, @yamldbm.has_value?('d')
- assert_equal false, @yamldbm.has_value?('f')
- end
-
- # Note:
- # YAML::DBM#index makes warning from internal of ::DBM#index.
- # It says 'DBM#index is deprecated; use DBM#key', but DBM#key
- # behaves not same as DBM#index.
- #
- # def test_index
- # @yamldbm['a'] = 'b'
- # @yamldbm['c'] = 'd'
- # assert_equal 'a', @yamldbm.index('b')
- # assert_equal 'c', @yamldbm.index('d')
- # assert_nil @yamldbm.index('f')
- # end
-
- def test_key
- @yamldbm['a'] = 'b'
- @yamldbm['c'] = 'd'
- assert_equal 'a', @yamldbm.key('b')
- assert_equal 'c', @yamldbm.key('d')
- assert_nil @yamldbm.key('f')
- end
-
- def test_fetch
- assert_equal('bar', @yamldbm['foo']='bar')
- assert_equal('bar', @yamldbm.fetch('foo'))
- assert_nil @yamldbm.fetch('bar')
- assert_equal('baz', @yamldbm.fetch('bar', 'baz'))
- assert_equal('foobar', @yamldbm.fetch('bar') {|key| 'foo' + key })
- end
-
- def test_shift
- @yamldbm['a'] = 'b'
- @yamldbm['c'] = 'd'
- assert_equal([['a','b'], ['c','d']],
- [@yamldbm.shift, @yamldbm.shift].sort)
- assert_nil @yamldbm.shift
- end
-
- def test_invert
- @yamldbm['a'] = 'b'
- @yamldbm['c'] = 'd'
- assert_equal({'b'=>'a','d'=>'c'}, @yamldbm.invert)
- end
-
- def test_update
- @yamldbm['a'] = 'b'
- @yamldbm['c'] = 'd'
- @yamldbm.update({'c'=>'d','e'=>'f'})
- assert_equal 'b', @yamldbm['a']
- assert_equal 'd', @yamldbm['c']
- assert_equal 'f', @yamldbm['e']
- end
-
- def test_replace
- @yamldbm['a'] = 'b'
- @yamldbm['c'] = 'd'
- @yamldbm.replace({'c'=>'d','e'=>'f'})
- assert_nil @yamldbm['a']
- assert_equal 'd', @yamldbm['c']
- assert_equal 'f', @yamldbm['e']
- end
-
- def test_delete
- @yamldbm['a'] = 'b'
- @yamldbm['c'] = 'd'
- assert_equal 'b', @yamldbm.delete('a')
- assert_nil @yamldbm['a']
- assert_equal 'd', @yamldbm['c']
- assert_nil @yamldbm.delete('e')
- end
-
- def test_delete_if
- @yamldbm['a'] = 'b'
- @yamldbm['c'] = 'd'
- @yamldbm['e'] = 'f'
-
- @yamldbm.delete_if {|k,v| k == 'a'}
- assert_nil @yamldbm['a']
- assert_equal 'd', @yamldbm['c']
- assert_equal 'f', @yamldbm['e']
-
- @yamldbm.delete_if {|k,v| v == 'd'}
- assert_nil @yamldbm['c']
- assert_equal 'f', @yamldbm['e']
-
- @yamldbm.delete_if {|k,v| false }
- assert_equal 'f', @yamldbm['e']
- end
-
- def test_reject
- @yamldbm['a'] = 'b'
- @yamldbm['c'] = 'd'
- @yamldbm['e'] = 'f'
- assert_equal({'c'=>'d','e'=>'f'}, @yamldbm.reject {|k,v| k == 'a'})
- assert_equal({'a'=>'b','e'=>'f'}, @yamldbm.reject {|k,v| v == 'd'})
- assert_equal({'a'=>'b','c'=>'d','e'=>'f'}, @yamldbm.reject {false})
- end
-
- def test_values
- assert_equal [], @yamldbm.values
- @yamldbm['a'] = 'b'
- @yamldbm['c'] = 'd'
- assert_equal ['b','d'], @yamldbm.values.sort
- end
-
- def test_values_at
- @yamldbm['a'] = 'b'
- @yamldbm['c'] = 'd'
- assert_equal ['b','d'], @yamldbm.values_at('a','c')
- end
-
- def test_selsct
- @yamldbm['a'] = 'b'
- @yamldbm['c'] = 'd'
- @yamldbm['e'] = 'f'
- assert_equal(['b','d'], @yamldbm.select('a','c'))
- end
-
- def test_selsct_with_block
- @yamldbm['a'] = 'b'
- @yamldbm['c'] = 'd'
- @yamldbm['e'] = 'f'
- assert_equal([['a','b']], @yamldbm.select {|k,v| k == 'a'})
- assert_equal([['c','d']], @yamldbm.select {|k,v| v == 'd'})
- assert_equal([], @yamldbm.select {false})
- end
- end
-end if defined?(YAML::DBM)
View
87 test/test_yamlstore.rb
@@ -1,87 +0,0 @@
-require 'test/unit'
-require 'yaml/store'
-require 'tmpdir'
-
-module Syck
- Store = YAML::Store unless defined?(Store)
-
- class YAMLStoreTest < Test::Unit::TestCase
- def setup
- @engine, YAML::ENGINE.yamler = YAML::ENGINE.yamler, 'syck'
- @dir = Dir.mktmpdir("rubytest-file")
- File.chown(-1, Process.gid, @dir)
- @yamlstore_file = make_tmp_filename("yamlstore")
- @yamlstore = YAML::Store.new(@yamlstore_file)
- end
-
- def teardown
- YAML::ENGINE.yamler = @engine
- FileUtils.remove_entry_secure @dir
- end
-
- def make_tmp_filename(prefix)
- @dir + "/" + prefix + File.basename(__FILE__) + ".#{$$}.test"
- end
-
- def test_opening_new_file_in_readonly_mode_should_result_in_empty_values
- @yamlstore.transaction(true) do
- assert_nil @yamlstore[:foo]
- assert_nil @yamlstore[:bar]
- end
- end
-
- def test_opening_new_file_in_readwrite_mode_should_result_in_empty_values
- @yamlstore.transaction do
- assert_nil @yamlstore[:foo]
- assert_nil @yamlstore[:bar]
- end
- end
-
- def test_data_should_be_loaded_correctly_when_in_readonly_mode
- @yamlstore.transaction do
- @yamlstore[:foo] = "bar"
- end
- @yamlstore.transaction(true) do
- assert_equal "bar", @yamlstore[:foo]
- end
- end
-
- def test_data_should_be_loaded_correctly_when_in_readwrite_mode
- @yamlstore.transaction do
- @yamlstore[:foo] = "bar"
- end
- @yamlstore.transaction do
- assert_equal "bar", @yamlstore[:foo]
- end
- end
-
- def test_changes_after_commit_are_discarded
- @yamlstore.transaction do
- @yamlstore[:foo] = "bar"
- @yamlstore.commit
- @yamlstore[:foo] = "baz"
- end
- @yamlstore.transaction(true) do
- assert_equal "bar", @yamlstore[:foo]
- end
- end
-
- def test_changes_are_not_written_on_abort
- @yamlstore.transaction do
- @yamlstore[:foo] = "bar"
- @yamlstore.abort
- end
- @yamlstore.transaction(true) do
- assert_nil @yamlstore[:foo]
- end
- end
-
- def test_writing_inside_readonly_transaction_raises_error
- assert_raise(PStore::Error) do
- @yamlstore.transaction(true) do
- @yamlstore[:foo] = "bar"
- end
- end
- end
- end
-end
Please sign in to comment.
Something went wrong with that request. Please try again.