File: String.js

package info (click to toggle)
libjs-extjs 3.4.0%2Bdfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: buster, jessie, jessie-kfreebsd, stretch
  • size: 53,188 kB
  • ctags: 3,384
  • sloc: php: 819; xml: 537; python: 60; sql: 44; makefile: 35
file content (64 lines) | stat: -rw-r--r-- 3,626 bytes parent folder | download
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
/*!
 * Ext JS Library 3.4.0
 * Copyright(c) 2006-2011 Sencha Inc.
 * licensing@sencha.com
 * http://www.sencha.com/license
 */
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');
    }
    
});