1// Copyright 2014 the V8 project authors. All rights reserved. 2// Redistribution and use in source and binary forms, with or without 3// modification, are permitted provided that the following conditions are 4// met: 5// 6// * Redistributions of source code must retain the above copyright 7// notice, this list of conditions and the following disclaimer. 8// * Redistributions in binary form must reproduce the above 9// copyright notice, this list of conditions and the following 10// disclaimer in the documentation and/or other materials provided 11// with the distribution. 12// * Neither the name of Google Inc. nor the names of its 13// contributors may be used to endorse or promote products derived 14// from this software without specific prior written permission. 15// 16// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 28// Mimics assert module in node. 29 30function compose(message1, message2) { 31 return message2 ? message1 + ': ' + message2 : message1 32} 33 34function fail(actual, expected, message, operator) { 35 var e = Error(compose('FAIL', message) + 36 ': (' + actual + ' ' + operator + ' ' + expected + ') should hold'); 37 fails.push(e); 38 throw e; 39} 40 41function ok(value, message) { 42 if (!value) { 43 throw Error(compose('FAIL', + message) + ': value = ' + value); 44 } 45} 46 47function equal(actual, expected, message) { 48 if (!(expected == actual)) { 49 fail(actual, expected, message, '=='); 50 } 51} 52 53function notEqual(actual, expected, message) { 54 if (!(expected != actual)) { 55 fail(actual, expected, message, '!='); 56 } 57} 58 59function strictEqual(actual, expected, message) { 60 if (!(expected === actual)) { 61 fail(actual, expected, message, '==='); 62 } 63} 64 65function notStrictEqual(actual, expected, message) { 66 if (!(expected !== actual)) { 67 fail(actual, expected, message, '!=='); 68 } 69} 70 71function assert(value, message) { 72 return ok(value, message); 73} 74 75function notImplemented() { 76 throw Error('FAIL: This assertion function is not yet implemented.'); 77} 78 79function clear() { 80 this.fails = []; 81} 82 83assert.fail = fail; 84assert.ok = ok; 85assert.equal = equal; 86assert.notEqual = notEqual; 87assert.deepEqual = notImplemented; 88assert.notDeepEqual = notImplemented; 89assert.strictEqual = strictEqual; 90assert.notStrictEqual = notStrictEqual; 91assert.throws = notImplemented; 92assert.doesNotThrow = notImplemented; 93assert.ifError = notImplemented; 94 95assert.clear = clear; 96 97exports = assert; 98