This Trac instance is not used for development anymore!

We migrated our development workflow to git and Gitea.
To test the future redirection, replace trac by ariadne in the page URL.

source: ps/trunk/build/premake/premake5/tests/test_string.lua

Last change on this file was 20366, checked in by Itms, 7 years ago

Alpha 12 version of Premake 5, including prebuilt binary for Windows.
Directly taken from https://premake.github.io/.

Refs #3729.

File size: 2.2 KB
Line 
1--
2-- tests/test_string.lua
3-- Automated test suite for the new string functions.
4-- Copyright (c) 2008 Jason Perkins and the Premake project
5--
6
7 local suite = test.declare("string")
8
9
10--
11-- string.endswith() tests
12--
13
14 function suite.endswith_ReturnsTrue_OnMatch()
15 test.istrue(string.endswith("Abcdef", "def"))
16 end
17
18 function suite.endswith_ReturnsFalse_OnMismatch()
19 test.isfalse(string.endswith("Abcedf", "efg"))
20 end
21
22 function suite.endswith_ReturnsFalse_OnLongerNeedle()
23 test.isfalse(string.endswith("Abc", "Abcdef"))
24 end
25
26 function suite.endswith_ReturnsFalse_OnNilHaystack()
27 test.isfalse(string.endswith(nil, "ghi"))
28 end
29
30 function suite.endswith_ReturnsFalse_OnNilNeedle()
31 test.isfalse(string.endswith("Abc", nil))
32 end
33
34 function suite.endswith_ReturnsTrue_OnExactMatch()
35 test.istrue(string.endswith("/", "/"))
36 end
37
38
39
40--
41-- string.explode() tests
42--
43
44 function suite.explode_ReturnsParts_OnValidCall()
45 test.isequal({"aaa","bbb","ccc"}, string.explode("aaa/bbb/ccc", "/", true))
46 end
47
48
49
50--
51-- string.startswith() tests
52--
53
54 function suite.startswith_OnMatch()
55 test.istrue(string.startswith("Abcdef", "Abc"))
56 end
57
58 function suite.startswith_OnMismatch()
59 test.isfalse(string.startswith("Abcdef", "ghi"))
60 end
61
62 function suite.startswith_OnLongerNeedle()
63 test.isfalse(string.startswith("Abc", "Abcdef"))
64 end
65
66 function suite.startswith_OnEmptyHaystack()
67 test.isfalse(string.startswith("", "Abc"))
68 end
69
70 function suite.startswith_OnEmptyNeedle()
71 test.istrue(string.startswith("Abcdef", ""))
72 end
73
74
75
76--
77-- string.escapepattern() tests
78--
79
80 function suite.escapepattern_escapes()
81 test.isequal("boost_filesystem%-vc140%.1%.61%.0%.0", string.escapepattern("boost_filesystem-vc140.1.61.0.0"))
82 test.isequal("footage/down/temp/cars_%[100%]_upper/cars_%[100%]_upper%.exr", string.escapepattern("footage/down/temp/cars_[100]_upper/cars_[100]_upper.exr"))
83 end
84
85 function suite.escapepattern_doesntEscape()
86 local s = '<something foo="bar" />'
87 test.isequal(s, s:escapepattern())
88
89 s = 'lorem ipsum dolor sit amet'
90 test.isequal(s, s:escapepattern())
91
92 s = 'forward/slashes/foo/bar'
93 test.isequal(s, s:escapepattern())
94
95 s = '\\back\\slashes'
96 test.isequal(s, s:escapepattern())
97
98 s = 'new\nlines'
99 test.isequal(s, s:escapepattern())
100 end
Note: See TracBrowser for help on using the repository browser.