~ubuntu-branches/ubuntu/precise/maas/precise-updates

« back to all changes in this revision

Viewing changes to src/maasserver/static/jslibs/yui/3.4.1/tests/text/tests/functional/text-wordbreak-test.js

Tags: 1.2+bzr1373+dfsg-0ubuntu1~12.04.4
* SECURITY UPDATE: failure to authenticate downloaded content (LP: #1039513)
  - debian/patches/CVE-2013-1058.patch: Authenticate downloaded files with
    GnuPG and MD5SUM files. Thanks to Julian Edwards.
  - CVE-2013-1058
* SECURITY UPDATE: configuration options may be loaded from current working
  directory (LP: #1158425)
  - debian/patches/CVE-2013-1057-1-2.patch: Do not load configuration
    options from the current working directory. Thanks to Julian Edwards.
  - CVE-2013-1057

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
YUI.add('text-wordbreak-test', function (Y) {
2
 
 
3
 
var Assert      = Y.Assert,
4
 
    ArrayAssert = Y.ArrayAssert,
5
 
    WB          = Y.Text.WordBreak;
6
 
 
7
 
Y.Test.Runner.add(new Y.Test.Case({
8
 
    name: 'Text.WordBreak',
9
 
 
10
 
    // -- isWordBoundary() -----------------------------------------------------
11
 
    'isWordBoundary() should not break between most letters': function () {
12
 
        Assert.isFalse(WB.isWordBoundary('aaa', 1));
13
 
        Assert.isFalse(WB.isWordBoundary('áåä', 1));
14
 
        Assert.isFalse(WB.isWordBoundary('aäa', 1));
15
 
    },
16
 
 
17
 
    'isWordBoundary() should not break letters across certain punctuation': function () {
18
 
        Assert.isFalse(WB.isWordBoundary("can't", 2));
19
 
        Assert.isFalse(WB.isWordBoundary("can’t", 2));
20
 
        Assert.isFalse(WB.isWordBoundary('foo.bar', 2));
21
 
        Assert.isFalse(WB.isWordBoundary('foo:bar', 2));
22
 
    },
23
 
 
24
 
    'isWordBoundary() should not break across sequences of digits or digits adjacent to letters': function () {
25
 
        Assert.isFalse(WB.isWordBoundary('123', 1));
26
 
        Assert.isFalse(WB.isWordBoundary('a123', 1));
27
 
        Assert.isFalse(WB.isWordBoundary('1a23', 1));
28
 
    },
29
 
 
30
 
    'isWordBoundary() should not break inside numeric sequences': function () {
31
 
        Assert.isFalse(WB.isWordBoundary('3.14', 1));
32
 
        Assert.isFalse(WB.isWordBoundary('1,024', 1));
33
 
    },
34
 
 
35
 
    'isWordBoundary() should ignore format and extend characters': function () {
36
 
        Assert.isFalse(WB.isWordBoundary('foo\u00ADbar', 2));
37
 
        Assert.isFalse(WB.isWordBoundary('foo\u0300bar', 2));
38
 
    },
39
 
 
40
 
    'isWordBoundary() should not break inside CRLF': function () {
41
 
        Assert.isFalse(WB.isWordBoundary('foo\r\nbar', 3));
42
 
    },
43
 
 
44
 
    'isWordBoundary() should break before newlines': function () {
45
 
        Assert.isTrue(WB.isWordBoundary('foo\rbar', 2));
46
 
        Assert.isTrue(WB.isWordBoundary('foo\nbar', 2));
47
 
        Assert.isTrue(WB.isWordBoundary('foo\r\nbar', 2));
48
 
    },
49
 
 
50
 
    'isWordBoundary() should break after newlines': function () {
51
 
        Assert.isTrue(WB.isWordBoundary('foo\rbar', 3));
52
 
        Assert.isTrue(WB.isWordBoundary('foo\nbar', 3));
53
 
        Assert.isTrue(WB.isWordBoundary('foo\r\nbar', 4));
54
 
    },
55
 
 
56
 
    'isWordBoundary() should not break between Katakana characters': function () {
57
 
        Assert.isFalse(WB.isWordBoundary('パイ', 0));
58
 
    },
59
 
 
60
 
    'isWordBoundary() should not break from extenders': function () {
61
 
        Assert.isFalse(WB.isWordBoundary('foo_bar', 2));
62
 
        Assert.isFalse(WB.isWordBoundary('__', 0));
63
 
    },
64
 
 
65
 
    'isWordBoundary() should break everywhere else': function () {
66
 
        Assert.isTrue(WB.isWordBoundary('foo bar', 2));
67
 
        Assert.isTrue(WB.isWordBoundary('foo\tbar', 2));
68
 
        Assert.isTrue(WB.isWordBoundary('foo&bar', 2));
69
 
        Assert.isTrue(WB.isWordBoundary('foo"bar"', 2));
70
 
        Assert.isTrue(WB.isWordBoundary('foo(bar)', 2));
71
 
        Assert.isTrue(WB.isWordBoundary('foo/bar', 2));
72
 
    },
73
 
 
74
 
    'isWordBoundary() should return false when given an out-of-bounds index': function () {
75
 
        Assert.isFalse(WB.isWordBoundary('', 5));
76
 
        Assert.isFalse(WB.isWordBoundary('', -1));
77
 
    },
78
 
 
79
 
    'isWordBoundary() should return true for index 0 of an empty string': function () {
80
 
        Assert.isTrue(WB.isWordBoundary('', 0));
81
 
    },
82
 
 
83
 
    // -- getWords() -----------------------------------------------------------
84
 
    'getWords() should split a string into words': function () {
85
 
        // Also tests default exclusion of whitespace.
86
 
        ArrayAssert.itemsAreSame(['foo', 'bar', 'baz'], WB.getWords('foo bar baz'));
87
 
        ArrayAssert.itemsAreSame(['パイ', 'が', '良', 'い', 'で', 'す'], WB.getWords('パイが良いです'));
88
 
    },
89
 
 
90
 
    'getWords() should preserve case by default': function () {
91
 
        ArrayAssert.itemsAreSame(['foo', 'BAR', 'baz'], WB.getWords('foo BAR baz'));
92
 
    },
93
 
 
94
 
    'getWords() should support an ignoreCase option': function () {
95
 
        ArrayAssert.itemsAreSame(['foo', 'bar'], WB.getWords('Foo Bar', {ignoreCase: true}));
96
 
    },
97
 
 
98
 
    'getWords() should exclude punctuation-only words by default': function () {
99
 
        ArrayAssert.itemsAreSame(
100
 
            ['Tut', 'tut', 'it', 'looks', 'like', 'rain'],
101
 
            WB.getWords('Tut-tut, it looks like rain.')
102
 
        );
103
 
    },
104
 
 
105
 
    'getWords() should support an includePunctuation option': function () {
106
 
        ArrayAssert.itemsAreSame(
107
 
            ['Tut', '-', 'tut', ',', 'it', 'looks', 'like', 'rain', '.'],
108
 
            WB.getWords('Tut-tut, it looks like rain.', {includePunctuation: true})
109
 
        );
110
 
    },
111
 
 
112
 
    'getWords() should support an includeWhitespace option': function () {
113
 
        ArrayAssert.itemsAreSame(
114
 
            ['foo', ' ', 'bar', ' ', 'baz'],
115
 
            WB.getWords('foo bar baz', {includeWhitespace: true})
116
 
        );
117
 
 
118
 
        ArrayAssert.itemsAreSame(
119
 
            ['foo', ' ', ' ', 'bar'],
120
 
            WB.getWords('foo  bar', {includeWhitespace: true})
121
 
        );
122
 
 
123
 
        ArrayAssert.itemsAreSame(
124
 
            ['foo', '\t', 'bar'],
125
 
            WB.getWords('foo\tbar', {includeWhitespace: true})
126
 
        );
127
 
 
128
 
        ArrayAssert.itemsAreSame(
129
 
            ['foo', '\n', 'bar'],
130
 
            WB.getWords('foo\nbar', {includeWhitespace: true})
131
 
        );
132
 
    },
133
 
 
134
 
    // -- getUniqueWords() -----------------------------------------------------
135
 
    'getUniqueWords() should only return unique words': function () {
136
 
        ArrayAssert.itemsAreSame(['hungry', 'hippo'], WB.getUniqueWords('hungry hungry hippo'));
137
 
    }
138
 
}));
139
 
 
140
 
}, '@VERSION@', {requires:['text-wordbreak', 'test']});