From 1221cd4f6b9a74a78489241c7886cfb15fcaff23 Mon Sep 17 00:00:00 2001 From: Jakub Sobolewski <37193264+jakubsob@users.noreply.github.com> Date: Sun, 9 Jun 2024 12:46:06 +0200 Subject: [PATCH] fix: detection of floats with multiple leading numbers (#2) Co-authored-by: Jakub Sobolewski --- .Rbuildignore | 1 + DESCRIPTION | 2 +- NEWS.md | 8 ++++++++ R/parameter.R | 2 +- cran-comments.md | 5 +++++ .../tests/testthat/addition.feature | 6 ++++++ tests/testthat/_snaps/examples.md | 16 ++++++++-------- tests/testthat/test-parameter.R | 14 ++++++++++++-- 8 files changed, 42 insertions(+), 12 deletions(-) create mode 100644 cran-comments.md diff --git a/.Rbuildignore b/.Rbuildignore index 8cea983..f4a7c51 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -12,3 +12,4 @@ ^pkgdown$ ^doc$ ^Meta$ +^cran-comments\.md$ diff --git a/DESCRIPTION b/DESCRIPTION index a5723d9..0a28648 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -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 = "jakupsob@gmail.com", 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. diff --git a/NEWS.md b/NEWS.md index 060f81d..4362210 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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. diff --git a/R/parameter.R b/R/parameter.R index 3cf947b..348a747 100644 --- a/R/parameter.R +++ b/R/parameter.R @@ -93,7 +93,7 @@ set_default_parameters <- function() { define_parameter_type( name = "float", - regexp = "[+-]?[[:digit:]+]?\\.[:digit:]+", + regexp = "[+-]?[:digit:]*?\\.[:digit:]+", transformer = as.double ) diff --git a/cran-comments.md b/cran-comments.md new file mode 100644 index 0000000..858617d --- /dev/null +++ b/cran-comments.md @@ -0,0 +1,5 @@ +## R CMD check results + +0 errors | 0 warnings | 1 note + +* This is a new release. diff --git a/inst/examples/multiple_features/tests/testthat/addition.feature b/inst/examples/multiple_features/tests/testthat/addition.feature index 221feec..da49805 100644 --- a/inst/examples/multiple_features/tests/testthat/addition.feature +++ b/inst/examples/multiple_features/tests/testthat/addition.feature @@ -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 diff --git a/tests/testthat/_snaps/examples.md b/tests/testthat/_snaps/examples.md index 97216cd..6d14aae 100644 --- a/tests/testthat/_snaps/examples.md +++ b/tests/testthat/_snaps/examples.md @@ -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 @@ -171,7 +171,7 @@ Backtrace: x 1. \-global ``(expected = 5L, context = ``) - 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 @@ -179,7 +179,7 @@ Backtrace: x 1. \-global ``(expected = 5L, context = ``) - 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 -------------------------------------------------------------------------------- @@ -190,7 +190,7 @@ Backtrace: x 1. \-global ``(n = 6L, context = ``) - 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 ---------------------------------------------------------------- @@ -201,7 +201,7 @@ Backtrace: x 1. \-global ``(expected = 5L, context = ``) - 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 @@ -209,7 +209,7 @@ Backtrace: x 1. \-global ``(expected = 5L, context = ``) - 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 @@ -217,6 +217,6 @@ Backtrace: x 1. \-global ``(n = 6L, context = ``) - 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 ] diff --git a/tests/testthat/test-parameter.R b/tests/testthat/test-parameter.R index 26b4571..4d51ac1 100644 --- a/tests/testthat/test-parameter.R +++ b/tests/testthat/test-parameter.R @@ -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 @@ -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 + ) ) }) })