forked from flapjack/flapjack
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinifile_spec.rb
66 lines (54 loc) · 2.29 KB
/
inifile_spec.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
#!/usr/bin/env ruby
require File.join(File.dirname(__FILE__), '..', 'lib', 'flapjack', 'inifile')
require File.join(File.dirname(__FILE__), 'helpers')
describe "inifile reader" do
it "should turn sections into keys" do
example = "[forks]\nhello = world\n[spoons]\nfoo = bar\n[splades]\nbar = baz"
ini = Flapjack::Inifile.new(example)
ini.keys.sort.should == %w{forks splades spoons}
end
it "should nest parameters under a section" do
example = "[forks]\nhello = world\n[spoons]\nfoo = bar\n[splades]\nbar = baz"
ini = Flapjack::Inifile.new(example)
ini['forks']['hello'].should == "world"
ini['spoons']['foo'].should == "bar"
ini['splades']['bar'].should == "baz"
end
it "should read a file" do
filename = File.join(File.dirname(__FILE__), 'simple.ini')
ini = Flapjack::Inifile.read(filename)
ini['forks']['hello'].should == "world"
ini['spoons']['foo'].should == "bar"
ini['splades']['bar'].should == "baz"
end
it "should ignore commented lines" do
example = "[forks]\nhello = world\n[spoons]\nfoo = bar\n# comment goes here\n[splades]\nbar = baz"
ini = Flapjack::Inifile.new(example)
ini['spoons'].keys.include?(/#/).should be_false
ini['spoons'].keys.include?(/comment goes here/).should be_false
ini['spoons'].values.include?(/#/).should be_false
ini['spoons'].values.include?(/comment goes here/).should be_false
end
it "should ignore blank lines" do
example = "\n\n\n\n\n\n\n[spoons]\n\n\n\n[of]\n[doom]"
ini = Flapjack::Inifile.new(example)
ini.keys.sort.should == %w(doom of spoons)
end
it "should ignore mid-line comments" do
example = "[forks] ; a comment \nhello = world ; another comment\n\n"
ini = Flapjack::Inifile.new(example)
ini.keys.include?("forks").should be_true
ini['forks']['hello'].should == 'world'
end
it "should append re-opened sections" do
example = "[forks]\nhello = world\n[forks]\nfoo = bar\n\n[forks]\nbar = baz"
ini = Flapjack::Inifile.new(example)
ini.keys.include?("forks").should be_true
ini["forks"].keys.sort.should == %w(bar foo hello)
end
it "should dump the raw config" do
example = "[forks]\nhello = world\n[spoons]\nfoo = bar\n[splades]\nbar = baz"
ini = Flapjack::Inifile.new(example)
ini.all.size.should == 3
end
end