begin adding tests, one of which already failed. fix it!
This commit is contained in:
parent
0d3f3c2f1f
commit
a3ee78b9ec
7
hall.scm
7
hall.scm
|
@ -17,7 +17,7 @@
|
|||
(native-language-support #f)
|
||||
(licensing #f)))
|
||||
(files (libraries
|
||||
((directory
|
||||
((directory
|
||||
"termenv"
|
||||
((scheme-file "style")
|
||||
(scheme-file "unix")
|
||||
|
@ -26,7 +26,10 @@
|
|||
(scheme-file "color")
|
||||
(scheme-file "hconfig")))
|
||||
(scheme-file "termenv")))
|
||||
(tests ((directory "tests" ())))
|
||||
(tests ((directory
|
||||
"tests"
|
||||
((scheme-file "test-screen")
|
||||
(scheme-file "test-style")))))
|
||||
(programs ((directory "scripts" ())))
|
||||
(documentation
|
||||
((org-file "README")
|
||||
|
|
|
@ -34,18 +34,19 @@
|
|||
(string style-string set-style-string)
|
||||
(sequences style-sequences set-style-sequences))
|
||||
|
||||
(define (make-style string)
|
||||
(_make-style 'ansi string '()))
|
||||
(define (make-style str)
|
||||
(_make-style 'ansi str '()))
|
||||
|
||||
(define (styled style port)
|
||||
(define str (style-string style))
|
||||
(define (just-str) (format port "~a" str))
|
||||
(cond
|
||||
((eq? 'ascii (style-profile style)) str)
|
||||
((eq? 0 (length (style-sequences style))) str)
|
||||
((eq? 'ascii (style-profile style)) (just-str))
|
||||
((eq? 0 (length (style-sequences style))) (just-str))
|
||||
(else
|
||||
(let ((seq (string-join (style-sequences style) ";")))
|
||||
(if (equal? seq "")
|
||||
str
|
||||
(just-str)
|
||||
(format port "~a~am~a~am" %CSI seq str (string-append %CSI %RESET)))))))
|
||||
|
||||
(set-record-type-printer! <style> styled)
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
(define-module (tests test-screen)
|
||||
#:use-module (termenv screen)
|
||||
#:use-module (srfi srfi-64)
|
||||
#:use-module (rnrs io ports)
|
||||
#:use-module (scheme base)
|
||||
#:use-module (ice-9 textual-ports))
|
||||
|
||||
(test-begin "test-screen")
|
||||
|
||||
(define (output-equal expected)
|
||||
"Ensures that the output sequence is what is expected"
|
||||
(define vec (get-output-bytevector (current-output-port)))
|
||||
(define str (bytevector->string vec (native-transcoder)))
|
||||
(test-equal str expected))
|
||||
|
||||
(parameterize ((current-output-port (open-output-bytevector)))
|
||||
#f)
|
||||
|
||||
(test-end "test-screen")
|
|
@ -0,0 +1,26 @@
|
|||
(define-module (tests test-style)
|
||||
#:use-module (termenv style)
|
||||
#:use-module (srfi srfi-64)
|
||||
#:use-module (rnrs io ports)
|
||||
#:use-module (scheme base)
|
||||
#:use-module (ice-9 textual-ports))
|
||||
|
||||
(test-begin "test-style")
|
||||
|
||||
(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 ...)))
|
||||
|
||||
(verify-output
|
||||
"hello there"
|
||||
(format #t "~a" (make-style "hello there")))
|
||||
|
||||
(test-end "test-style")
|
Loading…
Reference in New Issue