]>
git.saurik.com Git - apple/javascriptcore.git/blob - tests/mozilla/js1_2/function/tostring-2.js
146764d2f1822ee6dbfeacd85214e5ee4e22ac91
1 /* The contents of this file are subject to the Netscape Public
2 * License Version 1.1 (the "License"); you may not use this file
3 * except in compliance with the License. You may obtain a copy of
4 * the License at http://www.mozilla.org/NPL/
6 * Software distributed under the License is distributed on an "AS
7 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
8 * implied. See the License for the specific language governing
9 * rights and limitations under the License.
11 * The Original Code is Mozilla Communicator client code, released March
14 * The Initial Developer of the Original Code is Netscape Communications
15 * Corporation. Portions created by Netscape are
16 * Copyright (C) 1998 Netscape Communications Corporation. All
23 File Name: tostring-1.js
24 Section: Function.toString
27 Since the behavior of Function.toString() is implementation-dependent,
28 toString tests for function are not in the ECMA suite.
30 Currently, an attempt to parse the toString output for some functions
31 and verify that the result is something reasonable.
34 http://scopus.mcom.com/bugsplat/show_bug.cgi?id=99212
36 Author: christine@netscape.com
37 Date: 12 november 1997
40 var SECTION
= "tostring-2";
41 var VERSION
= "JS1_2";
43 var TITLE
= "Function.toString()";
44 var BUGNUMBER
="123444";
46 writeHeaderToLog( SECTION
+ " "+ TITLE
);
48 var testcases
= new Array();
53 var equals
= new TestFunction( "Equals", "a, b", tab
+ "return a == b;" );
54 function Equals (a
, b
) {
58 var reallyequals
= new TestFunction( "ReallyEquals", "a, b",
59 ( version() <= 120 ) ? tab
+"return a == b;" : tab
+"return a === b;" );
60 function ReallyEquals( a
, b
) {
64 var doesntequal
= new TestFunction( "DoesntEqual", "a, b", tab
+ "return a != b;" );
65 function DoesntEqual( a
, b
) {
69 var reallydoesntequal
= new TestFunction( "ReallyDoesntEqual", "a, b",
70 ( version() <= 120 ) ? tab
+"return a != b;" : tab
+"return a !== b;" );
71 function ReallyDoesntEqual( a
, b
) {
75 var testor
= new TestFunction( "TestOr", "a", tab
+"if (a == null || a == void 0) {\n"+
76 tab
+tab
+"return 0;\n"+tab
+"} else {\n"+tab
+tab
+"return a;\n"+tab
+"}" );
77 function TestOr( a
) {
78 if ( a
== null || a
== void 0 )
84 var testand
= new TestFunction( "TestAnd", "a", tab
+"if (a != null && a != void 0) {\n"+
85 tab
+tab
+"return a;\n" + tab
+ "} else {\n"+tab
+tab
+"return 0;\n"+tab
+"}" );
86 function TestAnd( a
) {
87 if ( a
!= null && a
!= void 0 )
93 var or
= new TestFunction( "Or", "a, b", tab
+ "return a | b;" );
98 var and
= new TestFunction( "And", "a, b", tab
+ "return a & b;" );
99 function And( a
, b
) {
103 var xor
= new TestFunction( "XOr", "a, b", tab
+ "return a ^ b;" );
104 function XOr( a
, b
) {
108 testcases
[testcases
.length
] = new TestCase( SECTION
,
113 testcases
[testcases
.length
] = new TestCase( SECTION
,
114 "ReallyEquals.toString()",
115 reallyequals
.valueOf(),
116 ReallyEquals
.toString() );
118 testcases
[testcases
.length
] = new TestCase( SECTION
,
119 "DoesntEqual.toString()",
120 doesntequal
.valueOf(),
121 DoesntEqual
.toString() );
123 testcases
[testcases
.length
] = new TestCase( SECTION
,
124 "ReallyDoesntEqual.toString()",
125 reallydoesntequal
.valueOf(),
126 ReallyDoesntEqual
.toString() );
128 testcases
[testcases
.length
] = new TestCase( SECTION
,
133 testcases
[testcases
.length
] = new TestCase( SECTION
,
134 "TestAnd.toString()",
136 TestAnd
.toString() );
138 testcases
[testcases
.length
] = new TestCase( SECTION
,
143 testcases
[testcases
.length
] = new TestCase( SECTION
,
148 testcases
[testcases
.length
] = new TestCase( SECTION
,
156 for ( tc
=0; tc
< testcases
.length
; tc
++ ) {
157 testcases
[tc
].passed
= writeTestCaseResult(
158 testcases
[tc
].expect
,
159 testcases
[tc
].actual
,
160 testcases
[tc
].description
+" = "+
161 testcases
[tc
].actual
);
163 testcases
[tc
].reason
+= ( testcases
[tc
].passed
) ? "" : "wrong value ";
166 return ( testcases
);
168 function TestFunction( name
, args
, body
) {
170 this.arguments
= args
.toString();
173 /* the format of Function.toString() in JavaScript 1.2 is:
175 function name ( arguments ) {
179 this.value
= "\nfunction " + (name
? name : "anonymous" )+
180 "("+args
+") {\n"+ (( body
) ? body
+"\n" : "") + "}\n";
182 this.toString
= new Function( "return this.value" );
183 this.valueOf
= new Function( "return this.value" );