summaryrefslogtreecommitdiff
path: root/test/psych/test_engine_manager.rb
blob: 33a67432ebca7b0456634176001addd7a6a479fa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
require_relative 'helper'
require 'yaml'

module Psych
 class TestEngineManager < TestCase
   def test_bad_engine
     assert_raises(ArgumentError) do
       YAML::ENGINE.yamler = 'foooo'
     end
   end

   def test_set_psych
     YAML::ENGINE.yamler = 'psych'
     assert_equal Psych, YAML
     assert_equal 'psych', YAML::ENGINE.yamler
   end

   A = Struct.new(:name)

   def test_dump_types
     YAML::ENGINE.yamler = 'psych'

     assert_to_yaml ::Object.new
     assert_to_yaml Time.now
     assert_to_yaml Date.today
     assert_to_yaml('a' => 'b')
     assert_to_yaml A.new('foo')
     assert_to_yaml %w{a b}
     assert_to_yaml Exception.new('foo')
     assert_to_yaml "hello!"
     assert_to_yaml :fooo
     assert_to_yaml(1..10)
     assert_to_yaml(/hello!~/)
     assert_to_yaml 1
     assert_to_yaml 1.2
     assert_to_yaml Rational(1, 2)
     assert_to_yaml Complex(1, 2)
     assert_to_yaml true
     assert_to_yaml false
     assert_to_yaml nil
   end

   def assert_to_yaml obj
     assert obj.to_yaml, "#{obj.class} to_yaml works"
   end
 end
end