-
Notifications
You must be signed in to change notification settings - Fork 0
/
project_config_test.rb
116 lines (103 loc) · 3.01 KB
/
project_config_test.rb
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# @BEGIN_LICENSE
#
# Halyard - Multimedia authoring and playback system
# Copyright 1993-2009 Trustees of Dartmouth College
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as
# published by the Free Software Foundation; either version 2.1 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
# USA.
#
# @END_LICENSE
require 'test/unit'
require 'fileutils'
require 'buildscript/project_config'
class ProjectConfigTest < Test::Unit::TestCase
def setup
rm_rf 'test_project_tmp'
mkdir_p 'test_project_tmp'
end
def teardown
rm_rf 'test_project_tmp'
end
def setup_config config
rm_rf 'config'
mkdir 'config'
File.open('config/project.conf', 'w') do |file|
file.write config
end
end
def run_test
FileUtils::cd 'test_project_tmp' do
yield
end
end
def assert_parsing_dies config
assert_raise RuntimeError do
run_test do
setup_config config
ProjectConfig.new
end
end
end
def test_key_value
run_test do
setup_config <<EOF
key = val
another-key=another-val
third_key = something
key4=blah
thisvalue=has spaces at the end
EOF
p = ProjectConfig.new
assert_equal "val", p['key']
assert_equal "another-val", p['another-key']
assert_equal "something", p['third_key']
assert_equal "blah", p['key4']
assert_equal "has spaces at the end", p['thisvalue']
end
end
def test_keys_in_section
run_test do
setup_config <<EOF
key_without_section = val
[section]
key = something
[new-section]
key1 = first
key2 = second
EOF
p = ProjectConfig.new
assert_equal "val", p['key_without_section']
assert_equal "something", p['section.key']
assert_equal "first", p['new-section.key1']
assert_equal "second", p['new-section.key2']
end
end
def test_errors
assert_parsing_dies "uknown"
assert_parsing_dies '[section with space]'
assert_parsing_dies '["sectionwithquotes"]'
assert_parsing_dies '[section=withequals]'
assert_parsing_dies '[section\with\escape]'
assert_parsing_dies 'key = "value with quotes"'
assert_parsing_dies 'key with space = value'
assert_parsing_dies 'key = value\ with\ escapes'
assert_parsing_dies 'key = value ; comment'
assert_parsing_dies 'key = value # comment'
assert_parsing_dies '\escape\in\key=value'
assert_parsing_dies '"quote"inkey = value'
assert_parsing_dies 'key=value with end quote"'
assert_parsing_dies 'key/with/slash=val'
end
end