@@ -211,13 +211,17 @@ test_that("Adding child tags", {
211211 expect_identical(t2a , t2 )
212212
213213
214- # tagSetChildren preserves attributes
215- x <- tagSetChildren(div(), HTML(" text" ))
216- expect_identical(attr(x $ children [[1 ]], " html" , TRUE ), TRUE )
214+ # tagSetChildren preserves classes and attributes
215+ txt <- HTML(" text" )
216+ attr(txt , " myattr" ) <- " foo"
217+ x <- tagSetChildren(div(), txt )
218+ expect_true(inherits(x $ children [[1 ]], " html" ))
219+ expect_identical(attr(x $ children [[1 ]], " myattr" , TRUE ), " foo" )
217220
218221 # tagAppendChildren preserves attributes
219- x <- tagAppendChildren(div(), HTML(" text" ))
220- expect_identical(attr(x $ children [[1 ]], " html" , TRUE ), TRUE )
222+ x <- tagAppendChildren(div(), txt )
223+ expect_true(inherits(x $ children [[1 ]], " html" ))
224+ expect_identical(attr(x $ children [[1 ]], " myattr" , TRUE ), " foo" )
221225})
222226
223227
@@ -389,22 +393,25 @@ test_that("tag/s with invalid noWS fails fast", {
389393})
390394
391395test_that(" Attributes are preserved" , {
392- # HTML() adds an attribute to the data structure (note that this is
393- # different from the 'attribs' field in the list)
394- x <- HTML(" <tag>&&</tag>" )
395- expect_identical(attr(x , " html" , TRUE ), TRUE )
396- expect_equivalent(format(x ), " <tag>&&</tag>" )
396+ html_txt <- HTML(" <tag>&&</tag>" )
397+ attr(html_txt , " myattr" ) <- " foo"
398+
399+ expect_true(inherits(html_txt , " html" ))
400+ expect_identical(attr(html_txt , " myattr" , TRUE ), " foo" )
401+ expect_equivalent(format(html_txt ), " <tag>&&</tag>" )
397402
398403 # Make sure attributes are preserved when wrapped in other tags
399- x <- div(HTML(" <tag>&&</tag>" ))
400- expect_equivalent(x $ children [[1 ]], HTML(" <tag>&&</tag>" ))
401- expect_identical(attr(x $ children [[1 ]], " html" , TRUE ), TRUE )
404+ x <- div(html_txt )
405+ expect_equivalent(x $ children [[1 ]], html_txt )
406+ expect_true(inherits(x $ children [[1 ]], " html" ))
407+ expect_identical(attr(x $ children [[1 ]], " myattr" , TRUE ), " foo" )
402408 expect_equivalent(format(x ), " <div><tag>&&</tag></div>" )
403409
404410 # Deeper nesting
405- x <- div(p(HTML(" <tag>&&</tag>" )))
406- expect_equivalent(x $ children [[1 ]]$ children [[1 ]], HTML(" <tag>&&</tag>" ))
407- expect_identical(attr(x $ children [[1 ]]$ children [[1 ]], " html" , TRUE ), TRUE )
411+ x <- div(p(html_txt ))
412+ expect_equivalent(x $ children [[1 ]]$ children [[1 ]], html_txt )
413+ expect_true(inherits(x $ children [[1 ]]$ children [[1 ]], " html" ))
414+ expect_identical(attr(x $ children [[1 ]]$ children [[1 ]], " myattr" , TRUE ), " foo" )
408415 expect_equivalent(format(x ), " <div>\n <p><tag>&&</tag></p>\n </div>" )
409416})
410417
0 commit comments