Skip to content

Commit

Permalink
Change HTML percent sign to literal % (#871)
Browse files Browse the repository at this point in the history
* Change HTML percent sign to literal `%`

* Update several testthat tests

Co-authored-by: Joe Cheng <joe@rstudio.com>
  • Loading branch information
rich-iannone and jcheng5 committed Feb 1, 2022
1 parent b370c73 commit 86014db
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 79 deletions.
2 changes: 1 addition & 1 deletion R/utils_formatters.R
Expand Up @@ -450,7 +450,7 @@ context_minus_mark <- function(context) {
context_percent_mark <- function(context) {

switch(context,
html = "&percnt;",
html = "%",
latex = "\\%",
"%")
}
Expand Down
12 changes: 5 additions & 7 deletions tests/testthat/test-cols_merge.R
@@ -1,5 +1,3 @@
context("Ensuring that the `cols_merge*()` functions work as expected")

# Create a shortened version of `mtcars`
mtcars_short <- mtcars[1:5, ]

Expand Down Expand Up @@ -480,17 +478,17 @@ test_that("the `cols_merge_n_pct()` function works correctly", {
expect_equal(
(tbl_html %>% render_formats_test("html"))[["a"]],
c(
"1 (7.1&percnt;)", "5 (35.7&percnt;)", "0", "2 (14.3&percnt;)",
"NA", "6 (42.9&percnt;)", "5", "NA", "0", "NA"
"1 (7.1%)", "5 (35.7%)", "0", "2 (14.3%)",
"NA", "6 (42.9%)", "5", "NA", "0", "NA"
)
)

expect_equal(
(tbl_html %>% render_formats_test("html"))[["b"]],
c(
"7.1&percnt;", "35.7&percnt;", "0.0&percnt;", "14.3&percnt;",
"NA", "42.9&percnt;", "NA", "100,000.0&percnt;", "NA",
"0.0&percnt;"
"7.1%", "35.7%", "0.0%", "14.3%",
"NA", "42.9%", "NA", "100,000.0%", "NA",
"0.0%"
)
)
})
6 changes: 3 additions & 3 deletions tests/testthat/test-conditional_fmt.R
Expand Up @@ -88,8 +88,8 @@ test_that("the `fmt_percent()` function works with conditional `rows`", {
decimals = 2,
rows = num_1 < 1000) %>%
render_formats_test(context = "html"))[["num_1"]],
c("1836.23", "2763.39", "93,729.00&percnt;", "64,300.00&percnt;",
"21,223.20&percnt;", "0.00&percnt;", "&minus;2,324.00&percnt;")
c("1836.23", "2763.39", "93,729.00%", "64,300.00%",
"21,223.20%", "0.00%", "&minus;2,324.00%")
)

expect_equal(
Expand All @@ -99,7 +99,7 @@ test_that("the `fmt_percent()` function works with conditional `rows`", {
decimals = 2,
rows = char_2 %in% c("june", "july") & grepl("sa.*", char_1)) %>%
render_formats_test(context = "html"))[["num_2"]],
c("3,400.00&percnt;", "74", "23", "NA", "35", "NA", "NA")
c("3,400.00%", "74", "23", "NA", "35", "NA", "NA")
)
})

Expand Down
18 changes: 9 additions & 9 deletions tests/testthat/test-fmt_number.R
Expand Up @@ -667,9 +667,9 @@ test_that("the `drop_trailing_dec_mark` option works in select `fmt_*()` functio
fmt_percent(columns = num, drop_trailing_dec_mark = TRUE) %>%
render_formats_test(context = "html"))[["num"]],
c(
"0.10&percnt;", "1.00&percnt;", "10.00&percnt;", "0.00&percnt;",
"100.00&percnt;", "110.00&percnt;", "112.00&percnt;", "5,000,000.00&percnt;",
"&minus;150.00&percnt;", "&minus;500.00&percnt;", "&minus;50,010.00&percnt;"
"0.10%", "1.00%", "10.00%", "0.00%",
"100.00%", "110.00%", "112.00%", "5,000,000.00%",
"&minus;150.00%", "&minus;500.00%", "&minus;50,010.00%"
)
)

Expand All @@ -679,9 +679,9 @@ test_that("the `drop_trailing_dec_mark` option works in select `fmt_*()` functio
fmt_percent(columns = num, decimals = 0) %>%
render_formats_test(context = "html"))[["num"]],
c(
"0&percnt;", "1&percnt;", "10&percnt;", "0&percnt;", "100&percnt;",
"110&percnt;", "112&percnt;", "5,000,000&percnt;", "&minus;150&percnt;",
"&minus;500&percnt;", "&minus;50,010&percnt;"
"0%", "1%", "10%", "0%", "100%",
"110%", "112%", "5,000,000%", "&minus;150%",
"&minus;500%", "&minus;50,010%"
)
)

Expand All @@ -692,9 +692,9 @@ test_that("the `drop_trailing_dec_mark` option works in select `fmt_*()` functio
fmt_percent(columns = num, decimals = 0, drop_trailing_dec_mark = FALSE) %>%
render_formats_test(context = "html"))[["num"]],
c(
"0.&percnt;", "1.&percnt;", "10.&percnt;", "0.&percnt;", "100.&percnt;",
"110.&percnt;", "112.&percnt;", "5,000,000.&percnt;", "&minus;150.&percnt;",
"&minus;500.&percnt;", "&minus;50,010.&percnt;"
"0.%", "1.%", "10.%", "0.%", "100.%",
"110.%", "112.%", "5,000,000.%", "&minus;150.%",
"&minus;500.%", "&minus;50,010.%"
)
)

Expand Down
118 changes: 59 additions & 59 deletions tests/testthat/test-fmt_percent.R
Expand Up @@ -35,9 +35,9 @@ test_that("the `fmt_percent()` function works correctly in the HTML context", {
fmt_percent(columns = num_1, decimals = 2) %>%
render_formats_test("html"))[["num_1"]],
c(
"183,623.00&percnt;", "276,339.00&percnt;", "93,729.00&percnt;",
"64,300.00&percnt;", "21,223.20&percnt;", "0.00&percnt;",
"&minus;2,324.00&percnt;"
"183,623.00%", "276,339.00%", "93,729.00%",
"64,300.00%", "21,223.20%", "0.00%",
"&minus;2,324.00%"
)
)

Expand All @@ -47,9 +47,9 @@ test_that("the `fmt_percent()` function works correctly in the HTML context", {
fmt_percent(columns = num_1, decimals = 5) %>%
render_formats_test("html"))[["num_1"]],
c(
"183,623.00000&percnt;", "276,339.00000&percnt;", "93,729.00000&percnt;",
"64,300.00000&percnt;", "21,223.20000&percnt;", "0.00000&percnt;",
"&minus;2,324.00000&percnt;"
"183,623.00000%", "276,339.00000%", "93,729.00000%",
"64,300.00000%", "21,223.20000%", "0.00000%",
"&minus;2,324.00000%"
)
)

Expand All @@ -61,8 +61,8 @@ test_that("the `fmt_percent()` function works correctly in the HTML context", {
drop_trailing_zeros = TRUE) %>%
render_formats_test("html"))[["num_1"]],
c(
"183,623&percnt;", "276,339&percnt;", "93,729&percnt;", "64,300&percnt;",
"21,223.2&percnt;", "0&percnt;", "&minus;2,324&percnt;"
"183,623%", "276,339%", "93,729%", "64,300%",
"21,223.2%", "0%", "&minus;2,324%"
)
)

Expand All @@ -73,9 +73,9 @@ test_that("the `fmt_percent()` function works correctly in the HTML context", {
fmt_percent(columns = num_1, decimals = 2, use_seps = FALSE) %>%
render_formats_test("html"))[["num_1"]],
c(
"183623.00&percnt;", "276339.00&percnt;", "93729.00&percnt;",
"64300.00&percnt;", "21223.20&percnt;", "0.00&percnt;",
"&minus;2324.00&percnt;"
"183623.00%", "276339.00%", "93729.00%",
"64300.00%", "21223.20%", "0.00%",
"&minus;2324.00%"
)
)

Expand All @@ -86,9 +86,9 @@ test_that("the `fmt_percent()` function works correctly in the HTML context", {
fmt_percent(columns = num_1, decimals = 2, sep_mark = " ") %>%
render_formats_test("html"))[["num_1"]],
c(
"183 623.00&percnt;", "276 339.00&percnt;", "93 729.00&percnt;",
"64 300.00&percnt;", "21 223.20&percnt;", "0.00&percnt;",
"&minus;2 324.00&percnt;"
"183 623.00%", "276 339.00%", "93 729.00%",
"64 300.00%", "21 223.20%", "0.00%",
"&minus;2 324.00%"
)
)

Expand All @@ -101,9 +101,9 @@ test_that("the `fmt_percent()` function works correctly in the HTML context", {
sep_mark = ".", dec_mark = ",") %>%
render_formats_test("html"))[["num_1"]],
c(
"183.623,00&percnt;", "276.339,00&percnt;", "93.729,00&percnt;",
"64.300,00&percnt;", "21.223,20&percnt;", "0,00&percnt;",
"&minus;2.324,00&percnt;"
"183.623,00%", "276.339,00%", "93.729,00%",
"64.300,00%", "21.223,20%", "0,00%",
"&minus;2.324,00%"
)
)

Expand All @@ -114,10 +114,10 @@ test_that("the `fmt_percent()` function works correctly in the HTML context", {
fmt_percent(columns = num_1, decimals = 2, pattern = "a {x}:n") %>%
render_formats_test("html"))[["num_1"]],
c(
"a 183,623.00&percnt;:n", "a 276,339.00&percnt;:n",
"a 93,729.00&percnt;:n", "a 64,300.00&percnt;:n",
"a 21,223.20&percnt;:n", "a 0.00&percnt;:n",
"a &minus;2,324.00&percnt;:n"
"a 183,623.00%:n", "a 276,339.00%:n",
"a 93,729.00%:n", "a 64,300.00%:n",
"a 21,223.20%:n", "a 0.00%:n",
"a &minus;2,324.00%:n"
)
)

Expand All @@ -129,9 +129,9 @@ test_that("the `fmt_percent()` function works correctly in the HTML context", {
placement = "right", incl_space = TRUE) %>%
render_formats_test("html"))[["num_1"]],
c(
"183,623 &percnt;", "276,339 &percnt;", "93,729 &percnt;",
"64,300 &percnt;", "21,223 &percnt;", "0 &percnt;",
"&minus;2,324 &percnt;"
"183,623 %", "276,339 %", "93,729 %",
"64,300 %", "21,223 %", "0 %",
"&minus;2,324 %"
)
)

Expand All @@ -143,9 +143,9 @@ test_that("the `fmt_percent()` function works correctly in the HTML context", {
placement = "left", incl_space = TRUE) %>%
render_formats_test("html"))[["num_1"]],
c(
"&percnt; 183,623", "&percnt; 276,339", "&percnt; 93,729",
"&percnt; 64,300", "&percnt; 21,223", "&percnt; 0",
"&minus;&percnt; 2,324"
"% 183,623", "% 276,339", "% 93,729",
"% 64,300", "% 21,223", "% 0",
"&minus;% 2,324"
)
)

Expand All @@ -155,8 +155,8 @@ test_that("the `fmt_percent()` function works correctly in the HTML context", {
fmt_percent(columns = num_1, accounting = TRUE) %>%
render_formats_test("html"))[["num_1"]],
c(
"183,623.00&percnt;", "276,339.00&percnt;", "93,729.00&percnt;",
"64,300.00&percnt;", "21,223.20&percnt;", "0.00&percnt;", "(2,324.00&percnt;)"
"183,623.00%", "276,339.00%", "93,729.00%",
"64,300.00%", "21,223.20%", "0.00%", "(2,324.00%)"
)
)

Expand All @@ -166,9 +166,9 @@ test_that("the `fmt_percent()` function works correctly in the HTML context", {
fmt_percent(columns = num_1, decimals = 3, accounting = TRUE) %>%
render_formats_test("html"))[["num_1"]],
c(
"183,623.000&percnt;", "276,339.000&percnt;", "93,729.000&percnt;",
"64,300.000&percnt;", "21,223.200&percnt;", "0.000&percnt;",
"(2,324.000&percnt;)"
"183,623.000%", "276,339.000%", "93,729.000%",
"64,300.000%", "21,223.200%", "0.000%",
"(2,324.000%)"
)
)

Expand All @@ -181,9 +181,9 @@ test_that("the `fmt_percent()` function works correctly in the HTML context", {
accounting = TRUE, pattern = "a{x}b") %>%
render_formats_test("html"))[["num_1"]],
c(
"a183,623.000&percnt;b", "a276,339.000&percnt;b", "a93,729.000&percnt;b",
"a64,300.000&percnt;b", "a21,223.200&percnt;b", "a0.000&percnt;b",
"a(2,324.000&percnt;)b"
"a183,623.000%b", "a276,339.000%b", "a93,729.000%b",
"a64,300.000%b", "a21,223.200%b", "a0.000%b",
"a(2,324.000%)b"
)
)

Expand All @@ -196,8 +196,8 @@ test_that("the `fmt_percent()` function works correctly in the HTML context", {
accounting = TRUE, drop_trailing_zeros = TRUE) %>%
render_formats_test("html"))[["num_1"]],
c(
"183,623&percnt;", "276,339&percnt;", "93,729&percnt;", "64,300&percnt;",
"21,223.2&percnt;", "0&percnt;", "(2,324&percnt;)"
"183,623%", "276,339%", "93,729%", "64,300%",
"21,223.2%", "0%", "(2,324%)"
)
)

Expand All @@ -210,8 +210,8 @@ test_that("the `fmt_percent()` function works correctly in the HTML context", {
) %>%
render_formats_test("html"))[["num_1"]],
c(
"+1,836.23&percnt;", "+2,763.39&percnt;", "+937.29&percnt;",
"+643&percnt;", "+212.23&percnt;", "0&percnt;", "&minus;23.24&percnt;"
"+1,836.23%", "+2,763.39%", "+937.29%",
"+643%", "+212.23%", "0%", "&minus;23.24%"
)
)

Expand Down Expand Up @@ -242,9 +242,9 @@ test_that("the `fmt_percent()` function works correctly in the HTML context", {
) %>%
render_formats_test("html"))[["num_1"]],
c(
"*+183,623&percnt;*", "*+276,339&percnt;*", "*+93,729&percnt;*",
"*+64,300&percnt;*", "*+21,223.2&percnt;*", "*0&percnt;*",
"*&minus;2,324&percnt;*"
"*+183,623%*", "*+276,339%*", "*+93,729%*",
"*+64,300%*", "*+21,223.2%*", "*0%*",
"*&minus;2,324%*"
)
)

Expand All @@ -255,9 +255,9 @@ test_that("the `fmt_percent()` function works correctly in the HTML context", {
fmt_percent(columns = num_1, decimals = 2, locale = "en_US") %>%
render_formats_test("html"))[["num_1"]],
c(
"183,623.00&percnt;", "276,339.00&percnt;", "93,729.00&percnt;",
"64,300.00&percnt;", "21,223.20&percnt;", "0.00&percnt;",
"&minus;2,324.00&percnt;"
"183,623.00%", "276,339.00%", "93,729.00%",
"64,300.00%", "21,223.20%", "0.00%",
"&minus;2,324.00%"
)
)

Expand All @@ -268,9 +268,9 @@ test_that("the `fmt_percent()` function works correctly in the HTML context", {
fmt_percent(columns = num_1, decimals = 2, locale = "da_DK") %>%
render_formats_test("html"))[["num_1"]],
c(
"183.623,00&percnt;", "276.339,00&percnt;", "93.729,00&percnt;",
"64.300,00&percnt;", "21.223,20&percnt;", "0,00&percnt;",
"&minus;2.324,00&percnt;"
"183.623,00%", "276.339,00%", "93.729,00%",
"64.300,00%", "21.223,20%", "0,00%",
"&minus;2.324,00%"
)
)

Expand All @@ -281,9 +281,9 @@ test_that("the `fmt_percent()` function works correctly in the HTML context", {
fmt_percent(columns = num_1, decimals = 2, locale = "de_AT") %>%
render_formats_test("html"))[["num_1"]],
c(
"183 623,00&percnt;", "276 339,00&percnt;", "93 729,00&percnt;",
"64 300,00&percnt;", "21 223,20&percnt;", "0,00&percnt;",
"&minus;2 324,00&percnt;"
"183 623,00%", "276 339,00%", "93 729,00%",
"64 300,00%", "21 223,20%", "0,00%",
"&minus;2 324,00%"
)
)

Expand All @@ -294,9 +294,9 @@ test_that("the `fmt_percent()` function works correctly in the HTML context", {
fmt_percent(columns = num_1, decimals = 2, locale = "et_EE") %>%
render_formats_test("html"))[["num_1"]],
c(
"183 623,00&percnt;", "276 339,00&percnt;", "93 729,00&percnt;",
"64 300,00&percnt;", "21 223,20&percnt;", "0,00&percnt;",
"&minus;2 324,00&percnt;"
"183 623,00%", "276 339,00%", "93 729,00%",
"64 300,00%", "21 223,20%", "0,00%",
"&minus;2 324,00%"
)
)

Expand All @@ -307,9 +307,9 @@ test_that("the `fmt_percent()` function works correctly in the HTML context", {
fmt_percent(columns = num_1, decimals = 2, locale = "gl_ES") %>%
render_formats_test("html"))[["num_1"]],
c(
"183.623,00&percnt;", "276.339,00&percnt;", "93.729,00&percnt;",
"64.300,00&percnt;", "21.223,20&percnt;", "0,00&percnt;",
"&minus;2.324,00&percnt;"
"183.623,00%", "276.339,00%", "93.729,00%",
"64.300,00%", "21.223,20%", "0,00%",
"&minus;2.324,00%"
)
)

Expand All @@ -320,8 +320,8 @@ test_that("the `fmt_percent()` function works correctly in the HTML context", {
fmt_percent(columns = num_2, decimals = 2, scale_values = FALSE) %>%
render_formats_test("html"))[["num_2"]],
c(
"34.00&percnt;", "74.00&percnt;", "23.00&percnt;", "93.00&percnt;",
"35.00&percnt;", "76.00&percnt;", "57.00&percnt;"
"34.00%", "74.00%", "23.00%", "93.00%",
"35.00%", "76.00%", "57.00%"
)
)
})

0 comments on commit 86014db

Please sign in to comment.