-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Core] Rewrite # language: tl to # language: te
With cucumber/common#1238 the iso code of Telugu was fixed from `tl` to `te`. To ensure this does not break Cucumber-JVM until it has gone through a deprecation cycle we rewrite ``# language: tl` to `# language: te` and warn about the deprecation.
- Loading branch information
1 parent
5c19bf4
commit ab27641
Showing
6 changed files
with
137 additions
and
50 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
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
26 changes: 26 additions & 0 deletions
26
core/src/main/java/io/cucumber/core/feature/LanguageParser.java
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,26 @@ | ||
package io.cucumber.core.feature; | ||
|
||
import io.cucumber.core.logging.Logger; | ||
import io.cucumber.core.logging.LoggerFactory; | ||
|
||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
/** | ||
* Parser for the {@code # language: <iso-code> } header. Replaces changed ISO | ||
* codes for backwards compatibility. | ||
*/ | ||
class LanguageParser { | ||
private static final Logger log = LoggerFactory.getLogger(FeatureParser.class); | ||
private static final Pattern LANGUAGE_PATTERN = Pattern.compile("^(\\s*#\\s*language\\s*:\\s*)tl"); | ||
|
||
String parse(String feature) { | ||
Matcher matcher = LANGUAGE_PATTERN.matcher(feature); | ||
if (matcher.find()) { | ||
log.warn( | ||
() -> "The ISO 639-1 code for Telugu was changed from tl to te. Please use '# language: te' in your feature files."); | ||
return matcher.replaceFirst("$1te"); | ||
} | ||
return feature; | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
core/src/test/java/io/cucumber/core/feature/EncodingParserTest.java
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,44 @@ | ||
package io.cucumber.core.feature; | ||
|
||
import io.cucumber.core.resource.Resource; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.io.FileInputStream; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.net.URI; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
|
||
class EncodingParserTest { | ||
|
||
private final EncodingParser parser = new EncodingParser(); | ||
|
||
@Test | ||
void test_utf8_bom_encode() throws RuntimeException, IOException { | ||
Resource resource = resource("src/test/resources/io/cucumber/core/feature/UTF_8_BOM_Encoded.feature"); | ||
assertFalse(parser.parse(resource).startsWith("\uFEFF"), "UTF-8 BOM encoding not removed."); | ||
} | ||
|
||
@Test | ||
void test_utf8_encode() throws RuntimeException, IOException { | ||
Resource resource = resource("src/test/resources/io/cucumber/core/feature/UTF_8_Encoded.feature"); | ||
assertFalse(parser.parse(resource).startsWith("\uFEFF"), "UTF-8 BOM encoding should not be present."); | ||
} | ||
|
||
private Resource resource(String name) { | ||
Resource resource = new Resource() { | ||
@Override | ||
public URI getUri() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public InputStream getInputStream() throws IOException { | ||
|
||
return new FileInputStream(name); | ||
} | ||
}; | ||
return resource; | ||
} | ||
} |
35 changes: 0 additions & 35 deletions
35
core/src/test/java/io/cucumber/core/feature/EncodingTest.java
This file was deleted.
Oops, something went wrong.
52 changes: 52 additions & 0 deletions
52
core/src/test/java/io/cucumber/core/feature/FeatureParserTest.java
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,52 @@ | ||
package io.cucumber.core.feature; | ||
|
||
import io.cucumber.core.gherkin.Feature; | ||
import io.cucumber.core.resource.Resource; | ||
import org.hamcrest.CoreMatchers; | ||
import org.hamcrest.MatcherAssert; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.net.URI; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.Optional; | ||
import java.util.UUID; | ||
|
||
import static java.nio.charset.StandardCharsets.UTF_8; | ||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.hamcrest.CoreMatchers.not; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.collection.IsEmptyIterable.emptyIterable; | ||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
class FeatureParserTest { | ||
|
||
FeatureParser featureParser = new FeatureParser(UUID::randomUUID); | ||
|
||
@Test | ||
void renamesDeprecatedTeToTl() { | ||
Feature feature = featureParser.parseResource(resource("" + | ||
"# language: tl\n" + | ||
"గుణము: Test feature\n" + | ||
" ఉదాహరణ: Test scenario\n" + | ||
" చెప్పబడినది some text\n")).get(); | ||
assertThat(feature.getPickles().get(0).getLanguage(), is("te")); | ||
} | ||
|
||
private Resource resource(String feature) { | ||
return new Resource() { | ||
@Override | ||
public URI getUri() { | ||
return URI.create("file:test.feature"); | ||
} | ||
|
||
@Override | ||
public InputStream getInputStream() { | ||
return new ByteArrayInputStream(feature.getBytes(UTF_8)); | ||
} | ||
}; | ||
} | ||
|
||
} |