1 | /*! |
---|
2 | * Ext JS Library 3.4.0 |
---|
3 | * Copyright(c) 2006-2011 Sencha Inc. |
---|
4 | * licensing@sencha.com |
---|
5 | * http://www.sencha.com/license |
---|
6 | */ |
---|
7 | Ext.test.session.addTest('String', { |
---|
8 | |
---|
9 | name: 'Global String Decorators', |
---|
10 | |
---|
11 | planned: 30, |
---|
12 | |
---|
13 | // 5 |
---|
14 | test_escape: function(){ |
---|
15 | Y.Assert.areEqual('', String.escape(''), 'Test with an empty string'); |
---|
16 | Y.Assert.areEqual('foo', String.escape('foo'), 'Test with an non-empty string, no escape characters'); |
---|
17 | Y.Assert.areEqual('\\\\', String.escape('\\'), 'Test with a string with a single \\'); |
---|
18 | Y.Assert.areEqual('\\\'', String.escape('\''), 'Test with a string with a single \''); |
---|
19 | Y.Assert.areEqual('\\\'foo\\\\', String.escape('\'foo\\'), 'Test with a mix of escape and non escape characters'); |
---|
20 | }, |
---|
21 | |
---|
22 | |
---|
23 | // 6 |
---|
24 | test_format: function(){ |
---|
25 | Y.Assert.areEqual('foo', String.format('foo'), 'Test with no format parameters, no function parameters'); |
---|
26 | Y.Assert.areEqual('foo', String.format('foo', 'x'), 'Test with no format parameters, 1 argument parameter'); |
---|
27 | Y.Assert.areEqual('foo', String.format('{0}', 'foo'), 'Test with only a format parameter'); |
---|
28 | Y.Assert.areEqual('xyz', String.format('{0}{1}{2}', 'x', 'y', 'z'), 'Test with several format parameters'); |
---|
29 | Y.Assert.areEqual('xy', String.format('{0}{1}', 'x', 'y', 'z'), 'Test with several format parameters, extra format parameters'); |
---|
30 | Y.Assert.areEqual('xfooy', String.format('{0}foo{1}', 'x', 'y'), 'Test with a mix of a string and format parameters'); |
---|
31 | }, |
---|
32 | |
---|
33 | // 7 |
---|
34 | test_leftPad: function(){ |
---|
35 | Y.Assert.areEqual(' ', String.leftPad('', 5), 'Test with empty string'); |
---|
36 | Y.Assert.areEqual(' foo', String.leftPad('foo', 5), 'Test with string smaller than the padding size'); |
---|
37 | Y.Assert.areEqual('foofoo', String.leftPad('foofoo', 5), 'Test with string bigger than the padding size'); |
---|
38 | Y.Assert.areEqual('foo', String.leftPad('foo', 0), 'Test with a padding size of 0'); |
---|
39 | Y.Assert.areEqual('foo', String.leftPad('foo', -5), 'Test with a padding size of less than 0'); |
---|
40 | Y.Assert.areEqual('00000', String.leftPad('', 5, '0'), 'Test with empty string, different padding character'); |
---|
41 | Y.Assert.areEqual('00foo', String.leftPad('foo', 5, '0'), 'Test with string smaller than the padding size, different padding character'); |
---|
42 | }, |
---|
43 | |
---|
44 | // 2 |
---|
45 | test_toggle: function(){ |
---|
46 | Y.Assert.areEqual('foo', 'baz'.toggle('foo', 'bar'), 'Test with a starting string that doesn\'t match either'); |
---|
47 | Y.Assert.areEqual('bar', 'foo'.toggle('foo', 'bar'), 'Test with a starting string that doesn\'t match either'); |
---|
48 | }, |
---|
49 | |
---|
50 | // 10 |
---|
51 | test_trim: function(){ |
---|
52 | Y.Assert.areEqual('', ''.trim(), 'Test with empty string'); |
---|
53 | Y.Assert.areEqual('foo', 'foo'.trim(), 'Test with string with no whitespace'); |
---|
54 | Y.Assert.areEqual('', ' '.trim(), 'Test with string with only whitespace'); |
---|
55 | Y.Assert.areEqual('bar', ' bar '.trim(), 'Test with string with leading and trailing whitespace'); |
---|
56 | Y.Assert.areEqual('foo', 'foo '.trim(), 'Test with only trailing spaces'); |
---|
57 | Y.Assert.areEqual('bar', ' bar'.trim(), 'Test with only leading spaces'); |
---|
58 | Y.Assert.areEqual('foo bar', 'foo bar'.trim(), 'Test with spaces in between words'); |
---|
59 | Y.Assert.areEqual('foo bar baz', ' foo bar baz '.trim(), 'Test with mixtures of different spaces'); |
---|
60 | Y.Assert.areEqual('foo', '\tfoo'.trim(), 'Test with tabs, as opposed to spaces'); |
---|
61 | Y.Assert.areEqual('text', '\ttext '.trim(), 'Test with mixture of spaces and tabs'); |
---|
62 | } |
---|
63 | |
---|
64 | }); |
---|