#+test
package markdown
import "core:strings"
import "core:testing"
@(test)
test_toc_sequential_nesting :: proc(t: ^testing.T) {
html := `
A
B
C
`
result := generate_toc(html, context.temp_allocator)
testing.expect(t, strings.contains(result, `A`))
testing.expect(t, strings.contains(result, `B`))
testing.expect(t, strings.contains(result, `C`))
// A well-formed list never places a directly inside a .
testing.expect(t, !strings.contains(result, "\n"))
}
// Regression: a heading level that jumps by more than one (h1 -> h3) must not
// emit stacked, parentless tags. Each skipped level is wrapped in an -
// so the list stays valid.
@(test)
test_toc_level_jump_stays_valid :: proc(t: ^testing.T) {
html := `
A
B
`
result := generate_toc(html, context.temp_allocator)
testing.expect(t, !strings.contains(result, "\n"))
// The intermediate level is hosted by an - .
testing.expect(t, strings.contains(result, "
- \n
"))
testing.expect(t, strings.contains(result, `B`))
}
@(test)
test_toc_empty_when_no_headings :: proc(t: ^testing.T) {
result := generate_toc("no headings here
", context.temp_allocator)
testing.expect_value(t, result, "")
}