-
Notifications
You must be signed in to change notification settings - Fork 3
/
PathTest.Mod
103 lines (93 loc) · 3.57 KB
/
PathTest.Mod
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
MODULE PathTest;
IMPORT T := Tests, Path, Chars;
VAR ts : T.TestSet;
PROCEDURE TestMaxPath() : BOOLEAN;
VAR test : BOOLEAN;
BEGIN test := TRUE;
T.ExpectedInt(1024, Path.MAXLENGTH, "Current path maximum assumption", test);
RETURN test
END TestMaxPath;
PROCEDURE TestSetDelimiter() : BOOLEAN;
VAR test : BOOLEAN;
BEGIN test := TRUE;
T.ExpectedChar(Chars.SLASH, Path.delimiter, "Checking default delimiter", test);
Path.SetDelimiter(Chars.BSLASH);
T.ExpectedChar(Chars.BSLASH, Path.delimiter, "Checking set delimiter to ';'", test);
Path.SetDelimiter(Chars.SLASH);
T.ExpectedChar(Chars.SLASH, Path.delimiter, "Checking set delimiter to ':'", test);
RETURN test
END TestSetDelimiter;
PROCEDURE TestPrepend() : BOOLEAN;
VAR test, ok : BOOLEAN; a : ARRAY Path.MAXLENGTH OF CHAR;
BEGIN test := TRUE;
a[0] := 0X;
Path.Prepend("", a, ok);
T.ExpectedBool(TRUE, ok, "Path.Prepend('', a) ok -> ''", test);
T.ExpectedString("", a, "Path.Prepend('', a)", test);
Path.Prepend("/me", a, ok);
T.ExpectedBool(TRUE, ok, "Path.Prepend('/me', a) ok -> /me", test);
T.ExpectedString("/me", a, "Path.Prepend('/me', a)", test);
Path.Prepend("/home", a, ok);
T.ExpectedBool(TRUE, ok, "Path.Prepend('/home', a) ok -> /home/me", test);
T.ExpectedString("/home/me", a, "Path.Prepend('home', a)", test);
RETURN test
END TestPrepend;
PROCEDURE TestAppend() : BOOLEAN;
VAR test, ok : BOOLEAN; a : ARRAY Path.MAXLENGTH OF CHAR;
BEGIN test := TRUE;
a := "";
Path.Append("", a, ok);
T.ExpectedBool(TRUE, ok, "Path.Append('', a) ok -> ''", test);
T.ExpectedString("", a, "Path.Append('', a)", test);
Path.Append("/", a, ok);
T.ExpectedBool(TRUE, ok, "Path.Append('/', a) ok -> '/'", test);
T.ExpectedString("/", a, "Path.Append('/', a)", test);
Path.Append("home", a, ok);
T.ExpectedBool(TRUE, ok, "Path.Append('home', a) ok -> /home", test);
T.ExpectedString("/home", a, "Path.Append('home', a)", test);
Path.Append("me", a, ok);
T.ExpectedBool(TRUE, ok, "Path.Append('', a) ok -> /home/me", test);
T.ExpectedString("/home/me", a, "Path.Append('me', a) ok -> /home/me", test);
RETURN test
END TestAppend;
PROCEDURE TestBasename() : BOOLEAN;
VAR test, ok : BOOLEAN; a, expected, got : ARRAY Path.MAXLENGTH OF CHAR;
BEGIN test := TRUE;
a := "/home/me/.profile";
expected := ".profile";
Path.Basename(a, got, ok);
T.ExpectedBool(TRUE, ok, "Basename(a, got, ok) ok -> ?", test);
T.ExpectedString(expected, got, "Path.Basename(a, got, ok)", test);
RETURN test
END TestBasename;
PROCEDURE TestDirname() : BOOLEAN;
VAR test, ok : BOOLEAN; a, expected, got : ARRAY Path.MAXLENGTH OF CHAR;
BEGIN test := TRUE;
a := "/home/me/.profile";
expected := "/home/me";
Path.Dirname(a, got, ok);
T.ExpectedBool(TRUE, ok, "Dirname(a, got, ok) ok -> ?", test);
T.ExpectedString(expected, got, "Path.Dirname(a, got, ok)", test);
RETURN test
END TestDirname;
PROCEDURE TestExt() : BOOLEAN;
VAR test, ok : BOOLEAN; a, expected, got : ARRAY Path.MAXLENGTH OF CHAR;
BEGIN test := TRUE;
a := "/home/me/README.txt";
expected := ".txt";
Path.Ext(a, got, ok);
T.ExpectedBool(TRUE, ok, "Ext(a, got, ok) ok -> ?", test);
T.ExpectedString(expected, got, "Path.Ext(a, got, ok)", test);
RETURN test
END TestExt;
BEGIN
T.Init(ts, "Test Path");
T.Add(ts, TestMaxPath);
T.Add(ts, TestSetDelimiter);
T.Add(ts, TestPrepend);
T.Add(ts, TestAppend);
T.Add(ts, TestDirname);
T.Add(ts, TestBasename);
T.Add(ts, TestExt);
ASSERT(T.Run(ts));
END PathTest.