test_that("strings_xml", { # some sst string si <- "foobar" expect_equal( xml_si_to_txt(read_xml(si)), c("foo", "bar") ) txt <- "foo" expect_equal( txt_to_si(txt, raw = TRUE, skip_control = FALSE), "foo" ) expect_equal( txt_to_si(txt, raw = FALSE, skip_control = FALSE), "\n foo\n\n" ) txt <- "foo " expect_equal( txt_to_si(txt, raw = TRUE, no_escapes = FALSE, skip_control = FALSE), "foo " ) expect_equal( txt_to_si(txt, raw = FALSE, no_escapes = FALSE, skip_control = FALSE), "\n foo \n\n" ) txt <- "foo&bar" expect_equal( txt_to_si(txt, no_escapes = FALSE, skip_control = FALSE), "foo&bar" ) expect_equal( txt_to_si(txt, no_escapes = TRUE, skip_control = FALSE), "foo&bar" ) txt <- "foo'abcd\037'" expect_equal( txt_to_si(txt, raw = TRUE, no_escapes = FALSE, skip_control = TRUE), "foo'abcd'" ) is <- c("foo", "bar") expect_equal( is_to_txt(is), c("foo", "bar") ) is <- "foo" expect_error(is_to_txt(is)) txt <- "foo" expect_equal( txt_to_is(txt, raw = TRUE, no_escapes = FALSE, skip_control = FALSE), "foo" ) expect_equal( txt_to_is(txt, raw = FALSE, no_escapes = FALSE, skip_control = FALSE), "\n foo\n\n" ) txt <- "foo " expect_equal( txt_to_is(txt, raw = TRUE, no_escapes = FALSE, skip_control = FALSE), "foo " ) expect_equal( txt_to_is(txt, raw = FALSE, no_escapes = FALSE, skip_control = FALSE), "\n foo \n\n" ) txt <- "foo&bar" expect_equal( txt_to_is(txt, raw = TRUE, no_escapes = FALSE, skip_control = FALSE), "foo&bar" ) expect_equal( txt_to_is(txt, raw = TRUE, no_escapes = TRUE, skip_control = FALSE), "foo&bar" ) txt <- "foo'abcd\037'" expect_equal( txt_to_is(txt, raw = TRUE, no_escapes = FALSE, skip_control = TRUE), "foo'abcd'" ) amp <- temp_xlsx() wb <- wb_workbook()$ add_worksheet()$ add_data(dims = "A1", x = "A & B")$ save(amp) got <- wb_to_df(amp, col_names = FALSE)[1, 1] expect_equal(got, "A & B") # a couple of saves and loads later ... got <- wb$worksheets[[1]]$sheet_data$cc$is expect_equal(got, "A & B") wb <- wb_load(amp) got <- wb$worksheets[[1]]$sheet_data$cc$is expect_equal(got, "A & B") wb$save(amp) wb <- wb_load(amp) got <- wb$worksheets[[1]]$sheet_data$cc$is expect_equal(got, "A & B") got <- txt_to_is('foo bar') exp <- "foo <em>bar</em>" expect_equal(got, exp) # exception to the rule: it is not possible to write characters starting with "" or """ got <- txt_to_is("foo") exp <- "foo" expect_equal(got, exp) got <- txt_to_is(fmt_txt('foo')) exp <- "<r>foo</r>" expect_equal(got, exp) got <- txt_to_is('foo') exp <- "<red>foo</red>" expect_equal(got, exp) got <- txt_to_is('foo') exp <- "foo</r>" expect_equal(got, exp) got <- txt_to_is(' foo') exp <- " <r>foo</r>" expect_equal(got, exp) })