-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
bas smit
committed
Mar 4, 2018
1 parent
5976962
commit 36a5517
Showing
1 changed file
with
142 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
require 'spec_helper' | ||
|
||
describe 'parameter_types' do | ||
let(:msg) { 'missing datatype for parameter spec::%s' } | ||
|
||
[ 'class', 'define' ].each do | rt | | ||
context "#{rt} without parameters" do | ||
let(:code) { 'class spec() {}' } | ||
it 'should not be a problem' do | ||
expect(problems).to have(0).problem | ||
end | ||
end | ||
context "simple #{rt} without type" do | ||
let(:code) { 'class spec($foo) { }' } | ||
it 'should be a problem' do | ||
expect(problems).to have(1).problem | ||
expect(problems).to contain_warning(msg % :foo).on_line(1) | ||
end | ||
end | ||
|
||
context "#{rt} with many params without type" do | ||
let(:code) do | ||
<<-EOL | ||
class spec ( | ||
$attr1, | ||
$attr2, | ||
$attr3 | ||
) { } | ||
EOL | ||
end | ||
it 'should be a problem' do | ||
expect(problems).to have(3).problem | ||
end | ||
end | ||
context "#{rt} with many params without type on one line" do | ||
let(:code) { 'class spec ($attr1, $attr2, $attr3 ) { }' } | ||
it 'should be a problem' do | ||
expect(problems).to have(3).problem | ||
end | ||
end | ||
context "#{rt} with many params and defaults without type" do | ||
let(:code) do | ||
<<-EOL | ||
class spec ( | ||
$attr0, | ||
$attr1 = 1, | ||
$attr2 = $attr1, | ||
$attr3 = [ 'array', 'with', 'entries'], | ||
$attr4 = { 'key' => 'value' } | ||
$attr5 = { | ||
'key' => 'value', | ||
'key2' => [ | ||
'val1', | ||
'val2', | ||
], | ||
}, | ||
) { } | ||
EOL | ||
end | ||
it 'should be a problem' do | ||
expect(problems).to have(5).problem | ||
end | ||
end | ||
|
||
context "#{rt} with some attributes typed" do | ||
let(:code) do | ||
<<-EOL | ||
class spec ( | ||
Integer $attr1, | ||
String $attr2 = 'foo', | ||
$attr3 = undef, | ||
$attr4 = { 'key' => 'value' } | ||
Array[Struct[{ | ||
name => String[1], | ||
source_url => String[1], | ||
delete => Optional[Boolean], | ||
exclude => Optional[Variant[String,Array[String]]], | ||
include => Optional[Variant[String,Array[String]]], | ||
sync_hour => Optional[String], | ||
}]] $repos = [], | ||
Hash $attr5 = { | ||
'key' => 'value', | ||
'key2' => [ | ||
'val1', | ||
'val2', | ||
], | ||
}, | ||
) { } | ||
EOL | ||
end | ||
it 'should be a problem' do | ||
expect(problems).to have(2).problem | ||
end | ||
end | ||
context "#{rt} with some attributes typed on one line" do | ||
let(:code) { 'class spec(Integer $attr1, $attr2 = 5, Variant[String,Integer] $attr 3, $attr4 = [1,2]) { }' } | ||
it 'should be a problem' do | ||
expect(problems).to have(2).problem | ||
end | ||
end | ||
|
||
context "#{rt} with all attributes typed" do | ||
let(:code) do | ||
<<-EOL | ||
class spec ( | ||
Integer $attr1, | ||
String $attr2 = 'foo', | ||
Optional[String] $attr3 = undef, | ||
Optional[Variant[Integer,Array[String] $attr4 = undef, | ||
Stdlib::MyType $attr5 = undef, | ||
) { } | ||
EOL | ||
end | ||
it 'should not be a problem' do | ||
expect(problems).to have(0).problem | ||
end | ||
end | ||
context "#{rt} with all attributes typed complex" do | ||
let(:code) do | ||
<<-EOL | ||
class spec ( | ||
Integer $attr1, | ||
String $attr2 = 'foo', | ||
Optional[String] $attr3 = undef, | ||
Optional[Variant[Integer,Array[String] $attr4, | ||
Array[Struct[{ | ||
name => String[1], | ||
source_url => String[1], | ||
delete => Optional[Boolean], | ||
exclude => Optional[Variant[String,Array[String]]], | ||
include => Optional[Variant[String,Array[String]]], | ||
sync_hour => Optional[String], | ||
}]] $repos = [], | ||
) { } | ||
EOL | ||
end | ||
it 'should not be a problem' do | ||
expect(problems).to have(0).problem | ||
end | ||
end | ||
end | ||
end |