-
Notifications
You must be signed in to change notification settings - Fork 203
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
59f905b
commit bffb39d
Showing
17 changed files
with
213 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,22 @@ | |||
#include <psych.h> | |||
|
|||
VALUE cPsychVisitorsToRuby; | |||
|
|||
static VALUE build_exception(VALUE self, VALUE klass, VALUE mesg) | |||
{ | |||
VALUE e = rb_obj_alloc(klass); | |||
|
|||
rb_iv_set(e, "mesg", mesg); | |||
|
|||
return e; | |||
} | |||
|
|||
void Init_psych_to_ruby(void) | |||
{ | |||
VALUE psych = rb_define_module("Psych"); | |||
VALUE visitors = rb_define_module_under(psych, "Visitors"); | |||
VALUE visitor = rb_define_class_under(visitors, "Visitor", rb_cObject); | |||
cPsychVisitorsToRuby = rb_define_class_under(visitors, "ToRuby", visitor); | |||
|
|||
rb_define_method(cPsychVisitorsToRuby, "build_exception", build_exception, 2); | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,8 @@ | |||
#ifndef PSYCH_TO_RUBY_H | |||
#define PSYCH_TO_RUBY_H | |||
|
|||
#include <psych.h> | |||
|
|||
void Init_psych_to_ruby(); | |||
|
|||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,2 @@ | |||
require 'test/unit' | |||
require 'psych' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters