R Under development (unstable) (2024-05-17 r86565 ucrt) -- "Unsuffered Consequences" Copyright (C) 2024 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > source(file.path("_helper", "init.R")) > > # - "read_line works" ---------------------------------------------------------- > > # read through prompt vals > > unitizer:::read_line_set_vals(letters[1:3]) > u.ns <- asNamespace("unitizer") > unitizer:::read_line() a [1] "a" > identical(u.ns$.global$prompt.vals, letters[2:3]) [1] TRUE > unitizer:::read_line() b [1] "b" > u.ns$.global$prompt.vals [1] "c" > unitizer:::read_line() c [1] "c" > u.ns$.global$prompt.vals character(0) > > try(unitizer:::read_line()) Error : Internal Error: ran out of predefined readline input; contact maintainer. > > # - "simple prompts" ----------------------------------------------------------- > > unitizer:::read_line_set_vals(c("y", "Y", "n", "N")) > try(unitizer:::simple_prompt(1:5)) Error in unitizer:::simple_prompt(1:5) : Argument `message` must be character > try(unitizer:::simple_prompt("hello", attempts = 1:5)) Error in unitizer:::simple_prompt("hello", attempts = 1:5) : Argument `attempts` must be numeric(1L), not NA, and one or greater > try(unitizer:::simple_prompt("hello", values = NA_character_)) Error in unitizer:::simple_prompt("hello", values = NA_character_) : Argument `values` must be character with no NAs > try(unitizer:::simple_prompt("hello", case.sensitive = 1)) Error in unitizer:::simple_prompt("hello", case.sensitive = 1) : Argument `case.sensitive` must be TRUE or FALSE > > unitizer:::simple_prompt("hello") | hello unitizer> y [1] "Y" > unitizer:::simple_prompt("hello")# | hello unitizer> Y [1] "Y" > unitizer:::simple_prompt("hello") | hello unitizer> n [1] "N" > unitizer:::read_line_set_vals(c("y", "y", "n")) > try(unitizer:::simple_prompt("hello", attempts = 1L, case.sensitive = TRUE)) | hello unitizer> y | Invalid input, please select one of: Y, N Error in unitizer:::simple_prompt("hello", attempts = 1L, case.sensitive = TRUE) : Gave up trying to collect user input after 1 attempts. > try(unitizer:::simple_prompt("hello", attempts = 1L, case.sensitive = TRUE), + silent = TRUE) | hello unitizer> y | Invalid input, please select one of: Y, N > try(unitizer:::simple_prompt("hello", attempts = 1L, case.sensitive = TRUE)) | hello unitizer> n | Invalid input, please select one of: Y, N Error in unitizer:::simple_prompt("hello", attempts = 1L, case.sensitive = TRUE) : Gave up trying to collect user input after 1 attempts. > > # - "faux prompt" -------------------------------------------------------------- > > unitizer:::read_line_set_vals(c("1 +", "1")) > unitizer:::faux_prompt(prompt = "> ", continue = "+ ")[[1L]] > 1 + + 1 1 + 1 > unitizer:::read_line_set_vals(c("(})")) > try(unitizer:::faux_prompt(prompt = "> ", continue = "+ ")) > (}) Error in "(})" : :1:2: unexpected '}' 1: (} ^ > > ## Test the new readLines based read_line > ## This test will not work in interactive mode, requiring input > unitizer:::read_line_set_vals(c("1 +", "1")) > unitizer:::faux_prompt() > 1 + + 1 expression(1 + 1) > > ## This one embeds a CTRL+C to test interrupt, but we can't test this without > ## read_line_setvals > unitizer:::read_line_set_vals(c("1 +", "\x03", "2 + ", "1")) > unitizer:::faux_prompt() > 1 + +  > 2 + + 1 expression(2 + 1) > > unitizer:::read_line_set_vals(c("\x03", "2 + ", "1")) > unitizer:::faux_prompt() >  | Type "Q" at the prompt to quit unitizer. > 2 + + 1 expression(2 + 1) > > ## Test that changing language doesn't affect partial parsing > lang <- Sys.getenv("LANGUAGE", unset=NA) > Sys.setenv("LANGUAGE"="fr") > unitizer:::read_line_set_vals(c("1 +", "1")) > unitizer:::faux_prompt(prompt = "> ", continue = "+ ") > 1 + + 1 expression(1 + 1) > if(is.na(lang)) Sys.unsetenv("LANGUAGE") else Sys.setenv("LANGUAGE"=lang) > > # - "unitizer prompt" ---------------------------------------------------------- > > # Some of this needs to be done outside of testthat due to sinking > suppressWarnings(glob <- unitizer:::unitizerGlobal$new()) > unitizer:::read_line_set_vals(c("1 +", "1", "H", "Y")) > unitizer:::unitizer_prompt( + "hello", valid.opts = c(Y = "[Y]es", N = "[N]o"), global = glob + ) unitizer> 1 + + 1 [1] 2 unitizer> H | No help available. | | hello ([Y]es, [N]o, [Q]uit, [H]elp)? unitizer> Y [1] "Y" > > unitizer:::read_line_set_vals(c("1 +", "1", "H", "Q")) > unitizer:::unitizer_prompt("hello", + valid.opts = c(Y = "[Y]es", N = "[N]o"), help = "This is all the help you get", + global = glob) unitizer> 1 + + 1 [1] 2 unitizer> H | This is all the help you get | | hello ([Y]es, [N]o, [Q]uit, [H]elp)? unitizer> Q [1] "Q" > > unitizer:::read_line_set_vals(c("hell())", "Q")) > txt3 <- unitizer:::capture_output(unitizer:::unitizer_prompt("hello", + valid.opts = c(Y = "[Y]es", N = "[N]o"), global = glob)) > txt3$message [1] "Error in \"hell())\": :1:7: unexpected ')'" [2] "1: hell())" [3] " ^" > > # and multiline stuff (#242) > unitizer:::read_line_set_vals(c("{\n 1 + 1\n 2 + 1\n}", "N")) > unitizer:::unitizer_prompt( + "hello", valid.opts = c(Y = "[Y]es", N = "[N]o"), global = glob + ) unitizer> { 1 + 1 2 + 1 } [1] 3 unitizer> N [1] "N" > > try( + unitizer:::unitizer_prompt( + "hello", valid.opts = c(Y = "[Y]es", N = "[N]o"), + browse.env = "not an env", global = glob + ) ) Error in unitizer:::unitizer_prompt("hello", valid.opts = c(Y = "[Y]es", : Argument `browse.env` must be an environment > > unitizer:::read_line_set_vals(character()) > try( + unitizer:::unitizer_prompt( + "hello", valid.opts = c(Y = "[Y]es", N = "[N]o"), global = glob + ) ) Error : Internal Error: ran out of predefined readline input; contact maintainer. > unitizer:::read_line_set_vals("1L") > try( + unitizer:::unitizer_prompt( + "hello", + valid.opts = c(Y = "[Y]es", N = "[N]o"), + exit.condition = unitizer:::exit_fun, + valid.vals = 2:3, global = glob + ) ) unitizer> 1L | Type a number in `2:3` at the prompt [1] 1 Error : Internal Error: ran out of predefined readline input; contact maintainer. > unitizer:::read_line_set_vals("2L") > unitizer:::unitizer_prompt("hello", valid.opts = c(Y = "[Y]es", + N = "[N]o"), exit.condition = unitizer:::exit_fun, valid.vals = 2:3, + global = glob) unitizer> 2L [1] 2 > > > proc.time() user system elapsed 0.39 0.15 0.48