1
YUI.add('text-wordbreak-test', function (Y) {
4
ArrayAssert = Y.ArrayAssert,
7
Y.Test.Runner.add(new Y.Test.Case({
8
name: 'Text.WordBreak',
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));
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));
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));
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));
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));
40
'isWordBoundary() should not break inside CRLF': function () {
41
Assert.isFalse(WB.isWordBoundary('foo\r\nbar', 3));
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));
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));
56
'isWordBoundary() should not break between Katakana characters': function () {
57
Assert.isFalse(WB.isWordBoundary('パイ', 0));
60
'isWordBoundary() should not break from extenders': function () {
61
Assert.isFalse(WB.isWordBoundary('foo_bar', 2));
62
Assert.isFalse(WB.isWordBoundary('__', 0));
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));
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));
79
'isWordBoundary() should return true for index 0 of an empty string': function () {
80
Assert.isTrue(WB.isWordBoundary('', 0));
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('パイが良いです'));
90
'getWords() should preserve case by default': function () {
91
ArrayAssert.itemsAreSame(['foo', 'BAR', 'baz'], WB.getWords('foo BAR baz'));
94
'getWords() should support an ignoreCase option': function () {
95
ArrayAssert.itemsAreSame(['foo', 'bar'], WB.getWords('Foo Bar', {ignoreCase: true}));
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.')
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})
112
'getWords() should support an includeWhitespace option': function () {
113
ArrayAssert.itemsAreSame(
114
['foo', ' ', 'bar', ' ', 'baz'],
115
WB.getWords('foo bar baz', {includeWhitespace: true})
118
ArrayAssert.itemsAreSame(
119
['foo', ' ', ' ', 'bar'],
120
WB.getWords('foo bar', {includeWhitespace: true})
123
ArrayAssert.itemsAreSame(
124
['foo', '\t', 'bar'],
125
WB.getWords('foo\tbar', {includeWhitespace: true})
128
ArrayAssert.itemsAreSame(
129
['foo', '\n', 'bar'],
130
WB.getWords('foo\nbar', {includeWhitespace: true})
134
// -- getUniqueWords() -----------------------------------------------------
135
'getUniqueWords() should only return unique words': function () {
136
ArrayAssert.itemsAreSame(['hungry', 'hippo'], WB.getUniqueWords('hungry hungry hippo'));
140
}, '@VERSION@', {requires:['text-wordbreak', 'test']});