1# Automatically generated from specification file: 'comments.json' 2# 3# Comment tags represent content that should never appear in the resulting 4# output. 5# 6# The tag's content may contain any substring (including newlines) EXCEPT the 7# closing delimiter. 8# 9# Comment tags SHOULD be treated as standalone when appropriate. 10# 11library(testthat) 12context('Spec v1.1, comments') 13 14test_that( "Inline", { 15 #"Comment blocks should be removed from the template." 16 template <- "12345{{! Comment Block! }}67890" 17 data <- list() 18 19 20 str <- whisker.render(template, data=data) 21 22 expect_equal(str, "1234567890", label=deparse(str), info="Comment blocks should be removed from the template.") 23}) 24 25test_that( "Multiline", { 26 #"Multiline comments should be permitted." 27 template <- "12345{{!\n This is a\n multi-line comment...\n}}67890\n" 28 data <- list() 29 30 31 str <- whisker.render(template, data=data) 32 33 expect_equal(str, "1234567890\n", label=deparse(str), info="Multiline comments should be permitted.") 34}) 35 36test_that( "Standalone", { 37 #"All standalone comment lines should be removed." 38 template <- "Begin.\n{{! Comment Block! }}\nEnd.\n" 39 data <- list() 40 41 42 str <- whisker.render(template, data=data) 43 44 expect_equal(str, "Begin.\nEnd.\n", label=deparse(str), info="All standalone comment lines should be removed.") 45}) 46 47test_that( "Indented Standalone", { 48 #"All standalone comment lines should be removed." 49 template <- "Begin.\n {{! Indented Comment Block! }}\nEnd.\n" 50 data <- list() 51 52 53 str <- whisker.render(template, data=data) 54 55 expect_equal(str, "Begin.\nEnd.\n", label=deparse(str), info="All standalone comment lines should be removed.") 56}) 57 58test_that( "Standalone Line Endings", { 59 #"\"\\r\\n\" should be considered a newline for standalone tags." 60 template <- "|\r\n{{! Standalone Comment }}\r\n|" 61 data <- list() 62 63 64 str <- whisker.render(template, data=data) 65 66 expect_equal(str, "|\r\n|", label=deparse(str), info="\"\\r\\n\" should be considered a newline for standalone tags.") 67}) 68 69test_that( "Standalone Without Previous Line", { 70 #"Standalone tags should not require a newline to precede them." 71 template <- " {{! I'm Still Standalone }}\n!" 72 data <- list() 73 74 75 str <- whisker.render(template, data=data) 76 77 expect_equal(str, "!", label=deparse(str), info="Standalone tags should not require a newline to precede them.") 78}) 79 80test_that( "Standalone Without Newline", { 81 #"Standalone tags should not require a newline to follow them." 82 template <- "!\n {{! I'm Still Standalone }}" 83 data <- list() 84 85 86 str <- whisker.render(template, data=data) 87 88 expect_equal(str, "!\n", label=deparse(str), info="Standalone tags should not require a newline to follow them.") 89}) 90 91test_that( "Multiline Standalone", { 92 #"All standalone comment lines should be removed." 93 template <- "Begin.\n{{!\nSomething's going on here...\n}}\nEnd.\n" 94 data <- list() 95 96 97 str <- whisker.render(template, data=data) 98 99 expect_equal(str, "Begin.\nEnd.\n", label=deparse(str), info="All standalone comment lines should be removed.") 100}) 101 102test_that( "Indented Multiline Standalone", { 103 #"All standalone comment lines should be removed." 104 template <- "Begin.\n {{!\n Something's going on here...\n }}\nEnd.\n" 105 data <- list() 106 107 108 str <- whisker.render(template, data=data) 109 110 expect_equal(str, "Begin.\nEnd.\n", label=deparse(str), info="All standalone comment lines should be removed.") 111}) 112 113test_that( "Indented Inline", { 114 #"Inline comments should not strip whitespace" 115 template <- " 12 {{! 34 }}\n" 116 data <- list() 117 118 119 str <- whisker.render(template, data=data) 120 121 expect_equal(str, " 12 \n", label=deparse(str), info="Inline comments should not strip whitespace") 122}) 123 124test_that( "Surrounding Whitespace", { 125 #"Comment removal should preserve surrounding whitespace." 126 template <- "12345 {{! Comment Block! }} 67890" 127 data <- list() 128 129 130 str <- whisker.render(template, data=data) 131 132 expect_equal(str, "12345 67890", label=deparse(str), info="Comment removal should preserve surrounding whitespace.") 133}) 134 135