Vivianne Langdon
31012d5b8f
- We change the stream iterator to *always* return a grapheme (except for EOF). The grapheme then gets built up over time. - This way, trans flag for example is first white flag, then white flag + zwj, etc until it finally transforms into the trans flag. - Users of the stream library can then use the `modification?' flag to determine if the stream value is a modification of the prior grapheme instead of a new grapheme. - Abstracted iteration to an iterator object to support use cases where we don't have an input stream (reflow needs this!)
67 lines
1.7 KiB
Scheme
67 lines
1.7 KiB
Scheme
(define-module (tests test-graphemes-stream)
|
|
#:use-module (uniseg graphemes)
|
|
#:use-module (uniseg graphemes stream)
|
|
#:use-module (uniseg internal)
|
|
#:use-module (srfi srfi-41)
|
|
#:use-module (srfi srfi-64))
|
|
|
|
(test-begin "tests-graphemes-stream")
|
|
|
|
;; silly double-em dash
|
|
(define stream (string->grapheme-stream "Trans 🏳️⚧️ rights are human rights⸺and that's a promise!"))
|
|
|
|
(define* (advance-stream! #:optional (times 1))
|
|
(for-each
|
|
(λ (_) (set! stream (stream-cdr stream)))
|
|
(make-list times)))
|
|
|
|
(advance-stream! 10)
|
|
|
|
(define trans-flag-grapheme (stream-car stream))
|
|
|
|
(test-equal "Trans flag stream is correct"
|
|
"🏳️⚧️" (grapheme-string trans-flag-grapheme))
|
|
|
|
(test-equal "Trans flag is width 2"
|
|
2 (grapheme-width trans-flag-grapheme))
|
|
|
|
(advance-stream! 2)
|
|
|
|
(define r-grapheme (stream-car stream))
|
|
|
|
(test-equal "r in rights is in correct place"
|
|
"r" (grapheme-string r-grapheme))
|
|
|
|
(test-equal "r is width 1"
|
|
1 (grapheme-width r-grapheme))
|
|
|
|
(advance-stream! 23)
|
|
|
|
(define double-em-dash-grapheme (stream-car stream))
|
|
|
|
(test-equal "double-em-dash is in right place"
|
|
"⸺" (grapheme-string double-em-dash-grapheme))
|
|
|
|
(test-equal "double-em-dash is triple-width"
|
|
3 (grapheme-width double-em-dash-grapheme))
|
|
|
|
(advance-stream!)
|
|
|
|
(define a-grapheme (stream-car stream))
|
|
|
|
(test-equal "advancing one goes to the a"
|
|
"a" (grapheme-string a-grapheme))
|
|
|
|
(define empty-stream (string->grapheme-stream ""))
|
|
|
|
(test-equal "a stream of nothing resolves to an empty stream"
|
|
#t (stream-null? empty-stream))
|
|
|
|
(define singleton-stream (string->grapheme-stream "a"))
|
|
|
|
(set! a-grapheme (stream-car stream))
|
|
|
|
(test-equal "a stream with a single character resolves to a grapheme"
|
|
"a" (grapheme-string a-grapheme))
|
|
|
|
(test-end "tests-graphemes-stream")
|