shithub: mc

ref: fd333ef7321e70c49b97d9ffb47805fe686e5d05
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")
}