///|
test "text location handling" {
let loc = @cmark_base.TextLoc::{
file: "test.md",
first_ccode: 0,
last_ccode: 10,
first_line: LinePos(1, 0),
last_line: LinePos(1, 10),
}
let after_loc = loc.after()
debug_inspect(
after_loc,
content=(
#|{
#| file: "test.md",
#| first_ccode: 1,
#| last_ccode: -1,
#| first_line: LinePos(1, 10),
#| last_line: LinePos(-1, -1),
#|}
),
)
let none_loc = @cmark_base.TextLoc::none()
debug_inspect(none_loc.is_none(), content="true")
}///|
test "link parsing" {
let txt = "Visit <https://mooncakes.io/>!"
debug_inspect(@cmark_base.autolink_uri(txt, start=6), content="Some(28)")
let email = "Contact <user@example.com> today!"
debug_inspect(@cmark_base.autolink_email(email, start=8), content="Some(25)")
}///|
test "string analysis" {
let start = 0
// Find first non-blank character
debug_inspect(
@cmark_base.first_non_blank(" hello", last=7, start~),
content="2",
)
// Count repeated characters
debug_inspect(
@cmark_base.run_of(char='-', "---hello", last=8, start~),
content="2",
)
}///|
test "line type detection" {
let start = 0
// ATX Heading
debug_inspect(
@cmark_base.LineType::atx_heading("# Heading", last=8, start~),
content="AtxHeadingLine(1, 1, 2, 8)",
)
// Thematic Break
debug_inspect(
@cmark_base.LineType::thematic_break("---", last=2, start~),
content="ThematicBreakLine(2)",
)
// List Items
debug_inspect(
@cmark_base.LineType::list_marker("- Item", last=5, start~),
content="ListMarkerLine(Unordered('-'), 0)",
)
debug_inspect(
@cmark_base.LineType::list_marker("1. Item", last=6, start~),
content="ListMarkerLine(Ordered(1, '.'), 1)",
)
}///|
test "list types" {
let unordered = @cmark_base.ListType::Unordered('-')
let ordered = @cmark_base.ListType::Ordered(1, '.')
// Check if lists are of same type
debug_inspect(unordered.is_same_type(unordered), content="true")
debug_inspect(unordered.is_same_type(ordered), content="false")
}///|
test "html blocks" {
let start = 0
debug_inspect(
@cmark_base.LineType::html_block_start("<div>", last=5, start~),
content="HtmlBlockLine(EndBlank)",
)
debug_inspect(
@cmark_base.LineType::html_block_end(
"</div></br>",
end_cond=EndStr("</div>"),
start~,
last=6,
),
content="true",
)
}///|
test "metadata handling" {
let loc = @cmark_base.TextLoc::{
file: "test.md",
first_ccode: 0,
last_ccode: 10,
first_line: LinePos(1, 0),
last_line: LinePos(1, 10),
}
let meta = @cmark_base.Meta::new(loc~)
debug_inspect(meta.is_none(), content="false")
let none_meta = @cmark_base.Meta::none()
debug_inspect(none_meta.is_none(), content="true")
}type Next = Intpub extenum ContextState {
}fn FencedCodeBlockContinue::new(s : String, fence~ : (Char, Int), last~ : Int, start~ : Int) -> FencedCodeBlockContinuepub(all) enum LineType {
AtxHeadingLine(Int, Int, Int, Int)
BlankLine
BlockQuoteLine
FencedCodeBlockLine(Int, Int, (Int, Int)?)
HtmlBlockLine(HtmlBlockEndCond)
IndentedCodeBlockLine
ListMarkerLine(ListType, Int)
ParagraphLine
SetextUnderlineLine(Int, Int)
ThematicBreakLine(Int)
ExtTableRow(Int)
ExtFootnoteLabel(Array[Span], Int, String)
Nomatch
} derive(Eq, Debug)fn LineType::ext_footnote_label(buf : StringBuilder, s : String, line_pos~ : LinePos, last~ : Int, start~ : Int) -> LineTypefn LineType::html_block_end(s : String, end_cond~ : HtmlBlockEndCond, last~ : Int, start~ : Int) -> Boolfn autolink_email(s : String, last? : Int, start? : Int) -> Int?fn autolink_uri(s : String, last? : Int, start? : Int) -> Int?fn could_be_link_ref_definition(s : String, last~ : Int, start~ : Int) -> Boolfn first_non_blank(s : String, last~ : Int, start~ : Int) -> Intfn[A] first_non_blank_over_nl(next_line~ : NextLineFn[A], s : String, lines : A, line~ : LineSpan, start~ : Int) -> NextLineResult?fn first_non_escaped_char(c : Char, s : String, last~ : Int, start~ : Int) -> Intfn last_non_blank(s : String, first~ : Int, start~ : Int) -> Intfn link_destination(s : String, last~ : Int, start~ : Int) -> (Bool, Int, Int)?fn[A] link_label(buf : StringBuilder, next_line~ : NextLineFn[A], s : String, lines : A, line~ : LineSpan, start~ : Int) -> (LineSpan, Array[Span], Int, String)?fn[A] link_title(next_line~ : NextLineFn[A], s : String, lines : A, line~ : LineSpan, start~ : Int) -> (LineSpan, Array[Span], Int)?fn[A] raw_html(next_line~ : NextLineFn[A], s : String, lines : A, line~ : LineSpan, start~ : Int) -> (LineSpan, Array[Span], Int)?fn rev_drop_spaces(s : String, first~ : Int, start~ : Int) -> Intfn run_of(char~ : Char, s : String, last~ : Int, start~ : Int) -> Int