@@ -345,3 +345,76 @@ test_that("Test case when using subline_by, page_by, group_by simultaneously wit
345345 )
346346 expect_true(tmp [[length(tmp )]])
347347})
348+
349+ test_that(" Test pagenumber_hardcoding with multi-page table" , {
350+ tbl <- iris [1 : 100 , ] | >
351+ rtf_title(" Table: Iris Data (\\ pagenumber_hardcoding/\\ totalpage)" ) | >
352+ rtf_colheader(" Sepal.Length | Sepal.Width | Petal.Length | Petal.Width | Species" ) | >
353+ rtf_body(col_rel_width = rep(1 , 5 ))
354+
355+ encoded <- rtf_encode_table(tbl )
356+
357+ expect_snapshot_output(encoded )
358+ })
359+
360+ test_that(" Test pagenumber_hardcoding replaces correctly per page" , {
361+ tbl <- iris [1 : 100 , ] | >
362+ rtf_title(" Table (\\ pagenumber_hardcoding/\\ totalpage)" ) | >
363+ rtf_body(col_rel_width = rep(1 , 5 ))
364+
365+ encoded <- rtf_encode_table(tbl )
366+
367+ pages <- strsplit(encoded $ body , " \\\\ page" )[[1 ]]
368+ n_pages <- length(pages )
369+
370+ for (i in seq_len(n_pages )) {
371+ expect_true(grepl(as.character(i ), pages [i ], fixed = TRUE ))
372+ expect_true(grepl(as.character(n_pages ), pages [i ], fixed = TRUE ))
373+ }
374+ })
375+
376+ test_that(" Test pagenumber_hardcoding in page header" , {
377+ tbl <- iris [1 : 100 , ] | >
378+ rtf_page() | >
379+ rtf_body() | >
380+ rtf_page_header(text = " Page \\ pagenumber_hardcoding of \\ totalpage" )
381+
382+ encoded <- rtf_encode_table(tbl )
383+
384+ pages <- strsplit(encoded $ body , " \\\\ page" )[[1 ]]
385+ n_pages <- length(pages )
386+
387+ for (i in seq_len(min(3 , n_pages ))) {
388+ expect_true(grepl(paste0(" Page " , i ), pages [i ]))
389+ expect_true(grepl(paste0(" of " , n_pages ), pages [i ]))
390+ }
391+ })
392+
393+ test_that(" Test pagenumber_hardcoding with totalpage in footnote" , {
394+ tbl <- iris [1 : 100 , ] | >
395+ rtf_body(col_rel_width = rep(1 , 5 )) | >
396+ rtf_footnote(" Page \\ pagenumber_hardcoding of \\ totalpage" )
397+
398+ attr(tbl , " page" )$ page_footnote <- " all"
399+
400+ encoded <- rtf_encode_table(tbl )
401+
402+ pages <- strsplit(encoded $ body , " \\\\ page" )[[1 ]]
403+ n_pages <- length(pages )
404+
405+ for (i in seq_len(min(3 , n_pages ))) {
406+ expect_true(grepl(as.character(i ), pages [i ]))
407+ expect_true(grepl(as.character(n_pages ), pages [i ]))
408+ }
409+ })
410+
411+ test_that(" Test pagenumber_hardcoding survives without extra spaces" , {
412+ tbl <- iris [1 : 50 , ] | >
413+ rtf_title(" Test (\\ pagenumber_hardcoding/\\ totalpage)" ) | >
414+ rtf_body()
415+
416+ encoded <- rtf_encode_table(tbl )
417+
418+ expect_false(grepl(" \\\\ totalpage " , encoded $ body , fixed = TRUE ))
419+ expect_false(grepl(" \\\\ pgnhardcoding" , encoded $ body , fixed = TRUE ))
420+ })
0 commit comments