UNPKG

eggtended-js

Version:

A extended version of the Egg programming language from the Eloquent Javascript book.

246 lines (210 loc) 15.6 kB
<!DOCTYPE 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(&quot;fs&quot;); const should = require(&quot;should&quot;); const sinon = require(&quot;sinon&quot;); const { Parser } = require(&quot;../lib/parser/parse.js&quot;); const { Eggvm } = require(&quot;../lib/interp/eggvm.js&quot;); const parser = new Parser(); describe(&quot;Testing programs from &apos;examples/&apos; folder&quot;, () =&gt; { // Spy calls to &apos;console.log&apos; beforeEach(() =&gt; { this.logSpy = sinon.spy(console, &quot;log&quot;); }); afterEach(() =&gt; { this.logSpy.restore(); }); // Method to test the number and values of &apos;logSpy&apos; calls const assertOutput = outs =&gt; { this.logSpy.callCount.should.be.eql(outs.length); outs.forEach((output, index) =&gt; { this.logSpy .getCall(index) .calledWithExactly(output) .should.be.true(); }); }; // Method for creating and executing the dynamic tests const executeTests = tests =&gt; { tests.forEach((outputs, file) =&gt; { // Path to the related .evm file const fileEVM = file + &quot;.evm&quot;; describe(`Test for ${file}`, () =&gt; { // -- TEST PARSING -- it(&quot;should be parsed correctly&quot;, () =&gt; { const rawData = fs.readFileSync(fileEVM); const expectedTree = JSON.parse(rawData); parser.parseFromFile(file).should.match(expectedTree); }); // -- TEST EXECUTION -- if (Array.isArray(outputs)) { it(&quot;should print the expected output after execution&quot;, () =&gt; { // Eggvm.runFromEVM(fileEVM); Eggvm.runFromEVM(fileEVM); assertOutput(outputs); }); } else { it(`should throw an exception of type ${outputs.name}`, () =&gt; { should.throws(() =&gt; { Eggvm.runFromFile(file); }, outputs); }); } }); }); }; // Define tests const tests = new Map(); tests.set(&quot;examples/one.egg&quot;, [50]); tests.set(&quot;examples/two.egg&quot;, [9]); tests.set(&quot;examples/scope.egg&quot;, [9, 8]); tests.set(&quot;examples/scope-err.egg&quot;, ReferenceError); tests.set(&quot;examples/boolean.egg&quot;, [&quot;true&quot;]); tests.set(&quot;examples/string.egg&quot;, [&quot;s&quot;]); tests.set(&quot;examples/sum.egg&quot;, [395.5]); tests.set(&quot;examples/reto.egg&quot;, [&quot;sum(array[1, 2, 3]) := 6&quot;]); tests.set(&quot;examples/array.egg&quot;, [[1, 4], 5]); tests.set(&quot;examples/array-index.egg&quot;, [1, [2, 3], 3, 3, 2]); tests.set(&quot;examples/array-properties.egg&quot;, [1, [5, 3], 3]); tests.set(&quot;examples/set-error.egg&quot;, TypeError); tests.set(&quot;examples/set-error2.egg&quot;, TypeError); tests.set(&quot;examples/method3.egg&quot;, [&quot;A-B-C&quot;]); tests.set(&quot;examples/method-concatenation.egg&quot;, [&quot;1-hello egg&quot;]); tests.set(&quot;examples/property.egg&quot;, [2, 3]); tests.set(&quot;examples/string-apply.egg&quot;, [5, &quot;4.00&quot;, 19]); tests.set(&quot;examples/operators-arithm.egg&quot;, [6, 5, 10, -5, 0, -10]); tests.set(&quot;examples/operators-arithm-errors.egg&quot;, [ &quot;Bad use of ++&quot;, &quot;Bad use of --&quot;, &quot;Bad use of +=&quot;, &quot;Bad use of -=&quot; ]); tests.set(&quot;examples/map.egg&quot;, [ new Map([[&quot;x&quot;, 4], [&quot;y&quot;, new Map([[&quot;z&quot;, 3]])]]), 4, new Map([[&quot;z&quot;, 3]]), 3, new Map([[&quot;z&quot;, 50]]) ]); tests.set(&quot;examples/map-colon.egg&quot;, [ new Map([[&quot;x&quot;, 4], [&quot;y&quot;, new Map([[&quot;z&quot;, 3]])]]), 4, new Map([[&quot;z&quot;, 3]]), 3, new Map([[&quot;z&quot;, 50]]) ]); tests.set(&quot;examples/multi-sub-set.egg&quot;, [ 1, new Map([[&quot;x&quot;, 2], [&quot;y&quot;, [3, 4]]]), [3, 4], new Map([[&quot;x&quot;, 2], [&quot;y&quot;, 5]]), [0, 1] ]); tests.set(&quot;examples/map-sub.egg&quot;, [1, new Map([[&quot;d&quot;, 5], [&quot;e&quot;, 3]]), 3]); tests.set(&quot;examples/fun-inside-map.egg&quot;, [7, 4]); tests.set(&quot;examples/missing.egg&quot;, [9]); tests.set(&quot;examples/missing-err.egg&quot;, SyntaxError); tests.set(&quot;examples/objects.egg&quot;, [0, 4, 5]); tests.set(&quot;examples/regex.egg&quot;, [true, 0, &quot;2015&quot;, &quot;02&quot;]); tests.set(&quot;examples/dot.egg&quot;, [&quot;1-4-5&quot;, 5]); tests.set(&quot;examples/dot-obj-2.egg&quot;, [0, 0, 0, 5, 5, 5]); tests.set(&quot;examples/dot-num.egg&quot;, [&quot;4.00&quot;, &quot;4.00&quot;, &quot;4.00&quot;]); tests.set(&quot;examples/for.egg&quot;, [0, 1, 2, 3, 4]); tests.set(&quot;examples/foreach.egg&quot;, [1, 2, 3, &quot;A&quot;, &quot;B&quot;, &quot;C&quot;]); tests.set(&quot;examples/client.egg&quot;, [&quot;inside module&quot;, 5, 5, 3]); tests.set(&quot;examples/ects-context.egg&quot;, [0, 4, 5]); tests.set(&quot;examples/child.egg&quot;, [5, 5, 5]); tests.set(&quot;examples/const.egg&quot;, ReferenceError); // tests.set(&quot;examples/const-2.egg&quot;, [5, 5]); tests.set(&quot;examples/const-3.egg&quot;, ReferenceError); tests.set(&quot;examples/trycatch.egg&quot;, [&quot;Caught error! 42&quot;, 20, &quot;Finally called&quot;]); tests.set(&quot;examples/trycatch-2.egg&quot;, [ &quot;Inner catch. Rethrowing...&quot;, &quot;Outer catch. 42&quot; ]); tests.set(&quot;examples/type-conversion.egg&quot;, [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>