|
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
2 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
5 |
|
6 //----------------------------------------------------------------------------- |
|
7 var BUGNUMBER = 306591; |
|
8 var summary = 'String static methods'; |
|
9 var actual = ''; |
|
10 var expect = ''; |
|
11 |
|
12 printBugNumber(BUGNUMBER); |
|
13 printStatus (summary); |
|
14 printStatus ('See https://bugzilla.mozilla.org/show_bug.cgi?id=304828'); |
|
15 |
|
16 expect = ['a', 'b', 'c'].toString(); |
|
17 actual = String.split(new String('abc'), '').toString(); |
|
18 reportCompare(expect, actual, summary + |
|
19 " String.split(new String('abc'), '')"); |
|
20 |
|
21 expect = '2'; |
|
22 actual = String.substring(new Number(123), 1, 2); |
|
23 reportCompare(expect, actual, summary + |
|
24 " String.substring(new Number(123), 1, 2)"); |
|
25 |
|
26 expect = 'TRUE'; |
|
27 actual = String.toUpperCase(new Boolean(true)); |
|
28 reportCompare(expect, actual, summary + |
|
29 " String.toUpperCase(new Boolean(true))"); |
|
30 |
|
31 try |
|
32 { |
|
33 String.indexOf(null, 'l'); |
|
34 throw new Error("should have thrown a TypeError"); |
|
35 } |
|
36 catch (e) |
|
37 { |
|
38 assertEq(e instanceof TypeError, true, |
|
39 "String.indexOf(null [, ...]) didn't work correctly"); |
|
40 } |
|
41 |
|
42 expect = 2; |
|
43 actual = String.indexOf(String(null), 'l'); |
|
44 reportCompare(expect, actual, summary + |
|
45 " String.indexOf(String(null), 'l')"); |
|
46 |
|
47 expect = ['a', 'b', 'c'].toString(); |
|
48 actual = String.split('abc', '').toString(); |
|
49 reportCompare(expect, actual, summary + |
|
50 " String.split('abc', '')"); |
|
51 |
|
52 expect = '2'; |
|
53 actual = String.substring(123, 1, 2); |
|
54 reportCompare(expect, actual, summary + |
|
55 " String.substring(123, 1, 2)"); |
|
56 |
|
57 expect = 'TRUE'; |
|
58 actual = String.toUpperCase(true); |
|
59 reportCompare(expect, actual, summary + |
|
60 " String.toUpperCase(true)"); |
|
61 |
|
62 try |
|
63 { |
|
64 String.indexOf(undefined, 'd'); |
|
65 throw new Error("should have thrown a TypeError"); |
|
66 } |
|
67 catch (e) |
|
68 { |
|
69 assertEq(e instanceof TypeError, true, |
|
70 "String.indexOf(undefined [, ...]) didn't work correctly"); |
|
71 } |
|
72 |
|
73 expect = 2; |
|
74 actual = String.indexOf(String(undefined), 'd'); |
|
75 reportCompare(expect, actual, summary + |
|
76 " String.indexOf(String(undefined), 'd')"); |