Update Jasmine to version 4

For the unit-tests that were updated in this patch, note that I settled on simply using `toEqual` comparisons rather than updating the custom matchers (since those don't seem necessary any more).

Please refer to the following resources for additional information:
 - https://github.com/jasmine/jasmine/blob/main/release_notes/4.0.0.md
 - https://github.com/jasmine/jasmine-npm/blob/main/release_notes/4.0.0.md
 - https://jasmine.github.io/tutorials/upgrading_to_Jasmine_4.0
This commit is contained in:
Jonas Jenwald 2022-01-09 10:27:06 +01:00
parent 38e574f1d5
commit 457ff0d54a
5 changed files with 89 additions and 171 deletions

30
package-lock.json generated
View File

@ -39,7 +39,7 @@
"gulp-rename": "^2.0.0", "gulp-rename": "^2.0.0",
"gulp-replace": "^1.1.3", "gulp-replace": "^1.1.3",
"gulp-zip": "^5.1.0", "gulp-zip": "^5.1.0",
"jasmine": "^3.99.0", "jasmine": "^4.0.1",
"jsdoc": "^3.6.7", "jsdoc": "^3.6.7",
"jstransformer-markdown-it": "^2.1.0", "jstransformer-markdown-it": "^2.1.0",
"merge-stream": "^2.0.0", "merge-stream": "^2.0.0",
@ -8475,22 +8475,22 @@
} }
}, },
"node_modules/jasmine": { "node_modules/jasmine": {
"version": "3.99.0", "version": "4.0.1",
"resolved": "https://registry.npmjs.org/jasmine/-/jasmine-3.99.0.tgz", "resolved": "https://registry.npmjs.org/jasmine/-/jasmine-4.0.1.tgz",
"integrity": "sha512-YIThBuHzaIIcjxeuLmPD40SjxkEcc8i//sGMDKCgkRMVgIwRJf5qyExtlJpQeh7pkeoBSOe6lQEdg+/9uKg9mw==", "integrity": "sha512-NAf9b80ie0pAXLW2l+Fxc8s0Q6SjVgi81jOyHJRQuZ+fPjbVAnXNfN2nIwf5yoRjoSTROyRiETjr9Cr+nNBTVw==",
"dev": true, "dev": true,
"dependencies": { "dependencies": {
"glob": "^7.1.6", "glob": "^7.1.6",
"jasmine-core": "~3.99.0" "jasmine-core": "^4.0.0"
}, },
"bin": { "bin": {
"jasmine": "bin/jasmine.js" "jasmine": "bin/jasmine.js"
} }
}, },
"node_modules/jasmine-core": { "node_modules/jasmine-core": {
"version": "3.99.0", "version": "4.0.0",
"resolved": "https://registry.npmjs.org/jasmine-core/-/jasmine-core-3.99.0.tgz", "resolved": "https://registry.npmjs.org/jasmine-core/-/jasmine-core-4.0.0.tgz",
"integrity": "sha512-+ZDaJlEfRopINQqgE+hvzRyDIQDeKfqqTvF8RzXsvU1yE3pBDRud2+Qfh9WvGgRpuzqxyQJVI6Amy5XQ11r/3w==", "integrity": "sha512-tq24OCqHElgU9KDpb/8O21r1IfotgjIzalfW9eCmRR40LZpvwXT68iariIyayMwi0m98RDt16aljdbwK0sBMmQ==",
"dev": true "dev": true
}, },
"node_modules/jasmine/node_modules/glob": { "node_modules/jasmine/node_modules/glob": {
@ -25134,13 +25134,13 @@
} }
}, },
"jasmine": { "jasmine": {
"version": "3.99.0", "version": "4.0.1",
"resolved": "https://registry.npmjs.org/jasmine/-/jasmine-3.99.0.tgz", "resolved": "https://registry.npmjs.org/jasmine/-/jasmine-4.0.1.tgz",
"integrity": "sha512-YIThBuHzaIIcjxeuLmPD40SjxkEcc8i//sGMDKCgkRMVgIwRJf5qyExtlJpQeh7pkeoBSOe6lQEdg+/9uKg9mw==", "integrity": "sha512-NAf9b80ie0pAXLW2l+Fxc8s0Q6SjVgi81jOyHJRQuZ+fPjbVAnXNfN2nIwf5yoRjoSTROyRiETjr9Cr+nNBTVw==",
"dev": true, "dev": true,
"requires": { "requires": {
"glob": "^7.1.6", "glob": "^7.1.6",
"jasmine-core": "~3.99.0" "jasmine-core": "^4.0.0"
}, },
"dependencies": { "dependencies": {
"glob": { "glob": {
@ -25160,9 +25160,9 @@
} }
}, },
"jasmine-core": { "jasmine-core": {
"version": "3.99.0", "version": "4.0.0",
"resolved": "https://registry.npmjs.org/jasmine-core/-/jasmine-core-3.99.0.tgz", "resolved": "https://registry.npmjs.org/jasmine-core/-/jasmine-core-4.0.0.tgz",
"integrity": "sha512-+ZDaJlEfRopINQqgE+hvzRyDIQDeKfqqTvF8RzXsvU1yE3pBDRud2+Qfh9WvGgRpuzqxyQJVI6Amy5XQ11r/3w==", "integrity": "sha512-tq24OCqHElgU9KDpb/8O21r1IfotgjIzalfW9eCmRR40LZpvwXT68iariIyayMwi0m98RDt16aljdbwK0sBMmQ==",
"dev": true "dev": true
}, },
"jest-worker": { "jest-worker": {

View File

@ -32,7 +32,7 @@
"gulp-rename": "^2.0.0", "gulp-rename": "^2.0.0",
"gulp-replace": "^1.1.3", "gulp-replace": "^1.1.3",
"gulp-zip": "^5.1.0", "gulp-zip": "^5.1.0",
"jasmine": "^3.99.0", "jasmine": "^4.0.1",
"jsdoc": "^3.6.7", "jsdoc": "^3.6.7",
"jstransformer-markdown-it": "^2.1.0", "jstransformer-markdown-it": "^2.1.0",
"merge-stream": "^2.0.0", "merge-stream": "^2.0.0",

View File

@ -19,6 +19,7 @@ const Jasmine = require("jasmine");
async function runTests(results) { async function runTests(results) {
const jasmine = new Jasmine(); const jasmine = new Jasmine();
jasmine.exitOnCompletion = false;
jasmine.jasmine.DEFAULT_TIMEOUT_INTERVAL = 30000; jasmine.jasmine.DEFAULT_TIMEOUT_INTERVAL = 30000;
jasmine.loadConfig({ jasmine.loadConfig({
@ -49,10 +50,7 @@ async function runTests(results) {
suiteStarted(result) {}, suiteStarted(result) {},
}); });
return new Promise(resolve => { return jasmine.execute();
jasmine.onComplete(resolve);
jasmine.execute();
});
} }
exports.runTests = runTests; exports.runTests = runTests;

View File

@ -21,52 +21,6 @@ import { PostScriptLexer, PostScriptParser } from "../../src/core/ps_parser.js";
import { StringStream } from "../../src/core/stream.js"; import { StringStream } from "../../src/core/stream.js";
describe("function", function () { describe("function", function () {
beforeEach(function () {
jasmine.addMatchers({
toMatchArray(util, customEqualityTesters) {
return {
compare(actual, expected) {
const result = {};
if (actual.length !== expected.length) {
result.pass = false;
result.message =
"Array length: " +
actual.length +
", expected: " +
expected.length;
return result;
}
result.pass = true;
for (let i = 0; i < expected.length; i++) {
const a = actual[i],
b = expected[i];
if (Array.isArray(b)) {
if (a.length !== b.length) {
result.pass = false;
break;
}
for (let j = 0; j < a.length; j++) {
const suba = a[j],
subb = b[j];
if (suba !== subb) {
result.pass = false;
break;
}
}
} else {
if (a !== b) {
result.pass = false;
break;
}
}
}
return result;
},
};
},
});
});
describe("PostScriptParser", function () { describe("PostScriptParser", function () {
function parse(program) { function parse(program) {
const stream = new StringStream(program); const stream = new StringStream(program);
@ -81,34 +35,34 @@ describe("function", function () {
const number = 999; const number = 999;
const program = parse("{ " + number + " }"); const program = parse("{ " + number + " }");
const expectedProgram = [number]; const expectedProgram = [number];
expect(program).toMatchArray(expectedProgram); expect(program).toEqual(expectedProgram);
}); });
it("parses negative numbers", function () { it("parses negative numbers", function () {
const number = -999; const number = -999;
const program = parse("{ " + number + " }"); const program = parse("{ " + number + " }");
const expectedProgram = [number]; const expectedProgram = [number];
expect(program).toMatchArray(expectedProgram); expect(program).toEqual(expectedProgram);
}); });
it("parses negative floats", function () { it("parses negative floats", function () {
const number = 3.3; const number = 3.3;
const program = parse("{ " + number + " }"); const program = parse("{ " + number + " }");
const expectedProgram = [number]; const expectedProgram = [number];
expect(program).toMatchArray(expectedProgram); expect(program).toEqual(expectedProgram);
}); });
it("parses operators", function () { it("parses operators", function () {
const program = parse("{ sub }"); const program = parse("{ sub }");
const expectedProgram = ["sub"]; const expectedProgram = ["sub"];
expect(program).toMatchArray(expectedProgram); expect(program).toEqual(expectedProgram);
}); });
it("parses if statements", function () { it("parses if statements", function () {
const program = parse("{ { 99 } if }"); const program = parse("{ { 99 } if }");
const expectedProgram = [3, "jz", 99]; const expectedProgram = [3, "jz", 99];
expect(program).toMatchArray(expectedProgram); expect(program).toEqual(expectedProgram);
}); });
it("parses ifelse statements", function () { it("parses ifelse statements", function () {
const program = parse("{ { 99 } { 44 } ifelse }"); const program = parse("{ { 99 } { 44 } ifelse }");
const expectedProgram = [5, "jz", 99, 6, "j", 44]; const expectedProgram = [5, "jz", 99, 6, "j", 44];
expect(program).toMatchArray(expectedProgram); expect(program).toEqual(expectedProgram);
}); });
it("handles missing brackets", function () { it("handles missing brackets", function () {
expect(function () { expect(function () {
@ -119,7 +73,7 @@ describe("function", function () {
const number = 3.3; const number = 3.3;
const program = parse("{ " + number + " }#"); const program = parse("{ " + number + " }#");
const expectedProgram = [number]; const expectedProgram = [number];
expect(program).toMatchArray(expectedProgram); expect(program).toEqual(expectedProgram);
}); });
}); });
@ -136,313 +90,313 @@ describe("function", function () {
it("pushes stack", function () { it("pushes stack", function () {
const stack = evaluate("{ 99 }"); const stack = evaluate("{ 99 }");
const expectedStack = [99]; const expectedStack = [99];
expect(stack).toMatchArray(expectedStack); expect(stack).toEqual(expectedStack);
}); });
it("handles if with true", function () { it("handles if with true", function () {
const stack = evaluate("{ 1 {99} if }"); const stack = evaluate("{ 1 {99} if }");
const expectedStack = [99]; const expectedStack = [99];
expect(stack).toMatchArray(expectedStack); expect(stack).toEqual(expectedStack);
}); });
it("handles if with false", function () { it("handles if with false", function () {
const stack = evaluate("{ 0 {99} if }"); const stack = evaluate("{ 0 {99} if }");
const expectedStack = []; const expectedStack = [];
expect(stack).toMatchArray(expectedStack); expect(stack).toEqual(expectedStack);
}); });
it("handles ifelse with true", function () { it("handles ifelse with true", function () {
const stack = evaluate("{ 1 {99} {77} ifelse }"); const stack = evaluate("{ 1 {99} {77} ifelse }");
const expectedStack = [99]; const expectedStack = [99];
expect(stack).toMatchArray(expectedStack); expect(stack).toEqual(expectedStack);
}); });
it("handles ifelse with false", function () { it("handles ifelse with false", function () {
const stack = evaluate("{ 0 {99} {77} ifelse }"); const stack = evaluate("{ 0 {99} {77} ifelse }");
const expectedStack = [77]; const expectedStack = [77];
expect(stack).toMatchArray(expectedStack); expect(stack).toEqual(expectedStack);
}); });
it("handles nested if", function () { it("handles nested if", function () {
const stack = evaluate("{ 1 {1 {77} if} if }"); const stack = evaluate("{ 1 {1 {77} if} if }");
const expectedStack = [77]; const expectedStack = [77];
expect(stack).toMatchArray(expectedStack); expect(stack).toEqual(expectedStack);
}); });
it("abs", function () { it("abs", function () {
const stack = evaluate("{ -2 abs }"); const stack = evaluate("{ -2 abs }");
const expectedStack = [2]; const expectedStack = [2];
expect(stack).toMatchArray(expectedStack); expect(stack).toEqual(expectedStack);
}); });
it("adds", function () { it("adds", function () {
const stack = evaluate("{ 1 2 add }"); const stack = evaluate("{ 1 2 add }");
const expectedStack = [3]; const expectedStack = [3];
expect(stack).toMatchArray(expectedStack); expect(stack).toEqual(expectedStack);
}); });
it("boolean and", function () { it("boolean and", function () {
const stack = evaluate("{ true false and }"); const stack = evaluate("{ true false and }");
const expectedStack = [false]; const expectedStack = [false];
expect(stack).toMatchArray(expectedStack); expect(stack).toEqual(expectedStack);
}); });
it("bitwise and", function () { it("bitwise and", function () {
const stack = evaluate("{ 254 1 and }"); const stack = evaluate("{ 254 1 and }");
const expectedStack = [254 & 1]; const expectedStack = [254 & 1];
expect(stack).toMatchArray(expectedStack); expect(stack).toEqual(expectedStack);
}); });
it("calculates the inverse tangent of a number", function () { it("calculates the inverse tangent of a number", function () {
const stack = evaluate("{ 90 atan }"); const stack = evaluate("{ 90 atan }");
const expectedStack = [Math.atan(90)]; const expectedStack = [Math.atan(90)];
expect(stack).toMatchArray(expectedStack); expect(stack).toEqual(expectedStack);
}); });
it("handles bitshifting ", function () { it("handles bitshifting ", function () {
const stack = evaluate("{ 50 2 bitshift }"); const stack = evaluate("{ 50 2 bitshift }");
const expectedStack = [200]; const expectedStack = [200];
expect(stack).toMatchArray(expectedStack); expect(stack).toEqual(expectedStack);
}); });
it("calculates the ceiling value", function () { it("calculates the ceiling value", function () {
const stack = evaluate("{ 9.9 ceiling }"); const stack = evaluate("{ 9.9 ceiling }");
const expectedStack = [10]; const expectedStack = [10];
expect(stack).toMatchArray(expectedStack); expect(stack).toEqual(expectedStack);
}); });
it("copies", function () { it("copies", function () {
const stack = evaluate("{ 99 98 2 copy }"); const stack = evaluate("{ 99 98 2 copy }");
const expectedStack = [99, 98, 99, 98]; const expectedStack = [99, 98, 99, 98];
expect(stack).toMatchArray(expectedStack); expect(stack).toEqual(expectedStack);
}); });
it("calculates the cosine of a number", function () { it("calculates the cosine of a number", function () {
const stack = evaluate("{ 90 cos }"); const stack = evaluate("{ 90 cos }");
const expectedStack = [Math.cos(90)]; const expectedStack = [Math.cos(90)];
expect(stack).toMatchArray(expectedStack); expect(stack).toEqual(expectedStack);
}); });
it("converts to int", function () { it("converts to int", function () {
const stack = evaluate("{ 9.9 cvi }"); const stack = evaluate("{ 9.9 cvi }");
const expectedStack = [9]; const expectedStack = [9];
expect(stack).toMatchArray(expectedStack); expect(stack).toEqual(expectedStack);
}); });
it("converts negatives to int", function () { it("converts negatives to int", function () {
const stack = evaluate("{ -9.9 cvi }"); const stack = evaluate("{ -9.9 cvi }");
const expectedStack = [-9]; const expectedStack = [-9];
expect(stack).toMatchArray(expectedStack); expect(stack).toEqual(expectedStack);
}); });
it("converts to real", function () { it("converts to real", function () {
const stack = evaluate("{ 55.34 cvr }"); const stack = evaluate("{ 55.34 cvr }");
const expectedStack = [55.34]; const expectedStack = [55.34];
expect(stack).toMatchArray(expectedStack); expect(stack).toEqual(expectedStack);
}); });
it("divides", function () { it("divides", function () {
const stack = evaluate("{ 6 5 div }"); const stack = evaluate("{ 6 5 div }");
const expectedStack = [1.2]; const expectedStack = [1.2];
expect(stack).toMatchArray(expectedStack); expect(stack).toEqual(expectedStack);
}); });
it("maps division by zero to infinity", function () { it("maps division by zero to infinity", function () {
const stack = evaluate("{ 6 0 div }"); const stack = evaluate("{ 6 0 div }");
const expectedStack = [Infinity]; const expectedStack = [Infinity];
expect(stack).toMatchArray(expectedStack); expect(stack).toEqual(expectedStack);
}); });
it("duplicates", function () { it("duplicates", function () {
const stack = evaluate("{ 99 dup }"); const stack = evaluate("{ 99 dup }");
const expectedStack = [99, 99]; const expectedStack = [99, 99];
expect(stack).toMatchArray(expectedStack); expect(stack).toEqual(expectedStack);
}); });
it("accepts an equality", function () { it("accepts an equality", function () {
const stack = evaluate("{ 9 9 eq }"); const stack = evaluate("{ 9 9 eq }");
const expectedStack = [true]; const expectedStack = [true];
expect(stack).toMatchArray(expectedStack); expect(stack).toEqual(expectedStack);
}); });
it("rejects an inequality", function () { it("rejects an inequality", function () {
const stack = evaluate("{ 9 8 eq }"); const stack = evaluate("{ 9 8 eq }");
const expectedStack = [false]; const expectedStack = [false];
expect(stack).toMatchArray(expectedStack); expect(stack).toEqual(expectedStack);
}); });
it("exchanges", function () { it("exchanges", function () {
const stack = evaluate("{ 44 99 exch }"); const stack = evaluate("{ 44 99 exch }");
const expectedStack = [99, 44]; const expectedStack = [99, 44];
expect(stack).toMatchArray(expectedStack); expect(stack).toEqual(expectedStack);
}); });
it("handles exponentiation", function () { it("handles exponentiation", function () {
const stack = evaluate("{ 10 2 exp }"); const stack = evaluate("{ 10 2 exp }");
const expectedStack = [100]; const expectedStack = [100];
expect(stack).toMatchArray(expectedStack); expect(stack).toEqual(expectedStack);
}); });
it("pushes false onto the stack", function () { it("pushes false onto the stack", function () {
const stack = evaluate("{ false }"); const stack = evaluate("{ false }");
const expectedStack = [false]; const expectedStack = [false];
expect(stack).toMatchArray(expectedStack); expect(stack).toEqual(expectedStack);
}); });
it("calculates the floor value", function () { it("calculates the floor value", function () {
const stack = evaluate("{ 9.9 floor }"); const stack = evaluate("{ 9.9 floor }");
const expectedStack = [9]; const expectedStack = [9];
expect(stack).toMatchArray(expectedStack); expect(stack).toEqual(expectedStack);
}); });
it("handles greater than or equal to", function () { it("handles greater than or equal to", function () {
const stack = evaluate("{ 10 9 ge }"); const stack = evaluate("{ 10 9 ge }");
const expectedStack = [true]; const expectedStack = [true];
expect(stack).toMatchArray(expectedStack); expect(stack).toEqual(expectedStack);
}); });
it("rejects less than for greater than or equal to", function () { it("rejects less than for greater than or equal to", function () {
const stack = evaluate("{ 8 9 ge }"); const stack = evaluate("{ 8 9 ge }");
const expectedStack = [false]; const expectedStack = [false];
expect(stack).toMatchArray(expectedStack); expect(stack).toEqual(expectedStack);
}); });
it("handles greater than", function () { it("handles greater than", function () {
const stack = evaluate("{ 10 9 gt }"); const stack = evaluate("{ 10 9 gt }");
const expectedStack = [true]; const expectedStack = [true];
expect(stack).toMatchArray(expectedStack); expect(stack).toEqual(expectedStack);
}); });
it("rejects less than or equal for greater than", function () { it("rejects less than or equal for greater than", function () {
const stack = evaluate("{ 9 9 gt }"); const stack = evaluate("{ 9 9 gt }");
const expectedStack = [false]; const expectedStack = [false];
expect(stack).toMatchArray(expectedStack); expect(stack).toEqual(expectedStack);
}); });
it("divides to integer", function () { it("divides to integer", function () {
const stack = evaluate("{ 2 3 idiv }"); const stack = evaluate("{ 2 3 idiv }");
const expectedStack = [0]; const expectedStack = [0];
expect(stack).toMatchArray(expectedStack); expect(stack).toEqual(expectedStack);
}); });
it("divides to negative integer", function () { it("divides to negative integer", function () {
const stack = evaluate("{ -2 3 idiv }"); const stack = evaluate("{ -2 3 idiv }");
const expectedStack = [0]; const expectedStack = [0];
expect(stack).toMatchArray(expectedStack); expect(stack).toEqual(expectedStack);
}); });
it("duplicates index", function () { it("duplicates index", function () {
const stack = evaluate("{ 4 3 2 1 2 index }"); const stack = evaluate("{ 4 3 2 1 2 index }");
const expectedStack = [4, 3, 2, 1, 3]; const expectedStack = [4, 3, 2, 1, 3];
expect(stack).toMatchArray(expectedStack); expect(stack).toEqual(expectedStack);
}); });
it("handles less than or equal to", function () { it("handles less than or equal to", function () {
const stack = evaluate("{ 9 10 le }"); const stack = evaluate("{ 9 10 le }");
const expectedStack = [true]; const expectedStack = [true];
expect(stack).toMatchArray(expectedStack); expect(stack).toEqual(expectedStack);
}); });
it("rejects greater than for less than or equal to", function () { it("rejects greater than for less than or equal to", function () {
const stack = evaluate("{ 10 9 le }"); const stack = evaluate("{ 10 9 le }");
const expectedStack = [false]; const expectedStack = [false];
expect(stack).toMatchArray(expectedStack); expect(stack).toEqual(expectedStack);
}); });
it("calculates the natural logarithm", function () { it("calculates the natural logarithm", function () {
const stack = evaluate("{ 10 ln }"); const stack = evaluate("{ 10 ln }");
const expectedStack = [Math.log(10)]; const expectedStack = [Math.log(10)];
expect(stack).toMatchArray(expectedStack); expect(stack).toEqual(expectedStack);
}); });
it("calculates the base 10 logarithm", function () { it("calculates the base 10 logarithm", function () {
const stack = evaluate("{ 100 log }"); const stack = evaluate("{ 100 log }");
const expectedStack = [2]; const expectedStack = [2];
expect(stack).toMatchArray(expectedStack); expect(stack).toEqual(expectedStack);
}); });
it("handles less than", function () { it("handles less than", function () {
const stack = evaluate("{ 9 10 lt }"); const stack = evaluate("{ 9 10 lt }");
const expectedStack = [true]; const expectedStack = [true];
expect(stack).toMatchArray(expectedStack); expect(stack).toEqual(expectedStack);
}); });
it("rejects greater than or equal to for less than", function () { it("rejects greater than or equal to for less than", function () {
const stack = evaluate("{ 10 9 lt }"); const stack = evaluate("{ 10 9 lt }");
const expectedStack = [false]; const expectedStack = [false];
expect(stack).toMatchArray(expectedStack); expect(stack).toEqual(expectedStack);
}); });
it("performs the modulo operation", function () { it("performs the modulo operation", function () {
const stack = evaluate("{ 4 3 mod }"); const stack = evaluate("{ 4 3 mod }");
const expectedStack = [1]; const expectedStack = [1];
expect(stack).toMatchArray(expectedStack); expect(stack).toEqual(expectedStack);
}); });
it("multiplies two numbers (positive result)", function () { it("multiplies two numbers (positive result)", function () {
const stack = evaluate("{ 9 8 mul }"); const stack = evaluate("{ 9 8 mul }");
const expectedStack = [72]; const expectedStack = [72];
expect(stack).toMatchArray(expectedStack); expect(stack).toEqual(expectedStack);
}); });
it("multiplies two numbers (negative result)", function () { it("multiplies two numbers (negative result)", function () {
const stack = evaluate("{ 9 -8 mul }"); const stack = evaluate("{ 9 -8 mul }");
const expectedStack = [-72]; const expectedStack = [-72];
expect(stack).toMatchArray(expectedStack); expect(stack).toEqual(expectedStack);
}); });
it("accepts an inequality", function () { it("accepts an inequality", function () {
const stack = evaluate("{ 9 8 ne }"); const stack = evaluate("{ 9 8 ne }");
const expectedStack = [true]; const expectedStack = [true];
expect(stack).toMatchArray(expectedStack); expect(stack).toEqual(expectedStack);
}); });
it("rejects an equality", function () { it("rejects an equality", function () {
const stack = evaluate("{ 9 9 ne }"); const stack = evaluate("{ 9 9 ne }");
const expectedStack = [false]; const expectedStack = [false];
expect(stack).toMatchArray(expectedStack); expect(stack).toEqual(expectedStack);
}); });
it("negates", function () { it("negates", function () {
const stack = evaluate("{ 4.5 neg }"); const stack = evaluate("{ 4.5 neg }");
const expectedStack = [-4.5]; const expectedStack = [-4.5];
expect(stack).toMatchArray(expectedStack); expect(stack).toEqual(expectedStack);
}); });
it("boolean not", function () { it("boolean not", function () {
const stack = evaluate("{ true not }"); const stack = evaluate("{ true not }");
const expectedStack = [false]; const expectedStack = [false];
expect(stack).toMatchArray(expectedStack); expect(stack).toEqual(expectedStack);
}); });
it("bitwise not", function () { it("bitwise not", function () {
const stack = evaluate("{ 12 not }"); const stack = evaluate("{ 12 not }");
const expectedStack = [-13]; const expectedStack = [-13];
expect(stack).toMatchArray(expectedStack); expect(stack).toEqual(expectedStack);
}); });
it("boolean or", function () { it("boolean or", function () {
const stack = evaluate("{ true false or }"); const stack = evaluate("{ true false or }");
const expectedStack = [true]; const expectedStack = [true];
expect(stack).toMatchArray(expectedStack); expect(stack).toEqual(expectedStack);
}); });
it("bitwise or", function () { it("bitwise or", function () {
const stack = evaluate("{ 254 1 or }"); const stack = evaluate("{ 254 1 or }");
const expectedStack = [254 | 1]; const expectedStack = [254 | 1];
expect(stack).toMatchArray(expectedStack); expect(stack).toEqual(expectedStack);
}); });
it("pops stack", function () { it("pops stack", function () {
const stack = evaluate("{ 1 2 pop }"); const stack = evaluate("{ 1 2 pop }");
const expectedStack = [1]; const expectedStack = [1];
expect(stack).toMatchArray(expectedStack); expect(stack).toEqual(expectedStack);
}); });
it("rolls stack right", function () { it("rolls stack right", function () {
const stack = evaluate("{ 1 3 2 2 4 1 roll }"); const stack = evaluate("{ 1 3 2 2 4 1 roll }");
const expectedStack = [2, 1, 3, 2]; const expectedStack = [2, 1, 3, 2];
expect(stack).toMatchArray(expectedStack); expect(stack).toEqual(expectedStack);
}); });
it("rolls stack left", function () { it("rolls stack left", function () {
const stack = evaluate("{ 1 3 2 2 4 -1 roll }"); const stack = evaluate("{ 1 3 2 2 4 -1 roll }");
const expectedStack = [3, 2, 2, 1]; const expectedStack = [3, 2, 2, 1];
expect(stack).toMatchArray(expectedStack); expect(stack).toEqual(expectedStack);
}); });
it("rounds a number", function () { it("rounds a number", function () {
const stack = evaluate("{ 9.52 round }"); const stack = evaluate("{ 9.52 round }");
const expectedStack = [10]; const expectedStack = [10];
expect(stack).toMatchArray(expectedStack); expect(stack).toEqual(expectedStack);
}); });
it("calculates the sine of a number", function () { it("calculates the sine of a number", function () {
const stack = evaluate("{ 90 sin }"); const stack = evaluate("{ 90 sin }");
const expectedStack = [Math.sin(90)]; const expectedStack = [Math.sin(90)];
expect(stack).toMatchArray(expectedStack); expect(stack).toEqual(expectedStack);
}); });
it("calculates a square root (integer)", function () { it("calculates a square root (integer)", function () {
const stack = evaluate("{ 100 sqrt }"); const stack = evaluate("{ 100 sqrt }");
const expectedStack = [10]; const expectedStack = [10];
expect(stack).toMatchArray(expectedStack); expect(stack).toEqual(expectedStack);
}); });
it("calculates a square root (float)", function () { it("calculates a square root (float)", function () {
const stack = evaluate("{ 99 sqrt }"); const stack = evaluate("{ 99 sqrt }");
const expectedStack = [Math.sqrt(99)]; const expectedStack = [Math.sqrt(99)];
expect(stack).toMatchArray(expectedStack); expect(stack).toEqual(expectedStack);
}); });
it("subtracts (positive result)", function () { it("subtracts (positive result)", function () {
const stack = evaluate("{ 6 4 sub }"); const stack = evaluate("{ 6 4 sub }");
const expectedStack = [2]; const expectedStack = [2];
expect(stack).toMatchArray(expectedStack); expect(stack).toEqual(expectedStack);
}); });
it("subtracts (negative result)", function () { it("subtracts (negative result)", function () {
const stack = evaluate("{ 4 6 sub }"); const stack = evaluate("{ 4 6 sub }");
const expectedStack = [-2]; const expectedStack = [-2];
expect(stack).toMatchArray(expectedStack); expect(stack).toEqual(expectedStack);
}); });
it("pushes true onto the stack", function () { it("pushes true onto the stack", function () {
const stack = evaluate("{ true }"); const stack = evaluate("{ true }");
const expectedStack = [true]; const expectedStack = [true];
expect(stack).toMatchArray(expectedStack); expect(stack).toEqual(expectedStack);
}); });
it("truncates a number", function () { it("truncates a number", function () {
const stack = evaluate("{ 35.004 truncate }"); const stack = evaluate("{ 35.004 truncate }");
const expectedStack = [35]; const expectedStack = [35];
expect(stack).toMatchArray(expectedStack); expect(stack).toEqual(expectedStack);
}); });
it("calculates an exclusive or value", function () { it("calculates an exclusive or value", function () {
const stack = evaluate("{ 3 9 xor }"); const stack = evaluate("{ 3 9 xor }");
const expectedStack = [10]; const expectedStack = [10];
expect(stack).toMatchArray(expectedStack); expect(stack).toEqual(expectedStack);
}); });
}); });
@ -465,9 +419,7 @@ describe("function", function () {
for (let i = 0; i < samples.length; i++) { for (let i = 0; i < samples.length; i++) {
const out = new Float32Array(samples[i].output.length); const out = new Float32Array(samples[i].output.length);
fn(samples[i].input, 0, out, 0); fn(samples[i].input, 0, out, 0);
expect(Array.prototype.slice.call(out, 0)).toMatchArray( expect(Array.prototype.slice.call(out, 0)).toEqual(samples[i].output);
samples[i].output
);
} }
} }
} }

View File

@ -18,36 +18,6 @@ import { PredictorStream } from "../../src/core/predictor_stream.js";
import { Stream } from "../../src/core/stream.js"; import { Stream } from "../../src/core/stream.js";
describe("stream", function () { describe("stream", function () {
beforeEach(function () {
jasmine.addMatchers({
toMatchTypedArray(util, customEqualityTesters) {
return {
compare(actual, expected) {
const result = {};
if (actual.length !== expected.length) {
result.pass = false;
result.message =
"Array length: " +
actual.length +
", expected: " +
expected.length;
return result;
}
result.pass = true;
for (let i = 0, ii = expected.length; i < ii; i++) {
const a = actual[i],
b = expected[i];
if (a !== b) {
result.pass = false;
break;
}
}
return result;
},
};
},
});
});
describe("PredictorStream", function () { describe("PredictorStream", function () {
it("should decode simple predictor data", function () { it("should decode simple predictor data", function () {
const dict = new Dict(); const dict = new Dict();
@ -65,9 +35,7 @@ describe("stream", function () {
const predictor = new PredictorStream(input, /* length = */ 9, dict); const predictor = new PredictorStream(input, /* length = */ 9, dict);
const result = predictor.getBytes(6); const result = predictor.getBytes(6);
expect(result).toMatchTypedArray( expect(result).toEqual(new Uint8Array([100, 3, 101, 2, 102, 1]));
new Uint8Array([100, 3, 101, 2, 102, 1])
);
predictor.reset(); predictor.reset();
const clampedResult = predictor.getBytes(6, /* forceClamped = */ true); const clampedResult = predictor.getBytes(6, /* forceClamped = */ true);