AtlatestRepositorysigil-ansi

sigil-ansi / tree / testtest-ansi.sgl

1(import (sigil test)
2 (sigil string)
3 (sigil ansi))
4
5;; ============================================================
6;; Color wrapping
7;; ============================================================
8
9(test-group "color wrapping"
10 (test "a:red wraps text with escape codes"
11 (let ((result (a:red "hello")))
12 (assert-true (> (string-length result) (string-length "hello")))
13 (assert-true (string-contains? result "hello"))))
15 (test "a:green wraps text"
16 (let ((result (a:green "test")))
17 (assert-true (> (string-length result) 4))))
19 (test "a:blue wraps text"
20 (let ((result (a:blue "test")))
21 (assert-true (> (string-length result) 4)))))
23;; ============================================================
24;; Style wrapping
25;; ============================================================
27(test-group "style wrapping"
28 (test "a:bold wraps text"
29 (let ((result (a:bold "text")))
30 (assert-true (> (string-length result) 4))
31 (assert-true (string-contains? result "text"))))
33 (test "a:underline wraps text"
34 (let ((result (a:underline "text")))
35 (assert-true (> (string-length result) 4)))))
37;; ============================================================
38;; strip-ansi
39;; ============================================================
41(test-group "strip-ansi"
42 (test "removes escape codes from colored text"
43 (assert-equal "hello" (strip-ansi (a:red "hello"))))
45 (test "passes through plain text unchanged"
46 (assert-equal "plain" (strip-ansi "plain")))
48 (test "handles nested styles"
49 (assert-equal "styled" (strip-ansi (a:bold (a:red "styled")))))
51 (test "empty string"
52 (assert-equal "" (strip-ansi ""))))
54;; ============================================================
55;; with-ansi-disabled
56;; ============================================================
58(test-group "with-ansi-disabled"
59 (test "a:red returns plain text inside disabled block"
60 (let ((result (with-ansi-disabled
61 (lambda () (a:red "text")))))
62 (assert-equal "text" result)))
64 (test "ansi-enabled? returns #f inside disabled block"
65 (with-ansi-disabled
66 (lambda ()
67 (assert-false (ansi-enabled?)))))
69 (test "ansi-enabled? returns #t outside disabled block"
70 (assert-true (ansi-enabled?)))
72 (test "re-enables after thunk exits"
73 (with-ansi-disabled (lambda () #t))
74 (assert-true (ansi-enabled?))))
76;; ============================================================
77;; Cursor control
78;; ============================================================
80(test-group "cursor control"
81 (test "a:cursor-position produces non-empty string"
82 (let ((result (a:cursor-position 10 20)))
83 (assert-true (> (string-length result) 0))))
85 (test "cursor control returns empty when disabled"
86 (let ((result (with-ansi-disabled
87 (lambda () (a:cursor-position 10 20)))))
88 (assert-equal "" result)))
90 (test "a:clear-screen produces non-empty string"
91 (assert-true (> (string-length (a:clear-screen)) 0)))
93 (test "a:clear-screen returns empty when disabled"
94 (assert-equal "" (with-ansi-disabled (lambda () (a:clear-screen))))))
96(run-tests)