;; This Source Code Form is subject to the terms of the Mozilla Public ;; License, v. 2.0. If a copy of the MPL was not distributed with this ;; file, You can obtain one at http://mozilla.org/MPL/2.0/. ;; Clusters and widths of (bjoterm text). ;; ;; bjo test tests/text.bjo (import (std prelude)) (import (std simpletest)) (import (bjoterm text)) (defun (main args) (expect "e and a combining accent is one cluster" (vec-length (text-clusters "e\u{301}x")) 2) (expect "an emoji with a skin tone is one cluster" (vec-length (text-clusters "πŸ‘πŸ½")) 1) (expect "CR LF is one cluster" (vec-length (text-clusters "\r\n")) 1) (expect "ASCII is 1 column" (text-width "abc") 3) (expect "CJK is 2 columns" (text-width "δΈ­ζ–‡") 4) (expect "a combining accent is 0 columns" (text-width "e\u{301}") 1) (expect "a zero-width joiner is 0 columns" (cluster-width "\u{200D}") 0) (expect "the soft hyphen is 1 column" (cluster-width "\u{AD}") 1) (expect "an emoji is 2 columns" (text-width "πŸ‘πŸ½") 2) (expect "a flag is 2 columns" (text-width "πŸ‡ΈπŸ‡ͺ") 2) (expect "a control is ^X, 2 columns" (cluster-width "\u{1}") 2) (expect "escape sequences in a prompt are 0 columns" (text-width "\u{1B}[1mΞ»>\u{1B}[0m ") 3) (expect-true "a letter is part of a word" (word-cluster? "Γ€")) (expect-true "a digit is part of a word" (word-cluster? "7")) (expect-true "_ is part of a word" (word-cluster? "_")) (expect-true "a bracket is not" (not (word-cluster? "("))) (expect "find-clusters does not match inside a cluster" (find-clusters "e\u{301}" "e") -1) (expect "common-prefix keeps whole clusters" (common-prefix ["e\u{301}a" "e\u{301}b"]) "e\u{301}") 0)