OSDN Git Service

Merge branch '201312-fix-sacrifice'
[shogi-server/shogi-server.git] / test / TC_config.rb
1 $:.unshift File.join(File.dirname(__FILE__), "..")
2 require 'test/unit'
3 $topdir = File.expand_path(File.dirname(__FILE__))
4 require 'shogi_server/config'
5
6
7 class TestHash < Test::Unit::TestCase
8   def test_merge1
9     a = {:a => 1}
10     b = {:a => 2}
11     a.merge! b
12     assert_equal({:a => 2}, a)
13   end
14
15   def test_merge2
16     a = {:a => 1}
17     b = {:b => 2}
18     a.merge! b
19     assert_equal({:a => 1, :b => 2}, a)
20   end
21
22   def test_merge3
23     a = {:a => {:aa => 1}}
24     b = {:a => {:aa => 2}}
25     a.merge! b
26     assert_equal({:a => {:aa => 2}}, a)
27   end
28
29   def test_merge4
30     a = {:a => 1}
31     b = {:a => {:aa => 2}}
32     a.merge! b
33     assert_equal({:a => {:aa => 2}}, a)
34   end
35 end
36
37
38 class TestConfig < Test::Unit::TestCase
39   def setup
40     remove_config_file
41   end
42
43   def teardown
44     remove_config_file
45   end
46
47   def remove_config_file
48     delete_file File.join(File.expand_path(File.dirname(__FILE__)), 
49                           ShogiServer::Config::FILENAME)
50     delete_file File.join("/", "tmp", ShogiServer::Config::FILENAME)
51   end
52
53   def delete_file(path)
54     if File.exist? path
55       File.delete path
56     end
57   end
58
59   def test_top_dir1
60     expected = File.expand_path(File.dirname(__FILE__)) 
61     assert_equal expected, $topdir
62
63     conf = ShogiServer::Config.new
64     assert_equal expected, conf[:topdir]
65   end
66
67   def test_top_dir2
68     assert !File.exist?(File.join("/", "tmp", ShogiServer::Config::FILENAME))
69     conf = ShogiServer::Config.new({:topdir => "/tmp"})
70     assert_equal "/tmp", conf[:topdir]
71   end
72
73   def test_braces1
74     conf = ShogiServer::Config.new({:a => 1})
75     assert_equal 1, conf[:a]
76   end
77
78   def test_braces2
79     conf = ShogiServer::Config.new({:a => {:b => 1}})
80     assert_equal 1, conf[:a, :b]
81   end
82
83   def test_braces3
84     conf = ShogiServer::Config.new({:a => {:b => 1}})
85     assert_equal nil, conf[:b]
86   end
87 end
88