eggtended-js
Version:
A extended version of the Egg programming language from the Eloquent Javascript book.
246 lines (210 loc) • 15.6 kB
HTML
<html>
<head>
<meta charset="utf-8">
<base data-ice="baseUrl" href="../../">
<title data-ice="title">test/examples-test.js | eggtended-js</title>
<link type="text/css" rel="stylesheet" href="css/style.css">
<link type="text/css" rel="stylesheet" href="css/prettify-tomorrow.css">
<script src="script/prettify/prettify.js"></script>
<script src="script/manual.js"></script>
<meta name="description" content="An extended version of the Egg programming language"><meta property="og:type" content="website"><meta property="og:url" content="http://my-library.org"><meta property="og:site_name" content="eggtended-js"><meta property="og:title" content="eggtended-js"><meta property="og:image" content="https://i.imgur.com/9N4qe98.png"><meta property="og:description" content="An extended version of the Egg programming language"><meta property="og:author" content="https://github.com/Dibad"><meta property="twitter:card" content="summary"><meta property="twitter:title" content="eggtended-js"><meta property="twitter:description" content="An extended version of the Egg programming language"><meta property="twitter:image" content="https://i.imgur.com/9N4qe98.png"></head>
<body class="layout-container" data-ice="rootContainer">
<header>
<a href="./">Home</a>
<a href="identifiers.html">Reference</a>
<a href="source.html">Source</a>
<a href="test.html" data-ice="testLink">Test</a>
<div class="search-box">
<span>
<img src="./image/search.png">
<span class="search-input-edge"></span><input class="search-input"><span class="search-input-edge"></span>
</span>
<ul class="search-result"></ul>
</div>
<a style="position:relative; top:3px;" href="https://github.com/Dibad/eggtended-js"><img width="20px" src="./image/github.png"></a></header>
<nav class="navigation" data-ice="nav"><div>
<ul>
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-checkIterable">checkIterable</a></span></span></li>
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-chunk">chunk</a></span></span></li>
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-getValidIndex">getValidIndex</a></span></span></li>
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-ins">ins</a></span></span></li>
<li data-ice="doc"><a data-ice="dirPath" class="nav-dir-path" href="identifiers.html#interp">interp</a><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/lib/interp/ast.js~Apply.html">Apply</a></span></span></li>
<li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/lib/interp/ast.js~Regex.html">Regex</a></span></span></li>
<li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/lib/interp/ast.js~Value.html">Value</a></span></span></li>
<li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/lib/interp/ast.js~Word.html">Word</a></span></span></li>
<li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/lib/interp/eggvm.js~Eggvm.html">Eggvm</a></span></span></li>
<li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/lib/interp/symboltable.js~SymbolTable.html">SymbolTable</a></span></span></li>
<li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-SpecialForms">SpecialForms</a></span></span></li>
<li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-TopEnv">TopEnv</a></span></span></li>
<li data-ice="doc"><a data-ice="dirPath" class="nav-dir-path" href="identifiers.html#parser">parser</a><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/lib/parser/lexer.js~Lexer.html">Lexer</a></span></span></li>
<li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/lib/parser/parse.js~Parser.html">Parser</a></span></span></li>
<li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/lib/parser/tokenRegex.js~TokenRegex.html">TokenRegex</a></span></span></li>
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-json2AST">json2AST</a></span></span></li>
<li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-COMMA">COMMA</a></span></span></li>
<li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-LP">LP</a></span></span></li>
<li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-NEWLINE">NEWLINE</a></span></span></li>
<li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-NUMBER">NUMBER</a></span></span></li>
<li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-REGEX">REGEX</a></span></span></li>
<li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-RP">RP</a></span></span></li>
<li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-STRING">STRING</a></span></span></li>
<li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-WHITES">WHITES</a></span></span></li>
<li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-WORD">WORD</a></span></span></li>
<li data-ice="doc"><a data-ice="dirPath" class="nav-dir-path" href="identifiers.html#repl">repl</a><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-eggCompleter">eggCompleter</a></span></span></li>
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-getPromptLine">getPromptLine</a></span></span></li>
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-repl">repl</a></span></span></li>
<li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-BLUE">BLUE</a></span></span></li>
<li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-DEFAULT">DEFAULT</a></span></span></li>
<li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-GREEN">GREEN</a></span></span></li>
<li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-RED">RED</a></span></span></li>
<li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-YELLOW">YELLOW</a></span></span></li>
<li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-eggClear">eggClear</a></span></span></li>
<li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-eggExit">eggExit</a></span></span></li>
<li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-eggHelp">eggHelp</a></span></span></li>
<li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-eggInfo">eggInfo</a></span></span></li>
<li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-eggRun">eggRun</a></span></span></li>
<li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-eggVersion">eggVersion</a></span></span></li>
</ul>
</div>
</nav>
<div class="content" data-ice="content"><h1 data-ice="title">test/examples-test.js</h1>
<pre class="source-code line-number raw-source-code"><code class="prettyprint linenums" data-ice="content">const fs = require("fs");
const should = require("should");
const sinon = require("sinon");
const { Parser } = require("../lib/parser/parse.js");
const { Eggvm } = require("../lib/interp/eggvm.js");
const parser = new Parser();
describe("Testing programs from 'examples/' folder", () => {
// Spy calls to 'console.log'
beforeEach(() => {
this.logSpy = sinon.spy(console, "log");
});
afterEach(() => {
this.logSpy.restore();
});
// Method to test the number and values of 'logSpy' calls
const assertOutput = outs => {
this.logSpy.callCount.should.be.eql(outs.length);
outs.forEach((output, index) => {
this.logSpy
.getCall(index)
.calledWithExactly(output)
.should.be.true();
});
};
// Method for creating and executing the dynamic tests
const executeTests = tests => {
tests.forEach((outputs, file) => {
// Path to the related .evm file
const fileEVM = file + ".evm";
describe(`Test for ${file}`, () => {
// -- TEST PARSING --
it("should be parsed correctly", () => {
const rawData = fs.readFileSync(fileEVM);
const expectedTree = JSON.parse(rawData);
parser.parseFromFile(file).should.match(expectedTree);
});
// -- TEST EXECUTION --
if (Array.isArray(outputs)) {
it("should print the expected output after execution", () => {
// Eggvm.runFromEVM(fileEVM);
Eggvm.runFromEVM(fileEVM);
assertOutput(outputs);
});
} else {
it(`should throw an exception of type ${outputs.name}`, () => {
should.throws(() => {
Eggvm.runFromFile(file);
}, outputs);
});
}
});
});
};
// Define tests
const tests = new Map();
tests.set("examples/one.egg", [50]);
tests.set("examples/two.egg", [9]);
tests.set("examples/scope.egg", [9, 8]);
tests.set("examples/scope-err.egg", ReferenceError);
tests.set("examples/boolean.egg", ["true"]);
tests.set("examples/string.egg", ["s"]);
tests.set("examples/sum.egg", [395.5]);
tests.set("examples/reto.egg", ["sum(array[1, 2, 3]) := 6"]);
tests.set("examples/array.egg", [[1, 4], 5]);
tests.set("examples/array-index.egg", [1, [2, 3], 3, 3, 2]);
tests.set("examples/array-properties.egg", [1, [5, 3], 3]);
tests.set("examples/set-error.egg", TypeError);
tests.set("examples/set-error2.egg", TypeError);
tests.set("examples/method3.egg", ["A-B-C"]);
tests.set("examples/method-concatenation.egg", ["1-hello egg"]);
tests.set("examples/property.egg", [2, 3]);
tests.set("examples/string-apply.egg", [5, "4.00", 19]);
tests.set("examples/operators-arithm.egg", [6, 5, 10, -5, 0, -10]);
tests.set("examples/operators-arithm-errors.egg", [
"Bad use of ++",
"Bad use of --",
"Bad use of +=",
"Bad use of -="
]);
tests.set("examples/map.egg", [
new Map([["x", 4], ["y", new Map([["z", 3]])]]),
4,
new Map([["z", 3]]),
3,
new Map([["z", 50]])
]);
tests.set("examples/map-colon.egg", [
new Map([["x", 4], ["y", new Map([["z", 3]])]]),
4,
new Map([["z", 3]]),
3,
new Map([["z", 50]])
]);
tests.set("examples/multi-sub-set.egg", [
1,
new Map([["x", 2], ["y", [3, 4]]]),
[3, 4],
new Map([["x", 2], ["y", 5]]),
[0, 1]
]);
tests.set("examples/map-sub.egg", [1, new Map([["d", 5], ["e", 3]]), 3]);
tests.set("examples/fun-inside-map.egg", [7, 4]);
tests.set("examples/missing.egg", [9]);
tests.set("examples/missing-err.egg", SyntaxError);
tests.set("examples/objects.egg", [0, 4, 5]);
tests.set("examples/regex.egg", [true, 0, "2015", "02"]);
tests.set("examples/dot.egg", ["1-4-5", 5]);
tests.set("examples/dot-obj-2.egg", [0, 0, 0, 5, 5, 5]);
tests.set("examples/dot-num.egg", ["4.00", "4.00", "4.00"]);
tests.set("examples/for.egg", [0, 1, 2, 3, 4]);
tests.set("examples/foreach.egg", [1, 2, 3, "A", "B", "C"]);
tests.set("examples/client.egg", ["inside module", 5, 5, 3]);
tests.set("examples/ects-context.egg", [0, 4, 5]);
tests.set("examples/child.egg", [5, 5, 5]);
tests.set("examples/const.egg", ReferenceError);
// tests.set("examples/const-2.egg", [5, 5]);
tests.set("examples/const-3.egg", ReferenceError);
tests.set("examples/trycatch.egg", ["Caught error! 42", 20, "Finally called"]);
tests.set("examples/trycatch-2.egg", [
"Inner catch. Rethrowing...",
"Outer catch. 42"
]);
tests.set("examples/type-conversion.egg", [false]);
// Execute all the defined tests
executeTests(tests);
});
</code></pre>
</div>
<footer class="footer">
Generated by <a href="https://esdoc.org">ESDoc<span data-ice="esdocVersion">(1.1.0)</span><img src="./image/esdoc-logo-mini-black.png"></a>
</footer>
<script src="script/search_index.js"></script>
<script src="script/search.js"></script>
<script src="script/pretty-print.js"></script>
<script src="script/inherited-summary.js"></script>
<script src="script/test-summary.js"></script>
<script src="script/inner-link.js"></script>
<script src="script/patch-for-local.js"></script>
</body>
</html>