1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is JavaScript Engine testing utilities.
17 * The Initial Developer of the Original Code is
19 * Portions created by the Initial Developer are Copyright (C) 2007
20 * the Initial Developer. All Rights Reserved.
23 * Mike Kaplinskiy <mike.kaplinskiy@gmail.com>
25 * Alternatively, the contents of this file may be used under the terms of
26 * either the GNU General Public License Version 2 or later (the "GPL"), or
27 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
37 * ***** END LICENSE BLOCK ***** */
39 var gTestfile
= 'regress-305064.js';
40 //-----------------------------------------------------------------------------
41 var BUGNUMBER
= 305064;
42 var summary
= 'Tests the trim, trimRight and trimLeft methods';
46 printBugNumber(BUGNUMBER
);
47 printStatus (summary
);
49 var trimMethods
= ['trim', 'trimLeft', 'trimRight'];
51 /** List from ES 3.1 Recommendation for String.trim (bug 305064) **/
53 {s
: '\u0009', t
: 'HORIZONTAL TAB'},
54 {s
: '\u000B', t
: 'VERTICAL TAB'},
55 {s
: '\u000C', t
: 'FORMFEED'},
56 {s
: '\u0020', t
: 'SPACE'},
57 {s
: '\u00A0', t
: 'NO-BREAK SPACE'},
58 {s
: '\u1680', t
: 'OGHAM SPACE MARK'},
59 {s
: '\u180E', t
: 'MONGOLIAN VOWEL SEPARATOR'},
60 {s
: '\u2000', t
: 'EN QUAD'},
61 {s
: '\u2001', t
: 'EM QUAD'},
62 {s
: '\u2002', t
: 'EN SPACE'},
63 {s
: '\u2003', t
: 'EM SPACE'},
64 {s
: '\u2004', t
: 'THREE-PER-EM SPACE'},
65 {s
: '\u2005', t
: 'FOUR-PER-EM SPACE'},
66 {s
: '\u2006', t
: 'SIX-PER-EM SPACE'},
67 {s
: '\u2007', t
: 'FIGURE SPACE'},
68 {s
: '\u2008', t
: 'PUNCTUATION SPACE'},
69 {s
: '\u2009', t
: 'THIN SPACE'},
70 {s
: '\u200A', t
: 'HAIR SPACE'},
71 {s
: '\u202F', t
: 'NARROW NO-BREAK SPACE'},
72 {s
: '\u205F', t
: 'MEDIUM MATHEMATICAL SPACE'},
73 {s
: '\u3000', t
: 'IDEOGRAPHIC SPACE'},
74 {s
: '\u000A', t
: 'LINE FEED OR NEW LINE'},
75 {s
: '\u000D', t
: 'CARRIAGE RETURN'},
76 {s
: '\u2028', t
: 'LINE SEPARATOR'},
77 {s
: '\u2029', t
: 'PARAGRAPH SEPARATOR'},
78 {s
: '\u200B', t
: 'ZERO WIDTH SPACE (category Cf)'}
81 for (var j
= 0; j
< trimMethods
.length
; ++j
)
85 var method
= trimMethods
[j
];
87 if (typeof String
.prototype[method
] == 'undefined')
89 reportCompare(true, true, 'Test skipped. String.prototype.' + method
+ ' is not supported');
93 print('Test empty string.');
96 actual
= str
[method
]();
97 reportCompare(expected
, actual
, '"' + toPrinted(str
) + '".' + method
+ '()');
99 print('Test string with no whitespace.');
102 actual
= str
[method
]();
103 reportCompare(expected
, actual
, '"' + toPrinted(str
) + '".' + method
+ '()');
105 for (var i
= 0; i
< whitespace
.length
; ++i
)
107 var v
= whitespace
[i
].s
;
108 var t
= whitespace
[i
].t
;
111 print('=======================================');
112 print('Test ' + method
+ ' with with only whitespace. : ' + t
);
115 actual
= str
[method
]();
116 reportCompare(expected
, actual
, t
+ ':' + '"' + toPrinted(str
) + '".' + method
+ '()');
118 print('Test ' + method
+ ' with with no leading or trailing whitespace. : ' + t
);
121 actual
= str
[method
]();
122 reportCompare(expected
, actual
, t
+ ':' + '"' + toPrinted(str
) + '".' + method
+ '()');
124 print('Test ' + method
+ ' with with leading whitespace. : ' + t
);
138 actual
= str
[method
]();
139 reportCompare(expected
, actual
, t
+ ':' + '"' + toPrinted(str
) + '".' + method
+ '()');
141 print('Test ' + method
+ ' with with trailing whitespace. : ' + t
);
155 actual
= str
[method
]();
156 reportCompare(expected
, actual
, t
+ ':' + '"' + toPrinted(str
) + '".' + method
+ '()');
158 print('Test ' + method
+ ' with with leading and trailing whitepace.');
172 actual
= str
[method
]();
173 reportCompare(expected
, actual
, t
+ ':' + '"' + toPrinted(str
) + '".' + method
+ '()');