summaryrefslogtreecommitdiff
path: root/test/yaml
diff options
context:
space:
mode:
Diffstat (limited to 'test/yaml')
-rw-r--r--test/yaml/test_array.rb17
-rw-r--r--test/yaml/test_class.rb17
-rw-r--r--test/yaml/test_exception.rb45
-rw-r--r--test/yaml/test_hash.rb17
-rw-r--r--test/yaml/test_string.rb5
-rw-r--r--test/yaml/test_symbol.rb21
-rw-r--r--test/yaml/test_yaml.rb2
7 files changed, 118 insertions, 6 deletions
diff --git a/test/yaml/test_array.rb b/test/yaml/test_array.rb
new file mode 100644
index 0000000..208c996
--- /dev/null
+++ b/test/yaml/test_array.rb
@@ -0,0 +1,17 @@
+require 'helper'
+
+module YAML
+ class TestArray < Test::Unit::TestCase
+ def setup
+ @list = [{ :a => 'b' }, 'foo']
+ 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))
+ end
+ end
+end
diff --git a/test/yaml/test_class.rb b/test/yaml/test_class.rb
new file mode 100644
index 0000000..effa852
--- /dev/null
+++ b/test/yaml/test_class.rb
@@ -0,0 +1,17 @@
+require 'helper'
+
+module YAML
+ class TestClass < Test::Unit::TestCase
+ def test_to_yaml
+ assert_raises(::TypeError) do
+ TestClass.to_yaml
+ end
+ end
+
+ def test_dump
+ assert_raises(::TypeError) do
+ YAML.dump TestClass
+ end
+ end
+ end
+end
diff --git a/test/yaml/test_exception.rb b/test/yaml/test_exception.rb
new file mode 100644
index 0000000..f646008
--- /dev/null
+++ b/test/yaml/test_exception.rb
@@ -0,0 +1,45 @@
+require 'helper'
+
+module YAML
+ class TestException < Test::Unit::TestCase
+ class Wups < Exception
+ attr_reader :foo, :bar
+ def initialize *args
+ super
+ @foo = 1
+ @bar = 2
+ end
+ end
+
+ def setup
+ @wups = Wups.new
+ end
+
+ def test_to_yaml
+ w = YAML.load(@wups.to_yaml)
+ assert_equal @wups, w
+ assert_equal 1, w.foo
+ assert_equal 2, w.bar
+ end
+
+ def test_dump
+ w = YAML.load(@wups.to_yaml)
+ assert_equal @wups, w
+ assert_equal 1, w.foo
+ assert_equal 2, w.bar
+ end
+
+ def test_to_yaml_properties
+ class << @wups
+ def to_yaml_properties
+ [:@foo]
+ end
+ end
+
+ w = YAML.load(YAML.dump(@wups))
+ assert_equal @wups, w
+ assert_equal 1, w.foo
+ assert_nil w.bar
+ end
+ end
+end
diff --git a/test/yaml/test_hash.rb b/test/yaml/test_hash.rb
new file mode 100644
index 0000000..e8869ae
--- /dev/null
+++ b/test/yaml/test_hash.rb
@@ -0,0 +1,17 @@
+require 'helper'
+
+module YAML
+ class TestHash < Test::Unit::TestCase
+ 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))
+ end
+ end
+end
diff --git a/test/yaml/test_string.rb b/test/yaml/test_string.rb
index 7857672..637d65b 100644
--- a/test/yaml/test_string.rb
+++ b/test/yaml/test_string.rb
@@ -1,7 +1,4 @@
-require 'test/unit'
-require 'psych'
-
-YAML = Psych
+require 'helper'
module YAML
class TestString < Test::Unit::TestCase
diff --git a/test/yaml/test_symbol.rb b/test/yaml/test_symbol.rb
new file mode 100644
index 0000000..c4f77c4
--- /dev/null
+++ b/test/yaml/test_symbol.rb
@@ -0,0 +1,21 @@
+require 'helper'
+
+module YAML
+ class TestSymbol < Test::Unit::TestCase
+ def test_to_yaml
+ assert_equal :a, YAML.load(:a.to_yaml)
+ end
+
+ def test_dump
+ assert_equal :a, YAML.load(YAML.dump(:a))
+ end
+
+ def test_stringy
+ assert_equal :"1", YAML.load(YAML.dump(:"1"))
+ end
+
+ def test_load_quoted
+ assert_equal :"1", YAML.load("--- :'1'\n")
+ end
+ end
+end
diff --git a/test/yaml/test_yaml.rb b/test/yaml/test_yaml.rb
index fbe33cd..b40279f 100644
--- a/test/yaml/test_yaml.rb
+++ b/test/yaml/test_yaml.rb
@@ -6,8 +6,6 @@ require 'test/unit'
require 'rational'
require 'psych'
-YAML = Psych
-
# [ruby-core:01946]
module YAML_Tests
StructTest = Struct::new( :c )