tests/testthat/test_repr_list.r

test_that('plain lists display correctly', {
	expect_identical(repr_html(list(1, 2)), '<ol>
\t<li>1</li>
\t<li>2</li>
</ol>
')
})

test_that('named lists display correctly', {
	expect_identical(repr_html(list(a = 1, b = 2)), '<dl>
\t<dt>$a</dt>
\t\t<dd>1</dd>
\t<dt>$b</dt>
\t\t<dd>2</dd>
</dl>
')
})

test_that('lists with unknown element types don’t display', {
	methods::setClass('__unknown', methods::representation(n = 'character'))
	expect_identical(repr_html(list(1, methods::new('__unknown'))), NULL)
})

test_that('lists with nonexistant names work', {
	expect_identical(repr_html(list(a = 0, 1)), '<dl>
\t<dt>$a</dt>
\t\t<dd>0</dd>
\t<dt>[[2]]</dt>
\t\t<dd>1</dd>
</dl>
')
})

test_that('NAs can occur in list names', {
	l <- as.list(1:2)
	names(l) <- c(NA, NA)
	expect_identical(repr_html(l), '<dl>
\t<dt>$&lt;NA&gt;</dt>
\t\t<dd>1</dd>
\t<dt>$&lt;NA&gt;</dt>
\t\t<dd>2</dd>
</dl>
')
})

test_that('Lists with empty strings as names work', {
	l <- structure(list(1), names = '')
	expect_identical(repr_html(l), '<ol>
\t<li>1</li>
</ol>
')
})

Try the repr package in your browser

Any scripts or data that you put into this service are public.

repr documentation built on Feb. 16, 2023, 6:57 p.m.