First passing unit test!

This commit is contained in:
Vivianne 2024-02-29 09:54:46 -05:00
parent 4cdd0bd08c
commit f4b4dde8e0
4 changed files with 44 additions and 4 deletions

View File

@ -21,7 +21,7 @@
(files (libraries
((directory "reflow" ((scheme-file "ansi")))
(scheme-file "reflow")))
(tests ((directory "tests" ())))
(tests ((directory "tests" ((scheme-file "test-ansi")))))
(programs ())
(documentation
((org-file "README")

View File

@ -66,7 +66,7 @@
(λ () #f))
"w"))
(define (last-sequence)
(define (current-sequence)
(and
(sequence?)
(if (= 1 (length current-sequence-list))
@ -81,8 +81,8 @@
(display %RESET-SEQ o-port)))
(define (restore-ansi)
(let ((seq (last-sequence)))
(let ((seq (current-sequence)))
(when seq
(display seq o-port))))
(values port last-sequence reset-ansi restore-ansi))
(values port current-sequence reset-ansi restore-ansi))

25
tests/test-ansi.scm Normal file
View File

@ -0,0 +1,25 @@
(define-module (tests test-ansi)
#:use-module (reflow ansi)
#:use-module (tests utils)
#:use-module (srfi srfi-64)
#:use-module (rnrs io ports))
(test-begin "test-ansi")
(define pink-text-then-reset "\x1B[38;2;249;38;114m你好reflow\x1B[0m")
(test-equal
"Text should be forwarded to the port properly"
pink-text-then-reset
(call-with-output-string
(λ (str-port)
(define-values (ansi-port cur-seq reset restore)
(make-ansi-port-tuple str-port))
(display pink-text-then-reset ansi-port)
(reset)
(restore)
(test-equal "Current sequence should be #f" #f (cur-seq)))))
(test-end "test-ansi")

15
tests/utils.scm Normal file
View File

@ -0,0 +1,15 @@
(define-module (tests utils)
#:use-module (srfi srfi-64)
#:export (verify-output))
(define (verify-output-fn expected proc)
"Ensures that the output sequence is what is expected"
(test-equal
expected
(call-with-output-string
(λ (port)
(parameterize ((current-output-port port))
(proc))))))
(define-syntax-rule (verify-output expected body ...)
(verify-output-fn expected (lambda () body ...)))