mirror of
https://github.com/inspec/inspec
synced 2025-02-17 06:28:40 +00:00
add tests for simple config
Signed-off-by: Dominik Richter <dominik.richter@gmail.com>
This commit is contained in:
parent
2d8b63cb22
commit
4d70aed6ee
1 changed files with 75 additions and 0 deletions
75
test/unit/simpleconfig_test.rb
Normal file
75
test/unit/simpleconfig_test.rb
Normal file
|
@ -0,0 +1,75 @@
|
|||
# encoding: utf-8
|
||||
require 'helper'
|
||||
|
||||
describe 'SimpleConfig' do
|
||||
describe 'default parser' do
|
||||
it 'should parse an empty string' do
|
||||
cur = SimpleConfig.new('')
|
||||
cur.params.must_equal({})
|
||||
end
|
||||
|
||||
it 'should parse only spaces' do
|
||||
cur = SimpleConfig.new(' ')
|
||||
cur.params.must_equal({})
|
||||
end
|
||||
|
||||
it 'should parse only tabs' do
|
||||
cur = SimpleConfig.new("\t")
|
||||
cur.params.must_equal({})
|
||||
end
|
||||
|
||||
it 'should parse only newlines' do
|
||||
cur = SimpleConfig.new("\n")
|
||||
cur.params.must_equal({})
|
||||
end
|
||||
|
||||
it 'should parse a simple assignment' do
|
||||
cur = SimpleConfig.new('a = b')
|
||||
cur.params.must_equal({ 'a' => 'b' })
|
||||
end
|
||||
|
||||
it 'should parse a multiple assignments' do
|
||||
cur = SimpleConfig.new("a = b\n\nc = d")
|
||||
cur.params.must_equal({ 'a' => 'b', 'c' => 'd' })
|
||||
end
|
||||
|
||||
it 'handles files with only comments' do
|
||||
cur = SimpleConfig.new('#a comment')
|
||||
cur.params.must_equal({})
|
||||
end
|
||||
|
||||
it 'handles separate comments and assignments' do
|
||||
cur = SimpleConfig.new("# hello world\n\na = b")
|
||||
cur.params.must_equal({ 'a' => 'b' })
|
||||
end
|
||||
|
||||
it 'handles comments and assignments combined' do
|
||||
cur = SimpleConfig.new('a = b# hello')
|
||||
cur.params.must_equal({ 'a' => 'b' })
|
||||
end
|
||||
|
||||
it 'handles groups' do
|
||||
cur = SimpleConfig.new('[g]')
|
||||
cur.params.must_equal({ 'g' => {} })
|
||||
end
|
||||
|
||||
it 'handles non-group assignments and groups' do
|
||||
cur = SimpleConfig.new("a = b\n[g]")
|
||||
cur.params.must_equal({ 'a' => 'b', 'g' => {} })
|
||||
end
|
||||
|
||||
it 'handles assignments in groups' do
|
||||
cur = SimpleConfig.new("[g]\na = b")
|
||||
cur.params.must_equal({ 'g' => { 'a' => 'b' } })
|
||||
end
|
||||
|
||||
it 'handles multiple groups' do
|
||||
cur = SimpleConfig.new("[g]\na = b\n[k]\n\nc = d")
|
||||
res = {
|
||||
'g' => { 'a' => 'b' },
|
||||
'k' => { 'c' => 'd' },
|
||||
}
|
||||
cur.params.must_equal(res)
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Reference in a new issue