UNPKG

diesel

Version:

Dumb Interpretively Executed String Expression Language

546 lines (545 loc) 35 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const node_assert_1 = __importDefault(require("node:assert")); const node_test_1 = require("node:test"); const index_1 = require("./index"); (0, node_test_1.describe)("Arithmetic", () => { (0, node_test_1.describe)("$(+,<val1>,<val2>,...<valn>)", () => { (0, node_test_1.test)("$(+)", () => __awaiter(void 0, void 0, void 0, function* () { const output = yield (0, index_1.evaluate)("$(+)"); node_assert_1.default.equal(output, "0"); })); (0, node_test_1.test)("$(+,1)", () => __awaiter(void 0, void 0, void 0, function* () { const output = yield (0, index_1.evaluate)("$(+,1)"); node_assert_1.default.equal(output, "1"); })); (0, node_test_1.test)("$(+,1.234e-2)", () => __awaiter(void 0, void 0, void 0, function* () { const output = yield (0, index_1.evaluate)("$(+,1.234e-2)"); node_assert_1.default.equal(output, "0.01234"); })); (0, node_test_1.test)("$(+,-18.3,4,56)", () => __awaiter(void 0, void 0, void 0, function* () { const output = yield (0, index_1.evaluate)("$(+,-18.3,4,56)"); node_assert_1.default.equal(output, "41.7"); })); }); (0, node_test_1.describe)("$(-,<val1>,<val2>,...<valn>)", () => { (0, node_test_1.test)("$(-)", () => __awaiter(void 0, void 0, void 0, function* () { const output = yield (0, index_1.evaluate)("$(-)"); node_assert_1.default.equal(output, "0"); })); (0, node_test_1.test)("$(-,4)", () => __awaiter(void 0, void 0, void 0, function* () { const output = yield (0, index_1.evaluate)("$(-,4)"); node_assert_1.default.equal(output, "4"); })); (0, node_test_1.test)("$(-,20,40.5)", () => __awaiter(void 0, void 0, void 0, function* () { const output = yield (0, index_1.evaluate)("$(-,20,40.5)"); node_assert_1.default.equal(output, "-20.5"); })); (0, node_test_1.test)("$(-,10,2,3)", () => __awaiter(void 0, void 0, void 0, function* () { const output = yield (0, index_1.evaluate)("$(-,10,2,3)"); node_assert_1.default.equal(output, "5"); })); }); (0, node_test_1.describe)("$(*,<val1>,<val2>,...<valn>)", () => { (0, node_test_1.test)("$(*)", () => __awaiter(void 0, void 0, void 0, function* () { const output = yield (0, index_1.evaluate)("$(*)"); node_assert_1.default.equal(output, "1"); })); (0, node_test_1.test)("$(*,-1002)", () => __awaiter(void 0, void 0, void 0, function* () { const output = yield (0, index_1.evaluate)("$(*,-1002)"); node_assert_1.default.equal(output, "-1002"); })); (0, node_test_1.test)("$(*,1.41414,1.41414)", () => __awaiter(void 0, void 0, void 0, function* () { const output = yield (0, index_1.evaluate)("$(*,1.41414,1.41414)"); node_assert_1.default.equal(output, "1.9997919396"); })); (0, node_test_1.test)("$(*,535,2,0.5)", () => __awaiter(void 0, void 0, void 0, function* () { const output = yield (0, index_1.evaluate)("$(*,535,2,0.5)"); node_assert_1.default.equal(output, "535"); })); }); (0, node_test_1.describe)("$(/,<val1>,<val2>,...<valn>)", () => { (0, node_test_1.test)("$(/)", () => __awaiter(void 0, void 0, void 0, function* () { const output = yield (0, index_1.evaluate)("$(/)"); node_assert_1.default.equal(output, "1"); })); (0, node_test_1.test)("$(/,12)", () => __awaiter(void 0, void 0, void 0, function* () { const output = yield (0, index_1.evaluate)("$(/,12)"); node_assert_1.default.equal(output, "12"); })); (0, node_test_1.test)("$(/,12,2)", () => __awaiter(void 0, void 0, void 0, function* () { const output = yield (0, index_1.evaluate)("$(/,12,2)"); node_assert_1.default.equal(output, "6"); })); (0, node_test_1.test)("$(/,1007,17)", () => __awaiter(void 0, void 0, void 0, function* () { const output = yield (0, index_1.evaluate)("$(/,1007,17)"); node_assert_1.default.equal(output, "59.235294117647"); })); (0, node_test_1.test)("$(/,-126,3,-2)", () => __awaiter(void 0, void 0, void 0, function* () { const output = yield (0, index_1.evaluate)("$(/,-126,3,-2)"); node_assert_1.default.equal(output, "21"); })); }); }); (0, node_test_1.describe)("Comparison", () => { (0, node_test_1.describe)("$(=,<val1>,<val2>)", () => { (0, node_test_1.test)("$(=,2,2)", () => __awaiter(void 0, void 0, void 0, function* () { const output = yield (0, index_1.evaluate)("$(=,2,2)"); node_assert_1.default.equal(output, "1"); })); (0, node_test_1.test)("$(=,2,-2)", () => __awaiter(void 0, void 0, void 0, function* () { const output = yield (0, index_1.evaluate)("$(=,2,-2)"); node_assert_1.default.equal(output, "0"); })); (0, node_test_1.test)("$(=,-2,2)", () => __awaiter(void 0, void 0, void 0, function* () { const output = yield (0, index_1.evaluate)("$(=,-2,2)"); node_assert_1.default.equal(output, "0"); })); }); (0, node_test_1.describe)("$(<,<val1>,<val2>)", () => { (0, node_test_1.test)("$(<,2,2)", () => __awaiter(void 0, void 0, void 0, function* () { const output = yield (0, index_1.evaluate)("$(<,2,2)"); node_assert_1.default.equal(output, "0"); })); (0, node_test_1.test)("$(<,2,-2)", () => __awaiter(void 0, void 0, void 0, function* () { const output = yield (0, index_1.evaluate)("$(<,2,-2)"); node_assert_1.default.equal(output, "0"); })); (0, node_test_1.test)("$(<,-2,2)", () => __awaiter(void 0, void 0, void 0, function* () { const output = yield (0, index_1.evaluate)("$(<,-2,2)"); node_assert_1.default.equal(output, "1"); })); }); (0, node_test_1.describe)("$(>,<val1>,<val2>)", () => { (0, node_test_1.test)("$(>,2,2)", () => __awaiter(void 0, void 0, void 0, function* () { const output = yield (0, index_1.evaluate)("$(>,2,2)"); node_assert_1.default.equal(output, "0"); })); (0, node_test_1.test)("$(>,2,-2)", () => __awaiter(void 0, void 0, void 0, function* () { const output = yield (0, index_1.evaluate)("$(>,2,-2)"); node_assert_1.default.equal(output, "1"); })); (0, node_test_1.test)("$(>,-2,2)", () => __awaiter(void 0, void 0, void 0, function* () { const output = yield (0, index_1.evaluate)("$(>,-2,2)"); node_assert_1.default.equal(output, "0"); })); }); (0, node_test_1.describe)("$(!=,<val1>,<val2>)", () => { (0, node_test_1.test)("$(!=,2,2)", () => __awaiter(void 0, void 0, void 0, function* () { const output = yield (0, index_1.evaluate)("$(!=,2,2)"); node_assert_1.default.equal(output, "0"); })); (0, node_test_1.test)("$(!=,2,-2)", () => __awaiter(void 0, void 0, void 0, function* () { const output = yield (0, index_1.evaluate)("$(!=,2,-2)"); node_assert_1.default.equal(output, "1"); })); (0, node_test_1.test)("$(!=,-2,2)", () => __awaiter(void 0, void 0, void 0, function* () { const output = yield (0, index_1.evaluate)("$(!=,-2,2)"); node_assert_1.default.equal(output, "1"); })); }); (0, node_test_1.describe)("$(<=,<val1>,<val2>)", () => { (0, node_test_1.test)("$(<=,2,2)", () => __awaiter(void 0, void 0, void 0, function* () { const output = yield (0, index_1.evaluate)("$(<=,2,2)"); node_assert_1.default.equal(output, "1"); })); (0, node_test_1.test)("$(<=,2,-2)", () => __awaiter(void 0, void 0, void 0, function* () { const output = yield (0, index_1.evaluate)("$(<=,2,-2)"); node_assert_1.default.equal(output, "0"); })); (0, node_test_1.test)("$(<=,-2,2)", () => __awaiter(void 0, void 0, void 0, function* () { const output = yield (0, index_1.evaluate)("$(<=,-2,2)"); node_assert_1.default.equal(output, "1"); })); }); (0, node_test_1.describe)("$(>=,<val1>,<val2>)", () => { (0, node_test_1.test)("$(>=,2,2)", () => __awaiter(void 0, void 0, void 0, function* () { const output = yield (0, index_1.evaluate)("$(>=,2,2)"); node_assert_1.default.equal(output, "1"); })); (0, node_test_1.test)("$(>=,2,-2)", () => __awaiter(void 0, void 0, void 0, function* () { const output = yield (0, index_1.evaluate)("$(>=,2,-2)"); node_assert_1.default.equal(output, "1"); })); (0, node_test_1.test)("$(>=,-2,2)", () => __awaiter(void 0, void 0, void 0, function* () { const output = yield (0, index_1.evaluate)("$(>=,-2,2)"); node_assert_1.default.equal(output, "0"); })); }); }); (0, node_test_1.describe)("Logical", () => { (0, node_test_1.describe)("$(EQ,<val1>,<val2>)", () => { (0, node_test_1.test)("$(eq,These strings are equal,These strings are equal)", () => __awaiter(void 0, void 0, void 0, function* () { const output = yield (0, index_1.evaluate)("$(eq,These strings are equal,These strings are equal)"); node_assert_1.default.equal(output, "1"); })); (0, node_test_1.test)("$(eq,These strings are equal,These strings are not equal)", () => __awaiter(void 0, void 0, void 0, function* () { const output = yield (0, index_1.evaluate)("$(eq,These strings are equal,These strings are not equal)"); node_assert_1.default.equal(output, "0"); })); (0, node_test_1.test)("$(eq,These neither,These Neither)", () => __awaiter(void 0, void 0, void 0, function* () { const output = yield (0, index_1.evaluate)("$(eq,These neither,These Neither)"); node_assert_1.default.equal(output, "0"); })); }); (0, node_test_1.describe)("$(AND,<val1>,<val2>,...<valn>))", () => { (0, node_test_1.test)("$(and)", () => __awaiter(void 0, void 0, void 0, function* () { const output = yield (0, index_1.evaluate)("$(and)"); node_assert_1.default.equal(output, "1"); })); (0, node_test_1.test)("$(and,276)", () => __awaiter(void 0, void 0, void 0, function* () { const output = yield (0, index_1.evaluate)("$(and,276)"); node_assert_1.default.equal(output, "276"); })); (0, node_test_1.test)("$(and,0x1234,0xF)", () => __awaiter(void 0, void 0, void 0, function* () { const output = yield (0, index_1.evaluate)("$(and,0x1234,0xF)"); node_assert_1.default.equal(output, "4"); })); (0, node_test_1.test)("$(and,0x10FF,0x1FF,63)", () => __awaiter(void 0, void 0, void 0, function* () { const output = yield (0, index_1.evaluate)("$(and,0x10FF,0x1FF,63)"); node_assert_1.default.equal(output, "63"); })); }); (0, node_test_1.describe)("$(OR,<val1>,<val2>,...<valn>))", () => { (0, node_test_1.test)("$(or)", () => __awaiter(void 0, void 0, void 0, function* () { const output = yield (0, index_1.evaluate)("$(or)"); node_assert_1.default.equal(output, "0"); })); (0, node_test_1.test)("$(or,276)", () => __awaiter(void 0, void 0, void 0, function* () { const output = yield (0, index_1.evaluate)("$(or,276)"); node_assert_1.default.equal(output, "276"); })); (0, node_test_1.test)("$(or,0x1000,1)", () => __awaiter(void 0, void 0, void 0, function* () { const output = yield (0, index_1.evaluate)("$(or,0x1000,1)"); node_assert_1.default.equal(output, "4097"); })); (0, node_test_1.test)("$(or,0x1000,0x200,0x30,0x4)", () => __awaiter(void 0, void 0, void 0, function* () { const output = yield (0, index_1.evaluate)("$(or,0x1000,0x200,0x30,0x4)"); node_assert_1.default.equal(output, "4660"); })); }); (0, node_test_1.describe)("$(XOR,<val1>,<val2>,...<valn>)", () => { (0, node_test_1.test)("$(xor)", () => __awaiter(void 0, void 0, void 0, function* () { const output = yield (0, index_1.evaluate)("$(xor)"); node_assert_1.default.equal(output, "0"); })); (0, node_test_1.test)("$(xor,276)", () => __awaiter(void 0, void 0, void 0, function* () { const output = yield (0, index_1.evaluate)("$(xor,276)"); node_assert_1.default.equal(output, "276"); })); (0, node_test_1.test)("$(xor,0xF0,0x81)", () => __awaiter(void 0, void 0, void 0, function* () { const output = yield (0, index_1.evaluate)("$(xor,0xF0,0x81)"); node_assert_1.default.equal(output, "113"); })); (0, node_test_1.test)("$(xor,0xF000,0x6200,0x31,0x8005)", () => __awaiter(void 0, void 0, void 0, function* () { const output = yield (0, index_1.evaluate)("$(xor,0xF000,0x6200,0x31,0x8005)"); node_assert_1.default.equal(output, "4660"); })); }); (0, node_test_1.describe)("$(IF,<expr>,<dotrue>,<dofalse>)", () => { (0, node_test_1.test)("$(if,0,true,false)", () => __awaiter(void 0, void 0, void 0, function* () { const output = yield (0, index_1.evaluate)("$(if,0,true,false)"); node_assert_1.default.equal(output, "false"); })); (0, node_test_1.test)("$(if,1,true,false)", () => __awaiter(void 0, void 0, void 0, function* () { const output = yield (0, index_1.evaluate)("$(if,1,true,false)"); node_assert_1.default.equal(output, "true"); })); (0, node_test_1.test)("$(if,-2873,true,false)", () => __awaiter(void 0, void 0, void 0, function* () { const output = yield (0, index_1.evaluate)("$(if,-2873,true,false)"); node_assert_1.default.equal(output, "true"); })); (0, node_test_1.test)("$(if,1,evaluated,$(bogus bogus not evaluated))", () => __awaiter(void 0, void 0, void 0, function* () { const output = yield (0, index_1.evaluate)("$(if,1,evaluated,$(bogus bogus not evaluated))"); node_assert_1.default.equal(output, "evaluated"); })); (0, node_test_1.test)("$(if,0,$(bogus bogus not evaluated),evaluated)", () => __awaiter(void 0, void 0, void 0, function* () { const output = yield (0, index_1.evaluate)("$(if,0,$(bogus bogus not evaluated),evaluated)"); node_assert_1.default.equal(output, "evaluated"); })); (0, node_test_1.test)("$(if,1,true only)", () => __awaiter(void 0, void 0, void 0, function* () { const output = yield (0, index_1.evaluate)("$(if,1,true only)"); node_assert_1.default.equal(output, "true only"); })); (0, node_test_1.test)("$(if,0,true only)", () => __awaiter(void 0, void 0, void 0, function* () { const output = yield (0, index_1.evaluate)("$(if,0,true only)"); node_assert_1.default.equal(output, ""); })); }); }); (0, node_test_1.describe)("String", () => { (0, node_test_1.describe)("$(STRFILL,<string>,<ncopies>)", () => __awaiter(void 0, void 0, void 0, function* () { (0, node_test_1.test)("$(strfill,,500)", () => __awaiter(void 0, void 0, void 0, function* () { const output = yield (0, index_1.evaluate)("$(strfill,,500)"); node_assert_1.default.equal(output, ""); })); (0, node_test_1.test)("$(strfill,.,75)", () => __awaiter(void 0, void 0, void 0, function* () { const output = yield (0, index_1.evaluate)("$(strfill,.,75)"); node_assert_1.default.equal(output, "..........................................................................."); })); (0, node_test_1.test)("$(strfill,this never is output,0)", () => __awaiter(void 0, void 0, void 0, function* () { const output = yield (0, index_1.evaluate)("$(strfill,this never is output,0)"); node_assert_1.default.equal(output, ""); })); (0, node_test_1.test)("$(strfill,this never is output,-1)", () => __awaiter(void 0, void 0, void 0, function* () { const output = yield (0, index_1.evaluate)("$(strfill,this never is output,-1)"); node_assert_1.default.equal(output, ""); })); })); (0, node_test_1.describe)("(STRLEN,<string>)", () => __awaiter(void 0, void 0, void 0, function* () { (0, node_test_1.test)("$(strlen,)", () => __awaiter(void 0, void 0, void 0, function* () { const output = yield (0, index_1.evaluate)("$(strlen,)"); node_assert_1.default.equal(output, "0"); })); (0, node_test_1.test)("$(strlen, )", () => __awaiter(void 0, void 0, void 0, function* () { const output = yield (0, index_1.evaluate)("$(strlen, )"); node_assert_1.default.equal(output, "1"); })); (0, node_test_1.test)("$(strlen,hello there)", () => __awaiter(void 0, void 0, void 0, function* () { const output = yield (0, index_1.evaluate)("$(strlen,hello there)"); node_assert_1.default.equal(output, "11"); })); })); (0, node_test_1.describe)("$(SUBSTR,<string>,<start>,<length>)", () => { (0, node_test_1.test)("$(substr,hello there,7)", () => __awaiter(void 0, void 0, void 0, function* () { const output = yield (0, index_1.evaluate)("$(substr,hello there,7)"); node_assert_1.default.equal(output, "there"); })); (0, node_test_1.test)("This is $(substr,hello there,7,3) right answer", () => __awaiter(void 0, void 0, void 0, function* () { const output = yield (0, index_1.evaluate)("This is $(substr,hello there,7,3) right answer"); node_assert_1.default.equal(output, "This is the right answer"); })); (0, node_test_1.test)("$(substr,hello there,2,0)", () => __awaiter(void 0, void 0, void 0, function* () { const output = yield (0, index_1.evaluate)("$(substr,hello there,2,0)"); node_assert_1.default.equal(output, ""); })); (0, node_test_1.test)("$(substr,hello there,23,12)", () => __awaiter(void 0, void 0, void 0, function* () { const output = yield (0, index_1.evaluate)("$(substr,hello there,23,12)"); node_assert_1.default.equal(output, ""); })); }); (0, node_test_1.describe)("$(UPPER,<string>)", () => { (0, node_test_1.test)("$(upper,lower case)", () => __awaiter(void 0, void 0, void 0, function* () { const output = yield (0, index_1.evaluate)("$(upper,lower case)"); node_assert_1.default.equal(output, "LOWER CASE"); })); (0, node_test_1.test)("$(upper,UPPER CASE)", () => __awaiter(void 0, void 0, void 0, function* () { const output = yield (0, index_1.evaluate)("$(upper,UPPER CASE)"); node_assert_1.default.equal(output, "UPPER CASE"); })); (0, node_test_1.test)("$(upper,123456789 !@#$%^&* =+\|`~-_ []{} ;: <>./? Mixed Case)", () => __awaiter(void 0, void 0, void 0, function* () { const output = yield (0, index_1.evaluate)("$(upper,123456789 !@#$%^&* =+\|`~-_ []{} ;: <>./? Mixed Case)"); node_assert_1.default.equal(output, "123456789 !@#$%^&* =+\|`~-_ []{} ;: <>./? MIXED CASE"); })); }); }); (0, node_test_1.describe)("Other", () => { (0, node_test_1.describe)("$(FIX,<value>)", () => { (0, node_test_1.test)("$(fix,3.75)", () => __awaiter(void 0, void 0, void 0, function* () { const output = yield (0, index_1.evaluate)("$(fix,3.75)"); node_assert_1.default.equal(output, "3"); })); (0, node_test_1.test)("$(fix,-11.99)", () => __awaiter(void 0, void 0, void 0, function* () { const output = yield (0, index_1.evaluate)("$(fix,-11.99)"); node_assert_1.default.equal(output, "-11"); })); }); (0, node_test_1.describe)("$(INDEX,<which>,<string>)", () => { (0, node_test_1.test)("$(index,0,\"first,second,third\")", () => __awaiter(void 0, void 0, void 0, function* () { const output = yield (0, index_1.evaluate)("$(index,0,\"first,second,third\")"); node_assert_1.default.equal(output, "first"); })); (0, node_test_1.test)("$(index,1,\"first,second,third\")", () => __awaiter(void 0, void 0, void 0, function* () { const output = yield (0, index_1.evaluate)("$(index,1,\"first,second,third\")"); node_assert_1.default.equal(output, "second"); })); (0, node_test_1.test)("$(index,2,\"first,second,third\")", () => __awaiter(void 0, void 0, void 0, function* () { const output = yield (0, index_1.evaluate)("$(index,2,\"first,second,third\")"); node_assert_1.default.equal(output, "third"); })); (0, node_test_1.test)("$(index,3,\"first,second,third\")", () => __awaiter(void 0, void 0, void 0, function* () { const output = yield (0, index_1.evaluate)("$(index,3,\"first,second,third\")"); node_assert_1.default.equal(output, ""); })); }); (0, node_test_1.describe)("$(NTH,<which>,<arg0>,<arg1>,...<argN>)", () => { (0, node_test_1.test)("$(nth,0,first,second,third)", () => __awaiter(void 0, void 0, void 0, function* () { const output = yield (0, index_1.evaluate)("$(nth,0,first,second,third)"); node_assert_1.default.equal(output, "first"); })); (0, node_test_1.test)("$(nth,1,first,second,third)", () => __awaiter(void 0, void 0, void 0, function* () { const output = yield (0, index_1.evaluate)("$(nth,1,first,second,third)"); node_assert_1.default.equal(output, "second"); })); (0, node_test_1.test)("$(nth,2,first,second,third)", () => __awaiter(void 0, void 0, void 0, function* () { const output = yield (0, index_1.evaluate)("$(nth,2,first,second,third)"); node_assert_1.default.equal(output, "third"); })); (0, node_test_1.test)("$(nth,1,$(bogus not evaluated),evaluated,$(bogus not evaluated))", () => __awaiter(void 0, void 0, void 0, function* () { const output = yield (0, index_1.evaluate)("$(nth,1,$(bogus not evaluated),evaluated,$(bogus not evaluated))"); node_assert_1.default.equal(output, "evaluated"); })); }); (0, node_test_1.describe)("$(EVAL,<str>)", () => { (0, node_test_1.test)("$(eval,\"$(+,1,2,3)\")", () => __awaiter(void 0, void 0, void 0, function* () { const output = yield (0, index_1.evaluate)("$(eval,\"$(+,1,2,3)\")"); node_assert_1.default.equal(output, "6"); })); }); }); (0, node_test_1.describe)("Variables", () => { // TODO: Finish those test (0, node_test_1.test)("$(setvar,kelvin,Hello there)$(getvar,kelvin)", () => __awaiter(void 0, void 0, void 0, function* () { const output = yield (0, index_1.evaluate)("$(setvar,kelvin,Hello there)$(getvar,kelvin)"); node_assert_1.default.equal(output, "Hello there"); })); (0, node_test_1.test)("$(setvar,pierre,Bonjour mesdames et messieurs)$(getvar,pierre)$(getvar,kelvin)", () => __awaiter(void 0, void 0, void 0, function* () { const output = yield (0, index_1.evaluate)("$(setvar,pierre,Bonjour mesdames et messieurs)$(getvar,pierre)$(getvar,kelvin)"); node_assert_1.default.equal(output, "Bonjour mesdames et messieursHello there"); })); node_test_1.test.skip("$(setvar,kelvin,Buenos dias)$(getvar,pierre)$(getvar,kelvin)", () => __awaiter(void 0, void 0, void 0, function* () { const output = yield (0, index_1.evaluate)("$(setvar,kelvin,Buenos dias)"); node_assert_1.default.equal(output, "Bonjour mesdames et messieursBuenos dias"); })); node_test_1.test.skip("$(setvar,pierre,$(getvar,kelvin))$(getvar,pierre)$(getvar,kelvin)", () => __awaiter(void 0, void 0, void 0, function* () { const output = yield (0, index_1.evaluate)("$(setvar,pierre,$(getvar,kelvin))$(getvar,pierre)$(getvar,kelvin)"); node_assert_1.default.equal(output, "Buenos diasBuenos dias"); })); node_test_1.test.skip("$(setvar,filler,$(strfill,-,75))$(getvar,pierre)$(getvar,kelvin)$(getvar,filler)", () => __awaiter(void 0, void 0, void 0, function* () { const output = yield (0, index_1.evaluate)("$(setvar,filler,$(strfill,-,75))$(getvar,pierre)$(getvar,kelvin)$(getvar,filler)"); node_assert_1.default.equal(output, "Buenos diasBuenos dias"); })); }); (0, node_test_1.describe)("Unix", () => { // TODO: Add test for UNIX functions }); (0, node_test_1.describe)("Errors", () => { (0, node_test_1.describe)("evaluate", () => { (0, node_test_1.describe)("Missing right paren", () => { (0, node_test_1.test)("$(bogus", () => __awaiter(void 0, void 0, void 0, function* () { yield node_assert_1.default.rejects(() => __awaiter(void 0, void 0, void 0, function* () { return yield (0, index_1.evaluate)("$(bogus"); }), index_1.DieselSyntaxError); })); (0, node_test_1.test)("$(bogus$(bogus", () => __awaiter(void 0, void 0, void 0, function* () { yield node_assert_1.default.rejects(() => __awaiter(void 0, void 0, void 0, function* () { return yield (0, index_1.evaluate)("$(bogus$(bogus"); }), index_1.DieselSyntaxError); })); }); (0, node_test_1.describe)("Runaway string", () => __awaiter(void 0, void 0, void 0, function* () { (0, node_test_1.test)("$(\"Where's the closing quote?)", () => __awaiter(void 0, void 0, void 0, function* () { yield node_assert_1.default.rejects(() => __awaiter(void 0, void 0, void 0, function* () { return yield (0, index_1.evaluate)("$(\"\"\"Here's trouble\"\")"); }), index_1.DieselSyntaxError); })); (0, node_test_1.test)("$(\"\"\"Here's trouble\"\")", () => __awaiter(void 0, void 0, void 0, function* () { yield node_assert_1.default.rejects(() => __awaiter(void 0, void 0, void 0, function* () { return yield (0, index_1.evaluate)("$(\"\"\"Here's trouble\"\")"); }), index_1.DieselSyntaxError); })); })); (0, node_test_1.describe)("Unknown function", () => __awaiter(void 0, void 0, void 0, function* () { (0, node_test_1.test)("$(binky)", () => __awaiter(void 0, void 0, void 0, function* () { yield node_assert_1.default.rejects(() => __awaiter(void 0, void 0, void 0, function* () { return yield (0, index_1.evaluate)("$(binky)"); }), index_1.DieselUnknownFunctionError); })); (0, node_test_1.test)("$()", () => __awaiter(void 0, void 0, void 0, function* () { // TODO: Is this correct type of error? yield node_assert_1.default.rejects(() => __awaiter(void 0, void 0, void 0, function* () { return yield (0, index_1.evaluate)("$()"); }), index_1.DieselUnknownError); })); })); (0, node_test_1.describe)("Incorrect arguments", () => __awaiter(void 0, void 0, void 0, function* () { // TODO: Fix those tests (0, node_test_1.test)("$(+,1,2,three)", () => __awaiter(void 0, void 0, void 0, function* () { yield node_assert_1.default.rejects(() => __awaiter(void 0, void 0, void 0, function* () { return yield (0, index_1.evaluate)("$(+,1,2,three)"); }), index_1.DieselIncorrectFunctionArgumentsError); })); (0, node_test_1.test)("$(upper,only takes,one argument)", () => __awaiter(void 0, void 0, void 0, function* () { yield node_assert_1.default.rejects(() => __awaiter(void 0, void 0, void 0, function* () { return yield (0, index_1.evaluate)("$(upper,only takes,one argument)"); }), index_1.DieselIncorrectFunctionArgumentsError); })); (0, node_test_1.test)("$(=,1)", () => __awaiter(void 0, void 0, void 0, function* () { yield node_assert_1.default.rejects(() => __awaiter(void 0, void 0, void 0, function* () { return yield (0, index_1.evaluate)("$(=,1)"); }), index_1.DieselIncorrectFunctionArgumentsError); })); })); (0, node_test_1.describe)("String too long", () => __awaiter(void 0, void 0, void 0, function* () { node_test_1.test.skip("$(strfill,.,80)$(strfill,-,80)$(strfill,*,80)", () => __awaiter(void 0, void 0, void 0, function* () { // TODO: Fix this test yield node_assert_1.default.rejects(() => __awaiter(void 0, void 0, void 0, function* () { return yield (0, index_1.evaluate)("$(strfill,.,80)$(strfill,-,80)$(strfill,*,80)"); }), index_1.DieselOutputTooLongError); })); node_test_1.test.skip("$(strfill,*hello*,100)", () => __awaiter(void 0, void 0, void 0, function* () { yield node_assert_1.default.rejects(() => __awaiter(void 0, void 0, void 0, function* () { return yield (0, index_1.evaluate)("$(strfill,*hello*,100)"); }), index_1.DieselOutputTooLongError); })); })); }); (0, node_test_1.describe)("evaluateC", () => { (0, node_test_1.describe)("Missing right paren", () => { (0, node_test_1.test)("$(bogus", () => __awaiter(void 0, void 0, void 0, function* () { const output = yield (0, index_1.evaluateC)("$(bogus"); node_assert_1.default.equal(output.output, "$?"); node_assert_1.default.equal(output.return, 7); })); (0, node_test_1.test)("$(bogus$(bogus", () => __awaiter(void 0, void 0, void 0, function* () { const output = yield (0, index_1.evaluateC)("$(bogus"); node_assert_1.default.equal(output.output, "$?"); node_assert_1.default.equal(output.return, 7); })); }); (0, node_test_1.describe)("Runaway string", () => __awaiter(void 0, void 0, void 0, function* () { (0, node_test_1.test)("$(\"Where's the closing quote?)", () => __awaiter(void 0, void 0, void 0, function* () { const output = yield (0, index_1.evaluateC)("$(\"Where's the closing quote?)"); node_assert_1.default.equal(output.output, "$?"); node_assert_1.default.equal(output.return, 30); })); (0, node_test_1.test)("$(\"\"\"Here's trouble\"\")", () => __awaiter(void 0, void 0, void 0, function* () { const output = yield (0, index_1.evaluateC)("$(\"\"\"Here's trouble\"\")"); node_assert_1.default.equal(output.output, "$?"); node_assert_1.default.equal(output.return, 22); })); })); (0, node_test_1.describe)("Unknown function", () => __awaiter(void 0, void 0, void 0, function* () { (0, node_test_1.test)("$(binky)", () => __awaiter(void 0, void 0, void 0, function* () { const output = yield (0, index_1.evaluateC)("$(binky)"); node_assert_1.default.equal(output.output, " $(BINKY)?? "); node_assert_1.default.equal(output.return, 8); })); (0, node_test_1.test)("$()", () => __awaiter(void 0, void 0, void 0, function* () { const output = yield (0, index_1.evaluateC)("$()"); node_assert_1.default.equal(output.output, " $()?? "); node_assert_1.default.equal(output.return, 3); })); })); (0, node_test_1.describe)("Incorrect arguments", () => __awaiter(void 0, void 0, void 0, function* () { (0, node_test_1.test)("$(+,1,2,three)", () => __awaiter(void 0, void 0, void 0, function* () { const output = yield (0, index_1.evaluateC)("$(+,1,2,three)"); node_assert_1.default.equal(output.output, " $(+,??) "); node_assert_1.default.equal(output.return, 14); })); (0, node_test_1.test)("$(upper,only takes,one argument)", () => __awaiter(void 0, void 0, void 0, function* () { const output = yield (0, index_1.evaluateC)("$(upper,only takes,one argument)"); node_assert_1.default.equal(output.output, " $(UPPER,??) "); node_assert_1.default.equal(output.return, 32); })); (0, node_test_1.test)("$(=,1)", () => __awaiter(void 0, void 0, void 0, function* () { const output = yield (0, index_1.evaluateC)("$(=,1)"); node_assert_1.default.equal(output.output, " $(=,??) "); node_assert_1.default.equal(output.return, 6); })); })); (0, node_test_1.describe)("String too long", () => __awaiter(void 0, void 0, void 0, function* () { node_test_1.test.skip("$(strfill,.,80)$(strfill,-,80)$(strfill,*,80)", () => __awaiter(void 0, void 0, void 0, function* () { // TODO: Fix this test const output = yield (0, index_1.evaluateC)("$(strfill,.,80)$(strfill,-,80)$(strfill,*,80)"); node_assert_1.default.equal(output.output, " $(++)"); node_assert_1.default.equal(output.return, 7); })); (0, node_test_1.test)("$(strfill,*hello*,100)", () => __awaiter(void 0, void 0, void 0, function* () { const output = yield (0, index_1.evaluateC)("$(strfill,*hello*,100)"); node_assert_1.default.equal(output.output, " $(++)"); node_assert_1.default.equal(output.return, 22); })); })); }); });