summaryrefslogtreecommitdiff
path: root/lib/std/test/cmp.myr
blob: 4d08539cd448f487aa7953097972f15e41e2cddb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
use std

const main = {
	expect(std.strcmp, "foo", "bar", `std.After)
	expect(std.strcmp, "foo", "foo", `std.Equal)
	expect(std.strcmp, "foo", "foos", `std.Before)
	expect(std.strcmp, "Foo", "foos", `std.Before)

	expect1(std.strncmp, "foo", "bar", 3, `std.After)
	expect1(std.strncmp, "foo", "foo", 3, `std.Equal)
	expect1(std.strncmp, "foo", "foos", 3, `std.Equal)
	expect1(std.strncmp, "foo", "foos", 4, `std.Before)
	expect1(std.strncmp, "Foo", "foos", 2, `std.Before)


	expect(std.strcasecmp, "FOo", "bar", `std.After)
	expect(std.strcasecmp, "FOo", "Bar", `std.After)
	expect(std.strcasecmp, "FOo", "FUCK", `std.Before)
	expect(std.strcasecmp, "FOo", "fuck", `std.Before)
	expect(std.strcasecmp, "FOo", "foo", `std.Equal)
	expect(std.strcasecmp, "FOo", "foos", `std.Before)

	expect(std.strcasecmp, "FOo", "bar", `std.After)
	expect(std.strcasecmp, "FOo", "foo", `std.Equal)
	expect(std.strcasecmp, "FOo", "foos", `std.Before)

	expect(std.strcasecmp, "Γειά σας", "γειά σας", `std.Equal)
	expect(std.strcasecmp, "γειά σας", "γειά σας", `std.Equal)
	expect(std.strcasecmp, "γειά σας", "Γειά σας", `std.Equal)
	expect(std.strcasecmp, "γειά", "Γειά σας", `std.Before)
}

const expect = {fn, a, b, e
	var val

	val = fn(a, b)
	match (val, e)
	| (`std.Before, `std.Before):	/* nothing */
	| (`std.After, `std.After):	/* nothing */
	| (`std.Equal, `std.Equal):	/* nothing */
	| _:
		std.fatal("cmp {}, {}: expected {}, got {}\n", a, b, e, val)
	;;

}

const expect1 = {fn, a, b, n, e
	var val

	val = fn(a, b, n)
	match (val, e)
	| (`std.Before, `std.Before):	/* nothing */
	| (`std.After, `std.After):	/* nothing */
	| (`std.Equal, `std.Equal):	/* nothing */
	| _:
		std.fatal("cmp {}, {}: expected {}, got {}\n", a, b, e, val)
	;;

}