summaryrefslogtreecommitdiff
path: root/test/psych/test_coder.rb
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2010-02-02 20:54:42 -0800
committerAaron Patterson <aaron.patterson@gmail.com>2010-02-02 20:54:42 -0800
commit182f450bd8b60a1b615db517e54d74c8a836e2a1 (patch)
tree14475168b6f9c4693ad42d232d68b66b213d8960 /test/psych/test_coder.rb
parent35ca1ca580905574a075ccb4ec032744954e6f0b (diff)
downloadpsych-182f450bd8b60a1b615db517e54d74c8a836e2a1.tar.gz
represent scalar workscoder
Diffstat (limited to 'test/psych/test_coder.rb')
-rw-r--r--test/psych/test_coder.rb30
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