shithub: mc

ref: 4ff322bbbc9b8c181b6f48b55c72f5482cec3c88
dir: /lib/regex/test/boundaries.myr/

View raw version
use std
use "testmatch"

const main = {
	/* expected matches */
	testmatch("\\<([a-z]*)\\>", "abcdef", `std.Some [
		"abcdef",
	][:])
	testmatch(".*(\\<.*\\>).*", "!m!", `std.Some [	/* single char word in midstring */
		"m",
	][:])
	testmatch(".*(\\<.*\\>).*", "!m", `std.Some [	/* single char word at end of string */
		"m",
	][:])
	testmatch(".*(\\<.*\\>).*", "m!", `std.Some [	/* single char word at start of string */
		"m",
	][:])
	testmatch(".*(\\<.*\\>).*", "!@#!!matches!!%!", `std.Some [	/* word in midstring */
		"matches",
	][:])
	testmatch(".*(\\<.*\\>).*", "matches!!%!", `std.Some [	/* word at start of string */
		"matches",
	][:])
	testmatch(".*(\\<.*\\>).*", "!@#!!matches", `std.Some [	/* word at end of string */
		"matches",
	][:])
	testmatch(".*(\\<.*\\>).*", "!@#!!matches!!%!foo", `std.Some [	/* matches last word in string */
		"foo",
	][:])
	testmatch(".*(\\<.*\\>).*", "123", `std.Some [	/* numbers are also word bounds */
		"123",
	][:])
	
	/* nonmatches */
	testmatch("\\<([a-z]*)\\>foo", "abcdefoo", `std.None)	/* word boundary needed in midstring */
}