Skip to content

Commit

Permalink
Merge pull request #30 from DanfengFu/master
Browse files Browse the repository at this point in the history
Update test-independent-test_utils_cli.R
  • Loading branch information
nanxstats authored Mar 9, 2022
2 parents 4a60e9b + 85273c0 commit cd648fc
Showing 1 changed file with 70 additions and 0 deletions.
70 changes: 70 additions & 0 deletions tests/testthat/test-independent-test_utils_cli.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# test cli_text
testthat::test_that("cli_text prints concatenated texts with \n as separator", {
strs <- c("str1","str2","str999")
cli_text(strs)
testthat::expect_output(cli_text(strs),regexp= "str1\\nstr2\\nstr999")
})

#test cli_h1
testthat::test_that("cli_h1 prints string as header with prefix and suffix", {
strs <- "This is a test heading"
strl <- "This is a really longgggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg heading"
cli_h1(strs)
cli_h1(strl)
testthat::expect_output(cli_h1(strs), regexp=".*?This is a test heading.*?\\-+.*")
testthat::expect_output(cli_h1(strl), regexp=".*?This is a really long+ heading.*?\\-*")
})

#test cli_rule
testthat::test_that("cli_rule combines strings and prints as header with prefix and suffix", {
strs <- "This is a test heading "
strs2 <- "plus other things"
strl <- "This is a heading with some special sympols like *,;%#$."
strs3 <- ""
cli_rule(strs,strs2)
cli_rule(strl,strs2)
testthat::expect_output(cli_rule(strs,strs2), regexp="\\-\\- This is a test heading plus other things \\-+")
testthat::expect_output(cli_rule(strl,strs2), regexp="\\-\\- This is a heading with some special sympols like \\*,;%#\\$\\.plus other things \\-+")
})
#test cli_li
testthat::test_that("cli_li prints string with a leading bullet point", {
strs <- "This is a test heading "
strs2 <- "plus other things"
cli_li(strs,strs2)
testthat::expect_output(cli_li(strs,strs2), regexp="\u2022 This is a test heading plus other things")
})
#test cli_str
testthat::test_that("cli_str create strings with double quotation in blue when printed in console", {
strs <- "This is a test string"
testthat::expect_equal(cli_str(strs), crayon::blue(paste0('"',strs,'"')))
})
#test cli_bool
testthat::test_that("cli_bool creates boolean object in blue color", {
strs <- TRUE
testthat::expect_equal(cli_bool(strs), crayon::blue(strs))
})
#test cli_num
testthat::test_that("cli_num output string as header with prefix and suffix", {
nums <- 123
testthat::expect_equal(cli_num(nums), crayon::green(nums))
})

#test cli_pkg
testthat::test_that("cli_pkg creates package name in blue", {
strs <- "test_pkg_name_in_blue"
testthat::expect_equal(cli_pkg(strs),crayon::blue(strs) )
})
#test cli_path_src
testthat::test_that("cli_path_src output string in green with double quotations surrounded", {
fd1 <- "/opt"
fd2 <- "bardsar"
fd3 <- "test"
testthat::expect_equal(cli_path_src(fd1,fd2,fd3),crayon::green('"/opt/bardsar/test"'))
})
#test cli_path_dst
testthat::test_that("cli_path_dst output string in blue with double quotations surrounded", {
fd1 <- "/opt"
fd2 <- "bardsar"
fd3 <- "test"
testthat::expect_equal(cli_path_dst(fd1,fd2,fd3), crayon::blue('"/opt/bardsar/test"'))
})

0 comments on commit cd648fc

Please sign in to comment.