// test_text.el - native test suite for text primitives. // // Mirrors the acceptance corpus in tests/text/examples/ using the // native test/assert system instead of run.sh + expected output files. test "count-substring" { let x: Int = str_count("abc abc abc", "abc") assert x == 3 } test "count-overlap-skip" { let x: Int = str_count("aaa", "aa") assert x == 1, "non-overlapping count of aa in aaa" } test "count-lines-words-letters" { let s: String = "hello world\nfoo bar" let lines: Int = str_count_lines(s) let words: Int = str_count_words(s) let letters: Int = str_count_letters(s) assert lines == 2, "line count" assert words == 4, "word count" assert letters == 16, "letter count" } test "index-of-all" { let positions: [Int] = str_index_of_all("abXcdXefX", "X") let n: Int = native_list_len(positions) assert n == 3, "should find 3 occurrences" let p0: Int = native_list_get(positions, 0) let p1: Int = native_list_get(positions, 1) let p2: Int = native_list_get(positions, 2) assert p0 == 2, "first X at index 2" assert p1 == 5, "second X at index 5" assert p2 == 8, "third X at index 8" } test "str-repeat" { let s: String = str_repeat("ab", 3) assert s == "ababab", "repeat 3 times" } test "str-reverse" { let s: String = str_reverse("hello") assert s == "olleh", "reverse hello" } test "str-strip-prefix" { let s: String = str_strip_prefix("foobar", "foo") assert s == "bar", "strip prefix foo" } test "str-strip-suffix" { let s: String = str_strip_suffix("hello.md", ".md") assert s == "hello", "strip suffix .md" } test "str-strip-chars" { let s: String = str_strip_chars(" \thello \n", " \t\n") assert s == "hello", "strip whitespace chars" } test "split-lines" { let lines: [String] = str_split_lines("alpha\nbeta\r\ngamma\n") let n: Int = native_list_len(lines) assert n == 3, "split into 3 lines" } test "str-join" { let parts: [String] = native_list_empty() let parts = native_list_append(parts, "alpha") let parts = native_list_append(parts, "beta") let parts = native_list_append(parts, "gamma") let result: String = str_join(parts, ", ") assert result == "alpha, beta, gamma", "join with separator" } test "char-classes" { assert is_letter("A"), "A is a letter" assert is_digit("7"), "7 is a digit" assert is_whitespace(" "), "space is whitespace" assert !is_letter("3"), "3 is not a letter" assert !is_digit("X"), "X is not a digit" }