michael@0: // |reftest| skip -- obsolete test michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: michael@0: /** michael@0: File Name: tostring-1.js michael@0: Section: Function.toString michael@0: Description: michael@0: michael@0: Since the behavior of Function.toString() is implementation-dependent, michael@0: toString tests for function are not in the ECMA suite. michael@0: michael@0: Currently, an attempt to parse the toString output for some functions michael@0: and verify that the result is something reasonable. michael@0: michael@0: This verifies michael@0: http://scopus.mcom.com/bugsplat/show_bug.cgi?id=99212 michael@0: michael@0: Author: christine@netscape.com michael@0: Date: 12 november 1997 michael@0: */ michael@0: michael@0: var SECTION = "tostring-2"; michael@0: var VERSION = "JS1_2"; michael@0: var TITLE = "Function.toString()"; michael@0: var BUGNUMBER="123444"; michael@0: startTest(); michael@0: michael@0: writeHeaderToLog( SECTION + " "+ TITLE); michael@0: michael@0: var tab = " "; michael@0: michael@0: michael@0: var equals = new TestFunction( "Equals", "a, b", tab+ "return a == b;" ); michael@0: function Equals (a, b) { michael@0: return a == b; michael@0: } michael@0: michael@0: var reallyequals = new TestFunction( "ReallyEquals", "a, b", michael@0: ( version() <= 120 ) ? tab +"return a == b;" : tab +"return a === b;" ); michael@0: function ReallyEquals( a, b ) { michael@0: return a === b; michael@0: } michael@0: michael@0: var doesntequal = new TestFunction( "DoesntEqual", "a, b", tab + "return a != b;" ); michael@0: function DoesntEqual( a, b ) { michael@0: return a != b; michael@0: } michael@0: michael@0: var reallydoesntequal = new TestFunction( "ReallyDoesntEqual", "a, b", michael@0: ( version() <= 120 ) ? tab +"return a != b;" : tab +"return a !== b;" ); michael@0: function ReallyDoesntEqual( a, b ) { michael@0: return a !== b; michael@0: } michael@0: michael@0: var testor = new TestFunction( "TestOr", "a", tab+"if (a == null || a == void 0) {\n"+ michael@0: tab +tab+"return 0;\n"+tab+"} else {\n"+tab+tab+"return a;\n"+tab+"}" ); michael@0: function TestOr( a ) { michael@0: if ( a == null || a == void 0 ) michael@0: return 0; michael@0: else michael@0: return a; michael@0: } michael@0: michael@0: var testand = new TestFunction( "TestAnd", "a", tab+"if (a != null && a != void 0) {\n"+ michael@0: tab+tab+"return a;\n" + tab+ "} else {\n"+tab+tab+"return 0;\n"+tab+"}" ); michael@0: function TestAnd( a ) { michael@0: if ( a != null && a != void 0 ) michael@0: return a; michael@0: else michael@0: return 0; michael@0: } michael@0: michael@0: var or = new TestFunction( "Or", "a, b", tab + "return a | b;" ); michael@0: function Or( a, b ) { michael@0: return a | b; michael@0: } michael@0: michael@0: var and = new TestFunction( "And", "a, b", tab + "return a & b;" ); michael@0: function And( a, b ) { michael@0: return a & b; michael@0: } michael@0: michael@0: var xor = new TestFunction( "XOr", "a, b", tab + "return a ^ b;" ); michael@0: function XOr( a, b ) { michael@0: return a ^ b; michael@0: } michael@0: michael@0: new TestCase( SECTION, michael@0: "Equals.toString()", michael@0: equals.valueOf(), michael@0: Equals.toString() ); michael@0: michael@0: new TestCase( SECTION, michael@0: "ReallyEquals.toString()", michael@0: reallyequals.valueOf(), michael@0: ReallyEquals.toString() ); michael@0: michael@0: new TestCase( SECTION, michael@0: "DoesntEqual.toString()", michael@0: doesntequal.valueOf(), michael@0: DoesntEqual.toString() ); michael@0: michael@0: new TestCase( SECTION, michael@0: "ReallyDoesntEqual.toString()", michael@0: reallydoesntequal.valueOf(), michael@0: ReallyDoesntEqual.toString() ); michael@0: michael@0: new TestCase( SECTION, michael@0: "TestOr.toString()", michael@0: testor.valueOf(), michael@0: TestOr.toString() ); michael@0: michael@0: new TestCase( SECTION, michael@0: "TestAnd.toString()", michael@0: testand.valueOf(), michael@0: TestAnd.toString() ); michael@0: michael@0: new TestCase( SECTION, michael@0: "Or.toString()", michael@0: or.valueOf(), michael@0: Or.toString() ); michael@0: michael@0: new TestCase( SECTION, michael@0: "And.toString()", michael@0: and.valueOf(), michael@0: And.toString() ); michael@0: michael@0: new TestCase( SECTION, michael@0: "XOr.toString()", michael@0: xor.valueOf(), michael@0: XOr.toString() ); michael@0: michael@0: test(); michael@0: michael@0: function TestFunction( name, args, body ) { michael@0: this.name = name; michael@0: this.arguments = args.toString(); michael@0: this.body = body; michael@0: michael@0: /* the format of Function.toString() in JavaScript 1.2 is: michael@0: function name ( arguments ) { michael@0: body michael@0: } michael@0: */ michael@0: this.value = "function " + (name ? name : "anonymous" )+ michael@0: "("+args+") {\n"+ (( body ) ? body +"\n" : "") + "}"; michael@0: michael@0: this.toString = new Function( "return this.value" ); michael@0: this.valueOf = new Function( "return this.value" ); michael@0: return this; michael@0: }