test_stringtransform.js
Go to the documentation of this file.
1 /*
2 //
3 // BEGIN SONGBIRD GPL
4 //
5 // This file is part of the Songbird web player.
6 //
7 // Copyright(c) 2005-2008 POTI, Inc.
8 // http://songbirdnest.com
9 //
10 // This file may be licensed under the terms of of the
11 // GNU General Public License Version 2 (the "GPL").
12 //
13 // Software distributed under the License is distributed
14 // on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
15 // express or implied. See the GPL for the specific language
16 // governing rights and limitations.
17 //
18 // You should have received a copy of the GPL along with this
19 // program. If not, go to http://www.gnu.org/licenses/gpl.html
20 // or write to the Free Software Foundation, Inc.,
21 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 //
23 // END SONGBIRD GPL
24 //
25 */
26 
27 function testTransform(aTestIn, aTestExpectedOut, aFlag) {
28  var stringTransform = Cc["@songbirdnest.com/Songbird/Intl/StringTransform;1"]
29  .createInstance(Ci.sbIStringTransform);
30  var testOut = stringTransform.normalizeString("",
31  aFlag,
32  aTestIn);
33  log("Pre-normalized string: '" + aTestIn + "'");
34  log("Expected normalized string: '" + aTestExpectedOut + "'");
35  log("Normalized string: '" + testOut + "'");
36  assertEqual(testOut, aTestExpectedOut);
37 }
38 
39 function runTest() {
40 
41  testTransform(" l't est gnial", "aaaeciie l'ete est genial",
42  Ci.sbIStringTransform.TRANSFORM_IGNORE_NONSPACE);
43 
44  testTransform("DP-6", "DP-6",
45  Ci.sbIStringTransform.TRANSFORM_IGNORE_NONSPACE);
46 
47  // Sadly, the implementation of IGNORE SYMBOLS on Windows is not consistent
48  // with Linux and Mac OS X :(
49 
50  testTransform("I have $5", "I have 5",
51  Ci.sbIStringTransform.TRANSFORM_IGNORE_SYMBOLS);
52 
53  testTransform("$5 ! I have $5 !!", "5 ! I have $5 !!",
54  Ci.sbIStringTransform.TRANSFORM_IGNORE_SYMBOLS |
55  Ci.sbIStringTransform.TRANSFORM_IGNORE_LEADING);
56 
57  testTransform("$5 ! I have $5 !!", "5 I have 5 ",
58  Ci.sbIStringTransform.TRANSFORM_IGNORE_NONALPHANUM);
59 
60  testTransform("$5 ! I have $5 !!", "5 ! I have $5 !!",
61  Ci.sbIStringTransform.TRANSFORM_IGNORE_NONALPHANUM |
62  Ci.sbIStringTransform.TRANSFORM_IGNORE_LEADING);
63 
64  testTransform(" $5 ! I have $5 !!", " 5 I have 5 ",
65  Ci.sbIStringTransform.TRANSFORM_IGNORE_NONALPHANUM);
66 
67  testTransform(" $5 ! I have $5 !!", " $5 ! I have $5 !!",
68  Ci.sbIStringTransform.TRANSFORM_IGNORE_NONALPHANUM |
69  Ci.sbIStringTransform.TRANSFORM_IGNORE_LEADING);
70 
71  testTransform(" $5 ! I have $5 !!", "5Ihave5",
72  Ci.sbIStringTransform.TRANSFORM_IGNORE_NONALPHANUM_IGNORE_SPACE);
73 
74  testTransform(" $5 ! I have $5 !!", "5 ! I have $5 !!",
75  Ci.sbIStringTransform.TRANSFORM_IGNORE_NONALPHANUM_IGNORE_SPACE |
76  Ci.sbIStringTransform.TRANSFORM_IGNORE_LEADING);
77 
78  testTransform(" +250 -25 Hello", "250 -25 Hello",
79  Ci.sbIStringTransform.TRANSFORM_IGNORE_NONALPHANUM_IGNORE_SPACE |
80  Ci.sbIStringTransform.TRANSFORM_IGNORE_LEADING);
81 
82 
83  testTransform(" +250 -25 Hello", "+250 -25 Hello",
84  Ci.sbIStringTransform.TRANSFORM_IGNORE_NONALPHANUM_IGNORE_SPACE |
85  Ci.sbIStringTransform.TRANSFORM_IGNORE_LEADING |
86  Ci.sbIStringTransform.TRANSFORM_IGNORE_KEEPNUMBERSYMBOLS);
87 
88  testTransform(" -45.3 Hi", "-45.3 Hi",
89  Ci.sbIStringTransform.TRANSFORM_IGNORE_NONALPHANUM_IGNORE_SPACE |
90  Ci.sbIStringTransform.TRANSFORM_IGNORE_LEADING |
91  Ci.sbIStringTransform.TRANSFORM_IGNORE_KEEPNUMBERSYMBOLS);
92 
93  testTransform(" -45.3 Hi", "45.3 Hi",
94  Ci.sbIStringTransform.TRANSFORM_IGNORE_NONALPHANUM_IGNORE_SPACE |
95  Ci.sbIStringTransform.TRANSFORM_IGNORE_LEADING);
96 
97  testTransform(" -.025 Hi", "-.025 Hi",
98  Ci.sbIStringTransform.TRANSFORM_IGNORE_NONALPHANUM_IGNORE_SPACE |
99  Ci.sbIStringTransform.TRANSFORM_IGNORE_LEADING |
100  Ci.sbIStringTransform.TRANSFORM_IGNORE_KEEPNUMBERSYMBOLS);
101 
102  testTransform(" -.025 Hi", "025 Hi",
103  Ci.sbIStringTransform.TRANSFORM_IGNORE_NONALPHANUM_IGNORE_SPACE |
104  Ci.sbIStringTransform.TRANSFORM_IGNORE_LEADING);
105 
106  testTransform(" .999 Hi", ".999 Hi",
107  Ci.sbIStringTransform.TRANSFORM_IGNORE_NONALPHANUM_IGNORE_SPACE |
108  Ci.sbIStringTransform.TRANSFORM_IGNORE_LEADING |
109  Ci.sbIStringTransform.TRANSFORM_IGNORE_KEEPNUMBERSYMBOLS);
110 
111  testTransform(" .999 Hi", "999 Hi",
112  Ci.sbIStringTransform.TRANSFORM_IGNORE_NONALPHANUM_IGNORE_SPACE |
113  Ci.sbIStringTransform.TRANSFORM_IGNORE_LEADING);
114 
115  testTransform(" 1e10 Hi", "1e10 Hi",
116  Ci.sbIStringTransform.TRANSFORM_IGNORE_NONALPHANUM_IGNORE_SPACE |
117  Ci.sbIStringTransform.TRANSFORM_IGNORE_LEADING |
118  Ci.sbIStringTransform.TRANSFORM_IGNORE_KEEPNUMBERSYMBOLS);
119 
120  testTransform(" 1e10 Hi", "1e10 Hi",
121  Ci.sbIStringTransform.TRANSFORM_IGNORE_NONALPHANUM_IGNORE_SPACE |
122  Ci.sbIStringTransform.TRANSFORM_IGNORE_LEADING);
123 
124  testTransform(" 1e-10 Hi", "1e-10 Hi",
125  Ci.sbIStringTransform.TRANSFORM_IGNORE_NONALPHANUM_IGNORE_SPACE |
126  Ci.sbIStringTransform.TRANSFORM_IGNORE_LEADING |
127  Ci.sbIStringTransform.TRANSFORM_IGNORE_KEEPNUMBERSYMBOLS);
128 
129  testTransform(" 1e-10 Hi", "1e-10 Hi",
130  Ci.sbIStringTransform.TRANSFORM_IGNORE_NONALPHANUM_IGNORE_SPACE |
131  Ci.sbIStringTransform.TRANSFORM_IGNORE_LEADING);
132 
133  testTransform(" -1e10 Hi", "-1e10 Hi",
134  Ci.sbIStringTransform.TRANSFORM_IGNORE_NONALPHANUM_IGNORE_SPACE |
135  Ci.sbIStringTransform.TRANSFORM_IGNORE_LEADING |
136  Ci.sbIStringTransform.TRANSFORM_IGNORE_KEEPNUMBERSYMBOLS);
137 
138  testTransform(" -1e10 Hi", "1e10 Hi",
139  Ci.sbIStringTransform.TRANSFORM_IGNORE_NONALPHANUM_IGNORE_SPACE |
140  Ci.sbIStringTransform.TRANSFORM_IGNORE_LEADING);
141 
142  testTransform(" +1e-10 Hi", "+1e-10 Hi",
143  Ci.sbIStringTransform.TRANSFORM_IGNORE_NONALPHANUM_IGNORE_SPACE |
144  Ci.sbIStringTransform.TRANSFORM_IGNORE_LEADING |
145  Ci.sbIStringTransform.TRANSFORM_IGNORE_KEEPNUMBERSYMBOLS);
146 
147  testTransform(" +1e-10 Hi", "1e-10 Hi",
148  Ci.sbIStringTransform.TRANSFORM_IGNORE_NONALPHANUM_IGNORE_SPACE |
149  Ci.sbIStringTransform.TRANSFORM_IGNORE_LEADING);
150 
151  testTransform(" +.21e-10 Hi", "+.21e-10 Hi",
152  Ci.sbIStringTransform.TRANSFORM_IGNORE_NONALPHANUM_IGNORE_SPACE |
153  Ci.sbIStringTransform.TRANSFORM_IGNORE_LEADING |
154  Ci.sbIStringTransform.TRANSFORM_IGNORE_KEEPNUMBERSYMBOLS);
155 
156  testTransform(" +.21e-10 Hi", "21e-10 Hi",
157  Ci.sbIStringTransform.TRANSFORM_IGNORE_NONALPHANUM_IGNORE_SPACE |
158  Ci.sbIStringTransform.TRANSFORM_IGNORE_LEADING);
159 
160  testTransform("I have $+5! How about that?! heh!", "I have aaaeciie +5 How about that heh",
161  Ci.sbIStringTransform.TRANSFORM_IGNORE_NONSPACE |
162  Ci.sbIStringTransform.TRANSFORM_IGNORE_NONALPHANUM |
163  Ci.sbIStringTransform.TRANSFORM_IGNORE_KEEPNUMBERSYMBOLS);
164 
165  testTransform("I have $+5! How about that?! heh!", "Ihaveaaaeciie+5Howaboutthatheh",
166  Ci.sbIStringTransform.TRANSFORM_IGNORE_NONSPACE |
167  Ci.sbIStringTransform.TRANSFORM_IGNORE_NONALPHANUM_IGNORE_SPACE |
168  Ci.sbIStringTransform.TRANSFORM_IGNORE_KEEPNUMBERSYMBOLS);
169 
170  return;
171 }
const Cc
function log(s)
function testTransform(aTestIn, aTestExpectedOut, aFlag)
function assertEqual(aExpected, aActual, aMessage)
const Ci
function runTest()
Advanced DataRemote unit tests.