Skip to content
This repository has been archived by the owner on May 28, 2019. It is now read-only.

Issue #309 - Makes I18n.get raises correctly when receiving invalid iso_code #310

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions java/src/main/java/gherkin/I18n.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ public I18n(String isoCode) {
this.keywords = new HashMap<String, List<String>>();

Map<String, String> keywordMap = I18N.get(isoCode);

if (keywordMap == null) {
throw new RuntimeException("Language not supported: \"" + isoCode + "\"");
}

for (Map.Entry<String, String> entry : keywordMap.entrySet()) {
List<String> keywordList = Arrays.asList(entry.getValue().split("\\|"));
if (STEP_KEYWORD_KEYS.contains(entry.getKey())) {
Expand Down
2 changes: 1 addition & 1 deletion lib/gherkin/i18n.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def languages
def initialize(iso_code)
@iso_code = iso_code
@keywords = LANGUAGES[iso_code]
raise "Language not supported: #{iso_code.inspect}" if @iso_code.nil?
raise "Language not supported: #{iso_code.inspect}" if @keywords.nil?
@keywords['grammar_name'] = @keywords['name'].gsub(/\s/, '')
end

Expand Down
9 changes: 9 additions & 0 deletions spec/gherkin/i18n_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,15 @@ def scan_file(lexer, file)
]
end

it "should not raise error if iso_code is valid" do
expect { Gherkin::I18n.get('pt') }.to_not raise_error
end

it "should raise error if iso_code is not valid" do
error_msg = 'Language not supported: "non-valid-iso_code"'
expect { Gherkin::I18n.get('non-valid-iso_code') }.to raise_error(error_msg)
end

describe 'keywords' do
it "should have code keywords without space, comma, exclamation or apostrophe" do
['Avast', 'Akkor', 'Etantdonné', 'Lorsque', '假設'].each do |code_keyword|
Expand Down