diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2010-02-02 20:54:42 -0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2010-02-02 20:54:42 -0800 |
commit | 182f450bd8b60a1b615db517e54d74c8a836e2a1 (patch) | |
tree | 14475168b6f9c4693ad42d232d68b66b213d8960 /test/psych/test_coder.rb | |
parent | 35ca1ca580905574a075ccb4ec032744954e6f0b (diff) | |
download | psych-182f450bd8b60a1b615db517e54d74c8a836e2a1.tar.gz |
represent scalar workscoder
Diffstat (limited to 'test/psych/test_coder.rb')
-rw-r--r-- | test/psych/test_coder.rb | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/test/psych/test_coder.rb b/test/psych/test_coder.rb index 1ce3c4c..95aef65 100644 --- a/test/psych/test_coder.rb +++ b/test/psych/test_coder.rb @@ -44,6 +44,36 @@ module Psych end end + class Represent + yaml_tag 'foo' + def encode_with coder + coder.represent_scalar 'foo', 'bar' + end + end + + class RepresentWithInit + yaml_tag name + attr_accessor :str + + def init_with coder + @str = coder.scalar + end + + def encode_with coder + coder.represent_scalar self.class.name, 'bar' + end + end + + def test_represent_with_init + thing = Psych.load(Psych.dump(RepresentWithInit.new)) + assert_equal 'bar', thing.str + end + + def test_represent! + assert_match(/foo/, Psych.dump(Represent.new)) + assert_instance_of(Represent, Psych.load(Psych.dump(Represent.new))) + end + def test_scalar_coder foo = Psych.load(Psych.dump(ScalarCoder.new)) assert_equal 'foo', foo |