Commit1d2cae35Recorded15 Feb 2026Repositorysigil-ansi

test(ansi): Add test coverage for sigil-ansi package (Phase 3.3)

Message

Tests color/style wrapping, strip-ansi, with-ansi-disabled behavior, and cursor control functions in both enabled and disabled modes.

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