Skip to content

Commit

Permalink
Simplify type matcher tests with shared examples
Browse files Browse the repository at this point in the history
  • Loading branch information
Yury Bushmelev committed Dec 3, 2024
1 parent a0fc8ff commit 16d686b
Showing 1 changed file with 12 additions and 22 deletions.
34 changes: 12 additions & 22 deletions spec/unit/puppet-lint/lexer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1359,6 +1359,14 @@
end

context ':TYPE' do
shared_examples 'a type matcher' do |type|
it "matches #{type}" do
token = lexer.tokenise(type).first
expect(token.type).to eq(:TYPE)
expect(token.value).to eq(type)
end
end

it 'matches Data Types' do
token = lexer.tokenise('Integer').first
expect(token.type).to eq(:TYPE)
Expand All @@ -1378,30 +1386,12 @@
end

describe 'Platform Types' do
it 'matches Callable' do
token = lexer.tokenise('Callable').first
expect(token.type).to eq(:TYPE)
expect(token.value).to eq('Callable')
end

it 'matches Sensitive' do
token = lexer.tokenise('Sensitive').first
expect(token.type).to eq(:TYPE)
expect(token.value).to eq('Sensitive')
end
it_behaves_like 'a type matcher', 'Callable'
it_behaves_like 'a type matcher', 'Sensitive'
end

it 'matches Error type' do
token = lexer.tokenise('Error').first
expect(token.type).to eq(:TYPE)
expect(token.value).to eq('Error')
end

it 'matches Binary type' do
token = lexer.tokenise('Binary').first
expect(token.type).to eq(:TYPE)
expect(token.value).to eq('Binary')
end
it_behaves_like 'a type matcher', 'Error'
it_behaves_like 'a type matcher', 'Binary'
end

context ':HEREDOC without interpolation' do
Expand Down

0 comments on commit 16d686b

Please sign in to comment.