Skip to content

Commit

Permalink
fix: detection of floats with multiple leading numbers (#2)
Browse files Browse the repository at this point in the history
Co-authored-by: Jakub Sobolewski <[email protected]>
  • Loading branch information
jakubsob and Jakub Sobolewski committed Jun 9, 2024
1 parent d23003b commit 1221cd4
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 12 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@
^pkgdown$
^doc$
^Meta$
^cran-comments\.md$
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: cucumber
Type: Package
Title: Behavior-Driven Development for R
Version: 1.0.1
Version: 1.0.3
Authors@R: person("Jakub", "Sobolewski", email = "[email protected]", role = c("aut", "cre"))
Description: Write executable specifications in a natural language that describes how your code should behave.
Write specifications in feature files using 'Gherkin' language and execute them using functions implemented in R.
Expand Down
8 changes: 8 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# cucumber 1.0.3

- Fixed float detection with multiple leading numbers, e.g. `11.1`, `+11.1`, `-11.1`.

# cucumber 1.0.2

- Fixed CRAN debian checks.

# cucumber 1.0.1

- ✨ Changed how `{string}` parameter is matched. It now matches on text in quotes. A step `Given I have a {string}` will match on `Given I have a "foo bar"`. This change brings the parser closer to how the original [cucumber expressions](https://github.com/cucumber/cucumber-expressions) work.
Expand Down
2 changes: 1 addition & 1 deletion R/parameter.R
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ set_default_parameters <- function() {

define_parameter_type(
name = "float",
regexp = "[+-]?[[:digit:]+]?\\.[:digit:]+",
regexp = "[+-]?[:digit:]*?\\.[:digit:]+",
transformer = as.double
)

Expand Down
5 changes: 5 additions & 0 deletions cran-comments.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## R CMD check results

0 errors | 0 warnings | 1 note

* This is a new release.
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,9 @@ Feature: Addition
Scenario: Adding float and float
When I add 1.1 and 1.1
Then the result is 2.2
Scenario: Adding float and float with signs
When I add +11.1 and +11.1
Then the result is +22.2
Scenario: Adding float and float of opposite signs
When I add +11.11 and -11.1
Then the result is +0.01
16 changes: 8 additions & 8 deletions tests/testthat/_snaps/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
show_praise = FALSE), stop_on_failure = FALSE)
Output
v | F W S OK | Context
v | 3 | Feature: Addition
v | 5 | Feature: Addition
v | 2 | Feature: Guess the word
== Results =====================================================================
[ FAIL 0 | WARN 0 | SKIP 0 | PASS 5 ]
[ FAIL 0 | WARN 0 | SKIP 0 | PASS 7 ]

# test: should run with box

Expand Down Expand Up @@ -171,15 +171,15 @@
Backtrace:
x
1. \-global `<step>`(expected = 5L, context = `<env>`)
2. \-testthat::expect_equal(context$result, expected) at ./steps/addition.R:7:2
2. \-testthat::expect_equal(context$result, expected) at ./steps/addition.R:7:3
Failure ('test-cucumber.R:1:1'): Scenario: Adding float and float
context$result (`actual`) not equal to `expected` (`expected`).
`actual`: 2
`expected`: 5
Backtrace:
x
1. \-global `<step>`(expected = 5L, context = `<env>`)
2. \-testthat::expect_equal(context$result, expected) at ./steps/addition.R:7:2
2. \-testthat::expect_equal(context$result, expected) at ./steps/addition.R:7:3
--------------------------------------------------------------------------------
x | 1 1 | Feature: Guess the word
--------------------------------------------------------------------------------
Expand All @@ -190,7 +190,7 @@
Backtrace:
x
1. \-global `<step>`(n = 6L, context = `<env>`)
2. \-testthat::expect_equal(nchar(context$word), n) at ./steps/guess_the_word.R:18:2
2. \-testthat::expect_equal(nchar(context$word), n) at ./steps/guess_the_word.R:18:3
--------------------------------------------------------------------------------
== Results =====================================================================
-- Failed tests ----------------------------------------------------------------
Expand All @@ -201,22 +201,22 @@
Backtrace:
x
1. \-global `<step>`(expected = 5L, context = `<env>`)
2. \-testthat::expect_equal(context$result, expected) at ./steps/addition.R:7:2
2. \-testthat::expect_equal(context$result, expected) at ./steps/addition.R:7:3
Failure ('test-cucumber.R:1:1'): Scenario: Adding float and float
context$result (`actual`) not equal to `expected` (`expected`).
`actual`: 2
`expected`: 5
Backtrace:
x
1. \-global `<step>`(expected = 5L, context = `<env>`)
2. \-testthat::expect_equal(context$result, expected) at ./steps/addition.R:7:2
2. \-testthat::expect_equal(context$result, expected) at ./steps/addition.R:7:3
Failure ('test-cucumber.R:1:1'): Scenario: Breaker joins a game
nchar(context$word) (`actual`) not equal to `n` (`expected`).
`actual`: 5
`expected`: 6
Backtrace:
x
1. \-global `<step>`(n = 6L, context = `<env>`)
2. \-testthat::expect_equal(nchar(context$word), n) at ./steps/guess_the_word.R:18:2
2. \-testthat::expect_equal(nchar(context$word), n) at ./steps/guess_the_word.R:18:3
[ FAIL 3 | WARN 0 | SKIP 0 | PASS 2 ]

14 changes: 12 additions & 2 deletions tests/testthat/test-parameter.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,13 @@ describe("int", {
describe("float", {
it("should detect floats", {
# Arrange
x <- c("+1.1", "-1.1", "1.1", ".1", "+1", "-1", "1", "a")
x <- c(
"+1.1", "-1.1", "1.1",
"+11.1", "-11.1", "11.1",
".1",
"+1", "-1", "1",
"a"
)
param <- get_parameters()$float

# Act
Expand All @@ -56,7 +62,11 @@ describe("float", {
# Assert
expect_equal(
result,
c(1.1, -1.1, 1.1, .1)
c(
1.1, -1.1, 1.1,
11.1, -11.1, 11.1,
.1
)
)
})
})
Expand Down

0 comments on commit 1221cd4

Please sign in to comment.