78 lines
4.1 KiB
JavaScript
78 lines
4.1 KiB
JavaScript
/*
|
|
This file is part of Ext JS 3.4
|
|
|
|
Copyright (c) 2011-2013 Sencha Inc
|
|
|
|
Contact: http://www.sencha.com/contact
|
|
|
|
GNU General Public License Usage
|
|
This file may be used under the terms of the GNU General Public License version 3.0 as
|
|
published by the Free Software Foundation and appearing in the file LICENSE included in the
|
|
packaging of this file.
|
|
|
|
Please review the following information to ensure the GNU General Public License version 3.0
|
|
requirements will be met: http://www.gnu.org/copyleft/gpl.html.
|
|
|
|
If you are unsure which license is appropriate for your use, please contact the sales department
|
|
at http://www.sencha.com/contact.
|
|
|
|
Build date: 2013-04-03 15:07:25
|
|
*/
|
|
Ext.test.session.addTest('String', {
|
|
|
|
name: 'Global String Decorators',
|
|
|
|
planned: 30,
|
|
|
|
// 5
|
|
test_escape: function(){
|
|
Y.Assert.areEqual('', String.escape(''), 'Test with an empty string');
|
|
Y.Assert.areEqual('foo', String.escape('foo'), 'Test with an non-empty string, no escape characters');
|
|
Y.Assert.areEqual('\\\\', String.escape('\\'), 'Test with a string with a single \\');
|
|
Y.Assert.areEqual('\\\'', String.escape('\''), 'Test with a string with a single \'');
|
|
Y.Assert.areEqual('\\\'foo\\\\', String.escape('\'foo\\'), 'Test with a mix of escape and non escape characters');
|
|
},
|
|
|
|
|
|
// 6
|
|
test_format: function(){
|
|
Y.Assert.areEqual('foo', String.format('foo'), 'Test with no format parameters, no function parameters');
|
|
Y.Assert.areEqual('foo', String.format('foo', 'x'), 'Test with no format parameters, 1 argument parameter');
|
|
Y.Assert.areEqual('foo', String.format('{0}', 'foo'), 'Test with only a format parameter');
|
|
Y.Assert.areEqual('xyz', String.format('{0}{1}{2}', 'x', 'y', 'z'), 'Test with several format parameters');
|
|
Y.Assert.areEqual('xy', String.format('{0}{1}', 'x', 'y', 'z'), 'Test with several format parameters, extra format parameters');
|
|
Y.Assert.areEqual('xfooy', String.format('{0}foo{1}', 'x', 'y'), 'Test with a mix of a string and format parameters');
|
|
},
|
|
|
|
// 7
|
|
test_leftPad: function(){
|
|
Y.Assert.areEqual(' ', String.leftPad('', 5), 'Test with empty string');
|
|
Y.Assert.areEqual(' foo', String.leftPad('foo', 5), 'Test with string smaller than the padding size');
|
|
Y.Assert.areEqual('foofoo', String.leftPad('foofoo', 5), 'Test with string bigger than the padding size');
|
|
Y.Assert.areEqual('foo', String.leftPad('foo', 0), 'Test with a padding size of 0');
|
|
Y.Assert.areEqual('foo', String.leftPad('foo', -5), 'Test with a padding size of less than 0');
|
|
Y.Assert.areEqual('00000', String.leftPad('', 5, '0'), 'Test with empty string, different padding character');
|
|
Y.Assert.areEqual('00foo', String.leftPad('foo', 5, '0'), 'Test with string smaller than the padding size, different padding character');
|
|
},
|
|
|
|
// 2
|
|
test_toggle: function(){
|
|
Y.Assert.areEqual('foo', 'baz'.toggle('foo', 'bar'), 'Test with a starting string that doesn\'t match either');
|
|
Y.Assert.areEqual('bar', 'foo'.toggle('foo', 'bar'), 'Test with a starting string that doesn\'t match either');
|
|
},
|
|
|
|
// 10
|
|
test_trim: function(){
|
|
Y.Assert.areEqual('', ''.trim(), 'Test with empty string');
|
|
Y.Assert.areEqual('foo', 'foo'.trim(), 'Test with string with no whitespace');
|
|
Y.Assert.areEqual('', ' '.trim(), 'Test with string with only whitespace');
|
|
Y.Assert.areEqual('bar', ' bar '.trim(), 'Test with string with leading and trailing whitespace');
|
|
Y.Assert.areEqual('foo', 'foo '.trim(), 'Test with only trailing spaces');
|
|
Y.Assert.areEqual('bar', ' bar'.trim(), 'Test with only leading spaces');
|
|
Y.Assert.areEqual('foo bar', 'foo bar'.trim(), 'Test with spaces in between words');
|
|
Y.Assert.areEqual('foo bar baz', ' foo bar baz '.trim(), 'Test with mixtures of different spaces');
|
|
Y.Assert.areEqual('foo', '\tfoo'.trim(), 'Test with tabs, as opposed to spaces');
|
|
Y.Assert.areEqual('text', '\ttext '.trim(), 'Test with mixture of spaces and tabs');
|
|
}
|
|
|
|
});
|