flan/test/programs/string-traps.flan

22 lines
864 B
Plaintext

;;;; What a String refuses at run time, one per run: the argument chooses.
;;;; Bytes that are not UTF-8, reached through a str, stop the program at the
;;;; append; so does a code point with no encoding; a character position past
;;;; the end signals BoundsError counted in characters. The test asserts the
;;;; line and column of each.
(defonce bad [2 u8])
(defn main [args [str]] i32
(let [which (if (> (length args) 1) (i32 (bytes->i64 (bytes-view (at args 1)))) 0)
s (string-new "日本")]
(set (at bad 0) 0xc3)
(set (at bad 1) 0x28)
(println "before")
(cond
(= which 0) (append s (str (slice bad)))
(= which 1) (append s (+ 0xd800 which -1))
(= which 2) (insert s 3 "x")
(= which 3) (println (remove s 2))
:else (append s (bytes->string (let [v (vec-new u8)] (push v 0xff) v))))
(println s))
0)