shithub: mc

ref: 6fb7d34b848c598e6398f960dc0a7e240e09a6f5
dir: /lib/escfmt/test/escurl.myr/

View raw version
use std
use escfmt
use testr

const main = {
	testr.run([\
		[.name="unchanged", .fn={ctx
			var s = std.fmt("{}", escfmt.url("word"))
			testr.check(ctx, std.eq("word", s), std.fmt("mismatched escape {}", s))
			std.slfree(s)
		}],
		[.name="allspecials", .fn={ctx
			var s = std.fmt("{}", escfmt.url(":/?#[]@!$&'()*+,;=%"))
			testr.check(ctx, \
				std.eq("%3a%2f%3f%23%5b%5d%40%21%24%26%27%28%29%2a%2b%2c%3b%3d%25", s), \
				std.fmt("mismatched escape {}", s))
			std.slfree(s)
		}],
		[.name="unicodes", .fn={ctx
			var s = std.fmt("{}", escfmt.url("᚛᚛ᚉᚑᚅᚔᚉᚉᚔ"))
			testr.check(ctx, \
				std.eq("%e1%9a%9b%e1%9a%9b%e1%9a%89%e1%9a%91%e1%9a%85%e1%9a%94%e1%9a%89%e1%9a%89%e1%9a%94", s), \
					std.fmt("mismatched escape {}", s))
			std.slfree(s)
		}],
	][:])
}