import std/html.{Attribute, Fragment, Node, Text} import std/option import std/string import std/test.{assert, assert_equal} import swap @test fn a_placeholder_is_its_skeleton_marked_as_loading :: { let skeleton = Node("nav", [Attribute("class", "labels")], [Text("…")]) assert_equal (html.render (swap.placeholder "swap-1" skeleton)) "" } @test fn a_skeleton_of_several_elements_is_wrapped :: { let skeleton = Fragment([Node("p", [], []), Node("p", [], [])]) assert_equal (html.render (swap.placeholder "swap-2" skeleton)) "

" } @test fn a_part_is_a_template_then_its_marker :: { assert_equal (swap.part "swap-1" "") "" } @test fn the_script_carries_the_nonce_and_defines_the_marker :: { let script = swap.script "abc123" assert (string.starts_with script "") script } @test fn an_opened_page_has_the_script_in_its_head_and_its_end_kept_for_last :: { let page = "t

x

" match swap.opened page "n1" { Some((first, last)) -> { assert_equal first "t{swap.script "n1"}

x

" assert_equal last "" } , None -> assert False "the page should open" } } @test fn a_head_that_holds_the_script_keeps_it_once :: { let script = swap.script "n1" let page = "{script}t

x

" match swap.opened page "n1" { Some((first, last)) -> { assert_equal first "{script}t

x

" assert_equal last "" } , None -> assert False "the page should open" } } @test fn a_head_with_another_nonce_s_script_gets_this_one :: { let page = "{swap.script "old"}" let first = swap.opened page "n1" |> option.map fn split { split.0 } assert_equal first Some("{swap.script "old"}{swap.script "n1"}") } @test fn a_page_splits_at_its_last_body_end :: { let page = "" let last = swap.opened page "n" |> option.map fn split { split.1 } assert_equal last Some("") } @test fn a_fragment_without_head_or_body_does_not_open :: { assert_equal (swap.opened "

x

" "n") None assert_equal (swap.opened "

x

" "n") None }