1load('string.js'); 2 3function test_strip() { 4 testing.assertEquals(string.strip(' foo '), 'foo'); 5 testing.assertEquals(string.strip('\tfoo'), 'foo'); 6 testing.assertEquals(string.strip('foo\r\n'), 'foo'); 7 testing.assertEquals(string.strip('\t\r\n \nfoo \t bar\r\n\t'), 'foo \t bar'); 8}; 9 10function test_reduceWhitespace() { 11 testing.assertEquals(string.reduceWhitespace('foo bar'), 'foo bar'); 12 testing.assertEquals(string.reduceWhitespace('foo\r\nbar'), 'foo bar'); 13 testing.assertEquals(string.reduceWhitespace('foo\t\r\n \tbar'), 'foo bar'); 14}; 15 16function test_entitize() { 17 testing.assertEquals(string.entitize('foo>bar'), 'foo>bar'); 18 testing.assertEquals(string.entitize('foo<&>bar'), 'foo<&>bar'); 19 testing.assertEquals(string.entitize('foo"\'bar'), 'foo"\'bar'); //'foo"'bar'); 20}; 21 22function test_deentitize() { 23 testing.assertEquals(string.deentitize('foo&bar'), 'foo&bar'); 24 testing.assertEquals(string.deentitize('foo&gtbar'), 'foo>bar'); 25 testing.assertEquals(string.deentitize('foo"'bar'), 'foo"'bar'); //'foo"\'bar'); 26}; 27 28function test_urldecode() { 29 testing.assertEquals(string.urldecode('foo%20bar'), 'foo bar'); 30 testing.assertEquals(string.urldecode('foo+bar%40baz'), 'foo bar@baz'); 31}; 32 33function test_urlencode() { 34 testing.assertEquals(string.urlencode('foo bar+baz'), escape('foo bar+baz')); 35}; 36 37function test_escape() { 38 testing.assertEquals(string.escape('foo\nbar\\baz'), 'foo\\\nbar\\\\baz'); 39}; 40 41function test_unescape() { 42 testing.assertEquals(string.unescape('foo\\\nbar\\\\baz'), 'foo\nbar\\baz'); 43}; 44 45function test_centerTruncate() { 46 testing.assertEquals(string.centerTruncate('foo', 10), 'foo'); 47 testing.assertEquals(string.centerTruncate('foo bar baz', 10), 'fo ... az'); 48}; 49 50function test_startsWith() { 51 testing.assert(string.startsWith('foo', 'f')); 52 testing.assert(string.startsWith('foobarbaz', 'foo')); 53 testing.assertFalse(string.startsWith('foo', 'b')); 54}; 55 56function test_endsWith() { 57 testing.assert(string.endsWith('foo', 'o')); 58 testing.assert(string.endsWith('foo bar baz', 'baz')); 59 testing.assertFalse(string.endsWith('foo', 'z')); 60}; 61