From 7b0693863e439cab6921c875aeb4c71214ea7dbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABlle=20Salmon?= Date: Tue, 11 Jul 2023 15:30:26 +0200 Subject: [PATCH] Add test --- DESCRIPTION | 1 + R/text-parsing-fns.R | 3 +-- autotest.Rproj | 20 ++++++++++++++++++++ tests/testthat.R | 8 ++++++++ tests/testthat/_snaps/text-parsing.md | 7 +++++++ tests/testthat/test-text-parsing.R | 6 ++++++ 6 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 autotest.Rproj create mode 100644 tests/testthat/_snaps/text-parsing.md diff --git a/DESCRIPTION b/DESCRIPTION index 6796e424..1e943819 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -43,3 +43,4 @@ Language: en-GB LazyData: true Roxygen: list(markdown = TRUE) RoxygenNote: 7.1.1 +Config/testthat/edition: 3 diff --git a/R/text-parsing-fns.R b/R/text-parsing-fns.R index ae861f00..8cf633ce 100644 --- a/R/text-parsing-fns.R +++ b/R/text-parsing-fns.R @@ -234,7 +234,7 @@ bracket_sequences <- function (x, open_sym, close_sym, both_sym) { start_multi_line_quote <- TRUE } else if (is.na (qstart_1) && !is.na (qend_1)) { multi_line_quote <- FALSE - } + } if (!multi_line_quote || (multi_line_quote && start_multi_line_quote)) { @@ -419,7 +419,6 @@ parse_expressions <- function (x) { xfirst <- x [1:(br_open [i] - 1)] if (br_closed [i] < length (x)) xlast <- x [(br_closed [i] + 1):length (x)] - x <- c (xfirst, xmid, xlast) } } diff --git a/autotest.Rproj b/autotest.Rproj new file mode 100644 index 00000000..5feaf978 --- /dev/null +++ b/autotest.Rproj @@ -0,0 +1,20 @@ +Version: 1.0 + +RestoreWorkspace: Default +SaveWorkspace: Default +AlwaysSaveHistory: Default + +EnableCodeIndexing: Yes +UseSpacesForTab: Yes +NumSpacesForTab: 4 +Encoding: UTF-8 + +RnwWeave: Sweave +LaTeX: XeLaTeX + +AutoAppendNewline: Yes +StripTrailingWhitespace: Yes + +BuildType: Package +PackageUseDevtools: Yes +PackageInstallArgs: --no-multiarch --with-keep.source diff --git a/tests/testthat.R b/tests/testthat.R index c98000dd..411cae09 100644 --- a/tests/testthat.R +++ b/tests/testthat.R @@ -1,3 +1,11 @@ +# This file is part of the standard setup for testthat. +# It is recommended that you do not modify it. +# +# Where should you do additional test configuration? +# Learn more about the roles of various files in: +# * https://r-pkgs.org/testing-design.html#sec-tests-files-overview +# * https://testthat.r-lib.org/articles/special-files.html + library(testthat) library(autotest) diff --git a/tests/testthat/_snaps/text-parsing.md b/tests/testthat/_snaps/text-parsing.md new file mode 100644 index 00000000..2acee4a2 --- /dev/null +++ b/tests/testthat/_snaps/text-parsing.md @@ -0,0 +1,7 @@ +# parse_expressions with two curly brace pairs + + Code + parse_expressions(ex) + Error + missing value where TRUE/FALSE needed + diff --git a/tests/testthat/test-text-parsing.R b/tests/testthat/test-text-parsing.R index d4a37ad4..23792831 100644 --- a/tests/testthat/test-text-parsing.R +++ b/tests/testthat/test-text-parsing.R @@ -59,6 +59,12 @@ test_that ("parse_expressions", { expect_silent (eval (parse (text = res2))) }) +test_that("parse_expressions with two curly brace pairs", { + ex <- c("if (TRUE) {", " message(\"blop\")", +"} else {", " message(\"bla\"", " ))", "}") + expect_snapshot(parse_expressions(ex), error = TRUE) +}) + test_that ("strip_if_cond", { x <- "if(x==1)y<-0" res <- strip_if_cond (x)