-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #67 from cucumber/optional-capture-groups
Add tests to highlight mapping of optional capture groups
- Loading branch information
Showing
3 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
scala/sources/src/test/resources/tests/misc/OptionalCaptureGroups.feature
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,7 @@ | ||
Feature: Optional capture groups are supported | ||
|
||
Scenario: present, using Java's Optional | ||
Given I have the name: Jack | ||
|
||
Scenario: absent, using Java's Optional | ||
Given I don't have the name: |
35 changes: 35 additions & 0 deletions
35
scala/sources/src/test/scala/tests/misc/OptionalCaptureGroupsSteps.scala
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,35 @@ | ||
package tests.misc | ||
|
||
import java.util.Optional | ||
|
||
import io.cucumber.scala.{EN, ScalaDsl} | ||
|
||
class OptionalCaptureGroupsSteps extends ScalaDsl with EN { | ||
|
||
// Scala 2.13 only | ||
// import scala.jdk.OptionConverters._ | ||
|
||
import OptionalCaptureGroupsSteps._ | ||
|
||
Given("""^I have the name:\s?(.+)?$""") { (name: Optional[String]) => | ||
val option = name.toScala | ||
assert(option.isDefined) | ||
assert(option.getOrElse("Nope") == "Jack") | ||
} | ||
|
||
Given("""^I don't have the name:\s?(.+)?$""") { (name: Optional[String]) => | ||
val option = name.toScala | ||
assert(option.isEmpty) | ||
} | ||
|
||
} | ||
|
||
object OptionalCaptureGroupsSteps { | ||
|
||
implicit class RichOptional[A](private val o: java.util.Optional[A]) extends AnyVal { | ||
|
||
def toScala: Option[A] = if (o.isPresent) Some(o.get) else None | ||
|
||
} | ||
|
||
} |
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,8 @@ | ||
package tests.misc | ||
|
||
import io.cucumber.junit.{Cucumber, CucumberOptions} | ||
import org.junit.runner.RunWith | ||
|
||
@RunWith(classOf[Cucumber]) | ||
@CucumberOptions(strict = true) | ||
class RunMiscTest |