shithub: mc

ref: 65ec134c5fc370d6df3382edb4cc633bd7802e3e
dir: /lib/std/test/striter.myr/

View raw version
use std

const main = {
	var chars = ['a', 'b', 'c']
	var splits = ["foo", "+bar"]
	var graphemes = [
		[0x300][:],	/* disconnected accent */
		[0x61][:],	/* 'a' */
		[0x53f2][:],	/* '史', single codepoint */
		[0x63][:],	/* 'b' */
		[0x9][:],	/* '\t' */
		[0x42f][:],	/* 'Я' */
		[0x78, 0x300, 0x300, 0x300, 0x300, 0x300][:], /* x, 4 accents */
		[0xa][:],	/* '\n' */
		[0x7a, 0x309][:]	/* 'z', accent */
	]

	var i

	i = 0
	for c : std.bychar("abc")
		std.assert(chars[i++] == c, "wrong char")
	;;
	std.assert(i == chars.len, "wrong split count")

	i = 0
	for sp : std.bysplit("foo+++bar", "++")
		std.assert(std.eq(splits[i++], sp), "wrong split {}", sp)
	;;
	std.assert(i == splits.len, "wrong split count")

	i = 0
	for g : std.bygrapheme("̀a史c\tЯx̀̀̀̀̀\nz̉")
		std.assert(std.eq(g, graphemes[i++]), "mismatched grapheme cluster\n")
	;;
	std.assert(i == graphemes.len, "wrong grapheme set length")
}