
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; MODULE      : tm-tools-test.scm
;; DESCRIPTION : Test suite for tm-tools
;; COPYRIGHT   : (C) 2023  jingkaimori
;;
;; This software falls under the GNU general public license version 3 or later.
;; It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE
;; in the root directory or <http://www.gnu.org/licenses/gpl-3.0.html>.
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(texmacs-module (texmacs texmacs tm-tools-test)
  (:use (texmacs texmacs tm-tools)))

(define (utf8-string-length-test)
  (regression-test-group
    "unicode character count" "utf8-string-length-test"
    utf8-string-length :none
    (test "empty length" "" 0)
    (test "ascii length (one byte in utf-8)" "Hello world!" 12)
    (test "russian length (two byte in utf-8)" "Ð’Ñ�ÐµÐ¼ Ð¿Ñ€Ð¸Ð²ÐµÑ‚!" 12)
    (test "kanji length (three byte in utf-8)" "ä½ å¥½ä¸–ç•Œï¼�" 5)
    (test "fraktur length (four byte in utf-8)" "ð�•³ð�–Šð�–‘ð�–‘ð�–” ð�–œð�–”ð�–—ð�–‘ð�–‰!" 12)
    (test "hybrid length" "Hello world!Ð’Ñ�ÐµÐ¼ Ð¿Ñ€Ð¸Ð²ÐµÑ‚!ä½ å¥½ä¸–ç•Œï¼�ð�•³ð�–Šð�–‘ð�–‘ð�–” ð�–œð�–”ð�–—ð�–‘ð�–‰!" 41)))

(tm-define (regtest-tm-tools)
  (let ((n (+ (utf8-string-length-test)
              0)))
    (display* "Total: " (object->string n) " tests.\n")
    (display "Test suite of tm-tools: ok\n")))