LibJS: Use the native assert() implementation now avaiable in 'js -t'

Switch the LibJS test suite to use the native assert implementation
surfaced inside the js repl when it's launched in test mode.
This commit is contained in:
Brian Gianforcaro 2020-04-05 05:52:09 -07:00 committed by Andreas Kling
parent 4233c8662b
commit bc40908d32
Notes: sideshowbarker 2024-07-19 07:54:00 +09:00
60 changed files with 2 additions and 119 deletions

View file

@ -1,5 +1,3 @@
function assert(x) { if (!x) throw 1; }
try {
assert(Array.length === 1);
assert(Array.prototype.length === 0);

View file

@ -1,5 +1,3 @@
function assert(x) { if (!x) throw 1; }
try {
var a = [1, 2, 3];
var value = a.pop();

View file

@ -1,5 +1,3 @@
function assert(x) { if (!x) throw 1; }
try {
var a = [1, 2, 3];
var value = a.shift();

View file

@ -1,5 +1,3 @@
function assert(x) { if (!x) throw 1; }
try {
var last = 0;
for (var i = 0; i < 100; ++i) {

View file

@ -1,5 +1,3 @@
function assert(x) { if (!x) throw 1; }
try {
var d = new Date();
assert(!isNaN(d.getDate()));

View file

@ -1,5 +1,3 @@
function assert(x) { if (!x) throw 1; }
try {
var d = new Date();
assert(!isNaN(d.getDay()));

View file

@ -1,5 +1,3 @@
function assert(x) { if (!x) throw 1; }
try {
var d = new Date();
assert(!isNaN(d.getFullYear()));

View file

@ -1,5 +1,3 @@
function assert(x) { if (!x) throw 1; }
try {
var d = new Date();
assert(!isNaN(d.getHours()));

View file

@ -1,5 +1,3 @@
function assert(x) { if (!x) throw 1; }
try {
var d = new Date();
assert(!isNaN(d.getMilliseconds()));

View file

@ -1,5 +1,3 @@
function assert(x) { if (!x) throw 1; }
try {
var d = new Date();
assert(!isNaN(d.getMinutes()));

View file

@ -1,5 +1,3 @@
function assert(x) { if (!x) throw 1; }
try {
var d = new Date();
assert(!isNaN(d.getMonth()));

View file

@ -1,5 +1,3 @@
function assert(x) { if (!x) throw 1; }
try {
var d = new Date();
assert(!isNaN(d.getSeconds()));

View file

@ -1,5 +1,3 @@
function assert(x) { if (!x) throw 1; }
try {
var d = new Date();
assert(!isNaN(d.getTime()));

View file

@ -1,5 +1,3 @@
function assert(x) { if (!x) throw 1; }
try {
var e;

View file

@ -1,5 +1,3 @@
function assert(x) { if (!x) throw 1; }
try {
assert(Error().toString() === "Error");
assert(Error(undefined).toString() === "Error");

View file

@ -1,5 +1,3 @@
function assert(x) { if (!x) throw 1; }
try {
assert(Function.length === 1);
assert(Function.prototype.length === 0);

View file

@ -1,5 +1,3 @@
function assert(x) { if (!x) throw 1; }
try {
function Foo(arg) {
this.foo = arg;

View file

@ -1,5 +1,3 @@
function assert(x) { if (!x) throw 1; }
try {
function Foo(arg) {
this.foo = arg;

View file

@ -1,5 +1,3 @@
function assert(x) { if (!x) throw 1; }
try {
assert((function() {}).toString() === "function () {\n ???\n}");
assert((function(foo) {}).toString() === "function (foo) {\n ???\n}");

View file

@ -1,5 +1,3 @@
function assert(x) { if (!x) throw 1; }
try {
assert(Infinity + "" === "Infinity");
assert(-Infinity + "" === "-Infinity");

View file

@ -1,5 +1,3 @@
function assert(x) { if (!x) throw 1; }
// FIXME: The parser seems to have issues with decimals,
// so we multiply everything and compare with whole numbers.
// I.e. 1233 < X * 1000 < 1235 instead of 1.233 < X < 1.235

View file

@ -1,5 +1,3 @@
function assert(x) { if (!x) throw 1; }
try {
assert(Math.abs('-1') === 1);
assert(Math.abs(-2) === 2);

View file

@ -1,5 +1,3 @@
function assert(x) { if (!x) throw 1; }
try {
assert(Math.ceil(0.95) === 1);
assert(Math.ceil(4) === 4);

View file

@ -1,5 +1,3 @@
function assert(x) { if (!x) throw 1; }
try {
assert(Math.max.length === 2);
assert(Math.max(1) === 1);

View file

@ -1,5 +1,3 @@
function assert(x) { if (!x) throw 1; }
try {
assert(Math.sqrt(9) === 3);
console.log("PASS");

View file

@ -1,5 +1,3 @@
function assert(x) { if (!x) throw 1; }
try {
assert(Math.trunc(13.37) === 13);
assert(Math.trunc(42.84) === 42);

View file

@ -1,5 +1,3 @@
function assert(x) { if (!x) throw 1; }
try {
var nan = undefined + 1;
assert(nan + "" == "NaN");

View file

@ -1,5 +1,3 @@
function assert(x) { if (!x) throw 1; }
try {
var names = Object.getOwnPropertyNames([1, 2, 3]);

View file

@ -1,5 +1,3 @@
function assert(x) { if (!x) throw 1; }
try {
var o1 = new Object();
var o2 = {};

View file

@ -1,5 +1,3 @@
function assert(x) { if (!x) throw 1; }
try {
var o = {};
o.foo = 1;

View file

@ -1,5 +1,3 @@
function assert(x) { if (!x) throw 1; }
try {
var o = new Object();
Object.prototype.foo = 123;

View file

@ -1,5 +1,3 @@
function assert(x) { if (!x) throw 1; }
try {
assert(typeof Object.prototype.toString() === "string");
console.log("PASS");

View file

@ -1,5 +1,3 @@
function assert(x) { if (!x) throw 1; }
try {
var s = "foobar"
assert(typeof s === "string");

View file

@ -1,5 +1,3 @@
function assert(x) { if (!x) throw 1; }
try {
var s = "hello friends"

View file

@ -1,5 +1,3 @@
function assert(x) { if (!x) throw 1; }
try {
var s = "foobar";
assert(s.startsWith("f") === true);

View file

@ -1,5 +1,3 @@
function assert(x) { if (!x) throw 1; }
try {
var a = [1, 2, 3];

View file

@ -1,4 +1,3 @@
function assert(x) { if (!x) throw 1; }
try {
let getNumber = () => 42;
assert(getNumber() === 42);

View file

@ -1,5 +1,3 @@
function assert(x) { if (!x) throw 1; }
try {
assert((0 | 0) === 0);
assert((0 | 1) === 1);

View file

@ -1,5 +1,3 @@
function assert(x) { if (!x) throw 1; }
try {
var j = 0;
for (var i = 0; i < 9; ++i) {

View file

@ -1,5 +1,3 @@
function assert(x) { if (!x) throw 1; }
try {
var number = 0;
do {

View file

@ -1,5 +1,3 @@
function assert(x) { if (!x) console.log("FAIL"); }
try {
i < 3;
} catch (e) {

View file

@ -1,5 +1,3 @@
function assert(x) { if (!x) throw 1; }
try {
var a = [];
for (var i = 0; i < 3; ++i) {

View file

@ -1,5 +1,3 @@
function assert(x) { if (!x) throw 1; }
try {
var number = 0;

View file

@ -1,5 +1,3 @@
function assert(x) { if (!x) throw 1; }
try {
try {
var b = true;

View file

@ -1,5 +1,3 @@
function assert(x) { if (!x) throw 1; }
try {
function foo() { }
assert(foo.length === 0);

View file

@ -1,5 +1,3 @@
function assert(x) { if (!x) throw 1; }
function foo(a, b) { return a + b; }
try {

View file

@ -1,5 +1,3 @@
function assert(x) { if (!x) throw 1; }
try {
assert(typeof this === "object");
assert(this === global);

View file

@ -1,5 +1,3 @@
function assert(x) { if (!x) throw 1; }
try {
function Foo() {
this.x = 123;

View file

@ -1,5 +1,3 @@
function assert(x) { if (!x) throw 1; }
try {
assert((true && true) === true);
assert((false && false) === false);

View file

@ -1,5 +1,3 @@
function assert(x) { if (!x) throw 1; }
try {
let foo = 1;
false && (foo = 2);

View file

@ -1,5 +1,3 @@
function assert(x) { if (!x) throw 1; }
try {
assert(10 % 3 === 1);
assert(10.5 % 2.5 === 0.5);

View file

@ -1,5 +1,3 @@
function assert(x) { if (!x) throw 1; }
try {
var o = {};
o.a = 1;

View file

@ -14,7 +14,7 @@ fail_count=0
count=0
for f in *.js; do
result=`$js_program $f`
result=`$js_program -t $f`
if [ "$result" = "PASS" ]; then
let pass_count++
echo -ne "( \033[32;1mPass\033[0m ) "

View file

@ -1,5 +1,3 @@
function assert(x) { if (!x) throw 1; }
try {
var i = 0;
var three;

View file

@ -1,10 +1,8 @@
function assert(x) { if (!x) throw 1; }
try {
var x = 1;
assert(x === 1 ? true : false);
assert(x ? x : 0);
assert((x ? x : 0) === x);
assert(1 < 2 ? (true) : (false));
var o = {};

View file

@ -1,5 +1,3 @@
function assert(x) { if (!x) console.log("FAIL"); }
try {
throw 1;
} catch (e) {

View file

@ -1,5 +1,3 @@
function assert(x) { if (!x) throw 1; }
try {
assert(+false === 0);
assert(-false === 0);

View file

@ -1,5 +1,3 @@
function assert(x) { if (!x) throw 1; }
try {
assert(typeof "foo" === "string");
assert(!(typeof "foo" !== "string"));

View file

@ -1,5 +1,3 @@
function assert(x) { if (!x) throw 1; }
try {
var a = 1, b = 2, c = a + b;
assert(a === 1);

View file

@ -1,5 +1,3 @@
function assert(x) { if (!x) throw 1; }
function foo(a) {
return a;
}