From 516327c2746633f4f26fb14fc9251c0438b0047d Mon Sep 17 00:00:00 2001 From: Teoxoy <28601907+Teoxoy@users.noreply.github.com> Date: Sun, 8 Sep 2019 05:52:25 +0200 Subject: [PATCH] typescript rewrite (v2) --- .eslint.base.yml | 94 + .eslint.import.yml | 39 + .eslint.typescript.yml | 17 + .eslintrc.js | 39 + .gitignore | 1 + .prettierrc.js | 10 + .vscode/extensions.json | 3 + .vscode/settings.json | 10 + CONTRIBUTING.md | 44 + LICENSE | 2 +- README.md | 100 +- dist/lua-in-js.js | 1 - package-lock.json | 5002 -------------------- package.json | 80 +- rollup.config.js | 33 + src/LuaError.ts | 10 + src/Scope.ts | 42 + src/Table.ts | 244 + src/index.js | 7 - src/index.ts | 98 + src/lib/globals.ts | 406 ++ src/lib/math.ts | 241 + src/lib/os.ts | 193 + src/lib/package.ts | 102 + src/lib/string.ts | 378 ++ src/lib/table.ts | 182 + src/operators.ts | 184 + src/parser.ts | 752 +++ src/parser/index.js | 508 -- src/runtime/LuaError.js | 10 - src/runtime/Scope.js | 44 - src/runtime/Table.js | 214 - src/runtime/index.js | 78 - src/runtime/lib/globals.js | 454 -- src/runtime/lib/math.js | 253 - src/runtime/lib/os.js | 115 - src/runtime/lib/package.js | 7 - src/runtime/lib/string.js | 319 -- src/runtime/lib/table.js | 136 - src/runtime/operators.js | 157 - src/runtime/utils.js | 173 - src/utils.ts | 191 + tests/lua-5.3/all.lua | 293 ++ tests/lua-5.3/api.lua | 1172 +++++ tests/lua-5.3/attrib.lua | 470 ++ tests/lua-5.3/big.lua | 82 + tests/lua-5.3/bitwise.lua | 328 ++ tests/lua-5.3/bwcoercion.lua | 78 + tests/lua-5.3/calls.lua | 401 ++ tests/lua-5.3/closure.lua | 247 + tests/lua-5.3/code.lua | 239 + tests/lua-5.3/constructs.lua | 313 ++ tests/lua-5.3/coroutine.lua | 874 ++++ tests/lua-5.3/db.lua | 857 ++++ tests/lua-5.3/errors.lua | 537 +++ tests/lua-5.3/events.lua | 456 ++ tests/lua-5.3/files.lua | 793 ++++ tests/lua-5.3/gc.lua | 624 +++ tests/lua-5.3/goto.lua | 232 + tests/lua-5.3/heavy.lua | 72 + tests/lua-5.3/literals.lua | 302 ++ tests/lua-5.3/locals.lua | 162 + tests/lua-5.3/main.lua | 381 ++ tests/lua-5.3/math.lua | 824 ++++ tests/lua-5.3/nextvar.lua | 631 +++ tests/lua-5.3/pm.lua | 374 ++ tests/lua-5.3/sort.lua | 310 ++ tests/lua-5.3/strings.lua | 379 ++ tests/lua-5.3/tpack.lua | 322 ++ tests/lua-5.3/utf8.lua | 210 + tests/lua-5.3/vararg.lua | 142 + tests/lua-5.3/verybig.lua | 152 + tests/starlight/coercion.lua | 188 + tests/starlight/control-structures.lua | 294 ++ tests/starlight/functions.lua | 134 + tests/starlight/lib-coroutine.lua | 60 + tests/starlight/lib-date.lua | 1164 +++++ tests/starlight/lib-loadfile.lua | 18 + tests/starlight/lib-math.lua | 168 + tests/starlight/lib-require.lua | 26 + tests/starlight/lib-require/sub-module.lua | 4 + tests/starlight/lib-string.lua | 616 +++ tests/starlight/lib-table.lua | 302 ++ tests/starlight/lib.lua | 561 +++ tests/starlight/metamethods.lua | 395 ++ tests/starlight/operators.lua | 278 ++ tests/starlight/tables.lua | 138 + tests/starlight/test-runner.lua | 84 + tests/test.js | 29 + tsconfig.json | 32 + webpack.config.js | 41 - yarn.lock | 1472 ++++++ 92 files changed, 21647 insertions(+), 7587 deletions(-) create mode 100644 .eslint.base.yml create mode 100644 .eslint.import.yml create mode 100644 .eslint.typescript.yml create mode 100644 .eslintrc.js create mode 100644 .prettierrc.js create mode 100644 .vscode/extensions.json create mode 100644 .vscode/settings.json create mode 100644 CONTRIBUTING.md delete mode 100644 dist/lua-in-js.js delete mode 100644 package-lock.json create mode 100644 rollup.config.js create mode 100644 src/LuaError.ts create mode 100644 src/Scope.ts create mode 100644 src/Table.ts delete mode 100644 src/index.js create mode 100644 src/index.ts create mode 100644 src/lib/globals.ts create mode 100644 src/lib/math.ts create mode 100644 src/lib/os.ts create mode 100644 src/lib/package.ts create mode 100644 src/lib/string.ts create mode 100644 src/lib/table.ts create mode 100644 src/operators.ts create mode 100644 src/parser.ts delete mode 100644 src/parser/index.js delete mode 100644 src/runtime/LuaError.js delete mode 100644 src/runtime/Scope.js delete mode 100644 src/runtime/Table.js delete mode 100644 src/runtime/index.js delete mode 100644 src/runtime/lib/globals.js delete mode 100644 src/runtime/lib/math.js delete mode 100644 src/runtime/lib/os.js delete mode 100644 src/runtime/lib/package.js delete mode 100644 src/runtime/lib/string.js delete mode 100644 src/runtime/lib/table.js delete mode 100644 src/runtime/operators.js delete mode 100644 src/runtime/utils.js create mode 100644 src/utils.ts create mode 100644 tests/lua-5.3/all.lua create mode 100644 tests/lua-5.3/api.lua create mode 100644 tests/lua-5.3/attrib.lua create mode 100644 tests/lua-5.3/big.lua create mode 100644 tests/lua-5.3/bitwise.lua create mode 100644 tests/lua-5.3/bwcoercion.lua create mode 100644 tests/lua-5.3/calls.lua create mode 100644 tests/lua-5.3/closure.lua create mode 100644 tests/lua-5.3/code.lua create mode 100644 tests/lua-5.3/constructs.lua create mode 100644 tests/lua-5.3/coroutine.lua create mode 100644 tests/lua-5.3/db.lua create mode 100644 tests/lua-5.3/errors.lua create mode 100644 tests/lua-5.3/events.lua create mode 100644 tests/lua-5.3/files.lua create mode 100644 tests/lua-5.3/gc.lua create mode 100644 tests/lua-5.3/goto.lua create mode 100644 tests/lua-5.3/heavy.lua create mode 100644 tests/lua-5.3/literals.lua create mode 100644 tests/lua-5.3/locals.lua create mode 100644 tests/lua-5.3/main.lua create mode 100644 tests/lua-5.3/math.lua create mode 100644 tests/lua-5.3/nextvar.lua create mode 100644 tests/lua-5.3/pm.lua create mode 100644 tests/lua-5.3/sort.lua create mode 100644 tests/lua-5.3/strings.lua create mode 100644 tests/lua-5.3/tpack.lua create mode 100644 tests/lua-5.3/utf8.lua create mode 100644 tests/lua-5.3/vararg.lua create mode 100644 tests/lua-5.3/verybig.lua create mode 100644 tests/starlight/coercion.lua create mode 100644 tests/starlight/control-structures.lua create mode 100644 tests/starlight/functions.lua create mode 100644 tests/starlight/lib-coroutine.lua create mode 100644 tests/starlight/lib-date.lua create mode 100644 tests/starlight/lib-loadfile.lua create mode 100644 tests/starlight/lib-math.lua create mode 100644 tests/starlight/lib-require.lua create mode 100644 tests/starlight/lib-require/sub-module.lua create mode 100644 tests/starlight/lib-string.lua create mode 100644 tests/starlight/lib-table.lua create mode 100644 tests/starlight/lib.lua create mode 100644 tests/starlight/metamethods.lua create mode 100644 tests/starlight/operators.lua create mode 100644 tests/starlight/tables.lua create mode 100644 tests/starlight/test-runner.lua create mode 100644 tests/test.js create mode 100644 tsconfig.json delete mode 100644 webpack.config.js create mode 100644 yarn.lock diff --git a/.eslint.base.yml b/.eslint.base.yml new file mode 100644 index 0000000..0fdc5d9 --- /dev/null +++ b/.eslint.base.yml @@ -0,0 +1,94 @@ +--- +rules: + # Best Practices (https://eslint.org/docs/rules/#best-practices) + curly: + - warn + - all + dot-notation: + - error + - allowPattern: '^[a-z]+(_[a-z]+)+$' + eqeqeq: + - warn + - always + guard-for-in: error + no-new-wrappers: error + no-param-reassign: error + no-return-assign: + - error + - always + no-return-await: error + no-self-compare: error + no-sequences: error + no-throw-literal: error + no-unmodified-loop-condition: error + no-unused-expressions: error + no-useless-concat: error + no-useless-return: error + no-void: error + no-with: error + wrap-iife: + - error + - inside + yoda: + - error + - never + - exceptRange: true + + # Stylistic Issues (https://eslint.org/docs/rules/#stylistic-issues) + func-style: + - error + - declaration + - allowArrowFunctions: true + no-mixed-operators: + - error + - groups: + - - '&' + - '|' + - '^' + - '~' + - '<<' + - '>>' + - '>>>' + - - '==' + - '!=' + - '===' + - '!==' + - '>' + - '>=' + - '<' + - '<=' + - - '&&' + - '||' + - - in + - instanceof + allowSamePrecedence: true + no-multi-assign: error + no-negated-condition: error + no-nested-ternary: error + no-new-object: error + no-plusplus: + - error + - allowForLoopAfterthoughts: true + no-unneeded-ternary: error + operator-assignment: + - error + - always + prefer-object-spread: error + spaced-comment: + - warn + - always + - block: + balanced: true + + # ECMAScript 6 (https://eslint.org/docs/rules/#ecmascript-6) + arrow-body-style: + - error + - as-needed + no-confusing-arrow: + - error + - allowParens: true + no-var: error + prefer-const: error + prefer-rest-params: error + prefer-spread: error + prefer-template: error diff --git a/.eslint.import.yml b/.eslint.import.yml new file mode 100644 index 0000000..ee4a4bd --- /dev/null +++ b/.eslint.import.yml @@ -0,0 +1,39 @@ +--- +rules: + import/no-unresolved: 2 + import/named: 2 + import/default: 2 + import/namespace: 2 + import/export: 2 + + import/no-named-as-default: 1 + import/no-named-as-default-member: 1 + import/no-duplicates: 1 + import/first: 1 + import/order: + - 1 + - groups: + - builtin + - external + - internal + - unknown + - parent + - sibling + - index + newlines-between: never + import/no-useless-path-segments: 2 + import/no-self-import: 2 + import/no-absolute-path: 2 + import/no-commonjs: 2 + import/no-amd: 2 + import/no-extraneous-dependencies: + - 2 + - devDependencies: true + peerDependencies: false + optionalDependencies: false + + import/exports-last: 1 + import/group-exports: 1 + # import/no-default-export: 2 + import/no-mutable-exports: 2 + import/no-named-default: 2 diff --git a/.eslint.typescript.yml b/.eslint.typescript.yml new file mode 100644 index 0000000..4afb637 --- /dev/null +++ b/.eslint.typescript.yml @@ -0,0 +1,17 @@ +--- +rules: + '@typescript-eslint/no-useless-constructor': warn + '@typescript-eslint/restrict-plus-operands': error + '@typescript-eslint/no-use-before-define': 'off' + '@typescript-eslint/consistent-type-assertions': + - error + - assertionStyle: 'as' + objectLiteralTypeAssertions: 'allow-as-parameter' + '@typescript-eslint/explicit-member-accessibility': warn + '@typescript-eslint/explicit-function-return-type': + - warn + - allowExpressions: true + allowTypedFunctionExpressions: true + allowHigherOrderFunctions: true + '@typescript-eslint/camelcase': + - error diff --git a/.eslintrc.js b/.eslintrc.js new file mode 100644 index 0000000..c7e69ec --- /dev/null +++ b/.eslintrc.js @@ -0,0 +1,39 @@ +module.exports = { + env: { + browser: true, + es6: true, + node: true + }, + parser: '@typescript-eslint/parser', + parserOptions: { + sourceType: 'module', + project: './tsconfig.json' + }, + plugins: ['@typescript-eslint', 'import', 'prettier'], + settings: { + 'import/extensions': ['.ts'], + 'import/parsers': { + '@typescript-eslint/parser': ['.ts'] + }, + 'import/resolver': { + node: { + extensions: ['.js', '.ts'] + } + } + }, + extends: [ + 'eslint:recommended', + './.eslint.base.yml', + 'plugin:@typescript-eslint/eslint-recommended', // Turn off conflicting rules + + 'plugin:@typescript-eslint/recommended', + './.eslint.typescript.yml', + 'prettier', // Turn off conflicting rules + 'prettier/@typescript-eslint', // Turn off conflicting rules + + './.eslint.import.yml' + ], + rules: { + 'prettier/prettier': 'warn' + } +} diff --git a/.gitignore b/.gitignore index 3c3629e..f06235c 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ node_modules +dist diff --git a/.prettierrc.js b/.prettierrc.js new file mode 100644 index 0000000..933469c --- /dev/null +++ b/.prettierrc.js @@ -0,0 +1,10 @@ +module.exports = { + printWidth: 120, + tabWidth: 4, + useTabs: false, + semi: false, + singleQuote: true, + trailingComma: 'none', + bracketSpacing: true, + arrowParens: 'avoid' +} diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..d824444 --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,3 @@ +{ + "recommendations": ["dbaeumer.vscode-eslint", "esbenp.prettier-vscode"] +} diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..6692f9b --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,10 @@ +{ + "editor.formatOnSave": true, + "[typescript]": { + "editor.formatOnSave": false + }, + "eslint.validate": [{ "language": "typescript", "autoFix": true }], + "eslint.autoFixOnSave": true, + "eslint.alwaysShowStatus": true, + "prettier.disableLanguages": ["ts"] +} diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..fdc368c --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,44 @@ +# Contributing + +First of all, thanks for your interest in helping out! 😃 + +# Submitting an Issue + +Before you submit an issue, please search the issue tracker, maybe an issue for your problem already exists and the discussion might inform you of workarounds readily available. + +We want to fix all the issues as soon as possible and a minimal reproduction scenario allows us to quickly confirm a bug (or point out a coding problem) as well as confirm that we are fixing the right problem. + +# Submitting a Pull Request + +## Prerequisites + +- [git](https://git-scm.com/) +- [yarn](https://yarnpkg.com) +- [node](https://nodejs.org/en/) +- [vscode](https://code.visualstudio.com/) + +### Note + +This project uses `eslint` and `prettier` to lint and format code. I would recommend that you use `vscode` for this project because the repo already contains the extension settings for autofixing linting errors and formatting code on save. So, make sure to **download the recommended workspace extensions** in vscode after cloning the repo. + +## Steps + +1. Fork the repo +2. Clone your fork +3. Download the recommended workspace extensions in vscode +4. Make your changes in a new git branch (`git checkout -b my-fix-branch master`) +5. Run `yarn` +6. Run `yarn start` +7. Open the link in a browser or use the vscode debugger +8. Make changes +9. Commit your changes using a descriptive commit message +10. Push your branch to GitHub `git push origin my-fix-branch` +11. Start a pull request from GitHub + +That's it! 🎉 Thank you for your contribution! 😃 + +## Working on your first Pull Request? + +Check out this [tutorial](https://github.com/firstcontributions/first-contributions/blob/master/github-windows-vs-code-tutorial.md) + +Also, [How to Contribute to an Open Source Project on GitHub](https://egghead.io/series/how-to-contribute-to-an-open-source-project-on-github) for a more in depth (video) tutorial diff --git a/LICENSE b/LICENSE index a83e693..d918559 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2018 Tanasoaia Teodor Andrei +Copyright (c) 2019 Tanasoaia Teodor Andrei Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 6bf81b7..996cbf8 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,11 @@ # lua-in-js -A Lua to JS transpiler / runtime +[![npm](https://img.shields.io/npm/v/lua-in-js.svg?style=flat-square)](https://www.npmjs.com/package/lua-in-js) +[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-blue.svg?style=flat-square)](./CONTRIBUTING.md) +[![GitHub](https://img.shields.io/github/license/teoxoy/lua-in-js.svg?style=flat-square&color=blue)](./LICENSE) +  _Badges are clickable!_ + +A Lua to JS transpiler/runtime. This library is a rewrite of [Starlight](https://github.com/paulcuth/starlight) with a lot of improvements. ## Install @@ -8,43 +13,68 @@ A Lua to JS transpiler / runtime npm i lua-in-js ``` -Usage example (I am using it just to convert a lua file to js; run the temporary js file and get some data from it): +## API + +### Import + +```js +const luainjs = require(luainjs) +// or +import luainjs from 'luainjs' +``` + +### Create the lua environment + +Lua environments are isolated from each other (they got different global scopes) + +```js +const luaEnv = luainjs.createEnv() +``` + +A config object can be passed in for extra functionality + ```js -const fs = require('fs') -const lua2injs = require('lua-in-js') -const execSync = require('child_process').execSync - -const data = luainjs.parser.parse(mainFileData) -fs.writeFileSync('./temp.js', ` - require("lua-in-js").runtime; - ${data} - require("fs").writeFileSync('./temp.json', JSON.stringify(Tget($get($, 'data'), 'raw').toObject(), null, 2)); -`) -execSync('node temp.js') +const luaEnv = luainjs.createEnv({ + LUA_PATH, // default value of package.path + fileExists, // function that takes in a path and returns a boolean + loadFile, // function that takes in a path and returns the content of a file + stdin, // string representing the standard input + stdout, // function representing the standard output + osExit // function called by os.exit +}) ``` -This library is based on the sourcecode of this library: https://github.com/paulcuth/starlight, which is under this license: +### Run a script or file +```js +luaEnv.run('print(\'Hello world!\')') ``` -The MIT License (MIT) - -Copyright 2015—2016 Paul Cuthbertson - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. + +```js +luaEnv.runfile('somefile.lua') ``` + +`runfile` uses `config.fileExists` and `config.loadFile` + +## Example + +Check out the [test runner](./tests/test.js) for a concrete example. + +## Missing functionality + + - coroutine library + - debug library + - utf8 library + - io library + - package.cpath + - package.loadlib + - string.dump + - string.pack + - string.packsize + - string.unpack + - os.clock + - os.execute + - os.getenv + - os.remove + - os.rename + - os.tmpname diff --git a/dist/lua-in-js.js b/dist/lua-in-js.js deleted file mode 100644 index 0f68edc..0000000 --- a/dist/lua-in-js.js +++ /dev/null @@ -1 +0,0 @@ -!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports["lua-in-js"]=t():e["lua-in-js"]=t()}(global,function(){return function(e){var t={};function r(n){if(t[n])return t[n].exports;var a=t[n]={i:n,l:!1,exports:{}};return e[n].call(a.exports,a,a.exports,r),a.l=!0,a.exports}return r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var a in e)r.d(n,a,function(t){return e[t]}.bind(null,a));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=5)}([function(e,t,r){(function(e){var r,n,a;!function(o,i,s){"use strict";var u={function:!0,object:!0},c=u[typeof t]&&t&&!t.nodeType&&t,l=u[typeof e]&&e&&!e.nodeType&&e,f=c&&l&&"object"==typeof global&&global,p=l&&l.exports===c&&c;!f||f.global!==f&&f.window!==f&&f.self,n=[t],void 0===(a="function"==typeof(r=s)?r.apply(t,n):r)||(e.exports=a),c&&p&&s(l.exports)}(0,0,function(e){"use strict";var t,r,n;e.version="0.2.1";var a=e.defaultOptions={wait:!1,comments:!0,scope:!1,locations:!1,ranges:!1,onCreateNode:null,onCreateScope:null,onDestroyScope:null},o=1,i=2,s=4,u=8,c=16,l=32,f=64,p=128,h=256;e.tokenTypes={EOF:o,StringLiteral:i,Keyword:s,Identifier:u,NumericLiteral:c,Punctuator:l,BooleanLiteral:f,NilLiteral:p,VarargLiteral:h};var d=e.errors={unexpected:"unexpected %1 '%2' near '%3'",expected:"'%1' expected near '%2'",expectedToken:"%1 expected near '%2'",unfinishedString:"unfinished string near '%1'",malformedNumber:"malformed number near '%1'",invalidVar:"invalid left-hand side of assignment near '%1'"},g=e.ast={labelStatement:function(e){return{type:"LabelStatement",label:e}},breakStatement:function(){return{type:"BreakStatement"}},gotoStatement:function(e){return{type:"GotoStatement",label:e}},returnStatement:function(e){return{type:"ReturnStatement",arguments:e}},ifStatement:function(e){return{type:"IfStatement",clauses:e}},ifClause:function(e,t){return{type:"IfClause",condition:e,body:t}},elseifClause:function(e,t){return{type:"ElseifClause",condition:e,body:t}},elseClause:function(e){return{type:"ElseClause",body:e}},whileStatement:function(e,t){return{type:"WhileStatement",condition:e,body:t}},doStatement:function(e){return{type:"DoStatement",body:e}},repeatStatement:function(e,t){return{type:"RepeatStatement",condition:e,body:t}},localStatement:function(e,t){return{type:"LocalStatement",variables:e,init:t}},assignmentStatement:function(e,t){return{type:"AssignmentStatement",variables:e,init:t}},callStatement:function(e){return{type:"CallStatement",expression:e}},functionStatement:function(e,t,r,n){return{type:"FunctionDeclaration",identifier:e,isLocal:r,parameters:t,body:n}},forNumericStatement:function(e,t,r,n,a){return{type:"ForNumericStatement",variable:e,start:t,end:r,step:n,body:a}},forGenericStatement:function(e,t,r){return{type:"ForGenericStatement",variables:e,iterators:t,body:r}},chunk:function(e){return{type:"Chunk",body:e}},identifier:function(e){return{type:"Identifier",name:e}},literal:function(e,t,r){return{type:e=e===i?"StringLiteral":e===c?"NumericLiteral":e===f?"BooleanLiteral":e===p?"NilLiteral":"VarargLiteral",value:t,raw:r}},tableKey:function(e,t){return{type:"TableKey",key:e,value:t}},tableKeyString:function(e,t){return{type:"TableKeyString",key:e,value:t}},tableValue:function(e){return{type:"TableValue",value:e}},tableConstructorExpression:function(e){return{type:"TableConstructorExpression",fields:e}},binaryExpression:function(e,t,r){return{type:"and"===e||"or"===e?"LogicalExpression":"BinaryExpression",operator:e,left:t,right:r}},unaryExpression:function(e,t){return{type:"UnaryExpression",operator:e,argument:t}},memberExpression:function(e,t,r){return{type:"MemberExpression",indexer:t,identifier:r,base:e}},indexExpression:function(e,t){return{type:"IndexExpression",base:e,index:t}},callExpression:function(e,t){return{type:"CallExpression",base:e,arguments:t}},tableCallExpression:function(e,t){return{type:"TableCallExpression",base:e,arguments:t}},stringCallExpression:function(e,t){return{type:"StringCallExpression",base:e,argument:t}},comment:function(e,t){return{type:"Comment",value:e,raw:t}}};function m(e){if(re){var t=ne.pop();t.complete(),r.locations&&(e.loc=t.loc),r.ranges&&(e.range=t.range)}return r.onCreateNode&&r.onCreateNode(e),e}var b,_,y,v,w,$,x,S,C,A,E,k=Array.prototype.slice,T=(Object.prototype.toString,function(e,t){for(var r=0,n=e.length;r=n)return{type:o,value:"",line:x,lineStart:S,range:[b,b]};var e=t.charCodeAt(b),r=t.charCodeAt(b+1);if($=b,function(e){return e>=65&&e<=90||e>=97&&e<=122||95===e}(e))return function(){var e,r;for(;n=t.charCodeAt(++b),n>=65&&n<=90||n>=97&&n<=122||95===n||n>=48&&n<=57;);var n;!function(e){switch(e.length){case 2:return"do"===e||"if"===e||"in"===e||"or"===e;case 3:return"and"===e||"end"===e||"for"===e||"not"===e;case 4:return"else"===e||"goto"===e||"then"===e;case 5:return"break"===e||"local"===e||"until"===e||"while"===e;case 6:return"elseif"===e||"repeat"===e||"return"===e;case 8:return"function"===e}return!1}(e=t.slice($,b))?"true"===e||"false"===e?(r=f,e="true"===e):"nil"===e?(r=p,e=null):r=u:r=s;return{type:r,value:e,line:x,lineStart:S,range:[$,b]}}();switch(e){case 39:case 34:return function(){var e,r=t.charCodeAt(b++),a=b,o="";for(;b=n||G(e))&&(o+=t.slice(a,b-1),O({},d.unfinishedString,o+String.fromCharCode(e)));return o+=t.slice(a,b-1),{type:i,value:o,line:x,lineStart:S,range:[$,b]}}();case 48:case 49:case 50:case 51:case 52:case 53:case 54:case 55:case 56:case 57:return U();case 46:return J(r)?U():46===r?46===t.charCodeAt(b+2)?{type:h,value:"...",line:x,lineStart:S,range:[$,b+=3]}:P(".."):P(".");case 61:return P(61===r?"==":"=");case 62:return P(61===r?">=":62===r?">>":">");case 60:return P(60===r?"<<":61===r?"<=":"<");case 126:return P(61===r?"~=":"~");case 58:return P(58===r?"::":":");case 91:return 91===r||61===r?function(){var e=z();!1===e&&O(_,d.expected,"[",_.value);return{type:i,value:e,line:x,lineStart:S,range:[$,b]}}():P("[");case 47:return P(47===r?"//":"/");case 42:case 94:case 37:case 44:case 123:case 124:case 125:case 93:case 40:case 41:case 59:case 38:case 35:case 45:case 43:return P(t.charAt(b))}return I(t.charAt(b))}function N(){var e=t.charCodeAt(b),r=t.charCodeAt(b+1);return!!G(e)&&(10===e&&13===r&&b++,13===e&&10===r&&b++,x++,S=++b,!0)}function V(){for(;b=0?function(){var e,r,n,a,o=0,i=1,s=1;a=b+=2,B(t.charCodeAt(b))||O({},d.malformedNumber,t.slice($,b));for(;B(t.charCodeAt(b));)b++;if(e=parseInt(t.slice(a,b),16),"."===t.charAt(b)){for(r=++b;B(t.charCodeAt(b));)b++;o=t.slice(r,b),o=r===b?0:parseInt(o,16)/Math.pow(16,b-r)}if("pP".indexOf(t.charAt(b)||null)>=0){for(b++,"+-".indexOf(t.charAt(b)||null)>=0&&(s="+"===t.charAt(b++)?1:-1),n=b,J(t.charCodeAt(b))||O({},d.malformedNumber,t.slice($,b));J(t.charCodeAt(b));)b++;i=t.slice(n,b),i=Math.pow(2,i*s)}return(e+o)*i}():function(){for(;J(t.charCodeAt(b));)b++;if("."===t.charAt(b))for(b++;J(t.charCodeAt(b));)b++;if("eE".indexOf(t.charAt(b)||null)>=0)for(b++,"+-".indexOf(t.charAt(b)||null)>=0&&b++,J(t.charCodeAt(b))||O({},d.malformedNumber,t.slice($,b));J(t.charCodeAt(b));)b++;return parseFloat(t.slice($,b))}();return{type:c,value:n,line:x,lineStart:S,range:[$,b]}}function F(){var e=b;switch(t.charAt(b)){case"n":return b++,"\n";case"r":return b++,"\r";case"t":return b++,"\t";case"v":return b++,"\v";case"b":return b++,"\b";case"f":return b++,"\f";case"z":return b++,V(),"";case"x":return B(t.charCodeAt(b+1))&&B(t.charCodeAt(b+2))?(b+=3,"\\"+t.slice(e,b)):"\\"+t.charAt(b++);default:if(J(t.charCodeAt(b))){for(;J(t.charCodeAt(++b)););return"\\"+t.slice(e,b)}return t.charAt(b++)}}function D(){$=b,b+=2;var e=t.charAt(b),a="",o=!1,i=b,s=S,u=x;if("["===e&&(!1===(a=z())?a=e:o=!0),!o){for(;b=48&&e<=57}function B(e){return e>=48&&e<=57||e>=97&&e<=102||e>=65&&e<=70}function K(e){if(o===e.type)return!0;if(s!==e.type)return!1;switch(e.value){case"else":case"elseif":case"end":case"until":return!0;default:return!1}}function Y(){var e=Array.apply(null,C[A++]);C.push(e),r.onCreateScope&&r.onCreateScope()}function H(){C.pop();A--,r.onDestroyScope&&r.onDestroyScope()}function X(e){-1===T(C[A],e)&&C[A].push(e)}function Q(e){X(e.name),ee(e,!0)}function ee(e,t){t||-1!==function(e,t,r){for(var n=0,a=e.length;n",_)}();case"if":return W(),function(){var e,t,n,a=[];re&&(n=ne[ne.length-1],ne.push(n));e=ge(),Z("then"),r.scope&&Y();t=ue(),r.scope&&H();a.push(m(g.ifClause(e,t))),re&&(n=ae());for(;q("elseif");)se(n),e=ge(),Z("then"),r.scope&&Y(),t=ue(),r.scope&&H(),a.push(m(g.elseifClause(e,t))),re&&(n=ae());q("else")&&(re&&(n=new oe(y),ne.push(n)),r.scope&&Y(),t=ue(),r.scope&&H(),a.push(m(g.elseClause(t))));return Z("end"),m(g.ifStatement(a))}();case"return":return W(),function(){var e=[];if("end"!==_.value){var t=de();for(null!=t&&e.push(t);q(",");)t=ge(),e.push(t);q(";")}return m(g.returnStatement(e))}();case"function":return W(),pe(function(){var e,t,n;re&&(n=ae());e=fe(),r.scope&&(ee(e,te(e.name)),Y());for(;q(".");)se(n),t=fe(),e=m(g.memberExpression(e,".",t));q(":")&&(se(n),t=fe(),e=m(g.memberExpression(e,":",t)),r.scope&&X("self"));return e}());case"while":return W(),function(){var e=ge();Z("do"),r.scope&&Y();var t=ue();r.scope&&H();return Z("end"),m(g.whileStatement(e,t))}();case"for":return W(),function(){var e,t=fe();r.scope&&(Y(),Q(t));if(q("=")){var n=ge();Z(",");var a=ge(),o=q(",")?ge():null;return Z("do"),e=ue(),Z("end"),r.scope&&H(),m(g.forNumericStatement(t,n,a,o,e))}for(var i=[t];q(",");)t=fe(),r.scope&&Q(t),i.push(t);Z("in");var s=[];do{var u=ge();s.push(u)}while(q(","));return Z("do"),e=ue(),Z("end"),r.scope&&H(),m(g.forGenericStatement(i,s,e))}();case"repeat":return W(),function(){r.scope&&Y();var e=ue();Z("until");var t=ge();r.scope&&H();return m(g.repeatStatement(t,e))}();case"break":return W(),m(g.breakStatement());case"do":return W(),function(){r.scope&&Y();var e=ue();r.scope&&H();return Z("end"),m(g.doStatement(e))}();case"goto":return W(),function(){_.value;var e=fe();return m(g.gotoStatement(e))}()}return l===_.type&&q("::")?function(){var e=_.value,t=fe();r.scope&&(X("::"+e+"::"),ee(t,!0));return Z("::"),m(g.labelStatement(t))}():(re&&ne.pop(),q(";")?void 0:function(){var e,t,r=_;re&&(t=ae());if(null==(e=be()))return I(_);if(",=".indexOf(_.value)>=0){var n,a=[e],o=[];for(le(e);q(",");)null==(n=be())&&j("",_),le(n),a.push(n);Z("=");do{n=ge(),o.push(n)}while(q(","));return se(t),m(g.assignmentStatement(a,o))}if(function(e){switch(e.type){case"CallExpression":case"TableCallExpression":case"StringCallExpression":return!0}return!1}(e))return se(t),m(g.callStatement(e));return I(r)}())}function le(e){(e.inParens||-1===["Identifier","MemberExpression","IndexExpression"].indexOf(e.type))&&O(_,d.invalidVar,_.value)}function fe(){ie();var e=_.value;return u!==_.type&&j("",_),W(),m(g.identifier(e))}function pe(e,t){var n=[];if(Z("("),!q(")"))for(;;)if(u===_.type){var a=fe();if(r.scope&&Q(a),n.push(a),q(","))continue;if(q(")"))break}else{if(h===_.type){n.push(ye()),Z(")");break}j(" or '...'",_)}var o=ue();return Z("end"),r.scope&&H(),t=t||!1,m(g.functionStatement(e,n,t,o))}function he(){for(var e,t,r=[];;){if(ie(),l===_.type&&q("["))e=ge(),Z("]"),Z("="),t=ge(),r.push(m(g.tableKey(e,t)));else if(u===_.type)"="===v.value?(e=fe(),W(),t=ge(),r.push(m(g.tableKeyString(e,t)))):(t=ge(),r.push(m(g.tableValue(t))));else{if(null==(t=de())){ne.pop();break}r.push(m(g.tableValue(t)))}if(!(",;".indexOf(_.value)>=0))break;W()}return Z("}"),m(g.tableConstructorExpression(r))}function de(){return function e(t){var r,n,a=_.value;re&&(n=ae());if(function(e){return l===e.type?"#-~".indexOf(e.value)>=0:s===e.type&&"not"===e.value}(_)){ie(),W();var o=e(10);null==o&&j("",_),r=m(g.unaryExpression(a,o))}null==r&&null==(r=ye())&&(r=be());if(null==r)return null;var i;for(;a=_.value,!(0===(i=l===_.type||s===_.type?me(a):0)||i<=t);){"^"!==a&&".."!==a||i--,W();var u=e(i);null==u&&j("",_),re&&ne.push(n),r=m(g.binaryExpression(a,r,u))}return r}(0)}function ge(){var e=de();if(null!=e)return e;j("",_)}function me(e){var t=e.charCodeAt(0),r=e.length;if(1===r)switch(t){case 94:return 12;case 42:case 47:case 37:return 10;case 43:case 45:return 9;case 38:return 6;case 126:return 5;case 124:return 4;case 60:case 62:return 3}else if(2===r)switch(t){case 47:return 10;case 46:return 8;case 60:case 62:return"<<"===e||">>"===e?7:3;case 61:case 126:return 3;case 111:return 1}else if(97===t&&"and"===e)return 2;return 0}function be(){var e,t,n,a,o;if(re&&(n=ae()),u===_.type)t=_.value,e=fe(),r.scope&&ee(e,te(t));else{if(!q("("))return null;e=ge(),Z(")"),e.inParens=!0}for(;;)if(l===_.type)switch(_.value){case"[":se(n),W(),a=ge(),e=m(g.indexExpression(e,a)),Z("]");break;case".":se(n),W(),o=fe(),e=m(g.memberExpression(e,".",o));break;case":":se(n),W(),o=fe(),e=m(g.memberExpression(e,":",o)),se(n),e=_e(e);break;case"(":case"{":se(n),e=_e(e);break;default:return e}else{if(i!==_.type)break;se(n),e=_e(e)}return e}function _e(e){if(l===_.type)switch(_.value){case"(":W();var t=[],r=de();for(null!=r&&t.push(r);q(",");)r=ge(),t.push(r);return Z(")"),m(g.callExpression(e,t));case"{":ie(),W();var n=he();return m(g.tableCallExpression(e,n))}else if(i===_.type)return m(g.stringCallExpression(e,ye()));j("function arguments",_)}function ye(){var e,n=i|c|f|p|h,a=_.value,o=_.type;if(re&&(e=ae()),o&n){se(e);var u=t.slice(_.range[0],_.range[1]);return W(),m(g.literal(o,a,u))}return s===o&&"function"===a?(se(e),W(),r.scope&&Y(),pe(null)):q("{")?(se(e),he()):void 0}function ve(r){return t+=String(r),n=t.length,e}function we(e){void 0!==e&&ve(e),t&&"#!"===t.substr(0,2)&&(t=t.replace(/^.*/,function(e){return e.replace(/./g," ")})),n=t.length,re=r.locations||r.ranges,v=L();var a=function(){W(),ie(),r.scope&&Y();var e=ue();return r.scope&&H(),o!==_.type&&I(_),re&&!e.length&&(y=_),m(g.chunk(e))}();if(r.comments&&(a.comments=w),r.scope&&(a.globals=E),ne.length>0)throw new Error("Location tracking failed. This is most likely a bug in luaparse");return a}oe.prototype.complete=function(){r.locations&&(this.loc.end.line=y.line,this.loc.end.column=y.range[1]-y.lineStart),r.ranges&&(this.range[1]=y.range[1])},e.parse=function(o,i){void 0===i&&"object"==typeof o&&(i=o,o=void 0);i||(i={});t=o||"",r=function(){for(var e,t,r=k.call(arguments),n={},a=0,o=r.length;a127)throw new Error("invalid character code passed to %c in printf");e.arg=isNaN(t)?""+t:String.fromCharCode(t)}}},s:{setMaxWidth:function(e){e.maxWidth="."==e.period?e.precision:-1}},e:{isDouble:!0,doubleNotation:"e"},E:{extend:["e"],toUpper:!0},f:{isDouble:!0,doubleNotation:"f"},F:{extend:["f"]},g:{isDouble:!0,doubleNotation:"g"},G:{extend:["g"],toUpper:!0},O:{isObject:!0}},a.prototype.format=function(e){if(this._mapped&&"object"!=typeof e)throw new Error("format requires a mapping");for(var t,r="",n=0,a=0;a=arguments.length)throw new Error("got "+arguments.length+" printf arguments, insufficient for '"+this._format+"'");t.arg=arguments[n++]}if(!t.compiled){t.compiled=!0,t.sign="",t.zeroPad=!1,t.rightJustify=!1,t.alternative=!1;for(var c={},l=t.flags.length;l--;){var f=t.flags.charAt(l);switch(c[f]=!0,f){case" ":t.sign=" ";break;case"+":t.sign="+";break;case"0":t.zeroPad=!c["-"];break;case"-":t.rightJustify=!0,t.zeroPad=!1;break;case"#":t.alternative=!0;break;default:throw Error("bad formatting flag '"+t.flags.charAt(l)+"'")}}t.minWidth=t._minWidth?parseInt(t._minWidth):0,t.maxWidth=-1,t.toUpper=!1,t.isUnsigned=!1,t.isInt=!1,t.isDouble=!1,t.isObject=!1,t.precision=1,"."==t.period&&(t._precision?t.precision=parseInt(t._precision):t.precision=0);var p=this._specifiers[t.specifier];if(void 0===p)throw new Error("unexpected specifier '"+t.specifier+"'");if(p.extend){var h=this._specifiers[p.extend];for(var d in h)p[d]=h[d];delete p.extend}for(var g in p)t[g]=p[g]}if("function"==typeof t.setArg&&t.setArg(t),"function"==typeof t.setMaxWidth&&t.setMaxWidth(t),"*"==t._minWidth){if(this._mapped)throw new Error("* width not supported in mapped formats");if(t.minWidth=parseInt(arguments[n++]),isNaN(t.minWidth))throw new Error("the argument for * width at position "+n+" is not a number in "+this._format);t.minWidth<0&&(t.rightJustify=!0,t.minWidth=-t.minWidth)}if("*"==t._precision&&"."==t.period){if(this._mapped)throw new Error("* precision not supported in mapped formats");if(t.precision=parseInt(arguments[n++]),isNaN(t.precision))throw Error("the argument for * precision at position "+n+" is not a number in "+this._format);t.precision<0&&(t.precision=1,t.period="")}t.isInt?("."==t.period&&(t.zeroPad=!1),this.formatInt(t)):t.isDouble?("."!=t.period&&(t.precision=6),this.formatDouble(t)):t.isObject&&this.formatObject(t),this.fitField(t),r+=""+t.arg}return r},a.prototype._zeros10="0000000000",a.prototype._spaces10=" ",a.prototype.formatInt=function(e){var t=parseInt(e.arg);if(!isFinite(t)){if("number"!=typeof e.arg)throw new Error("format argument '"+e.arg+"' not an integer; parseInt returned "+t);t=0}t<0&&(e.isUnsigned||10!=e.base)&&(t=4294967295+t+1),t<0?(e.arg=(-t).toString(e.base),this.zeroPad(e),e.arg="-"+e.arg):(e.arg=t.toString(e.base),t||e.precision?this.zeroPad(e):e.arg="",e.sign&&(e.arg=e.sign+e.arg)),16==e.base&&(e.alternative&&(e.arg="0x"+e.arg),e.arg=e.toUpper?e.arg.toUpperCase():e.arg.toLowerCase()),8==e.base&&e.alternative&&"0"!=e.arg.charAt(0)&&(e.arg="0"+e.arg)},a.prototype.formatDouble=function(e){var t=parseFloat(e.arg);if(!isFinite(t)){if("number"!=typeof e.arg)throw new Error("format argument '"+e.arg+"' not a float; parseFloat returned "+t);t=0}switch(e.doubleNotation){case"e":e.arg=t.toExponential(e.precision);break;case"f":e.arg=t.toFixed(e.precision);break;case"g":Math.abs(t)<1e-4?e.arg=t.toExponential(e.precision>0?e.precision-1:e.precision):e.arg=t.toPrecision(e.precision),e.alternative||(e.arg=e.arg.replace(/(\..*[^0])0*e/,"$1e"),e.arg=e.arg.replace(/\.0*e/,"e").replace(/\.0$/,""));break;default:throw new Error("unexpected double notation '"+e.doubleNotation+"'")}e.arg=e.arg.replace(/e\+(\d)$/,"e+0$1").replace(/e\-(\d)$/,"e-0$1"),e.alternative&&(e.arg=e.arg.replace(/^(\d+)$/,"$1."),e.arg=e.arg.replace(/^(\d+)e/,"$1.e")),t>=0&&e.sign&&(e.arg=e.sign+e.arg),e.arg=e.toUpper?e.arg.toUpperCase():e.arg.toLowerCase()},a.prototype.formatObject=function(e){var t="."===e.period?e.precision:null;e.arg=n.inspect(e.arg,!e.alternative,t,e.sign)},a.prototype.zeroPad=function(e,t){t=2==arguments.length?t:e.precision;var r=!1;"string"!=typeof e.arg&&(e.arg=""+e.arg),"-"===e.arg.substr(0,1)&&(r=!0,e.arg=e.arg.substr(1));for(var n=t-10;e.arg.length=0&&e.arg.length>e.maxWidth)return e.arg.substring(0,e.maxWidth);e.zeroPad?this.zeroPad(e,e.minWidth):this.spacePad(e)},a.prototype.spacePad=function(e,t){t=2==arguments.length?t:e.minWidth,"string"!=typeof e.arg&&(e.arg=""+e.arg);for(var r=t-10;e.arg.length":"gt","<=":"lte",">=":"gte","^":"pow"},h={AssignmentStatement(e,t){let r=e.variables.map((e,r)=>{const n=m(e,t);if(n instanceof s)return n.set(`__star_tmp[${r}]`);{const[e,t]=[].concat(n.match(/^\$get\((.*)\)$/));if(!e)throw new Error("Unhandled");return`$set(${t}, __star_tmp[${r}])`}}).join(";\n");return`__star_tmp = [${d(e.init,t).join(", ")}];${r}`},BinaryExpression(e,t){let r=m(e.left,t),n=m(e.right,t),a=p[e.operator];if(b(e.left)&&(r+="[0]"),b(e.right)&&(n+="[0]"),!a)throw console.info(e),new Error(`Unhandled binary operator: ${e.operator}`);return`__star_op_${a}(${r}, ${n})`},BooleanLiteral:e=>e.value?"true":"false",BreakStatement:e=>"break",CallStatement:(e,t)=>_(e.expression,t),CallExpression(e,t){let r=m(e.base,t);const n=d(e.arguments,t);return b(e.base)?n.unshift(`${r}[0]`):(r instanceof s&&":"===e.base.indexer&&n.unshift(r.base),n.unshift(`${r}`)),`__star_call(${n})`},Chunk:(e,t)=>e.body.map(e=>_(e,t)+";").join("\n"),DoStatement(e,t){let{scope:r,scopeDef:n}=g(t),a=this.Chunk(e,r);return`${n=n.replace(",",";")}\n${a}\n$=$${t};`},ElseClause(e,t){return`{\n${this.Chunk(e,t)}\n}`},ElseifClause(e,t){return this.IfClause(e,t)},ForNumericStatement(e,t){let{scope:r,scopeDef:n}=g(t),a=_(e.variable,t),o=m(e.start,t),i=m(e.end,t),s=null===e.step?1:_(e.step,t),u=s>0?"<=":">=",c=this.Chunk(e,r),f=++l;return`for (${`$${t}._forLoop${f} = ${o}`}; ${`$${t}._forLoop${f} ${u} ${i}`}; ${`$${t}._forLoop${f} += ${s}`}) {\n${n}\n${`$${r}.setLocal('${a}',$${t}._forLoop${f});`}\n${c}\n}`},ForGenericStatement(e,t){const{scope:r,scopeDef:n}=g(t),{scope:a,scopeDef:o}=g(r),i=d(e.iterators,t).join(", "),s=this.Chunk(e,a),u=e.variables.map((e,t)=>{return`$setLocal($, '${_(e,r)}', __star_tmp[${t}])`}).join(";\n");return`${n.split(", ")[0]};\n[$${r}._iterator, $${r}._table, $${r}._next] = [${i}];\nwhile((__star_tmp = __star_call($${r}._iterator, $${r}._table, $${r}._next)),__star_tmp[0] !== undefined) {\n${o}$${r}._next = __star_tmp[0]\n${u}\n${s}\n}`},FunctionDeclaration(e,t){let r,{scope:n,scopeDef:a}=g(t),o=!e.identifier,i=o?"":_(e.identifier,t),u=i instanceof s,l=e.parameters.map((e,t)=>{let r=_(e,n);return"...$.getVarargs()"===r?"$.setVarargs(args)":`$setLocal($, '${r}', __star_shift(args))`});u?(r=i.property.replace(/'/g,""),":"===e.identifier.indexer&&l.unshift("$setLocal($, 'self', __star_shift(args))")):r=i;let f=`(__star_tmp = function ${o?"":"func$"}${r}(...args){${a}\n${l.join(";\n")};\n${this.Chunk(e,n)} return [];}, __star_tmp.toString=()=>'function: 0x${(++c).toString(16)}', __star_tmp)`;if(o)return f;if(u)return i.set(f);return`$set${e.isLocal?"Local":""}($, '${i}', ${f})`},Identifier:(e,t)=>e.name,IfClause(e,t){let r=m(e.condition,t);return b(e.condition)&&(r+="[0]"),`if (__star_op_bool(${r})) {\n${this.Chunk(e,t)}\n}`},IfStatement:(e,t)=>e.clauses.map(e=>_(e,t)).join(" else "),IndexExpression(e,t){let r=m(e.base,t),n=m(e.index,t);return b(e.base)&&(r+="[0]"),b(e.index)&&(n+="[0]"),new s(r,n)},LocalStatement(e,t){let r=e.variables.map((e,r)=>{return`$setLocal($, '${_(e,t)}', __star_tmp[${r}])`}).join(";\n");return`__star_tmp = [${d(e.init,t).join(", ")}];${r}`},LogicalExpression(e,t){let r=m(e.left,t),n=m(e.right,t),a=e.operator;if(b(e.left)&&(r+="[0]"),b(e.right)&&(n+="[0]"),"and"===a)return`(!__star.op.bool(${r})?${r}:${n})`;if("or"===a)return`(__star.op.bool(${r})?${r}:${n})`;throw console.info(e),new Error(`Unhandled logical operator: ${e.operator}`)},MemberExpression(e,t){let r=m(e.base,t),n=_(e.identifier,t);return b(e.base)&&(r+="[0]"),new s(r,`'${n}'`)},NilLiteral:e=>"undefined",NumericLiteral:e=>e.value.toString(),RepeatStatement(e,t){let{scope:r,scopeDef:n}=g(t),a=m(e.condition,t);return`do{\n${n}\n${this.Chunk(e,r)}\n}while(!(${a}))`},ReturnStatement:(e,t)=>`return [${d(e.arguments,t).join(", ")}];`,StringCallExpression(e,t){return e.arguments=e.argument,this.TableCallExpression(e,t)},StringLiteral(e){let t=e.raw;return/^\[\[[^]*]$/m.test(t)?`\`${t.substr(2,t.length-4).replace(/\\/g,"\\\\")}\``:t=t.replace(/([^\\])\\(\d{1,3})/g,(e,t,r)=>`${t}\\u${("000"+parseInt(r,10).toString(16)).substr(-4)}`)},TableCallExpression(e,t){let r=m(e.base,t),n=[_(e.arguments,t)];return b(e.base)?`__star_call(${r}[0],${n})`:(r instanceof s&&":"===e.base.indexer&&n.unshift(r.base),`__star_call(${r},${n})`)},TableConstructorExpression(e,t){return`new __star_T(t => {${e.fields.map((e,r,n)=>{if("TableValue"==e.type){const a=r===n.length-1;return this.TableValue(e,t,a)}return _(e,t)}).join(";\n")}})`},TableKeyString:(e,t)=>`Tset(t, '${_(e.key,t)}', ${m(e.value,t)})`,TableKey:(e,t)=>`Tset(t, ${m(e.key,t)}, ${m(e.value,t)})`,TableValue(e,t,r){let n=m(e.value,t);return b(e.value)&&(n=r?`...${n}`:`${n}[0]`),`Tins(t, ${n})`},UnaryExpression(e,t){let r=f[e.operator],n=m(e.argument,t);if(b(e.argument)&&(n+="[0]"),!r)throw console.info(e),new Error(`Unhandled unary operator: ${e.operator}`);return`__star_op_${r}(${n})`},VarargLiteral:e=>"...$.getVarargs()",WhileStatement(e,t){let{scope:r,scopeDef:n}=g(t);return`while(${m(e.condition,t)}) {\n${n}\n${this.Chunk(e,r)}\n}`}};function d(e,t){return e.map((e,r,n)=>{let a=m(e,t);return b(e)?r==n.length-1?`...${a}`:`${a}[0]`:a})}function g(e){let t=u++;return{scope:t,scopeDef:`let $${t} = $${e}.extend(), $ = $${t};`}}function m(e,t){let r=_(e,t);return"Identifier"===e.type?`$get($, '${r}')`:r}function b(e){return!!e.type.match(/CallExpression$/)}function _(e,t){let r=h[e.type];if(!r)throw console.info(e),new Error(`No generator found for: ${e.type}`);return r.call(h,e,t)}function v(e){return`\n\t"use strict"; if (typeof global === 'undefined' && typeof window !== 'undefined') { window.global = window; }\n\tlet __star = global.starlight.runtime, $0 = __star.globalScope, $ = $0, __star_tmp;\n\tlet __star_call = __star.call, __star_T = __star.T, __star_op_bool = __star.op.bool;\n\tlet __star_op_unm = __star.op.unm, __star_op_not = __star.op.not, __star_op_len = __star.op.len, __star_op_concat = __star.op.concat, __star_op_add = __star.op.add, __star_op_sub = __star.op.sub, __star_op_mul = __star.op.mul, __star_op_div = __star.op.div, __star_op_mod = __star.op.mod, __star_op_eq = __star.op.eq, __star_op_neq = __star.op.neq, __star_op_lt = __star.op.lt, __star_op_gt = __star.op.gt, __star_op_lte = __star.op.lte, __star_op_gte = __star.op.gte, __star_op_pow = __star.op.pow;\n\tlet __star_op_and = __star.op.and, __star_op_or = __star.op.or;\n\tlet Tget, Tset, Tins, $get, $set, $setLocal, __star_shift;\n\t(()=>{\n\t\tlet call = Function.prototype.call, bind = call.bind.bind(call), Tproto = __star_T.prototype, $proto = __star.globalScope.constructor.prototype;\n\t\tTget = bind(Tproto.get), Tset = bind(Tproto.set), Tins = bind(Tproto.insert);\n\t\t$get = bind($proto.get), $set = bind($proto.set), $setLocal = bind($proto.setLocal);\n\t\t__star_shift = bind(Array.prototype.shift);\n\t})();\n\t${_(i.a.parse(e),0)}\n\t`}const w=Object.prototype.hasOwnProperty;class ${constructor(e={}){this._variables=e}get(e){return this._variables[e]}set(e,t){let r=this._variables;w.call(this._variables,e)||!this.parent?r[e]=t:this.parent.set(e,t)}setLocal(e,t){this._variables[e]=t}setVarargs(e){this._varargs=e}getVarargs(){return this._varargs||this.parent&&this.parent.getVarargs()}add(e,t){this._variables[e]+=t}extend(e){let t=Object.create(this._variables),r=new $(t);return r.parent=this,r}}class x extends Error{constructor(e){super(),this.message=e}toString(){return`LuaError: ${this.message}`}}let S,C,A=0;class E{constructor(e){if(this.index=++A,this.numValues=[void 0],this.strValues={},this.keys=[],this.values=[],this.metatable=null,e)if("function"==typeof e)e(this);else{let t=e instanceof Array;for(let r in e)if(e.hasOwnProperty(r)){let n=e[r];null===n&&(n=void 0);let a=t?parseInt(r,10)+1:r,o="object"==typeof n&&n.constructor===Object||n instanceof Array;this.set(a,o?new E(n):n)}}else;}get(e){if(!(this instanceof E)){if("string"==ne(this))return S.get(e);if(("userdata"===ne(this)||"function"===ne(this)&&"new"===e)&&e in this)return this[e];throw new x(`attempt to index a ${ne(this)} value`)}let t=this.rawget(e);if(void 0===t){let r,n;if((r=this.metatable)&&(n=r.get("__index")))switch(n.constructor){case E:return n.get(e);case Function:return(t=n.call(void 0,this,e))instanceof Array?t[0]:t}}return t}rawget(e){switch(typeof e){case"string":return Object.prototype.hasOwnProperty.call(this.strValues,e)?this.strValues[e]:void 0;case"number":if(e>0&&e==e>>0)return this.numValues[e];default:let t=this.keys.indexOf(e);return t>=0?this.values[t]:void 0}}set(e,t){if(!(this instanceof E)){if("userdata"==ne(this))return void(this[e]=t);throw new x(`attempt to index a ${ne(this)} value`)}let r,n;if((r=this.metatable)&&(n=r.get("__newindex"))){let r;switch(typeof e){case"string":r=this.strValues[e];break;case"number":if(e>0&&e==e>>0){r=this.numValues[e];break}default:let t=this.keys.indexOf(e);r=-1==t?void 0:this.values[t]}if(void 0===r)switch(n.constructor){case E:return n.set(e,t);case Function:return n(this,e,t)}}this.rawset(e,t)}rawset(e,t){switch(t instanceof Array&&(t=t[0]),typeof e){case"string":this.strValues[e]=t;break;case"number":if(e>0&&e==e>>0){this.numValues[e]=t;break}default:let r=this.keys,n=r.indexOf(e);n<0&&(r[n=r.length]=e),this.values[n]=t}}insert(...e){this.numValues.push(...e)}toString(){let e,t;return(e=this.metatable)&&(t=e.get("__tostring"))?t(this)[0]:"table: 0x"+this.index.toString(16)}toObject(){const e=C(this)>0?[]:{},t=this.numValues,r=this.strValues;let n;const a=t.length;for(n=1;n{let e,t,r;return(e=global.starlight)&&(t=e.config)&&(r=t.stdout)&&r.writeln||j})()};function L(e,t){if(t)throw t=(""+t).replace(/\%type/gi,ne(e)),new x(t)}function N(e){return!(!1===e||void 0===e)}function V(e,t){let r,n,a;switch(!0){case"number"==typeof e:return e;case void 0===e:return;case"inf"===e:return 1/0;case"-inf"===e:return-1/0;case"nan"===e:return NaN;default:return(""+e).match(M)?r=parseFloat(e):(n=(""+e).match(O))&&(a=n[3],((r=n[2])||a)&&(r=parseInt(r,16)||0,a&&(r+=parseInt(a,16)/Math.pow(16,a.length)),n[1]&&(r*=-1))),void 0===r&&L(e,t),r}}function P(e,t){switch(!0){case"string"==typeof e:return e;case void 0===e:case null===e:return"nil";case e===1/0:return"inf";case e===-1/0:return"-inf";case"number"==typeof e:case"boolean"==typeof e:return global.isNaN(e)?"nan":`${e}`;default:return L(e,t)||"userdata"}}function U(e,t,r,n,a){return t(e,`bad argument #${a} to '${n}' (${r} expected, got %type)`)}function F(e,t,r){return U(e,V,"number",t,r)}function D(e,t,r){return U(e,P,"string",t,r)}function z(e,t,r){if(e instanceof E)return e;{let n=ne(e);throw new x(`bad argument #${r} to '${t}' (table expected, got ${n})`)}}function W(e,t,r){if(e instanceof Function)return e;{let n=ne(e);throw new x(`bad argument #${r} to '${t}' (function expected, got ${n})`)}}const q={"([^a-zA-Z0-9%(])-":"$1*?","([^%])-([^a-zA-Z0-9?])":"$1*?$2","(.)-$":"$1*?","%a":"[a-zA-Z]","%A":"[^a-zA-Z]","%c":"[\0-]","%C":"[^\0-]","%d":"\\d","%D":"[^d]","%l":"[a-z]","%L":"[^a-z]","%p":"[.,\"'?!;:#$%&()*+-/<>=@\\[\\]\\\\^_{}|~]","%P":"[^.,\"'?!;:#$%&()*+-/<>=@\\[\\]\\\\^_{}|~]","%s":"[ \\t\\n\\f\\v\\r]","%S":"[^ \t\n\f\v\r]","%u":"[A-Z]","%U":"[^A-Z]","%w":"[a-zA-Z0-9]","%W":"[^a-zA-Z0-9]","%x":"[a-fA-F0-9]","%X":"[^a-fA-F0-9]","%([^a-zA-Z])":"\\$1"};function Z(e){e=(e=""+e).replace(new RegExp("\\\\","g"),"\\\\");for(let t in q)q.hasOwnProperty(t)&&(e=e.replace(new RegExp(t,"g"),q[t]));let t=e.length,r=0;for(let n=0;ne.charCodeAt(0))},char:function(...e){return e.map((e,t)=>(e=F(e,"char",t),String.fromCharCode(e))).join("")},dump:function(e){throw e=W(e,"dump",1),new x("string.dump() is not supported")},find:function(e,t,r=1,n=!1){if(e=D(e,"find",1),t=D(t,"find",2),r=F(r,"find",3),!(n=N(n))){t=Z(t);let n=new RegExp(t),a=e.substr(r-1).search(n);if(a<0)return;let o=e.substr(r-1).match(n),i=[a+r,a+r+o[0].length-1];return o.shift(),i.concat(o)}let a=e.indexOf(t,r-1);return-1===a?void 0:[a+1,a+t.length]},format:function(e,...t){return T()(e,...t)},gmatch:function(e,t){e=D(e,"gmatch",1),t=Z(t=D(t,"gmatch",2));let r=new RegExp(t,"g"),n=e.match(r);return()=>{let e=n.shift(),r=new RegExp(t).exec(e);if(void 0!==e)return r.shift(),r.length?r:e}},gsub:function(e,t,r,n=1/0){e=D(e,"gsub",1),t=D(t,"gsub",2),n=F(n,"gsub",3),t=Z(""+t);let a,o,i,s,u="function"==typeof r,c=0,l="";for(;ci[t]),o=0===i[0].length?void 0===s?"":e.substr(0,1):e.substr(0,i.index),s=i[0],l+=`${o}${a}`,e=e.substr(`${o}${s}`.length),c++;return[`${l}${e}`,c]},len:function(e){return(e=D(e,"len",1)).length},lower:function(e){return(e=D(e,"lower",1)).toLowerCase()},match:function(e,t,r=0){e=D(e,"match",1),t=D(t,"match",2),r=F(r,"match",3);let n=(e=e.substr(r)).match(new RegExp(Z(t)));if(n)return n[1]?(n.shift(),n):n[0]},rep:function(e,t){return e=D(e,"rep",1),t=F(t,"rep",2),Array(t+1).join(e)},reverse:function(e){return e=D(e,"reverse",1),Array.prototype.map.call(e,e=>e).reverse().join("")},sub:function(e,t=1,r){return e=D(e,"sub",1),t=F(t,"sub",2),void 0===r?e.length:r=F(r,"sub",3),t>0?t-=1:t<0&&(t=e.length+t),r<0&&(r=e.length+r+1),e.substring(t,r)},upper:function(e){return(e=D(e,"upper",1)).toUpperCase()}});var G=R;const J=new E({__index:R});function B(e){let t=(e=z(e,"getn",1)).numValues,r=[],n=0;for(let e in t)t.hasOwnProperty(e)&&(r[e]=!0);for(;r[n+1];)n++;if(n>0&&void 0===t[n]){let e=0;for(;n-e>1;){let r=Math.floor((e+n)/2);void 0===t[r]?n=r:e=r}return e}return n}function K(e){return(e=z(e,"maxn",1)).numValues.length-1}var Y=new E({concat:function(e,t="",r=1,n){return e=z(e,"concat",1),t=D(t,"concat",2),r=F(r,"concat",3),n=void 0===n?K(e):F(n,"concat",4),[].concat(e.numValues).splice(r,n-r+1).join(t)},getn:B,insert:function(e,t,r){e=z(e,"insert",1),void 0===r?(r=t,t=e.numValues.length):t=F(t,"insert",2),e.numValues.splice(t,0,void 0),e.set(t,r)},maxn:K,remove:function(e,t){e=z(e,"remove",1),t=F(t,"remove",2);let r=B(e),n=e.numValues;if(t>r)return;void 0===t&&(t=r);let a=n.splice(t,1);for(;tN(t(e,r)[0])?-1:1)):r=((e,t)=>et),t}function Q(e,t){if(void 0===t)throw new x("Bad argument #2 to ipairs() iterator");var r=t+1,n=e.numValues;if(n.hasOwnProperty(r)&&void 0!==n[r])return[r,n[r]]}function ee(e){if(e&&e instanceof E){let t=e.metatable;if(t){let e;return(e=t.rawget("__metatable"))?e:t}}else if("string"==typeof e)return J}function te(e,t){e=z(e,"next",1);let r,n,a,o,i=void 0===t;if(i||"number"==typeof t&&t>0&&t==t>>0){let s=e.numValues;if("keys"in Object){let e=Object.keys(s);if(i?a=1:(a=e.indexOf(""+t)+1)&&(i=!0),i){for(;void 0!==(r=e[a])&&void 0===(n=s[r]);)a++;if(void 0!==n)return[r>>=0,n]}}else for(o in s)if(a=o>>0,i){if(void 0!==s[a])return[a,s[a]]}else a===t&&(i=!0)}for(a in e.strValues)if(e.strValues.hasOwnProperty(a))if(i){if(void 0!==e.strValues[a])return[a,e.strValues[a]]}else a==t&&(i=!0);for(a in e.keys)if(e.keys.hasOwnProperty(a)){let r=e.keys[a];if(i){if(void 0!==e.values[a])return[r,e.values[a]]}else r===t&&(i=!0)}return[]}function re(e){let t,r;return void 0!==e&&e instanceof E&&(t=e.metatable)&&(r=t.rawget("__tostring"))?r.call(r,e):e instanceof E?e.toString():e instanceof Function?e.hasOwnProperty("toString")?`${e}`:"function: [host code]":P(e)}function ne(e){let t=typeof e;switch(t){case"undefined":return"nil";case"number":case"string":case"boolean":case"function":return t;case"object":return e.constructor===E?"table":e&&e instanceof Function?"function":"userdata"}}const ae=new E({_VERSION:"Lua 5.1",assert:function(e,t){if(!N(e))throw t=D(t,"assert",2),new x(t||"Assertion failed!");return[e,t]},error:function(e){throw"string"!=typeof e&&"number"!=typeof e&&(e="(error object is not a string)"),new x(e)},getmetatable:ee,ipairs:function(e){const t=ee(e=z(e,"ipairs",1)),r=t&&t.get("__ipairs");return r?r(e).slice(0,3):[Q,e,0]},loadstring:function(e,t){e=D(e,"loadstring",1);let r=global.starlight.parser;if(!r)throw new Error("Starlight parser not found in call to loadstring(). The parser is required to execute Lua strings at runtime.");try{return r.parse(e)}catch(e){return[void 0,e.message]}},next:te,pairs:function(e){const t=ee(e=z(e,"pairs",1)),r=t&&t.get("__pairs");return r?r(e).slice(0,3):[te,e]},pcall:function(e,...t){let r;try{if("function"!=typeof e)throw new x("Attempt to call non-function");r=e(...t)}catch(e){return[!1,e&&e.toString()]}return r=[].concat(r),[!0,...r]},print:function(...e){let t=e.map(e=>re(e)).join("\t");I.writeln(t)},rawequal:function(e,t){return e===t},rawget:function(e,t){return(e=z(e,"rawget",1)).rawget(t)},rawset:function(e,t,r){if(e=z(e,"rawset",1),void 0===t)throw new x("table index is nil");return e.rawset(t,r),e},require:function(e){e=(e=D(e,"require",1)).replace(/\//g,".");let[t,r]=X(),n=r.rawget(e);if(n)return n;let a=t.rawget(e);if(void 0===a)throw new x(`module '${e}' not found:\n\tno field package.preload['${e}']`);let o=a(e);return n=o instanceof Array?o[0]:o,r.rawset(e,void 0===n||n),n},select:function(e,...t){if("#"===e)return t.length;if(e=parseInt(e,10))return t.slice(e-1);{let t=ne(e);throw new x(`bad argument #1 to 'select' (number expected, got ${t})`)}},setmetatable:function(e,t){let r;if(e=z(e,"setmetatable",1),void 0!==t&&(t=z(t,"setmetatable",2)),(r=e.metatable)&&r.rawget("__metatable"))throw new x("cannot change a protected metatable");return e.metatable=t,e},tonumber:function(e,t=10){if(t=F(t,"tonumber",2),""===e)return;if(t<2||t>36)throw new x("bad argument #2 to 'tonumber' (base out of range)");if(10==t&&(e===1/0||e===-1/0||"number"==typeof e&&global.isNaN(e)))return e;if(10!=t&&void 0===e)throw new x("bad argument #1 to 'tonumber' (string expected, got nil)");if(e=`${e}`.trim(),10===t)return V(e);let r;return e=P(e),16===t&&(r=e.match(/^(\-)?0[xX](.+)$/))&&(e=`${r[1]||""}${r[2]}`),new RegExp("^["+H.substr(0,t)+"]*$","gi").test(e)?parseInt(e,t):void 0},tostring:re,type:ne,unpack:function(e,t=1,r){return e=z(e,"unpack",1),t=F(t,"unpack",2),r=void 0===r?B(e):F(r,"unpack",3),e.numValues.slice(t,r+1)},xpcall:function(e,t){let r,n,a;try{"function"==typeof e?r=e():a=!0,n=!0}catch(e){r=t(void 0,!0)[0],n=!1}if(a)throw new x("Attempt to call non-function");return r&&r instanceof Array||(r=[r]),r.unshift(n),r}});ae.rawset("_G",ae);var oe=ae;function ie(e,t,r,n){let a,o;return e&&e instanceof E&&(a=e.metatable)&&(o=a.rawget(r))||t&&t instanceof E&&(a=t.metatable)&&(o=a.rawget(r))?o(e,t)[0]:("number"!=typeof e&&(e=V(e,"attempt to perform arithmetic on a %type value")),"number"!=typeof t&&(t=V(t,"attempt to perform arithmetic on a %type value")),n(e,t))}function se(e,t,r,n){return"string"==typeof e&&"string"==typeof t?n(e,t):ie(e,t,r,n)}function ue(e,t){var r,n,a;return t!==e&&e&&e instanceof E&&t&&t instanceof E&&(r=e.metatable)&&(n=t.metatable)&&r===n&&(a=r.rawget("__eq"))?!!a(e,t)[0]:e===t}function ce(e,t){if(0===t||t===-1/0||t===1/0||global.isNaN(e)||global.isNaN(t))return NaN;let r=Math.abs(t),n=Math.abs(e)%r;return e*t<0&&(n=r-n),t<0&&(n*=-1),n}const le={concat:function(e,t){let r,n;return e&&e instanceof E&&(r=e.metatable)&&(n=r.rawget("__concat"))||t&&t instanceof E&&(r=t.metatable)&&(n=r.rawget("__concat"))?n(e,t)[0]:(t=P(t,"attempt to concatenate a %type value"),`${e=P(e,"attempt to concatenate a %type value")}${t}`)},len:function(e){if(void 0===e)throw new x("attempt to get length of a nil value");if(e instanceof E)return B(e);if("object"==typeof e){let t=0;for(let r in e)e.hasOwnProperty(r)&&t++;return t}return e.length},eq:ue,unm:function(e){var t,r;return e&&e instanceof E&&(t=e.metatable)&&(r=t.rawget("__unm"))?r(e)[0]:("number"!=typeof e&&(e=V(e,"attempt to perform arithmetic on a %type value")),-e)},bool:N,neq:(...e)=>!ue(...e),not:(...e)=>!N(...e),add:(e,t)=>ie(e,t,"__add",(e,t)=>e+t),sub:(e,t)=>ie(e,t,"__sub",(e,t)=>e-t),mul:(e,t)=>ie(e,t,"__mul",(e,t)=>e*t),div:(e,t)=>{if(void 0===t)throw new x("attempt to perform arithmetic on a nil value");return ie(e,t,"__div",(e,t)=>e/t)},mod:(e,t)=>ie(e,t,"__mod",ce),pow:(e,t)=>ie(e,t,"__pow",Math.pow),lt:(e,t)=>se(e,t,"__lt",(e,t)=>ese(e,t,"__le",(e,t)=>e<=t),gt:(e,t)=>!le.lte(e,t),gte:(e,t)=>!le.lt(e,t)};var fe=le;const pe=16807,he=2147483647;let de=1;function ge(){return(de=pe*de%he)/he}function me(e){return e=F(e,"exp",1),Math.exp(e)}const be=Math.PI;var _e=new E({abs:function(e){return e=F(e,"abs",1),Math.abs(e)},acos:function(e){return e=F(e,"acos",1),Math.acos(e)},asin:function(e){return e=F(e,"asin",1),Math.asin(e)},atan:function(e){return e=F(e,"atan",1),Math.atan(e)},atan2:function(e,t){return e=F(e,"atan2",1),t=F(t,"atan2",2),Math.atan2(e,t)},ceil:function(e){return e=F(e,"ceil",1),Math.ceil(e)},cos:function(e){return e=F(e,"cos",1),Math.cos(e)},cosh:function(e){return(me(e=F(e,"cosh",1))+me(-e))/2},deg:function(e){return 180*(e=F(e,"deg",1))/Math.PI},exp:me,floor:function(e){return e=F(e,"floor",1),Math.floor(e)},fmod:function(e,t){return(e=F(e,"fmod",1))%(t=F(t,"fmod",2))},frexp:function(e){if(0===(e=F(e,"frexp",1)))return[0,0];let t=e>0?1:-1;e*=t;let r=Math.floor(Math.log(e)/Math.log(2))+1;return[e/Math.pow(2,r)*t,r]},huge:1/0,ldexp:function(e,t){return e=F(e,"ldexp",1),t=F(t,"ldexp",2),e*Math.pow(2,t)},log:function(e,t){return e=F(e,"log",1),void 0===t?Math.log(e):(y=F(y,"log",2),Math.log(e)/Math.log(t))},log10:function(e){return e=F(e,"log10",1),Math.log(e)/Math.log(10)},max:function(...e){return Math.max(...e)},min:function(...e){return Math.min(...e)},modf:function(e){e=F(e,"modf",1);let t=Math.floor(e);return[t,e-t]},pi:be,pow:function(e,t){return e=F(e,"pow",1),t=F(t,"pow",2),Math.pow(e,t)},rad:function(e){return e=F(e,"rad",1),Math.PI/180*e},random:function(e,t){if(void 0===e&&void 0===t)return ge();if(e=F(e,"random",1),void 0===t?(t=e,e=1):t=F(t,"random",2),e>t)throw new shine.Error("bad argument #2 to 'random' (interval is empty)");return Math.floor(ge()*(t-e+1)+e)},randomseed:function(e){e=F(e,"randomseed",1),de=e},sin:function(e){return e=F(e,"sin",1),Math.sin(e)},sinh:function(e){return(me(e=F(e,"sinh",1))-me(-e))/2},sqrt:function(e){return e=F(e,"sqrt",1),Math.sqrt(e)},tan:function(e){return e=F(e,"tan",1),Math.tan(e)},tanh:function(e){return(me(e=F(e,"tanh",1))-me(-e))/(me(e)+me(-e))}});const ye=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],ve=["January","February","March","April","May","June","July","August","September","October","November","December"],we=[31,28,31,30,31,30,31,31,30,31,30,31],$e={"%a":(e,t)=>ye[e["get"+(t?"UTC":"")+"Day"]()].substr(0,3),"%A":(e,t)=>ye[e["get"+(t?"UTC":"")+"Day"]()],"%b":(e,t)=>ve[e["get"+(t?"UTC":"")+"Month"]()].substr(0,3),"%B":(e,t)=>ve[e["get"+(t?"UTC":"")+"Month"]()],"%c":(e,t)=>e["to"+(t?"UTC":"")+"LocaleString"](),"%d":(e,t)=>("0"+e["get"+(t?"UTC":"")+"Date"]()).substr(-2),"%H":(e,t)=>("0"+e["get"+(t?"UTC":"")+"Hours"]()).substr(-2),"%I":(e,t)=>("0"+((e["get"+(t?"UTC":"")+"Hours"]()+11)%12+1)).substr(-2),"%j":(e,t)=>{let r=e["get"+(t?"UTC":"")+"Date"](),n=e["get"+(t?"UTC":"")+"Month"]();for(let e=0;e1&&e["get"+(t?"UTC":"")+"FullYear"]()%4==0&&(r+=1),("00"+r).substr(-3)},"%m":(e,t)=>("0"+(e["get"+(t?"UTC":"")+"Month"]()+1)).substr(-2),"%M":(e,t)=>("0"+e["get"+(t?"UTC":"")+"Minutes"]()).substr(-2),"%p":(e,t)=>e["get"+(t?"UTC":"")+"Hours"]()<12?"AM":"PM","%S":(e,t)=>("0"+e["get"+(t?"UTC":"")+"Seconds"]()).substr(-2),"%U":(e,t)=>Se(e,0,t),"%w":(e,t)=>""+e["get"+(t?"UTC":"")+"Day"](),"%W":(e,t)=>Se(e,1,t),"%x":(e,t)=>$e["%m"](e,t)+"/"+$e["%d"](e,t)+"/"+$e["%y"](e,t),"%X":(e,t)=>$e["%H"](e,t)+":"+$e["%M"](e,t)+":"+$e["%S"](e,t),"%y":(e,t)=>$e["%Y"](e,t).substr(-2),"%Y":(e,t)=>""+e["get"+(t?"UTC":"")+"FullYear"](),"%Z":(e,t)=>{let r;return t?"UTC":(r=e.toString().match(/[A-Z][A-Z][A-Z]/))&&r[0]},"%%":()=>"%"};function xe(e){let t=e.getFullYear(),r=new Date(t,0);return e.getTimezoneOffset()!==r.getTimezoneOffset()}function Se(e,t,r){let n=parseInt($e["%j"](e),10),a=(8-new Date(e.getFullYear(),0,1,12)["get"+(r?"UTC":"")+"Day"]()+t)%7;return("0"+(Math.floor((n-a)/7)+1)).substr(-2)}var Ce=new E({date:function(e="%c",t){let r,n=new Date;if(t&&n.setTime(1e3*t),"!"===e.substr(0,1)&&(e=e.substr(1),r=!0),"*t"===e)return new E({year:parseInt($e["%Y"](n,r),10),month:parseInt($e["%m"](n,r),10),day:parseInt($e["%d"](n,r),10),hour:parseInt($e["%H"](n,r),10),min:parseInt($e["%M"](n,r),10),sec:parseInt($e["%S"](n,r),10),wday:parseInt($e["%w"](n,r),10)+1,yday:parseInt($e["%j"](n,r),10),isdst:xe(n)});for(let t in $e)$e.hasOwnProperty(t)&&e.indexOf(t)>=0&&(e=e.replace(t,$e[t](n,r)));return e},exit:function(e=0){var t=global.process;if(!t||!t.exit)throw new Error(`Exit with code: ${e}`);t.exit(e)}}),Ae=new E({preload:new E,loaded:new E});let Ee=global.starlight=global.starlight||{},ke=oe;!function(){let e=Ee.config&&Ee.config.env;if(e)for(let t in e)oe.set(t,e[t])}();Ee.runtime={globalScope:new $(oe.strValues),_G:ke,op:fe,T:E,LuaError:x,call:function(e,...t){if(!(e instanceof Function)){if(e instanceof E){let r,n;(r=e.metatable)&&(n=r.rawget("__call"))&&(t.unshift(e),e=n)}if(!(e instanceof Function)){let t=ne(e);throw new x(`attempt to call a ${t} value`)}}return(r=e(...t))instanceof Array?r:[r];var r}};var Te;ke.set("math",_e),ke.set("table",Y),ke.set("string",G),ke.set("os",Ce),ke.set("package",Ae),S=(Te={string:G,getn:B}).string,C=Te.getn,r.d(t,"parser",function(){return n}),r.d(t,"runtime",function(){return a})}])}); \ No newline at end of file diff --git a/package-lock.json b/package-lock.json deleted file mode 100644 index b2e4994..0000000 --- a/package-lock.json +++ /dev/null @@ -1,5002 +0,0 @@ -{ - "name": "lua-in-js", - "version": "1.1.0", - "lockfileVersion": 1, - "requires": true, - "dependencies": { - "@babel/code-frame": { - "version": "7.0.0", - "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.0.0.tgz", - "integrity": "sha512-OfC2uemaknXr87bdLUkWog7nYuliM9Ij5HUcajsVcMCpQrcLmtxRbVFTIqmcSkSeYRBFBRxs2FiUqFJDLdiebA==", - "dev": true, - "requires": { - "@babel/highlight": "^7.0.0" - } - }, - "@babel/core": { - "version": "7.2.2", - "resolved": "https://registry.npmjs.org/@babel/core/-/core-7.2.2.tgz", - "integrity": "sha512-59vB0RWt09cAct5EIe58+NzGP4TFSD3Bz//2/ELy3ZeTeKF6VTD1AXlH8BGGbCX0PuobZBsIzO7IAI9PH67eKw==", - "dev": true, - "requires": { - "@babel/code-frame": "^7.0.0", - "@babel/generator": "^7.2.2", - "@babel/helpers": "^7.2.0", - "@babel/parser": "^7.2.2", - "@babel/template": "^7.2.2", - "@babel/traverse": "^7.2.2", - "@babel/types": "^7.2.2", - "convert-source-map": "^1.1.0", - "debug": "^4.1.0", - "json5": "^2.1.0", - "lodash": "^4.17.10", - "resolve": "^1.3.2", - "semver": "^5.4.1", - "source-map": "^0.5.0" - } - }, - "@babel/generator": { - "version": "7.2.2", - "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.2.2.tgz", - "integrity": "sha512-I4o675J/iS8k+P38dvJ3IBGqObLXyQLTxtrR4u9cSUJOURvafeEWb/pFMOTwtNrmq73mJzyF6ueTbO1BtN0Zeg==", - "dev": true, - "requires": { - "@babel/types": "^7.2.2", - "jsesc": "^2.5.1", - "lodash": "^4.17.10", - "source-map": "^0.5.0", - "trim-right": "^1.0.1" - } - }, - "@babel/helper-annotate-as-pure": { - "version": "7.0.0", - "resolved": "https://registry.npmjs.org/@babel/helper-annotate-as-pure/-/helper-annotate-as-pure-7.0.0.tgz", - "integrity": "sha512-3UYcJUj9kvSLbLbUIfQTqzcy5VX7GRZ/CCDrnOaZorFFM01aXp1+GJwuFGV4NDDoAS+mOUyHcO6UD/RfqOks3Q==", - "dev": true, - "requires": { - "@babel/types": "^7.0.0" - } - }, - "@babel/helper-builder-binary-assignment-operator-visitor": { - "version": "7.1.0", - "resolved": "https://registry.npmjs.org/@babel/helper-builder-binary-assignment-operator-visitor/-/helper-builder-binary-assignment-operator-visitor-7.1.0.tgz", - "integrity": "sha512-qNSR4jrmJ8M1VMM9tibvyRAHXQs2PmaksQF7c1CGJNipfe3D8p+wgNwgso/P2A2r2mdgBWAXljNWR0QRZAMW8w==", - "dev": true, - "requires": { - "@babel/helper-explode-assignable-expression": "^7.1.0", - "@babel/types": "^7.0.0" - } - }, - "@babel/helper-call-delegate": { - "version": "7.1.0", - "resolved": "https://registry.npmjs.org/@babel/helper-call-delegate/-/helper-call-delegate-7.1.0.tgz", - "integrity": "sha512-YEtYZrw3GUK6emQHKthltKNZwszBcHK58Ygcis+gVUrF4/FmTVr5CCqQNSfmvg2y+YDEANyYoaLz/SHsnusCwQ==", - "dev": true, - "requires": { - "@babel/helper-hoist-variables": "^7.0.0", - "@babel/traverse": "^7.1.0", - "@babel/types": "^7.0.0" - } - }, - "@babel/helper-define-map": { - "version": "7.1.0", - "resolved": "https://registry.npmjs.org/@babel/helper-define-map/-/helper-define-map-7.1.0.tgz", - "integrity": "sha512-yPPcW8dc3gZLN+U1mhYV91QU3n5uTbx7DUdf8NnPbjS0RMwBuHi9Xt2MUgppmNz7CJxTBWsGczTiEp1CSOTPRg==", - "dev": true, - "requires": { - "@babel/helper-function-name": "^7.1.0", - "@babel/types": "^7.0.0", - "lodash": "^4.17.10" - } - }, - "@babel/helper-explode-assignable-expression": { - "version": "7.1.0", - "resolved": "https://registry.npmjs.org/@babel/helper-explode-assignable-expression/-/helper-explode-assignable-expression-7.1.0.tgz", - "integrity": "sha512-NRQpfHrJ1msCHtKjbzs9YcMmJZOg6mQMmGRB+hbamEdG5PNpaSm95275VD92DvJKuyl0s2sFiDmMZ+EnnvufqA==", - "dev": true, - "requires": { - "@babel/traverse": "^7.1.0", - "@babel/types": "^7.0.0" - } - }, - "@babel/helper-function-name": { - "version": "7.1.0", - "resolved": "https://registry.npmjs.org/@babel/helper-function-name/-/helper-function-name-7.1.0.tgz", - "integrity": "sha512-A95XEoCpb3TO+KZzJ4S/5uW5fNe26DjBGqf1o9ucyLyCmi1dXq/B3c8iaWTfBk3VvetUxl16e8tIrd5teOCfGw==", - "dev": true, - "requires": { - "@babel/helper-get-function-arity": "^7.0.0", - "@babel/template": "^7.1.0", - "@babel/types": "^7.0.0" - } - }, - "@babel/helper-get-function-arity": { - "version": "7.0.0", - "resolved": "https://registry.npmjs.org/@babel/helper-get-function-arity/-/helper-get-function-arity-7.0.0.tgz", - "integrity": "sha512-r2DbJeg4svYvt3HOS74U4eWKsUAMRH01Z1ds1zx8KNTPtpTL5JAsdFv8BNyOpVqdFhHkkRDIg5B4AsxmkjAlmQ==", - "dev": true, - "requires": { - "@babel/types": "^7.0.0" - } - }, - "@babel/helper-hoist-variables": { - "version": "7.0.0", - "resolved": "https://registry.npmjs.org/@babel/helper-hoist-variables/-/helper-hoist-variables-7.0.0.tgz", - "integrity": "sha512-Ggv5sldXUeSKsuzLkddtyhyHe2YantsxWKNi7A+7LeD12ExRDWTRk29JCXpaHPAbMaIPZSil7n+lq78WY2VY7w==", - "dev": true, - "requires": { - "@babel/types": "^7.0.0" - } - }, - "@babel/helper-member-expression-to-functions": { - "version": "7.0.0", - "resolved": "https://registry.npmjs.org/@babel/helper-member-expression-to-functions/-/helper-member-expression-to-functions-7.0.0.tgz", - "integrity": "sha512-avo+lm/QmZlv27Zsi0xEor2fKcqWG56D5ae9dzklpIaY7cQMK5N8VSpaNVPPagiqmy7LrEjK1IWdGMOqPu5csg==", - "dev": true, - "requires": { - "@babel/types": "^7.0.0" - } - }, - "@babel/helper-module-imports": { - "version": "7.0.0", - "resolved": "https://registry.npmjs.org/@babel/helper-module-imports/-/helper-module-imports-7.0.0.tgz", - "integrity": "sha512-aP/hlLq01DWNEiDg4Jn23i+CXxW/owM4WpDLFUbpjxe4NS3BhLVZQ5i7E0ZrxuQ/vwekIeciyamgB1UIYxxM6A==", - "dev": true, - "requires": { - "@babel/types": "^7.0.0" - } - }, - "@babel/helper-module-transforms": { - "version": "7.2.2", - "resolved": "https://registry.npmjs.org/@babel/helper-module-transforms/-/helper-module-transforms-7.2.2.tgz", - "integrity": "sha512-YRD7I6Wsv+IHuTPkAmAS4HhY0dkPobgLftHp0cRGZSdrRvmZY8rFvae/GVu3bD00qscuvK3WPHB3YdNpBXUqrA==", - "dev": true, - "requires": { - "@babel/helper-module-imports": "^7.0.0", - "@babel/helper-simple-access": "^7.1.0", - "@babel/helper-split-export-declaration": "^7.0.0", - "@babel/template": "^7.2.2", - "@babel/types": "^7.2.2", - "lodash": "^4.17.10" - } - }, - "@babel/helper-optimise-call-expression": { - "version": "7.0.0", - "resolved": "https://registry.npmjs.org/@babel/helper-optimise-call-expression/-/helper-optimise-call-expression-7.0.0.tgz", - "integrity": "sha512-u8nd9NQePYNQV8iPWu/pLLYBqZBa4ZaY1YWRFMuxrid94wKI1QNt67NEZ7GAe5Kc/0LLScbim05xZFWkAdrj9g==", - "dev": true, - "requires": { - "@babel/types": "^7.0.0" - } - }, - "@babel/helper-plugin-utils": { - "version": "7.0.0", - "resolved": "https://registry.npmjs.org/@babel/helper-plugin-utils/-/helper-plugin-utils-7.0.0.tgz", - "integrity": "sha512-CYAOUCARwExnEixLdB6sDm2dIJ/YgEAKDM1MOeMeZu9Ld/bDgVo8aiWrXwcY7OBh+1Ea2uUcVRcxKk0GJvW7QA==", - "dev": true - }, - "@babel/helper-regex": { - "version": "7.0.0", - "resolved": "https://registry.npmjs.org/@babel/helper-regex/-/helper-regex-7.0.0.tgz", - "integrity": "sha512-TR0/N0NDCcUIUEbqV6dCO+LptmmSQFQ7q70lfcEB4URsjD0E1HzicrwUH+ap6BAQ2jhCX9Q4UqZy4wilujWlkg==", - "dev": true, - "requires": { - "lodash": "^4.17.10" - } - }, - "@babel/helper-remap-async-to-generator": { - "version": "7.1.0", - "resolved": "https://registry.npmjs.org/@babel/helper-remap-async-to-generator/-/helper-remap-async-to-generator-7.1.0.tgz", - "integrity": "sha512-3fOK0L+Fdlg8S5al8u/hWE6vhufGSn0bN09xm2LXMy//REAF8kDCrYoOBKYmA8m5Nom+sV9LyLCwrFynA8/slg==", - "dev": true, - "requires": { - "@babel/helper-annotate-as-pure": "^7.0.0", - "@babel/helper-wrap-function": "^7.1.0", - "@babel/template": "^7.1.0", - "@babel/traverse": "^7.1.0", - "@babel/types": "^7.0.0" - } - }, - "@babel/helper-replace-supers": { - "version": "7.2.3", - "resolved": "https://registry.npmjs.org/@babel/helper-replace-supers/-/helper-replace-supers-7.2.3.tgz", - "integrity": "sha512-GyieIznGUfPXPWu0yLS6U55Mz67AZD9cUk0BfirOWlPrXlBcan9Gz+vHGz+cPfuoweZSnPzPIm67VtQM0OWZbA==", - "dev": true, - "requires": { - "@babel/helper-member-expression-to-functions": "^7.0.0", - "@babel/helper-optimise-call-expression": "^7.0.0", - "@babel/traverse": "^7.2.3", - "@babel/types": "^7.0.0" - } - }, - "@babel/helper-simple-access": { - "version": "7.1.0", - "resolved": "https://registry.npmjs.org/@babel/helper-simple-access/-/helper-simple-access-7.1.0.tgz", - "integrity": "sha512-Vk+78hNjRbsiu49zAPALxTb+JUQCz1aolpd8osOF16BGnLtseD21nbHgLPGUwrXEurZgiCOUmvs3ExTu4F5x6w==", - "dev": true, - "requires": { - "@babel/template": "^7.1.0", - "@babel/types": "^7.0.0" - } - }, - "@babel/helper-split-export-declaration": { - "version": "7.0.0", - "resolved": "https://registry.npmjs.org/@babel/helper-split-export-declaration/-/helper-split-export-declaration-7.0.0.tgz", - "integrity": "sha512-MXkOJqva62dfC0w85mEf/LucPPS/1+04nmmRMPEBUB++hiiThQ2zPtX/mEWQ3mtzCEjIJvPY8nuwxXtQeQwUag==", - "dev": true, - "requires": { - "@babel/types": "^7.0.0" - } - }, - "@babel/helper-wrap-function": { - "version": "7.2.0", - "resolved": "https://registry.npmjs.org/@babel/helper-wrap-function/-/helper-wrap-function-7.2.0.tgz", - "integrity": "sha512-o9fP1BZLLSrYlxYEYyl2aS+Flun5gtjTIG8iln+XuEzQTs0PLagAGSXUcqruJwD5fM48jzIEggCKpIfWTcR7pQ==", - "dev": true, - "requires": { - "@babel/helper-function-name": "^7.1.0", - "@babel/template": "^7.1.0", - "@babel/traverse": "^7.1.0", - "@babel/types": "^7.2.0" - } - }, - "@babel/helpers": { - "version": "7.2.0", - "resolved": "https://registry.npmjs.org/@babel/helpers/-/helpers-7.2.0.tgz", - "integrity": "sha512-Fr07N+ea0dMcMN8nFpuK6dUIT7/ivt9yKQdEEnjVS83tG2pHwPi03gYmk/tyuwONnZ+sY+GFFPlWGgCtW1hF9A==", - "dev": true, - "requires": { - "@babel/template": "^7.1.2", - "@babel/traverse": "^7.1.5", - "@babel/types": "^7.2.0" - } - }, - "@babel/highlight": { - "version": "7.0.0", - "resolved": "https://registry.npmjs.org/@babel/highlight/-/highlight-7.0.0.tgz", - "integrity": "sha512-UFMC4ZeFC48Tpvj7C8UgLvtkaUuovQX+5xNWrsIoMG8o2z+XFKjKaN9iVmS84dPwVN00W4wPmqvYoZF3EGAsfw==", - "dev": true, - "requires": { - "chalk": "^2.0.0", - "esutils": "^2.0.2", - "js-tokens": "^4.0.0" - } - }, - "@babel/parser": { - "version": "7.2.3", - "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.2.3.tgz", - "integrity": "sha512-0LyEcVlfCoFmci8mXx8A5oIkpkOgyo8dRHtxBnK9RRBwxO2+JZPNsqtVEZQ7mJFPxnXF9lfmU24mHOPI0qnlkA==", - "dev": true - }, - "@babel/plugin-proposal-async-generator-functions": { - "version": "7.2.0", - "resolved": "https://registry.npmjs.org/@babel/plugin-proposal-async-generator-functions/-/plugin-proposal-async-generator-functions-7.2.0.tgz", - "integrity": "sha512-+Dfo/SCQqrwx48ptLVGLdE39YtWRuKc/Y9I5Fy0P1DDBB9lsAHpjcEJQt+4IifuSOSTLBKJObJqMvaO1pIE8LQ==", - "dev": true, - "requires": { - "@babel/helper-plugin-utils": "^7.0.0", - "@babel/helper-remap-async-to-generator": "^7.1.0", - "@babel/plugin-syntax-async-generators": "^7.2.0" - } - }, - "@babel/plugin-proposal-json-strings": { - "version": "7.2.0", - "resolved": "https://registry.npmjs.org/@babel/plugin-proposal-json-strings/-/plugin-proposal-json-strings-7.2.0.tgz", - "integrity": "sha512-MAFV1CA/YVmYwZG0fBQyXhmj0BHCB5egZHCKWIFVv/XCxAeVGIHfos3SwDck4LvCllENIAg7xMKOG5kH0dzyUg==", - "dev": true, - "requires": { - "@babel/helper-plugin-utils": "^7.0.0", - "@babel/plugin-syntax-json-strings": "^7.2.0" - } - }, - "@babel/plugin-proposal-object-rest-spread": { - "version": "7.2.0", - "resolved": "https://registry.npmjs.org/@babel/plugin-proposal-object-rest-spread/-/plugin-proposal-object-rest-spread-7.2.0.tgz", - "integrity": "sha512-1L5mWLSvR76XYUQJXkd/EEQgjq8HHRP6lQuZTTg0VA4tTGPpGemmCdAfQIz1rzEuWAm+ecP8PyyEm30jC1eQCg==", - "dev": true, - "requires": { - "@babel/helper-plugin-utils": "^7.0.0", - "@babel/plugin-syntax-object-rest-spread": "^7.2.0" - } - }, - "@babel/plugin-proposal-optional-catch-binding": { - "version": "7.2.0", - "resolved": "https://registry.npmjs.org/@babel/plugin-proposal-optional-catch-binding/-/plugin-proposal-optional-catch-binding-7.2.0.tgz", - "integrity": "sha512-mgYj3jCcxug6KUcX4OBoOJz3CMrwRfQELPQ5560F70YQUBZB7uac9fqaWamKR1iWUzGiK2t0ygzjTScZnVz75g==", - "dev": true, - "requires": { - "@babel/helper-plugin-utils": "^7.0.0", - "@babel/plugin-syntax-optional-catch-binding": "^7.2.0" - } - }, - "@babel/plugin-proposal-unicode-property-regex": { - "version": "7.2.0", - "resolved": "https://registry.npmjs.org/@babel/plugin-proposal-unicode-property-regex/-/plugin-proposal-unicode-property-regex-7.2.0.tgz", - "integrity": "sha512-LvRVYb7kikuOtIoUeWTkOxQEV1kYvL5B6U3iWEGCzPNRus1MzJweFqORTj+0jkxozkTSYNJozPOddxmqdqsRpw==", - "dev": true, - "requires": { - "@babel/helper-plugin-utils": "^7.0.0", - "@babel/helper-regex": "^7.0.0", - "regexpu-core": "^4.2.0" - } - }, - "@babel/plugin-syntax-async-generators": { - "version": "7.2.0", - "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-async-generators/-/plugin-syntax-async-generators-7.2.0.tgz", - "integrity": "sha512-1ZrIRBv2t0GSlcwVoQ6VgSLpLgiN/FVQUzt9znxo7v2Ov4jJrs8RY8tv0wvDmFN3qIdMKWrmMMW6yZ0G19MfGg==", - "dev": true, - "requires": { - "@babel/helper-plugin-utils": "^7.0.0" - } - }, - "@babel/plugin-syntax-json-strings": { - "version": "7.2.0", - "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-json-strings/-/plugin-syntax-json-strings-7.2.0.tgz", - "integrity": "sha512-5UGYnMSLRE1dqqZwug+1LISpA403HzlSfsg6P9VXU6TBjcSHeNlw4DxDx7LgpF+iKZoOG/+uzqoRHTdcUpiZNg==", - "dev": true, - "requires": { - "@babel/helper-plugin-utils": "^7.0.0" - } - }, - "@babel/plugin-syntax-object-rest-spread": { - "version": "7.2.0", - "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-object-rest-spread/-/plugin-syntax-object-rest-spread-7.2.0.tgz", - "integrity": "sha512-t0JKGgqk2We+9may3t0xDdmneaXmyxq0xieYcKHxIsrJO64n1OiMWNUtc5gQK1PA0NpdCRrtZp4z+IUaKugrSA==", - "dev": true, - "requires": { - "@babel/helper-plugin-utils": "^7.0.0" - } - }, - "@babel/plugin-syntax-optional-catch-binding": { - "version": "7.2.0", - "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-optional-catch-binding/-/plugin-syntax-optional-catch-binding-7.2.0.tgz", - "integrity": "sha512-bDe4xKNhb0LI7IvZHiA13kff0KEfaGX/Hv4lMA9+7TEc63hMNvfKo6ZFpXhKuEp+II/q35Gc4NoMeDZyaUbj9w==", - "dev": true, - "requires": { - "@babel/helper-plugin-utils": "^7.0.0" - } - }, - "@babel/plugin-transform-arrow-functions": { - "version": "7.2.0", - "resolved": "https://registry.npmjs.org/@babel/plugin-transform-arrow-functions/-/plugin-transform-arrow-functions-7.2.0.tgz", - "integrity": "sha512-ER77Cax1+8/8jCB9fo4Ud161OZzWN5qawi4GusDuRLcDbDG+bIGYY20zb2dfAFdTRGzrfq2xZPvF0R64EHnimg==", - "dev": true, - "requires": { - "@babel/helper-plugin-utils": "^7.0.0" - } - }, - "@babel/plugin-transform-async-to-generator": { - "version": "7.2.0", - "resolved": "https://registry.npmjs.org/@babel/plugin-transform-async-to-generator/-/plugin-transform-async-to-generator-7.2.0.tgz", - "integrity": "sha512-CEHzg4g5UraReozI9D4fblBYABs7IM6UerAVG7EJVrTLC5keh00aEuLUT+O40+mJCEzaXkYfTCUKIyeDfMOFFQ==", - "dev": true, - "requires": { - "@babel/helper-module-imports": "^7.0.0", - "@babel/helper-plugin-utils": "^7.0.0", - "@babel/helper-remap-async-to-generator": "^7.1.0" - } - }, - "@babel/plugin-transform-block-scoped-functions": { - "version": "7.2.0", - "resolved": "https://registry.npmjs.org/@babel/plugin-transform-block-scoped-functions/-/plugin-transform-block-scoped-functions-7.2.0.tgz", - "integrity": "sha512-ntQPR6q1/NKuphly49+QiQiTN0O63uOwjdD6dhIjSWBI5xlrbUFh720TIpzBhpnrLfv2tNH/BXvLIab1+BAI0w==", - "dev": true, - "requires": { - "@babel/helper-plugin-utils": "^7.0.0" - } - }, - "@babel/plugin-transform-block-scoping": { - "version": "7.2.0", - "resolved": "https://registry.npmjs.org/@babel/plugin-transform-block-scoping/-/plugin-transform-block-scoping-7.2.0.tgz", - "integrity": "sha512-vDTgf19ZEV6mx35yiPJe4fS02mPQUUcBNwWQSZFXSzTSbsJFQvHt7DqyS3LK8oOWALFOsJ+8bbqBgkirZteD5Q==", - "dev": true, - "requires": { - "@babel/helper-plugin-utils": "^7.0.0", - "lodash": "^4.17.10" - } - }, - "@babel/plugin-transform-classes": { - "version": "7.2.2", - "resolved": "https://registry.npmjs.org/@babel/plugin-transform-classes/-/plugin-transform-classes-7.2.2.tgz", - "integrity": "sha512-gEZvgTy1VtcDOaQty1l10T3jQmJKlNVxLDCs+3rCVPr6nMkODLELxViq5X9l+rfxbie3XrfrMCYYY6eX3aOcOQ==", - "dev": true, - "requires": { - "@babel/helper-annotate-as-pure": "^7.0.0", - "@babel/helper-define-map": "^7.1.0", - "@babel/helper-function-name": "^7.1.0", - "@babel/helper-optimise-call-expression": "^7.0.0", - "@babel/helper-plugin-utils": "^7.0.0", - "@babel/helper-replace-supers": "^7.1.0", - "@babel/helper-split-export-declaration": "^7.0.0", - "globals": "^11.1.0" - } - }, - "@babel/plugin-transform-computed-properties": { - "version": "7.2.0", - "resolved": "https://registry.npmjs.org/@babel/plugin-transform-computed-properties/-/plugin-transform-computed-properties-7.2.0.tgz", - "integrity": "sha512-kP/drqTxY6Xt3NNpKiMomfgkNn4o7+vKxK2DDKcBG9sHj51vHqMBGy8wbDS/J4lMxnqs153/T3+DmCEAkC5cpA==", - "dev": true, - "requires": { - "@babel/helper-plugin-utils": "^7.0.0" - } - }, - "@babel/plugin-transform-destructuring": { - "version": "7.2.0", - "resolved": "https://registry.npmjs.org/@babel/plugin-transform-destructuring/-/plugin-transform-destructuring-7.2.0.tgz", - "integrity": "sha512-coVO2Ayv7g0qdDbrNiadE4bU7lvCd9H539m2gMknyVjjMdwF/iCOM7R+E8PkntoqLkltO0rk+3axhpp/0v68VQ==", - "dev": true, - "requires": { - "@babel/helper-plugin-utils": "^7.0.0" - } - }, - "@babel/plugin-transform-dotall-regex": { - "version": "7.2.0", - "resolved": "https://registry.npmjs.org/@babel/plugin-transform-dotall-regex/-/plugin-transform-dotall-regex-7.2.0.tgz", - "integrity": "sha512-sKxnyHfizweTgKZf7XsXu/CNupKhzijptfTM+bozonIuyVrLWVUvYjE2bhuSBML8VQeMxq4Mm63Q9qvcvUcciQ==", - "dev": true, - "requires": { - "@babel/helper-plugin-utils": "^7.0.0", - "@babel/helper-regex": "^7.0.0", - "regexpu-core": "^4.1.3" - } - }, - "@babel/plugin-transform-duplicate-keys": { - "version": "7.2.0", - "resolved": "https://registry.npmjs.org/@babel/plugin-transform-duplicate-keys/-/plugin-transform-duplicate-keys-7.2.0.tgz", - "integrity": "sha512-q+yuxW4DsTjNceUiTzK0L+AfQ0zD9rWaTLiUqHA8p0gxx7lu1EylenfzjeIWNkPy6e/0VG/Wjw9uf9LueQwLOw==", - "dev": true, - "requires": { - "@babel/helper-plugin-utils": "^7.0.0" - } - }, - "@babel/plugin-transform-exponentiation-operator": { - "version": "7.2.0", - "resolved": "https://registry.npmjs.org/@babel/plugin-transform-exponentiation-operator/-/plugin-transform-exponentiation-operator-7.2.0.tgz", - "integrity": "sha512-umh4hR6N7mu4Elq9GG8TOu9M0bakvlsREEC+ialrQN6ABS4oDQ69qJv1VtR3uxlKMCQMCvzk7vr17RHKcjx68A==", - "dev": true, - "requires": { - "@babel/helper-builder-binary-assignment-operator-visitor": "^7.1.0", - "@babel/helper-plugin-utils": "^7.0.0" - } - }, - "@babel/plugin-transform-for-of": { - "version": "7.2.0", - "resolved": "https://registry.npmjs.org/@babel/plugin-transform-for-of/-/plugin-transform-for-of-7.2.0.tgz", - "integrity": "sha512-Kz7Mt0SsV2tQk6jG5bBv5phVbkd0gd27SgYD4hH1aLMJRchM0dzHaXvrWhVZ+WxAlDoAKZ7Uy3jVTW2mKXQ1WQ==", - "dev": true, - "requires": { - "@babel/helper-plugin-utils": "^7.0.0" - } - }, - "@babel/plugin-transform-function-name": { - "version": "7.2.0", - "resolved": "https://registry.npmjs.org/@babel/plugin-transform-function-name/-/plugin-transform-function-name-7.2.0.tgz", - "integrity": "sha512-kWgksow9lHdvBC2Z4mxTsvc7YdY7w/V6B2vy9cTIPtLEE9NhwoWivaxdNM/S37elu5bqlLP/qOY906LukO9lkQ==", - "dev": true, - "requires": { - "@babel/helper-function-name": "^7.1.0", - "@babel/helper-plugin-utils": "^7.0.0" - } - }, - "@babel/plugin-transform-literals": { - "version": "7.2.0", - "resolved": "https://registry.npmjs.org/@babel/plugin-transform-literals/-/plugin-transform-literals-7.2.0.tgz", - "integrity": "sha512-2ThDhm4lI4oV7fVQ6pNNK+sx+c/GM5/SaML0w/r4ZB7sAneD/piDJtwdKlNckXeyGK7wlwg2E2w33C/Hh+VFCg==", - "dev": true, - "requires": { - "@babel/helper-plugin-utils": "^7.0.0" - } - }, - "@babel/plugin-transform-modules-amd": { - "version": "7.2.0", - "resolved": "https://registry.npmjs.org/@babel/plugin-transform-modules-amd/-/plugin-transform-modules-amd-7.2.0.tgz", - "integrity": "sha512-mK2A8ucqz1qhrdqjS9VMIDfIvvT2thrEsIQzbaTdc5QFzhDjQv2CkJJ5f6BXIkgbmaoax3zBr2RyvV/8zeoUZw==", - "dev": true, - "requires": { - "@babel/helper-module-transforms": "^7.1.0", - "@babel/helper-plugin-utils": "^7.0.0" - } - }, - "@babel/plugin-transform-modules-commonjs": { - "version": "7.2.0", - "resolved": "https://registry.npmjs.org/@babel/plugin-transform-modules-commonjs/-/plugin-transform-modules-commonjs-7.2.0.tgz", - "integrity": "sha512-V6y0uaUQrQPXUrmj+hgnks8va2L0zcZymeU7TtWEgdRLNkceafKXEduv7QzgQAE4lT+suwooG9dC7LFhdRAbVQ==", - "dev": true, - "requires": { - "@babel/helper-module-transforms": "^7.1.0", - "@babel/helper-plugin-utils": "^7.0.0", - "@babel/helper-simple-access": "^7.1.0" - } - }, - "@babel/plugin-transform-modules-systemjs": { - "version": "7.2.0", - "resolved": "https://registry.npmjs.org/@babel/plugin-transform-modules-systemjs/-/plugin-transform-modules-systemjs-7.2.0.tgz", - "integrity": "sha512-aYJwpAhoK9a+1+O625WIjvMY11wkB/ok0WClVwmeo3mCjcNRjt+/8gHWrB5i+00mUju0gWsBkQnPpdvQ7PImmQ==", - "dev": true, - "requires": { - "@babel/helper-hoist-variables": "^7.0.0", - "@babel/helper-plugin-utils": "^7.0.0" - } - }, - "@babel/plugin-transform-modules-umd": { - "version": "7.2.0", - "resolved": "https://registry.npmjs.org/@babel/plugin-transform-modules-umd/-/plugin-transform-modules-umd-7.2.0.tgz", - "integrity": "sha512-BV3bw6MyUH1iIsGhXlOK6sXhmSarZjtJ/vMiD9dNmpY8QXFFQTj+6v92pcfy1iqa8DeAfJFwoxcrS/TUZda6sw==", - "dev": true, - "requires": { - "@babel/helper-module-transforms": "^7.1.0", - "@babel/helper-plugin-utils": "^7.0.0" - } - }, - "@babel/plugin-transform-new-target": { - "version": "7.0.0", - "resolved": "https://registry.npmjs.org/@babel/plugin-transform-new-target/-/plugin-transform-new-target-7.0.0.tgz", - "integrity": "sha512-yin069FYjah+LbqfGeTfzIBODex/e++Yfa0rH0fpfam9uTbuEeEOx5GLGr210ggOV77mVRNoeqSYqeuaqSzVSw==", - "dev": true, - "requires": { - "@babel/helper-plugin-utils": "^7.0.0" - } - }, - "@babel/plugin-transform-object-super": { - "version": "7.2.0", - "resolved": "https://registry.npmjs.org/@babel/plugin-transform-object-super/-/plugin-transform-object-super-7.2.0.tgz", - "integrity": "sha512-VMyhPYZISFZAqAPVkiYb7dUe2AsVi2/wCT5+wZdsNO31FojQJa9ns40hzZ6U9f50Jlq4w6qwzdBB2uwqZ00ebg==", - "dev": true, - "requires": { - "@babel/helper-plugin-utils": "^7.0.0", - "@babel/helper-replace-supers": "^7.1.0" - } - }, - "@babel/plugin-transform-parameters": { - "version": "7.2.0", - "resolved": "https://registry.npmjs.org/@babel/plugin-transform-parameters/-/plugin-transform-parameters-7.2.0.tgz", - "integrity": "sha512-kB9+hhUidIgUoBQ0MsxMewhzr8i60nMa2KgeJKQWYrqQpqcBYtnpR+JgkadZVZoaEZ/eKu9mclFaVwhRpLNSzA==", - "dev": true, - "requires": { - "@babel/helper-call-delegate": "^7.1.0", - "@babel/helper-get-function-arity": "^7.0.0", - "@babel/helper-plugin-utils": "^7.0.0" - } - }, - "@babel/plugin-transform-regenerator": { - "version": "7.0.0", - "resolved": "https://registry.npmjs.org/@babel/plugin-transform-regenerator/-/plugin-transform-regenerator-7.0.0.tgz", - "integrity": "sha512-sj2qzsEx8KDVv1QuJc/dEfilkg3RRPvPYx/VnKLtItVQRWt1Wqf5eVCOLZm29CiGFfYYsA3VPjfizTCV0S0Dlw==", - "dev": true, - "requires": { - "regenerator-transform": "^0.13.3" - } - }, - "@babel/plugin-transform-shorthand-properties": { - "version": "7.2.0", - "resolved": "https://registry.npmjs.org/@babel/plugin-transform-shorthand-properties/-/plugin-transform-shorthand-properties-7.2.0.tgz", - "integrity": "sha512-QP4eUM83ha9zmYtpbnyjTLAGKQritA5XW/iG9cjtuOI8s1RuL/3V6a3DeSHfKutJQ+ayUfeZJPcnCYEQzaPQqg==", - "dev": true, - "requires": { - "@babel/helper-plugin-utils": "^7.0.0" - } - }, - "@babel/plugin-transform-spread": { - "version": "7.2.2", - "resolved": "https://registry.npmjs.org/@babel/plugin-transform-spread/-/plugin-transform-spread-7.2.2.tgz", - "integrity": "sha512-KWfky/58vubwtS0hLqEnrWJjsMGaOeSBn90Ezn5Jeg9Z8KKHmELbP1yGylMlm5N6TPKeY9A2+UaSYLdxahg01w==", - "dev": true, - "requires": { - "@babel/helper-plugin-utils": "^7.0.0" - } - }, - "@babel/plugin-transform-sticky-regex": { - "version": "7.2.0", - "resolved": "https://registry.npmjs.org/@babel/plugin-transform-sticky-regex/-/plugin-transform-sticky-regex-7.2.0.tgz", - "integrity": "sha512-KKYCoGaRAf+ckH8gEL3JHUaFVyNHKe3ASNsZ+AlktgHevvxGigoIttrEJb8iKN03Q7Eazlv1s6cx2B2cQ3Jabw==", - "dev": true, - "requires": { - "@babel/helper-plugin-utils": "^7.0.0", - "@babel/helper-regex": "^7.0.0" - } - }, - "@babel/plugin-transform-template-literals": { - "version": "7.2.0", - "resolved": "https://registry.npmjs.org/@babel/plugin-transform-template-literals/-/plugin-transform-template-literals-7.2.0.tgz", - "integrity": "sha512-FkPix00J9A/XWXv4VoKJBMeSkyY9x/TqIh76wzcdfl57RJJcf8CehQ08uwfhCDNtRQYtHQKBTwKZDEyjE13Lwg==", - "dev": true, - "requires": { - "@babel/helper-annotate-as-pure": "^7.0.0", - "@babel/helper-plugin-utils": "^7.0.0" - } - }, - "@babel/plugin-transform-typeof-symbol": { - "version": "7.2.0", - "resolved": "https://registry.npmjs.org/@babel/plugin-transform-typeof-symbol/-/plugin-transform-typeof-symbol-7.2.0.tgz", - "integrity": "sha512-2LNhETWYxiYysBtrBTqL8+La0jIoQQnIScUJc74OYvUGRmkskNY4EzLCnjHBzdmb38wqtTaixpo1NctEcvMDZw==", - "dev": true, - "requires": { - "@babel/helper-plugin-utils": "^7.0.0" - } - }, - "@babel/plugin-transform-unicode-regex": { - "version": "7.2.0", - "resolved": "https://registry.npmjs.org/@babel/plugin-transform-unicode-regex/-/plugin-transform-unicode-regex-7.2.0.tgz", - "integrity": "sha512-m48Y0lMhrbXEJnVUaYly29jRXbQ3ksxPrS1Tg8t+MHqzXhtBYAvI51euOBaoAlZLPHsieY9XPVMf80a5x0cPcA==", - "dev": true, - "requires": { - "@babel/helper-plugin-utils": "^7.0.0", - "@babel/helper-regex": "^7.0.0", - "regexpu-core": "^4.1.3" - } - }, - "@babel/preset-env": { - "version": "7.2.3", - "resolved": "https://registry.npmjs.org/@babel/preset-env/-/preset-env-7.2.3.tgz", - "integrity": "sha512-AuHzW7a9rbv5WXmvGaPX7wADxFkZIqKlbBh1dmZUQp4iwiPpkE/Qnrji6SC4UQCQzvWY/cpHET29eUhXS9cLPw==", - "dev": true, - "requires": { - "@babel/helper-module-imports": "^7.0.0", - "@babel/helper-plugin-utils": "^7.0.0", - "@babel/plugin-proposal-async-generator-functions": "^7.2.0", - "@babel/plugin-proposal-json-strings": "^7.2.0", - "@babel/plugin-proposal-object-rest-spread": "^7.2.0", - "@babel/plugin-proposal-optional-catch-binding": "^7.2.0", - "@babel/plugin-proposal-unicode-property-regex": "^7.2.0", - "@babel/plugin-syntax-async-generators": "^7.2.0", - "@babel/plugin-syntax-object-rest-spread": "^7.2.0", - "@babel/plugin-syntax-optional-catch-binding": "^7.2.0", - "@babel/plugin-transform-arrow-functions": "^7.2.0", - "@babel/plugin-transform-async-to-generator": "^7.2.0", - "@babel/plugin-transform-block-scoped-functions": "^7.2.0", - "@babel/plugin-transform-block-scoping": "^7.2.0", - "@babel/plugin-transform-classes": "^7.2.0", - "@babel/plugin-transform-computed-properties": "^7.2.0", - "@babel/plugin-transform-destructuring": "^7.2.0", - "@babel/plugin-transform-dotall-regex": "^7.2.0", - "@babel/plugin-transform-duplicate-keys": "^7.2.0", - "@babel/plugin-transform-exponentiation-operator": "^7.2.0", - "@babel/plugin-transform-for-of": "^7.2.0", - "@babel/plugin-transform-function-name": "^7.2.0", - "@babel/plugin-transform-literals": "^7.2.0", - "@babel/plugin-transform-modules-amd": "^7.2.0", - "@babel/plugin-transform-modules-commonjs": "^7.2.0", - "@babel/plugin-transform-modules-systemjs": "^7.2.0", - "@babel/plugin-transform-modules-umd": "^7.2.0", - "@babel/plugin-transform-new-target": "^7.0.0", - "@babel/plugin-transform-object-super": "^7.2.0", - "@babel/plugin-transform-parameters": "^7.2.0", - "@babel/plugin-transform-regenerator": "^7.0.0", - "@babel/plugin-transform-shorthand-properties": "^7.2.0", - "@babel/plugin-transform-spread": "^7.2.0", - "@babel/plugin-transform-sticky-regex": "^7.2.0", - "@babel/plugin-transform-template-literals": "^7.2.0", - "@babel/plugin-transform-typeof-symbol": "^7.2.0", - "@babel/plugin-transform-unicode-regex": "^7.2.0", - "browserslist": "^4.3.4", - "invariant": "^2.2.2", - "js-levenshtein": "^1.1.3", - "semver": "^5.3.0" - } - }, - "@babel/template": { - "version": "7.2.2", - "resolved": "https://registry.npmjs.org/@babel/template/-/template-7.2.2.tgz", - "integrity": "sha512-zRL0IMM02AUDwghf5LMSSDEz7sBCO2YnNmpg3uWTZj/v1rcG2BmQUvaGU8GhU8BvfMh1k2KIAYZ7Ji9KXPUg7g==", - "dev": true, - "requires": { - "@babel/code-frame": "^7.0.0", - "@babel/parser": "^7.2.2", - "@babel/types": "^7.2.2" - } - }, - "@babel/traverse": { - "version": "7.2.3", - "resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.2.3.tgz", - "integrity": "sha512-Z31oUD/fJvEWVR0lNZtfgvVt512ForCTNKYcJBGbPb1QZfve4WGH8Wsy7+Mev33/45fhP/hwQtvgusNdcCMgSw==", - "dev": true, - "requires": { - "@babel/code-frame": "^7.0.0", - "@babel/generator": "^7.2.2", - "@babel/helper-function-name": "^7.1.0", - "@babel/helper-split-export-declaration": "^7.0.0", - "@babel/parser": "^7.2.3", - "@babel/types": "^7.2.2", - "debug": "^4.1.0", - "globals": "^11.1.0", - "lodash": "^4.17.10" - } - }, - "@babel/types": { - "version": "7.2.2", - "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.2.2.tgz", - "integrity": "sha512-fKCuD6UFUMkR541eDWL+2ih/xFZBXPOg/7EQFeTluMDebfqR4jrpaCjLhkWlQS4hT6nRa2PMEgXKbRB5/H2fpg==", - "dev": true, - "requires": { - "esutils": "^2.0.2", - "lodash": "^4.17.10", - "to-fast-properties": "^2.0.0" - } - }, - "@webassemblyjs/ast": { - "version": "1.7.11", - "resolved": "https://registry.npmjs.org/@webassemblyjs/ast/-/ast-1.7.11.tgz", - "integrity": "sha512-ZEzy4vjvTzScC+SH8RBssQUawpaInUdMTYwYYLh54/s8TuT0gBLuyUnppKsVyZEi876VmmStKsUs28UxPgdvrA==", - "dev": true, - "requires": { - "@webassemblyjs/helper-module-context": "1.7.11", - "@webassemblyjs/helper-wasm-bytecode": "1.7.11", - "@webassemblyjs/wast-parser": "1.7.11" - } - }, - "@webassemblyjs/floating-point-hex-parser": { - "version": "1.7.11", - "resolved": "https://registry.npmjs.org/@webassemblyjs/floating-point-hex-parser/-/floating-point-hex-parser-1.7.11.tgz", - "integrity": "sha512-zY8dSNyYcgzNRNT666/zOoAyImshm3ycKdoLsyDw/Bwo6+/uktb7p4xyApuef1dwEBo/U/SYQzbGBvV+nru2Xg==", - "dev": true - }, - "@webassemblyjs/helper-api-error": { - "version": "1.7.11", - "resolved": "https://registry.npmjs.org/@webassemblyjs/helper-api-error/-/helper-api-error-1.7.11.tgz", - "integrity": "sha512-7r1qXLmiglC+wPNkGuXCvkmalyEstKVwcueZRP2GNC2PAvxbLYwLLPr14rcdJaE4UtHxQKfFkuDFuv91ipqvXg==", - "dev": true - }, - "@webassemblyjs/helper-buffer": { - "version": "1.7.11", - "resolved": "https://registry.npmjs.org/@webassemblyjs/helper-buffer/-/helper-buffer-1.7.11.tgz", - "integrity": "sha512-MynuervdylPPh3ix+mKZloTcL06P8tenNH3sx6s0qE8SLR6DdwnfgA7Hc9NSYeob2jrW5Vql6GVlsQzKQCa13w==", - "dev": true - }, - "@webassemblyjs/helper-code-frame": { - "version": "1.7.11", - "resolved": "https://registry.npmjs.org/@webassemblyjs/helper-code-frame/-/helper-code-frame-1.7.11.tgz", - "integrity": "sha512-T8ESC9KMXFTXA5urJcyor5cn6qWeZ4/zLPyWeEXZ03hj/x9weSokGNkVCdnhSabKGYWxElSdgJ+sFa9G/RdHNw==", - "dev": true, - "requires": { - "@webassemblyjs/wast-printer": "1.7.11" - } - }, - "@webassemblyjs/helper-fsm": { - "version": "1.7.11", - "resolved": "https://registry.npmjs.org/@webassemblyjs/helper-fsm/-/helper-fsm-1.7.11.tgz", - "integrity": "sha512-nsAQWNP1+8Z6tkzdYlXT0kxfa2Z1tRTARd8wYnc/e3Zv3VydVVnaeePgqUzFrpkGUyhUUxOl5ML7f1NuT+gC0A==", - "dev": true - }, - "@webassemblyjs/helper-module-context": { - "version": "1.7.11", - "resolved": "https://registry.npmjs.org/@webassemblyjs/helper-module-context/-/helper-module-context-1.7.11.tgz", - "integrity": "sha512-JxfD5DX8Ygq4PvXDucq0M+sbUFA7BJAv/GGl9ITovqE+idGX+J3QSzJYz+LwQmL7fC3Rs+utvWoJxDb6pmC0qg==", - "dev": true - }, - "@webassemblyjs/helper-wasm-bytecode": { - "version": "1.7.11", - "resolved": "https://registry.npmjs.org/@webassemblyjs/helper-wasm-bytecode/-/helper-wasm-bytecode-1.7.11.tgz", - "integrity": "sha512-cMXeVS9rhoXsI9LLL4tJxBgVD/KMOKXuFqYb5oCJ/opScWpkCMEz9EJtkonaNcnLv2R3K5jIeS4TRj/drde1JQ==", - "dev": true - }, - "@webassemblyjs/helper-wasm-section": { - "version": "1.7.11", - "resolved": "https://registry.npmjs.org/@webassemblyjs/helper-wasm-section/-/helper-wasm-section-1.7.11.tgz", - "integrity": "sha512-8ZRY5iZbZdtNFE5UFunB8mmBEAbSI3guwbrsCl4fWdfRiAcvqQpeqd5KHhSWLL5wuxo53zcaGZDBU64qgn4I4Q==", - "dev": true, - "requires": { - "@webassemblyjs/ast": "1.7.11", - "@webassemblyjs/helper-buffer": "1.7.11", - "@webassemblyjs/helper-wasm-bytecode": "1.7.11", - "@webassemblyjs/wasm-gen": "1.7.11" - } - }, - "@webassemblyjs/ieee754": { - "version": "1.7.11", - "resolved": "https://registry.npmjs.org/@webassemblyjs/ieee754/-/ieee754-1.7.11.tgz", - "integrity": "sha512-Mmqx/cS68K1tSrvRLtaV/Lp3NZWzXtOHUW2IvDvl2sihAwJh4ACE0eL6A8FvMyDG9abes3saB6dMimLOs+HMoQ==", - "dev": true, - "requires": { - "@xtuc/ieee754": "^1.2.0" - } - }, - "@webassemblyjs/leb128": { - "version": "1.7.11", - "resolved": "https://registry.npmjs.org/@webassemblyjs/leb128/-/leb128-1.7.11.tgz", - "integrity": "sha512-vuGmgZjjp3zjcerQg+JA+tGOncOnJLWVkt8Aze5eWQLwTQGNgVLcyOTqgSCxWTR4J42ijHbBxnuRaL1Rv7XMdw==", - "dev": true, - "requires": { - "@xtuc/long": "4.2.1" - } - }, - "@webassemblyjs/utf8": { - "version": "1.7.11", - "resolved": "https://registry.npmjs.org/@webassemblyjs/utf8/-/utf8-1.7.11.tgz", - "integrity": "sha512-C6GFkc7aErQIAH+BMrIdVSmW+6HSe20wg57HEC1uqJP8E/xpMjXqQUxkQw07MhNDSDcGpxI9G5JSNOQCqJk4sA==", - "dev": true - }, - "@webassemblyjs/wasm-edit": { - "version": "1.7.11", - "resolved": "https://registry.npmjs.org/@webassemblyjs/wasm-edit/-/wasm-edit-1.7.11.tgz", - "integrity": "sha512-FUd97guNGsCZQgeTPKdgxJhBXkUbMTY6hFPf2Y4OedXd48H97J+sOY2Ltaq6WGVpIH8o/TGOVNiVz/SbpEMJGg==", - "dev": true, - "requires": { - "@webassemblyjs/ast": "1.7.11", - "@webassemblyjs/helper-buffer": "1.7.11", - "@webassemblyjs/helper-wasm-bytecode": "1.7.11", - "@webassemblyjs/helper-wasm-section": "1.7.11", - "@webassemblyjs/wasm-gen": "1.7.11", - "@webassemblyjs/wasm-opt": "1.7.11", - "@webassemblyjs/wasm-parser": "1.7.11", - "@webassemblyjs/wast-printer": "1.7.11" - } - }, - "@webassemblyjs/wasm-gen": { - "version": "1.7.11", - "resolved": "https://registry.npmjs.org/@webassemblyjs/wasm-gen/-/wasm-gen-1.7.11.tgz", - "integrity": "sha512-U/KDYp7fgAZX5KPfq4NOupK/BmhDc5Kjy2GIqstMhvvdJRcER/kUsMThpWeRP8BMn4LXaKhSTggIJPOeYHwISA==", - "dev": true, - "requires": { - "@webassemblyjs/ast": "1.7.11", - "@webassemblyjs/helper-wasm-bytecode": "1.7.11", - "@webassemblyjs/ieee754": "1.7.11", - "@webassemblyjs/leb128": "1.7.11", - "@webassemblyjs/utf8": "1.7.11" - } - }, - "@webassemblyjs/wasm-opt": { - "version": "1.7.11", - "resolved": "https://registry.npmjs.org/@webassemblyjs/wasm-opt/-/wasm-opt-1.7.11.tgz", - "integrity": "sha512-XynkOwQyiRidh0GLua7SkeHvAPXQV/RxsUeERILmAInZegApOUAIJfRuPYe2F7RcjOC9tW3Cb9juPvAC/sCqvg==", - "dev": true, - "requires": { - "@webassemblyjs/ast": "1.7.11", - "@webassemblyjs/helper-buffer": "1.7.11", - "@webassemblyjs/wasm-gen": "1.7.11", - "@webassemblyjs/wasm-parser": "1.7.11" - } - }, - "@webassemblyjs/wasm-parser": { - "version": "1.7.11", - "resolved": "https://registry.npmjs.org/@webassemblyjs/wasm-parser/-/wasm-parser-1.7.11.tgz", - "integrity": "sha512-6lmXRTrrZjYD8Ng8xRyvyXQJYUQKYSXhJqXOBLw24rdiXsHAOlvw5PhesjdcaMadU/pyPQOJ5dHreMjBxwnQKg==", - "dev": true, - "requires": { - "@webassemblyjs/ast": "1.7.11", - "@webassemblyjs/helper-api-error": "1.7.11", - "@webassemblyjs/helper-wasm-bytecode": "1.7.11", - "@webassemblyjs/ieee754": "1.7.11", - "@webassemblyjs/leb128": "1.7.11", - "@webassemblyjs/utf8": "1.7.11" - } - }, - "@webassemblyjs/wast-parser": { - "version": "1.7.11", - "resolved": "https://registry.npmjs.org/@webassemblyjs/wast-parser/-/wast-parser-1.7.11.tgz", - "integrity": "sha512-lEyVCg2np15tS+dm7+JJTNhNWq9yTZvi3qEhAIIOaofcYlUp0UR5/tVqOwa/gXYr3gjwSZqw+/lS9dscyLelbQ==", - "dev": true, - "requires": { - "@webassemblyjs/ast": "1.7.11", - "@webassemblyjs/floating-point-hex-parser": "1.7.11", - "@webassemblyjs/helper-api-error": "1.7.11", - "@webassemblyjs/helper-code-frame": "1.7.11", - "@webassemblyjs/helper-fsm": "1.7.11", - "@xtuc/long": "4.2.1" - } - }, - "@webassemblyjs/wast-printer": { - "version": "1.7.11", - "resolved": "https://registry.npmjs.org/@webassemblyjs/wast-printer/-/wast-printer-1.7.11.tgz", - "integrity": "sha512-m5vkAsuJ32QpkdkDOUPGSltrg8Cuk3KBx4YrmAGQwCZPRdUHXxG4phIOuuycLemHFr74sWL9Wthqss4fzdzSwg==", - "dev": true, - "requires": { - "@webassemblyjs/ast": "1.7.11", - "@webassemblyjs/wast-parser": "1.7.11", - "@xtuc/long": "4.2.1" - } - }, - "@xtuc/ieee754": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/@xtuc/ieee754/-/ieee754-1.2.0.tgz", - "integrity": "sha512-DX8nKgqcGwsc0eJSqYt5lwP4DH5FlHnmuWWBRy7X0NcaGR0ZtuyeESgMwTYVEtxmsNGY+qit4QYT/MIYTOTPeA==", - "dev": true - }, - "@xtuc/long": { - "version": "4.2.1", - "resolved": "https://registry.npmjs.org/@xtuc/long/-/long-4.2.1.tgz", - "integrity": "sha512-FZdkNBDqBRHKQ2MEbSC17xnPFOhZxeJ2YGSfr2BKf3sujG49Qe3bB+rGCwQfIaA7WHnGeGkSijX4FuBCdrzW/g==", - "dev": true - }, - "abbrev": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz", - "integrity": "sha512-nne9/IiQ/hzIhY6pdDnbBtz7DjPTKrY00P/zvPSm5pOFkl6xuGrGnXn/VtTNNfNtAfZ9/1RtehkszU9qcTii0Q==", - "dev": true, - "optional": true - }, - "acorn": { - "version": "5.7.3", - "resolved": "https://registry.npmjs.org/acorn/-/acorn-5.7.3.tgz", - "integrity": "sha512-T/zvzYRfbVojPWahDsE5evJdHb3oJoQfFbsrKM7w5Zcs++Tr257tia3BmMP8XYVjp1S9RZXQMh7gao96BlqZOw==", - "dev": true - }, - "acorn-dynamic-import": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/acorn-dynamic-import/-/acorn-dynamic-import-3.0.0.tgz", - "integrity": "sha512-zVWV8Z8lislJoOKKqdNMOB+s6+XV5WERty8MnKBeFgwA+19XJjJHs2RP5dzM57FftIs+jQnRToLiWazKr6sSWg==", - "dev": true, - "requires": { - "acorn": "^5.0.0" - } - }, - "ajv": { - "version": "6.7.0", - "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.7.0.tgz", - "integrity": "sha512-RZXPviBTtfmtka9n9sy1N5M5b82CbxWIR6HIis4s3WQTXDJamc/0gpCWNGz6EWdWp4DOfjzJfhz/AS9zVPjjWg==", - "dev": true, - "requires": { - "fast-deep-equal": "^2.0.1", - "fast-json-stable-stringify": "^2.0.0", - "json-schema-traverse": "^0.4.1", - "uri-js": "^4.2.2" - } - }, - "ajv-errors": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/ajv-errors/-/ajv-errors-1.0.1.tgz", - "integrity": "sha512-DCRfO/4nQ+89p/RK43i8Ezd41EqdGIU4ld7nGF8OQ14oc/we5rEntLCUa7+jrn3nn83BosfwZA0wb4pon2o8iQ==", - "dev": true - }, - "ajv-keywords": { - "version": "3.2.0", - "resolved": "https://registry.npmjs.org/ajv-keywords/-/ajv-keywords-3.2.0.tgz", - "integrity": "sha1-6GuBnGAs+IIa1jdBNpjx3sAhhHo=", - "dev": true - }, - "ansi-regex": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.1.1.tgz", - "integrity": "sha1-w7M6te42DYbg5ijwRorn7yfWVN8=", - "dev": true - }, - "ansi-styles": { - "version": "3.2.1", - "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz", - "integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==", - "dev": true, - "requires": { - "color-convert": "^1.9.0" - } - }, - "anymatch": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/anymatch/-/anymatch-2.0.0.tgz", - "integrity": "sha512-5teOsQWABXHHBFP9y3skS5P3d/WfWXpv3FUpy+LorMrNYaT9pI4oLMQX7jzQ2KklNpGpWHzdCXTDT2Y3XGlZBw==", - "dev": true, - "requires": { - "micromatch": "^3.1.4", - "normalize-path": "^2.1.1" - } - }, - "aproba": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/aproba/-/aproba-1.2.0.tgz", - "integrity": "sha512-Y9J6ZjXtoYh8RnXVCMOU/ttDmk1aBjunq9vO0ta5x85WDQiQfUF9sIPBITdbiiIVcBo03Hi3jMxigBtsddlXRw==", - "dev": true - }, - "are-we-there-yet": { - "version": "1.1.5", - "resolved": "https://registry.npmjs.org/are-we-there-yet/-/are-we-there-yet-1.1.5.tgz", - "integrity": "sha512-5hYdAkZlcG8tOLujVDTgCT+uPX0VnpAH28gWsLfzpXYm7wP6mp5Q/gYyR7YQ0cKVJcXJnl3j2kpBan13PtQf6w==", - "dev": true, - "optional": true, - "requires": { - "delegates": "^1.0.0", - "readable-stream": "^2.0.6" - } - }, - "arr-diff": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/arr-diff/-/arr-diff-4.0.0.tgz", - "integrity": "sha1-1kYQdP6/7HHn4VI1dhoyml3HxSA=", - "dev": true - }, - "arr-flatten": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/arr-flatten/-/arr-flatten-1.1.0.tgz", - "integrity": "sha512-L3hKV5R/p5o81R7O02IGnwpDmkp6E982XhtbuwSe3O4qOtMMMtodicASA1Cny2U+aCXcNpml+m4dPsvsJ3jatg==", - "dev": true - }, - "arr-union": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/arr-union/-/arr-union-3.1.0.tgz", - "integrity": "sha1-45sJrqne+Gao8gbiiK9jkZuuOcQ=", - "dev": true - }, - "array-unique": { - "version": "0.3.2", - "resolved": "https://registry.npmjs.org/array-unique/-/array-unique-0.3.2.tgz", - "integrity": "sha1-qJS3XUvE9s1nnvMkSp/Y9Gri1Cg=", - "dev": true - }, - "asn1.js": { - "version": "4.10.1", - "resolved": "https://registry.npmjs.org/asn1.js/-/asn1.js-4.10.1.tgz", - "integrity": "sha512-p32cOF5q0Zqs9uBiONKYLm6BClCoBCM5O9JfeUSlnQLBTxYdTK+pW+nXflm8UkKd2UYlEbYz5qEi0JuZR9ckSw==", - "dev": true, - "requires": { - "bn.js": "^4.0.0", - "inherits": "^2.0.1", - "minimalistic-assert": "^1.0.0" - } - }, - "assert": { - "version": "1.4.1", - "resolved": "https://registry.npmjs.org/assert/-/assert-1.4.1.tgz", - "integrity": "sha1-mZEtWRg2tab1s0XA8H7vwI/GXZE=", - "dev": true, - "requires": { - "util": "0.10.3" - }, - "dependencies": { - "inherits": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.1.tgz", - "integrity": "sha1-sX0I0ya0Qj5Wjv9xn5GwscvfafE=", - "dev": true - }, - "util": { - "version": "0.10.3", - "resolved": "https://registry.npmjs.org/util/-/util-0.10.3.tgz", - "integrity": "sha1-evsa/lCAUkZInj23/g7TeTNqwPk=", - "dev": true, - "requires": { - "inherits": "2.0.1" - } - } - } - }, - "assign-symbols": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/assign-symbols/-/assign-symbols-1.0.0.tgz", - "integrity": "sha1-WWZ/QfrdTyDMvCu5a41Pf3jsA2c=", - "dev": true - }, - "async-each": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/async-each/-/async-each-1.0.1.tgz", - "integrity": "sha1-GdOGodntxufByF04iu28xW0zYC0=", - "dev": true - }, - "atob": { - "version": "2.1.2", - "resolved": "https://registry.npmjs.org/atob/-/atob-2.1.2.tgz", - "integrity": "sha512-Wm6ukoaOGJi/73p/cl2GvLjTI5JM1k/O14isD73YML8StrH/7/lRFgmg8nICZgD3bZZvjwCGxtMOD3wWNAu8cg==", - "dev": true - }, - "babel-loader": { - "version": "8.0.5", - "resolved": "https://registry.npmjs.org/babel-loader/-/babel-loader-8.0.5.tgz", - "integrity": "sha512-NTnHnVRd2JnRqPC0vW+iOQWU5pchDbYXsG2E6DMXEpMfUcQKclF9gmf3G3ZMhzG7IG9ji4coL0cm+FxeWxDpnw==", - "dev": true, - "requires": { - "find-cache-dir": "^2.0.0", - "loader-utils": "^1.0.2", - "mkdirp": "^0.5.1", - "util.promisify": "^1.0.0" - } - }, - "balanced-match": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", - "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=", - "dev": true - }, - "base": { - "version": "0.11.2", - "resolved": "https://registry.npmjs.org/base/-/base-0.11.2.tgz", - "integrity": "sha512-5T6P4xPgpp0YDFvSWwEZ4NoE3aM4QBQXDzmVbraCkFj8zHM+mba8SyqB5DbZWyR7mYHo6Y7BdQo3MoA4m0TeQg==", - "dev": true, - "requires": { - "cache-base": "^1.0.1", - "class-utils": "^0.3.5", - "component-emitter": "^1.2.1", - "define-property": "^1.0.0", - "isobject": "^3.0.1", - "mixin-deep": "^1.2.0", - "pascalcase": "^0.1.1" - }, - "dependencies": { - "define-property": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/define-property/-/define-property-1.0.0.tgz", - "integrity": "sha1-dp66rz9KY6rTr56NMEybvnm/sOY=", - "dev": true, - "requires": { - "is-descriptor": "^1.0.0" - } - }, - "is-accessor-descriptor": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/is-accessor-descriptor/-/is-accessor-descriptor-1.0.0.tgz", - "integrity": "sha512-m5hnHTkcVsPfqx3AKlyttIPb7J+XykHvJP2B9bZDjlhLIoEq4XoK64Vg7boZlVWYK6LUY94dYPEE7Lh0ZkZKcQ==", - "dev": true, - "requires": { - "kind-of": "^6.0.0" - } - }, - "is-data-descriptor": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/is-data-descriptor/-/is-data-descriptor-1.0.0.tgz", - "integrity": "sha512-jbRXy1FmtAoCjQkVmIVYwuuqDFUbaOeDjmed1tOGPrsMhtJA4rD9tkgA0F1qJ3gRFRXcHYVkdeaP50Q5rE/jLQ==", - "dev": true, - "requires": { - "kind-of": "^6.0.0" - } - }, - "is-descriptor": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/is-descriptor/-/is-descriptor-1.0.2.tgz", - "integrity": "sha512-2eis5WqQGV7peooDyLmNEPUrps9+SXX5c9pL3xEB+4e9HnGuDa7mB7kHxHw4CbqS9k1T2hOH3miL8n8WtiYVtg==", - "dev": true, - "requires": { - "is-accessor-descriptor": "^1.0.0", - "is-data-descriptor": "^1.0.0", - "kind-of": "^6.0.2" - } - } - } - }, - "base64-js": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.3.0.tgz", - "integrity": "sha512-ccav/yGvoa80BQDljCxsmmQ3Xvx60/UpBIij5QN21W3wBi/hhIC9OoO+KLpu9IJTS9j4DRVJ3aDDF9cMSoa2lw==", - "dev": true - }, - "big.js": { - "version": "5.2.2", - "resolved": "https://registry.npmjs.org/big.js/-/big.js-5.2.2.tgz", - "integrity": "sha512-vyL2OymJxmarO8gxMr0mhChsO9QGwhynfuu4+MHTAW6czfq9humCB7rKpUjDd9YUiDPU4mzpyupFSvOClAwbmQ==", - "dev": true - }, - "binary-extensions": { - "version": "1.12.0", - "resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-1.12.0.tgz", - "integrity": "sha512-DYWGk01lDcxeS/K9IHPGWfT8PsJmbXRtRd2Sx72Tnb8pcYZQFF1oSDb8hJtS1vhp212q1Rzi5dUf9+nq0o9UIg==", - "dev": true - }, - "bluebird": { - "version": "3.5.3", - "resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.5.3.tgz", - "integrity": "sha512-/qKPUQlaW1OyR51WeCPBvRnAlnZFUJkCSG5HzGnuIqhgyJtF+T94lFnn33eiazjRm2LAHVy2guNnaq48X9SJuw==", - "dev": true - }, - "bn.js": { - "version": "4.11.8", - "resolved": "https://registry.npmjs.org/bn.js/-/bn.js-4.11.8.tgz", - "integrity": "sha512-ItfYfPLkWHUjckQCk8xC+LwxgK8NYcXywGigJgSwOP8Y2iyWT4f2vsZnoOXTTbo+o5yXmIUJ4gn5538SO5S3gA==", - "dev": true - }, - "brace-expansion": { - "version": "1.1.11", - "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", - "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", - "dev": true, - "requires": { - "balanced-match": "^1.0.0", - "concat-map": "0.0.1" - } - }, - "braces": { - "version": "2.3.2", - "resolved": "https://registry.npmjs.org/braces/-/braces-2.3.2.tgz", - "integrity": "sha512-aNdbnj9P8PjdXU4ybaWLK2IF3jc/EoDYbC7AazW6to3TRsfXxscC9UXOB5iDiEQrkyIbWp2SLQda4+QAa7nc3w==", - "dev": true, - "requires": { - "arr-flatten": "^1.1.0", - "array-unique": "^0.3.2", - "extend-shallow": "^2.0.1", - "fill-range": "^4.0.0", - "isobject": "^3.0.1", - "repeat-element": "^1.1.2", - "snapdragon": "^0.8.1", - "snapdragon-node": "^2.0.1", - "split-string": "^3.0.2", - "to-regex": "^3.0.1" - }, - "dependencies": { - "extend-shallow": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/extend-shallow/-/extend-shallow-2.0.1.tgz", - "integrity": "sha1-Ua99YUrZqfYQ6huvu5idaxxWiQ8=", - "dev": true, - "requires": { - "is-extendable": "^0.1.0" - } - } - } - }, - "brorand": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/brorand/-/brorand-1.1.0.tgz", - "integrity": "sha1-EsJe/kCkXjwyPrhnWgoM5XsiNx8=", - "dev": true - }, - "browserify-aes": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/browserify-aes/-/browserify-aes-1.2.0.tgz", - "integrity": "sha512-+7CHXqGuspUn/Sl5aO7Ea0xWGAtETPXNSAjHo48JfLdPWcMng33Xe4znFvQweqc/uzk5zSOI3H52CYnjCfb5hA==", - "dev": true, - "requires": { - "buffer-xor": "^1.0.3", - "cipher-base": "^1.0.0", - "create-hash": "^1.1.0", - "evp_bytestokey": "^1.0.3", - "inherits": "^2.0.1", - "safe-buffer": "^5.0.1" - } - }, - "browserify-cipher": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/browserify-cipher/-/browserify-cipher-1.0.1.tgz", - "integrity": "sha512-sPhkz0ARKbf4rRQt2hTpAHqn47X3llLkUGn+xEJzLjwY8LRs2p0v7ljvI5EyoRO/mexrNunNECisZs+gw2zz1w==", - "dev": true, - "requires": { - "browserify-aes": "^1.0.4", - "browserify-des": "^1.0.0", - "evp_bytestokey": "^1.0.0" - } - }, - "browserify-des": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/browserify-des/-/browserify-des-1.0.2.tgz", - "integrity": "sha512-BioO1xf3hFwz4kc6iBhI3ieDFompMhrMlnDFC4/0/vd5MokpuAc3R+LYbwTA9A5Yc9pq9UYPqffKpW2ObuwX5A==", - "dev": true, - "requires": { - "cipher-base": "^1.0.1", - "des.js": "^1.0.0", - "inherits": "^2.0.1", - "safe-buffer": "^5.1.2" - } - }, - "browserify-rsa": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/browserify-rsa/-/browserify-rsa-4.0.1.tgz", - "integrity": "sha1-IeCr+vbyApzy+vsTNWenAdQTVSQ=", - "dev": true, - "requires": { - "bn.js": "^4.1.0", - "randombytes": "^2.0.1" - } - }, - "browserify-sign": { - "version": "4.0.4", - "resolved": "https://registry.npmjs.org/browserify-sign/-/browserify-sign-4.0.4.tgz", - "integrity": "sha1-qk62jl17ZYuqa/alfmMMvXqT0pg=", - "dev": true, - "requires": { - "bn.js": "^4.1.1", - "browserify-rsa": "^4.0.0", - "create-hash": "^1.1.0", - "create-hmac": "^1.1.2", - "elliptic": "^6.0.0", - "inherits": "^2.0.1", - "parse-asn1": "^5.0.0" - } - }, - "browserify-zlib": { - "version": "0.2.0", - "resolved": "https://registry.npmjs.org/browserify-zlib/-/browserify-zlib-0.2.0.tgz", - "integrity": "sha512-Z942RysHXmJrhqk88FmKBVq/v5tqmSkDz7p54G/MGyjMnCFFnC79XWNbg+Vta8W6Wb2qtSZTSxIGkJrRpCFEiA==", - "dev": true, - "requires": { - "pako": "~1.0.5" - } - }, - "browserslist": { - "version": "4.4.0", - "resolved": "https://registry.npmjs.org/browserslist/-/browserslist-4.4.0.tgz", - "integrity": "sha512-tQkHS8VVxWbrjnNDXgt7/+SuPJ7qDvD0Y2e6bLtoQluR2SPvlmPUcfcU75L1KAalhqULlIFJlJ6BDfnYyJxJsw==", - "dev": true, - "requires": { - "caniuse-lite": "^1.0.30000928", - "electron-to-chromium": "^1.3.100", - "node-releases": "^1.1.3" - } - }, - "buffer": { - "version": "4.9.1", - "resolved": "https://registry.npmjs.org/buffer/-/buffer-4.9.1.tgz", - "integrity": "sha1-bRu2AbB6TvztlwlBMgkwJ8lbwpg=", - "dev": true, - "requires": { - "base64-js": "^1.0.2", - "ieee754": "^1.1.4", - "isarray": "^1.0.0" - } - }, - "buffer-from": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.1.tgz", - "integrity": "sha512-MQcXEUbCKtEo7bhqEs6560Hyd4XaovZlO/k9V3hjVUF/zwW7KBVdSK4gIt/bzwS9MbR5qob+F5jusZsb0YQK2A==", - "dev": true - }, - "buffer-xor": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/buffer-xor/-/buffer-xor-1.0.3.tgz", - "integrity": "sha1-JuYe0UIvtw3ULm42cp7VHYVf6Nk=", - "dev": true - }, - "builtin-status-codes": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/builtin-status-codes/-/builtin-status-codes-3.0.0.tgz", - "integrity": "sha1-hZgoeOIbmOHGZCXgPQF0eI9Wnug=", - "dev": true - }, - "cacache": { - "version": "11.3.2", - "resolved": "https://registry.npmjs.org/cacache/-/cacache-11.3.2.tgz", - "integrity": "sha512-E0zP4EPGDOaT2chM08Als91eYnf8Z+eH1awwwVsngUmgppfM5jjJ8l3z5vO5p5w/I3LsiXawb1sW0VY65pQABg==", - "dev": true, - "requires": { - "bluebird": "^3.5.3", - "chownr": "^1.1.1", - "figgy-pudding": "^3.5.1", - "glob": "^7.1.3", - "graceful-fs": "^4.1.15", - "lru-cache": "^5.1.1", - "mississippi": "^3.0.0", - "mkdirp": "^0.5.1", - "move-concurrently": "^1.0.1", - "promise-inflight": "^1.0.1", - "rimraf": "^2.6.2", - "ssri": "^6.0.1", - "unique-filename": "^1.1.1", - "y18n": "^4.0.0" - } - }, - "cache-base": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/cache-base/-/cache-base-1.0.1.tgz", - "integrity": "sha512-AKcdTnFSWATd5/GCPRxr2ChwIJ85CeyrEyjRHlKxQ56d4XJMGym0uAiKn0xbLOGOl3+yRpOTi484dVCEc5AUzQ==", - "dev": true, - "requires": { - "collection-visit": "^1.0.0", - "component-emitter": "^1.2.1", - "get-value": "^2.0.6", - "has-value": "^1.0.0", - "isobject": "^3.0.1", - "set-value": "^2.0.0", - "to-object-path": "^0.3.0", - "union-value": "^1.0.0", - "unset-value": "^1.0.0" - } - }, - "camelcase": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-5.0.0.tgz", - "integrity": "sha512-faqwZqnWxbxn+F1d399ygeamQNy3lPp/H9H6rNrqYh4FSVCtcY+3cub1MxA8o9mDd55mM8Aghuu/kuyYA6VTsA==", - "dev": true - }, - "caniuse-lite": { - "version": "1.0.30000929", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30000929.tgz", - "integrity": "sha512-n2w1gPQSsYyorSVYqPMqbSaz1w7o9ZC8VhOEGI9T5MfGDzp7sbopQxG6GaQmYsaq13Xfx/mkxJUWC1Dz3oZfzw==", - "dev": true - }, - "chalk": { - "version": "2.4.2", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz", - "integrity": "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==", - "dev": true, - "requires": { - "ansi-styles": "^3.2.1", - "escape-string-regexp": "^1.0.5", - "supports-color": "^5.3.0" - } - }, - "chokidar": { - "version": "2.0.4", - "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-2.0.4.tgz", - "integrity": "sha512-z9n7yt9rOvIJrMhvDtDictKrkFHeihkNl6uWMmZlmL6tJtX9Cs+87oK+teBx+JIgzvbX3yZHT3eF8vpbDxHJXQ==", - "dev": true, - "requires": { - "anymatch": "^2.0.0", - "async-each": "^1.0.0", - "braces": "^2.3.0", - "fsevents": "^1.2.2", - "glob-parent": "^3.1.0", - "inherits": "^2.0.1", - "is-binary-path": "^1.0.0", - "is-glob": "^4.0.0", - "lodash.debounce": "^4.0.8", - "normalize-path": "^2.1.1", - "path-is-absolute": "^1.0.0", - "readdirp": "^2.0.0", - "upath": "^1.0.5" - } - }, - "chownr": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/chownr/-/chownr-1.1.1.tgz", - "integrity": "sha512-j38EvO5+LHX84jlo6h4UzmOwi0UgW61WRyPtJz4qaadK5eY3BTS5TY/S1Stc3Uk2lIM6TPevAlULiEJwie860g==", - "dev": true - }, - "chrome-trace-event": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/chrome-trace-event/-/chrome-trace-event-1.0.0.tgz", - "integrity": "sha512-xDbVgyfDTT2piup/h8dK/y4QZfJRSa73bw1WZ8b4XM1o7fsFubUVGYcE+1ANtOzJJELGpYoG2961z0Z6OAld9A==", - "dev": true, - "requires": { - "tslib": "^1.9.0" - } - }, - "cipher-base": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/cipher-base/-/cipher-base-1.0.4.tgz", - "integrity": "sha512-Kkht5ye6ZGmwv40uUDZztayT2ThLQGfnj/T71N/XzeZeo3nf8foyW7zGTsPYkEya3m5f3cAypH+qe7YOrM1U2Q==", - "dev": true, - "requires": { - "inherits": "^2.0.1", - "safe-buffer": "^5.0.1" - } - }, - "class-utils": { - "version": "0.3.6", - "resolved": "https://registry.npmjs.org/class-utils/-/class-utils-0.3.6.tgz", - "integrity": "sha512-qOhPa/Fj7s6TY8H8esGu5QNpMMQxz79h+urzrNYN6mn+9BnxlDGf5QZ+XeCDsxSjPqsSR56XOZOJmpeurnLMeg==", - "dev": true, - "requires": { - "arr-union": "^3.1.0", - "define-property": "^0.2.5", - "isobject": "^3.0.0", - "static-extend": "^0.1.1" - }, - "dependencies": { - "define-property": { - "version": "0.2.5", - "resolved": "https://registry.npmjs.org/define-property/-/define-property-0.2.5.tgz", - "integrity": "sha1-w1se+RjsPJkPmlvFe+BKrOxcgRY=", - "dev": true, - "requires": { - "is-descriptor": "^0.1.0" - } - } - } - }, - "clean-webpack-plugin": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/clean-webpack-plugin/-/clean-webpack-plugin-1.0.0.tgz", - "integrity": "sha512-+f96f52UIET4tOFBbCqezx7KH+w7lz/p4fA1FEjf0hC6ugxqwZedBtENzekN2FnmoTF/bn1LrlkvebOsDZuXKw==", - "dev": true, - "requires": { - "rimraf": "^2.6.1" - } - }, - "cliui": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/cliui/-/cliui-4.1.0.tgz", - "integrity": "sha512-4FG+RSG9DL7uEwRUZXZn3SS34DiDPfzP0VOiEwtUWlE+AR2EIg+hSyvrIgUUfhdgR/UkAeW2QHgeP+hWrXs7jQ==", - "dev": true, - "requires": { - "string-width": "^2.1.1", - "strip-ansi": "^4.0.0", - "wrap-ansi": "^2.0.0" - }, - "dependencies": { - "ansi-regex": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-3.0.0.tgz", - "integrity": "sha1-7QMXwyIGT3lGbAKWa922Bas32Zg=", - "dev": true - }, - "is-fullwidth-code-point": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz", - "integrity": "sha1-o7MKXE8ZkYMWeqq5O+764937ZU8=", - "dev": true - }, - "string-width": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/string-width/-/string-width-2.1.1.tgz", - "integrity": "sha512-nOqH59deCq9SRHlxq1Aw85Jnt4w6KvLKqWVik6oA9ZklXLNIOlqg4F2yrT1MVaTjAqvVwdfeZ7w7aCvJD7ugkw==", - "dev": true, - "requires": { - "is-fullwidth-code-point": "^2.0.0", - "strip-ansi": "^4.0.0" - } - }, - "strip-ansi": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-4.0.0.tgz", - "integrity": "sha1-qEeQIusaw2iocTibY1JixQXuNo8=", - "dev": true, - "requires": { - "ansi-regex": "^3.0.0" - } - } - } - }, - "code-point-at": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/code-point-at/-/code-point-at-1.1.0.tgz", - "integrity": "sha1-DQcLTQQ6W+ozovGkDi7bPZpMz3c=", - "dev": true - }, - "collection-visit": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/collection-visit/-/collection-visit-1.0.0.tgz", - "integrity": "sha1-S8A3PBZLwykbTTaMgpzxqApZ3KA=", - "dev": true, - "requires": { - "map-visit": "^1.0.0", - "object-visit": "^1.0.0" - } - }, - "color-convert": { - "version": "1.9.3", - "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz", - "integrity": "sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==", - "dev": true, - "requires": { - "color-name": "1.1.3" - } - }, - "color-name": { - "version": "1.1.3", - "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", - "integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=", - "dev": true - }, - "commander": { - "version": "2.17.1", - "resolved": "https://registry.npmjs.org/commander/-/commander-2.17.1.tgz", - "integrity": "sha512-wPMUt6FnH2yzG95SA6mzjQOEKUU3aLaDEmzs1ti+1E9h+CsrZghRlqEM/EJ4KscsQVG8uNN4uVreUeT8+drlgg==", - "dev": true - }, - "commondir": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/commondir/-/commondir-1.0.1.tgz", - "integrity": "sha1-3dgA2gxmEnOTzKWVDqloo6rxJTs=", - "dev": true - }, - "component-emitter": { - "version": "1.2.1", - "resolved": "https://registry.npmjs.org/component-emitter/-/component-emitter-1.2.1.tgz", - "integrity": "sha1-E3kY1teCg/ffemt8WmPhQOaUJeY=", - "dev": true - }, - "concat-map": { - "version": "0.0.1", - "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", - "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=", - "dev": true - }, - "concat-stream": { - "version": "1.6.2", - "resolved": "https://registry.npmjs.org/concat-stream/-/concat-stream-1.6.2.tgz", - "integrity": "sha512-27HBghJxjiZtIk3Ycvn/4kbJk/1uZuJFfuPEns6LaEvpvG1f0hTea8lilrouyo9mVc2GWdcEZ8OLoGmSADlrCw==", - "dev": true, - "requires": { - "buffer-from": "^1.0.0", - "inherits": "^2.0.3", - "readable-stream": "^2.2.2", - "typedarray": "^0.0.6" - } - }, - "console-browserify": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/console-browserify/-/console-browserify-1.1.0.tgz", - "integrity": "sha1-8CQcRXMKn8YyOyBtvzjtx0HQuxA=", - "dev": true, - "requires": { - "date-now": "^0.1.4" - } - }, - "console-control-strings": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/console-control-strings/-/console-control-strings-1.1.0.tgz", - "integrity": "sha1-PXz0Rk22RG6mRL9LOVB/mFEAjo4=", - "dev": true, - "optional": true - }, - "constants-browserify": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/constants-browserify/-/constants-browserify-1.0.0.tgz", - "integrity": "sha1-wguW2MYXdIqvHBYCF2DNJ/y4y3U=", - "dev": true - }, - "convert-source-map": { - "version": "1.6.0", - "resolved": "https://registry.npmjs.org/convert-source-map/-/convert-source-map-1.6.0.tgz", - "integrity": "sha512-eFu7XigvxdZ1ETfbgPBohgyQ/Z++C0eEhTor0qRwBw9unw+L0/6V8wkSuGgzdThkiS5lSpdptOQPD8Ak40a+7A==", - "dev": true, - "requires": { - "safe-buffer": "~5.1.1" - } - }, - "copy-concurrently": { - "version": "1.0.5", - "resolved": "https://registry.npmjs.org/copy-concurrently/-/copy-concurrently-1.0.5.tgz", - "integrity": "sha512-f2domd9fsVDFtaFcbaRZuYXwtdmnzqbADSwhSWYxYB/Q8zsdUUFMXVRwXGDMWmbEzAn1kdRrtI1T/KTFOL4X2A==", - "dev": true, - "requires": { - "aproba": "^1.1.1", - "fs-write-stream-atomic": "^1.0.8", - "iferr": "^0.1.5", - "mkdirp": "^0.5.1", - "rimraf": "^2.5.4", - "run-queue": "^1.0.0" - } - }, - "copy-descriptor": { - "version": "0.1.1", - "resolved": "https://registry.npmjs.org/copy-descriptor/-/copy-descriptor-0.1.1.tgz", - "integrity": "sha1-Z29us8OZl8LuGsOpJP1hJHSPV40=", - "dev": true - }, - "core-util-is": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz", - "integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=", - "dev": true - }, - "create-ecdh": { - "version": "4.0.3", - "resolved": "https://registry.npmjs.org/create-ecdh/-/create-ecdh-4.0.3.tgz", - "integrity": "sha512-GbEHQPMOswGpKXM9kCWVrremUcBmjteUaQ01T9rkKCPDXfUHX0IoP9LpHYo2NPFampa4e+/pFDc3jQdxrxQLaw==", - "dev": true, - "requires": { - "bn.js": "^4.1.0", - "elliptic": "^6.0.0" - } - }, - "create-hash": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/create-hash/-/create-hash-1.2.0.tgz", - "integrity": "sha512-z00bCGNHDG8mHAkP7CtT1qVu+bFQUPjYq/4Iv3C3kWjTFV10zIjfSoeqXo9Asws8gwSHDGj/hl2u4OGIjapeCg==", - "dev": true, - "requires": { - "cipher-base": "^1.0.1", - "inherits": "^2.0.1", - "md5.js": "^1.3.4", - "ripemd160": "^2.0.1", - "sha.js": "^2.4.0" - } - }, - "create-hmac": { - "version": "1.1.7", - "resolved": "https://registry.npmjs.org/create-hmac/-/create-hmac-1.1.7.tgz", - "integrity": "sha512-MJG9liiZ+ogc4TzUwuvbER1JRdgvUFSB5+VR/g5h82fGaIRWMWddtKBHi7/sVhfjQZ6SehlyhvQYrcYkaUIpLg==", - "dev": true, - "requires": { - "cipher-base": "^1.0.3", - "create-hash": "^1.1.0", - "inherits": "^2.0.1", - "ripemd160": "^2.0.0", - "safe-buffer": "^5.0.1", - "sha.js": "^2.4.8" - } - }, - "cross-spawn": { - "version": "6.0.5", - "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-6.0.5.tgz", - "integrity": "sha512-eTVLrBSt7fjbDygz805pMnstIs2VTBNkRm0qxZd+M7A5XDdxVRWO5MxGBXZhjY4cqLYLdtrGqRf8mBPmzwSpWQ==", - "dev": true, - "requires": { - "nice-try": "^1.0.4", - "path-key": "^2.0.1", - "semver": "^5.5.0", - "shebang-command": "^1.2.0", - "which": "^1.2.9" - } - }, - "crypto-browserify": { - "version": "3.12.0", - "resolved": "https://registry.npmjs.org/crypto-browserify/-/crypto-browserify-3.12.0.tgz", - "integrity": "sha512-fz4spIh+znjO2VjL+IdhEpRJ3YN6sMzITSBijk6FK2UvTqruSQW+/cCZTSNsMiZNvUeq0CqurF+dAbyiGOY6Wg==", - "dev": true, - "requires": { - "browserify-cipher": "^1.0.0", - "browserify-sign": "^4.0.0", - "create-ecdh": "^4.0.0", - "create-hash": "^1.1.0", - "create-hmac": "^1.1.0", - "diffie-hellman": "^5.0.0", - "inherits": "^2.0.1", - "pbkdf2": "^3.0.3", - "public-encrypt": "^4.0.0", - "randombytes": "^2.0.0", - "randomfill": "^1.0.3" - } - }, - "cyclist": { - "version": "0.2.2", - "resolved": "https://registry.npmjs.org/cyclist/-/cyclist-0.2.2.tgz", - "integrity": "sha1-GzN5LhHpFKL9bW7WRHRkRE5fpkA=", - "dev": true - }, - "date-now": { - "version": "0.1.4", - "resolved": "https://registry.npmjs.org/date-now/-/date-now-0.1.4.tgz", - "integrity": "sha1-6vQ5/U1ISK105cx9vvIAZyueNFs=", - "dev": true - }, - "debug": { - "version": "4.1.1", - "resolved": "https://registry.npmjs.org/debug/-/debug-4.1.1.tgz", - "integrity": "sha512-pYAIzeRo8J6KPEaJ0VWOh5Pzkbw/RetuzehGM7QRRX5he4fPHx2rdKMB256ehJCkX+XRQm16eZLqLNS8RSZXZw==", - "dev": true, - "requires": { - "ms": "^2.1.1" - } - }, - "decamelize": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/decamelize/-/decamelize-1.2.0.tgz", - "integrity": "sha1-9lNNFRSCabIDUue+4m9QH5oZEpA=", - "dev": true - }, - "decode-uri-component": { - "version": "0.2.0", - "resolved": "https://registry.npmjs.org/decode-uri-component/-/decode-uri-component-0.2.0.tgz", - "integrity": "sha1-6zkTMzRYd1y4TNGh+uBiEGu4dUU=", - "dev": true - }, - "deep-extend": { - "version": "0.6.0", - "resolved": "https://registry.npmjs.org/deep-extend/-/deep-extend-0.6.0.tgz", - "integrity": "sha512-LOHxIOaPYdHlJRtCQfDIVZtfw/ufM8+rVj649RIHzcm/vGwQRXFt6OPqIFWsm2XEMrNIEtWR64sY1LEKD2vAOA==", - "dev": true, - "optional": true - }, - "define-properties": { - "version": "1.1.3", - "resolved": "https://registry.npmjs.org/define-properties/-/define-properties-1.1.3.tgz", - "integrity": "sha512-3MqfYKj2lLzdMSf8ZIZE/V+Zuy+BgD6f164e8K2w7dgnpKArBDerGYpM46IYYcjnkdPNMjPk9A6VFB8+3SKlXQ==", - "dev": true, - "requires": { - "object-keys": "^1.0.12" - } - }, - "define-property": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/define-property/-/define-property-2.0.2.tgz", - "integrity": "sha512-jwK2UV4cnPpbcG7+VRARKTZPUWowwXA8bzH5NP6ud0oeAxyYPuGZUAC7hMugpCdz4BeSZl2Dl9k66CHJ/46ZYQ==", - "dev": true, - "requires": { - "is-descriptor": "^1.0.2", - "isobject": "^3.0.1" - }, - "dependencies": { - "is-accessor-descriptor": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/is-accessor-descriptor/-/is-accessor-descriptor-1.0.0.tgz", - "integrity": "sha512-m5hnHTkcVsPfqx3AKlyttIPb7J+XykHvJP2B9bZDjlhLIoEq4XoK64Vg7boZlVWYK6LUY94dYPEE7Lh0ZkZKcQ==", - "dev": true, - "requires": { - "kind-of": "^6.0.0" - } - }, - "is-data-descriptor": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/is-data-descriptor/-/is-data-descriptor-1.0.0.tgz", - "integrity": "sha512-jbRXy1FmtAoCjQkVmIVYwuuqDFUbaOeDjmed1tOGPrsMhtJA4rD9tkgA0F1qJ3gRFRXcHYVkdeaP50Q5rE/jLQ==", - "dev": true, - "requires": { - "kind-of": "^6.0.0" - } - }, - "is-descriptor": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/is-descriptor/-/is-descriptor-1.0.2.tgz", - "integrity": "sha512-2eis5WqQGV7peooDyLmNEPUrps9+SXX5c9pL3xEB+4e9HnGuDa7mB7kHxHw4CbqS9k1T2hOH3miL8n8WtiYVtg==", - "dev": true, - "requires": { - "is-accessor-descriptor": "^1.0.0", - "is-data-descriptor": "^1.0.0", - "kind-of": "^6.0.2" - } - } - } - }, - "delegates": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/delegates/-/delegates-1.0.0.tgz", - "integrity": "sha1-hMbhWbgZBP3KWaDvRM2HDTElD5o=", - "dev": true, - "optional": true - }, - "des.js": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/des.js/-/des.js-1.0.0.tgz", - "integrity": "sha1-wHTS4qpqipoH29YfmhXCzYPsjsw=", - "dev": true, - "requires": { - "inherits": "^2.0.1", - "minimalistic-assert": "^1.0.0" - } - }, - "detect-file": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/detect-file/-/detect-file-1.0.0.tgz", - "integrity": "sha1-8NZtA2cqglyxtzvbP+YjEMjlUrc=", - "dev": true - }, - "detect-libc": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-1.0.3.tgz", - "integrity": "sha1-+hN8S9aY7fVc1c0CrFWfkaTEups=", - "dev": true, - "optional": true - }, - "diffie-hellman": { - "version": "5.0.3", - "resolved": "https://registry.npmjs.org/diffie-hellman/-/diffie-hellman-5.0.3.tgz", - "integrity": "sha512-kqag/Nl+f3GwyK25fhUMYj81BUOrZ9IuJsjIcDE5icNM9FJHAVm3VcUDxdLPoQtTuUylWm6ZIknYJwwaPxsUzg==", - "dev": true, - "requires": { - "bn.js": "^4.1.0", - "miller-rabin": "^4.0.0", - "randombytes": "^2.0.0" - } - }, - "domain-browser": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/domain-browser/-/domain-browser-1.2.0.tgz", - "integrity": "sha512-jnjyiM6eRyZl2H+W8Q/zLMA481hzi0eszAaBUzIVnmYVDBbnLxVNnfu1HgEBvCbL+71FrxMl3E6lpKH7Ge3OXA==", - "dev": true - }, - "duplexify": { - "version": "3.6.1", - "resolved": "https://registry.npmjs.org/duplexify/-/duplexify-3.6.1.tgz", - "integrity": "sha512-vM58DwdnKmty+FSPzT14K9JXb90H+j5emaR4KYbr2KTIz00WHGbWOe5ghQTx233ZCLZtrGDALzKwcjEtSt35mA==", - "dev": true, - "requires": { - "end-of-stream": "^1.0.0", - "inherits": "^2.0.1", - "readable-stream": "^2.0.0", - "stream-shift": "^1.0.0" - } - }, - "electron-to-chromium": { - "version": "1.3.103", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.103.tgz", - "integrity": "sha512-tObPqGmY9X8MUM8i3MEimYmbnLLf05/QV5gPlkR8MQ3Uj8G8B2govE1U4cQcBYtv3ymck9Y8cIOu4waoiykMZQ==", - "dev": true - }, - "elliptic": { - "version": "6.4.1", - "resolved": "https://registry.npmjs.org/elliptic/-/elliptic-6.4.1.tgz", - "integrity": "sha512-BsXLz5sqX8OHcsh7CqBMztyXARmGQ3LWPtGjJi6DiJHq5C/qvi9P3OqgswKSDftbu8+IoI/QDTAm2fFnQ9SZSQ==", - "dev": true, - "requires": { - "bn.js": "^4.4.0", - "brorand": "^1.0.1", - "hash.js": "^1.0.0", - "hmac-drbg": "^1.0.0", - "inherits": "^2.0.1", - "minimalistic-assert": "^1.0.0", - "minimalistic-crypto-utils": "^1.0.0" - } - }, - "emojis-list": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/emojis-list/-/emojis-list-2.1.0.tgz", - "integrity": "sha1-TapNnbAPmBmIDHn6RXrlsJof04k=", - "dev": true - }, - "end-of-stream": { - "version": "1.4.1", - "resolved": "https://registry.npmjs.org/end-of-stream/-/end-of-stream-1.4.1.tgz", - "integrity": "sha512-1MkrZNvWTKCaigbn+W15elq2BB/L22nqrSY5DKlo3X6+vclJm8Bb5djXJBmEX6fS3+zCh/F4VBK5Z2KxJt4s2Q==", - "dev": true, - "requires": { - "once": "^1.4.0" - } - }, - "enhanced-resolve": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/enhanced-resolve/-/enhanced-resolve-4.1.0.tgz", - "integrity": "sha512-F/7vkyTtyc/llOIn8oWclcB25KdRaiPBpZYDgJHgh/UHtpgT2p2eldQgtQnLtUvfMKPKxbRaQM/hHkvLHt1Vng==", - "dev": true, - "requires": { - "graceful-fs": "^4.1.2", - "memory-fs": "^0.4.0", - "tapable": "^1.0.0" - } - }, - "errno": { - "version": "0.1.7", - "resolved": "https://registry.npmjs.org/errno/-/errno-0.1.7.tgz", - "integrity": "sha512-MfrRBDWzIWifgq6tJj60gkAwtLNb6sQPlcFrSOflcP1aFmmruKQ2wRnze/8V6kgyz7H3FF8Npzv78mZ7XLLflg==", - "dev": true, - "requires": { - "prr": "~1.0.1" - } - }, - "es-abstract": { - "version": "1.13.0", - "resolved": "https://registry.npmjs.org/es-abstract/-/es-abstract-1.13.0.tgz", - "integrity": "sha512-vDZfg/ykNxQVwup/8E1BZhVzFfBxs9NqMzGcvIJrqg5k2/5Za2bWo40dK2J1pgLngZ7c+Shh8lwYtLGyrwPutg==", - "dev": true, - "requires": { - "es-to-primitive": "^1.2.0", - "function-bind": "^1.1.1", - "has": "^1.0.3", - "is-callable": "^1.1.4", - "is-regex": "^1.0.4", - "object-keys": "^1.0.12" - } - }, - "es-to-primitive": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/es-to-primitive/-/es-to-primitive-1.2.0.tgz", - "integrity": "sha512-qZryBOJjV//LaxLTV6UC//WewneB3LcXOL9NP++ozKVXsIIIpm/2c13UDiD9Jp2eThsecw9m3jPqDwTyobcdbg==", - "dev": true, - "requires": { - "is-callable": "^1.1.4", - "is-date-object": "^1.0.1", - "is-symbol": "^1.0.2" - } - }, - "escape-string-regexp": { - "version": "1.0.5", - "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", - "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=", - "dev": true - }, - "eslint-scope": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-4.0.0.tgz", - "integrity": "sha512-1G6UTDi7Jc1ELFwnR58HV4fK9OQK4S6N985f166xqXxpjU6plxFISJa2Ba9KCQuFa8RCnj/lSFJbHo7UFDBnUA==", - "dev": true, - "requires": { - "esrecurse": "^4.1.0", - "estraverse": "^4.1.1" - } - }, - "esrecurse": { - "version": "4.2.1", - "resolved": "https://registry.npmjs.org/esrecurse/-/esrecurse-4.2.1.tgz", - "integrity": "sha512-64RBB++fIOAXPw3P9cy89qfMlvZEXZkqqJkjqqXIvzP5ezRZjW+lPWjw35UX/3EhUPFYbg5ER4JYgDw4007/DQ==", - "dev": true, - "requires": { - "estraverse": "^4.1.0" - } - }, - "estraverse": { - "version": "4.2.0", - "resolved": "https://registry.npmjs.org/estraverse/-/estraverse-4.2.0.tgz", - "integrity": "sha1-De4/7TH81GlhjOc0IJn8GvoL2xM=", - "dev": true - }, - "esutils": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/esutils/-/esutils-2.0.2.tgz", - "integrity": "sha1-Cr9PHKpbyx96nYrMbepPqqBLrJs=", - "dev": true - }, - "events": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/events/-/events-1.1.1.tgz", - "integrity": "sha1-nr23Y1rQmccNzEwqH1AEKI6L2SQ=", - "dev": true - }, - "evp_bytestokey": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/evp_bytestokey/-/evp_bytestokey-1.0.3.tgz", - "integrity": "sha512-/f2Go4TognH/KvCISP7OUsHn85hT9nUkxxA9BEWxFn+Oj9o8ZNLm/40hdlgSLyuOimsrTKLUMEorQexp/aPQeA==", - "dev": true, - "requires": { - "md5.js": "^1.3.4", - "safe-buffer": "^5.1.1" - } - }, - "execa": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/execa/-/execa-1.0.0.tgz", - "integrity": "sha512-adbxcyWV46qiHyvSp50TKt05tB4tK3HcmF7/nxfAdhnox83seTDbwnaqKO4sXRy7roHAIFqJP/Rw/AuEbX61LA==", - "dev": true, - "requires": { - "cross-spawn": "^6.0.0", - "get-stream": "^4.0.0", - "is-stream": "^1.1.0", - "npm-run-path": "^2.0.0", - "p-finally": "^1.0.0", - "signal-exit": "^3.0.0", - "strip-eof": "^1.0.0" - } - }, - "expand-brackets": { - "version": "2.1.4", - "resolved": "https://registry.npmjs.org/expand-brackets/-/expand-brackets-2.1.4.tgz", - "integrity": "sha1-t3c14xXOMPa27/D4OwQVGiJEliI=", - "dev": true, - "requires": { - "debug": "^2.3.3", - "define-property": "^0.2.5", - "extend-shallow": "^2.0.1", - "posix-character-classes": "^0.1.0", - "regex-not": "^1.0.0", - "snapdragon": "^0.8.1", - "to-regex": "^3.0.1" - }, - "dependencies": { - "debug": { - "version": "2.6.9", - "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", - "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", - "dev": true, - "requires": { - "ms": "2.0.0" - } - }, - "define-property": { - "version": "0.2.5", - "resolved": "https://registry.npmjs.org/define-property/-/define-property-0.2.5.tgz", - "integrity": "sha1-w1se+RjsPJkPmlvFe+BKrOxcgRY=", - "dev": true, - "requires": { - "is-descriptor": "^0.1.0" - } - }, - "extend-shallow": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/extend-shallow/-/extend-shallow-2.0.1.tgz", - "integrity": "sha1-Ua99YUrZqfYQ6huvu5idaxxWiQ8=", - "dev": true, - "requires": { - "is-extendable": "^0.1.0" - } - }, - "ms": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", - "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=", - "dev": true - } - } - }, - "expand-tilde": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/expand-tilde/-/expand-tilde-2.0.2.tgz", - "integrity": "sha1-l+gBqgUt8CRU3kawK/YhZCzchQI=", - "dev": true, - "requires": { - "homedir-polyfill": "^1.0.1" - } - }, - "extend-shallow": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/extend-shallow/-/extend-shallow-3.0.2.tgz", - "integrity": "sha1-Jqcarwc7OfshJxcnRhMcJwQCjbg=", - "dev": true, - "requires": { - "assign-symbols": "^1.0.0", - "is-extendable": "^1.0.1" - }, - "dependencies": { - "is-extendable": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/is-extendable/-/is-extendable-1.0.1.tgz", - "integrity": "sha512-arnXMxT1hhoKo9k1LZdmlNyJdDDfy2v0fXjFlmok4+i8ul/6WlbVge9bhM74OpNPQPMGUToDtz+KXa1PneJxOA==", - "dev": true, - "requires": { - "is-plain-object": "^2.0.4" - } - } - } - }, - "extglob": { - "version": "2.0.4", - "resolved": "https://registry.npmjs.org/extglob/-/extglob-2.0.4.tgz", - "integrity": "sha512-Nmb6QXkELsuBr24CJSkilo6UHHgbekK5UiZgfE6UHD3Eb27YC6oD+bhcT+tJ6cl8dmsgdQxnWlcry8ksBIBLpw==", - "dev": true, - "requires": { - "array-unique": "^0.3.2", - "define-property": "^1.0.0", - "expand-brackets": "^2.1.4", - "extend-shallow": "^2.0.1", - "fragment-cache": "^0.2.1", - "regex-not": "^1.0.0", - "snapdragon": "^0.8.1", - "to-regex": "^3.0.1" - }, - "dependencies": { - "define-property": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/define-property/-/define-property-1.0.0.tgz", - "integrity": "sha1-dp66rz9KY6rTr56NMEybvnm/sOY=", - "dev": true, - "requires": { - "is-descriptor": "^1.0.0" - } - }, - "extend-shallow": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/extend-shallow/-/extend-shallow-2.0.1.tgz", - "integrity": "sha1-Ua99YUrZqfYQ6huvu5idaxxWiQ8=", - "dev": true, - "requires": { - "is-extendable": "^0.1.0" - } - }, - "is-accessor-descriptor": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/is-accessor-descriptor/-/is-accessor-descriptor-1.0.0.tgz", - "integrity": "sha512-m5hnHTkcVsPfqx3AKlyttIPb7J+XykHvJP2B9bZDjlhLIoEq4XoK64Vg7boZlVWYK6LUY94dYPEE7Lh0ZkZKcQ==", - "dev": true, - "requires": { - "kind-of": "^6.0.0" - } - }, - "is-data-descriptor": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/is-data-descriptor/-/is-data-descriptor-1.0.0.tgz", - "integrity": "sha512-jbRXy1FmtAoCjQkVmIVYwuuqDFUbaOeDjmed1tOGPrsMhtJA4rD9tkgA0F1qJ3gRFRXcHYVkdeaP50Q5rE/jLQ==", - "dev": true, - "requires": { - "kind-of": "^6.0.0" - } - }, - "is-descriptor": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/is-descriptor/-/is-descriptor-1.0.2.tgz", - "integrity": "sha512-2eis5WqQGV7peooDyLmNEPUrps9+SXX5c9pL3xEB+4e9HnGuDa7mB7kHxHw4CbqS9k1T2hOH3miL8n8WtiYVtg==", - "dev": true, - "requires": { - "is-accessor-descriptor": "^1.0.0", - "is-data-descriptor": "^1.0.0", - "kind-of": "^6.0.2" - } - } - } - }, - "fast-deep-equal": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-2.0.1.tgz", - "integrity": "sha1-ewUhjd+WZ79/Nwv3/bLLFf3Qqkk=", - "dev": true - }, - "fast-json-stable-stringify": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.0.0.tgz", - "integrity": "sha1-1RQsDK7msRifh9OnYREGT4bIu/I=", - "dev": true - }, - "figgy-pudding": { - "version": "3.5.1", - "resolved": "https://registry.npmjs.org/figgy-pudding/-/figgy-pudding-3.5.1.tgz", - "integrity": "sha512-vNKxJHTEKNThjfrdJwHc7brvM6eVevuO5nTj6ez8ZQ1qbXTvGthucRF7S4vf2cr71QVnT70V34v0S1DyQsti0w==", - "dev": true - }, - "fill-range": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-4.0.0.tgz", - "integrity": "sha1-1USBHUKPmOsGpj3EAtJAPDKMOPc=", - "dev": true, - "requires": { - "extend-shallow": "^2.0.1", - "is-number": "^3.0.0", - "repeat-string": "^1.6.1", - "to-regex-range": "^2.1.0" - }, - "dependencies": { - "extend-shallow": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/extend-shallow/-/extend-shallow-2.0.1.tgz", - "integrity": "sha1-Ua99YUrZqfYQ6huvu5idaxxWiQ8=", - "dev": true, - "requires": { - "is-extendable": "^0.1.0" - } - } - } - }, - "find-cache-dir": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/find-cache-dir/-/find-cache-dir-2.0.0.tgz", - "integrity": "sha512-LDUY6V1Xs5eFskUVYtIwatojt6+9xC9Chnlk/jYOOvn3FAFfSaWddxahDGyNHh0b2dMXa6YW2m0tk8TdVaXHlA==", - "dev": true, - "requires": { - "commondir": "^1.0.1", - "make-dir": "^1.0.0", - "pkg-dir": "^3.0.0" - } - }, - "find-up": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/find-up/-/find-up-3.0.0.tgz", - "integrity": "sha512-1yD6RmLI1XBfxugvORwlck6f75tYL+iR0jqwsOrOxMZyGYqUuDhJ0l4AXdO1iX/FTs9cBAMEk1gWSEx1kSbylg==", - "dev": true, - "requires": { - "locate-path": "^3.0.0" - } - }, - "findup-sync": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/findup-sync/-/findup-sync-2.0.0.tgz", - "integrity": "sha1-kyaxSIwi0aYIhlCoaQGy2akKLLw=", - "dev": true, - "requires": { - "detect-file": "^1.0.0", - "is-glob": "^3.1.0", - "micromatch": "^3.0.4", - "resolve-dir": "^1.0.1" - }, - "dependencies": { - "is-glob": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/is-glob/-/is-glob-3.1.0.tgz", - "integrity": "sha1-e6WuJCF4BKxwcHuWkiVnSGzD6Eo=", - "dev": true, - "requires": { - "is-extglob": "^2.1.0" - } - } - } - }, - "flush-write-stream": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/flush-write-stream/-/flush-write-stream-1.0.3.tgz", - "integrity": "sha512-calZMC10u0FMUqoiunI2AiGIIUtUIvifNwkHhNupZH4cbNnW1Itkoh/Nf5HFYmDrwWPjrUxpkZT0KhuCq0jmGw==", - "dev": true, - "requires": { - "inherits": "^2.0.1", - "readable-stream": "^2.0.4" - } - }, - "for-in": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/for-in/-/for-in-1.0.2.tgz", - "integrity": "sha1-gQaNKVqBQuwKxybG4iAMMPttXoA=", - "dev": true - }, - "fragment-cache": { - "version": "0.2.1", - "resolved": "https://registry.npmjs.org/fragment-cache/-/fragment-cache-0.2.1.tgz", - "integrity": "sha1-QpD60n8T6Jvn8zeZxrxaCr//DRk=", - "dev": true, - "requires": { - "map-cache": "^0.2.2" - } - }, - "from2": { - "version": "2.3.0", - "resolved": "https://registry.npmjs.org/from2/-/from2-2.3.0.tgz", - "integrity": "sha1-i/tVAr3kpNNs/e6gB/zKIdfjgq8=", - "dev": true, - "requires": { - "inherits": "^2.0.1", - "readable-stream": "^2.0.0" - } - }, - "fs-minipass": { - "version": "1.2.5", - "resolved": "https://registry.npmjs.org/fs-minipass/-/fs-minipass-1.2.5.tgz", - "integrity": "sha512-JhBl0skXjUPCFH7x6x61gQxrKyXsxB5gcgePLZCwfyCGGsTISMoIeObbrvVeP6Xmyaudw4TT43qV2Gz+iyd2oQ==", - "dev": true, - "optional": true, - "requires": { - "minipass": "^2.2.1" - } - }, - "fs-write-stream-atomic": { - "version": "1.0.10", - "resolved": "https://registry.npmjs.org/fs-write-stream-atomic/-/fs-write-stream-atomic-1.0.10.tgz", - "integrity": "sha1-tH31NJPvkR33VzHnCp3tAYnbQMk=", - "dev": true, - "requires": { - "graceful-fs": "^4.1.2", - "iferr": "^0.1.5", - "imurmurhash": "^0.1.4", - "readable-stream": "1 || 2" - } - }, - "fs.realpath": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", - "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=", - "dev": true - }, - "fsevents": { - "version": "1.2.6", - "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-1.2.6.tgz", - "integrity": "sha512-BalK54tfK0pMC0jQFb2oHn1nz7JNQD/2ex5pBnCHgBi2xG7VV0cAOGy2RS2VbCqUXx5/6obMrMcQTJ8yjcGzbg==", - "dev": true, - "optional": true, - "requires": { - "nan": "^2.9.2", - "node-pre-gyp": "^0.10.0" - } - }, - "function-bind": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz", - "integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==", - "dev": true - }, - "gauge": { - "version": "2.7.4", - "resolved": "https://registry.npmjs.org/gauge/-/gauge-2.7.4.tgz", - "integrity": "sha1-LANAXHU4w51+s3sxcCLjJfsBi/c=", - "dev": true, - "optional": true, - "requires": { - "aproba": "^1.0.3", - "console-control-strings": "^1.0.0", - "has-unicode": "^2.0.0", - "object-assign": "^4.1.0", - "signal-exit": "^3.0.0", - "string-width": "^1.0.1", - "strip-ansi": "^3.0.1", - "wide-align": "^1.1.0" - } - }, - "get-caller-file": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-1.0.3.tgz", - "integrity": "sha512-3t6rVToeoZfYSGd8YoLFR2DJkiQrIiUrGcjvFX2mDw3bn6k2OtwHN0TNCLbBO+w8qTvimhDkv+LSscbJY1vE6w==", - "dev": true - }, - "get-stream": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-4.1.0.tgz", - "integrity": "sha512-GMat4EJ5161kIy2HevLlr4luNjBgvmj413KaQA7jt4V8B4RDsfpHk7WQ9GVqfYyyx8OS/L66Kox+rJRNklLK7w==", - "dev": true, - "requires": { - "pump": "^3.0.0" - } - }, - "get-value": { - "version": "2.0.6", - "resolved": "https://registry.npmjs.org/get-value/-/get-value-2.0.6.tgz", - "integrity": "sha1-3BXKHGcjh8p2vTesCjlbogQqLCg=", - "dev": true - }, - "glob": { - "version": "7.1.3", - "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.3.tgz", - "integrity": "sha512-vcfuiIxogLV4DlGBHIUOwI0IbrJ8HWPc4MU7HzviGeNho/UJDfi6B5p3sHeWIQ0KGIU0Jpxi5ZHxemQfLkkAwQ==", - "dev": true, - "requires": { - "fs.realpath": "^1.0.0", - "inflight": "^1.0.4", - "inherits": "2", - "minimatch": "^3.0.4", - "once": "^1.3.0", - "path-is-absolute": "^1.0.0" - } - }, - "glob-parent": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-3.1.0.tgz", - "integrity": "sha1-nmr2KZ2NO9K9QEMIMr0RPfkGxa4=", - "dev": true, - "requires": { - "is-glob": "^3.1.0", - "path-dirname": "^1.0.0" - }, - "dependencies": { - "is-glob": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/is-glob/-/is-glob-3.1.0.tgz", - "integrity": "sha1-e6WuJCF4BKxwcHuWkiVnSGzD6Eo=", - "dev": true, - "requires": { - "is-extglob": "^2.1.0" - } - } - } - }, - "global-modules": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/global-modules/-/global-modules-1.0.0.tgz", - "integrity": "sha512-sKzpEkf11GpOFuw0Zzjzmt4B4UZwjOcG757PPvrfhxcLFbq0wpsgpOqxpxtxFiCG4DtG93M6XRVbF2oGdev7bg==", - "dev": true, - "requires": { - "global-prefix": "^1.0.1", - "is-windows": "^1.0.1", - "resolve-dir": "^1.0.0" - } - }, - "global-modules-path": { - "version": "2.3.1", - "resolved": "https://registry.npmjs.org/global-modules-path/-/global-modules-path-2.3.1.tgz", - "integrity": "sha512-y+shkf4InI7mPRHSo2b/k6ix6+NLDtyccYv86whhxrSGX9wjPX1VMITmrDbE1eh7zkzhiWtW2sHklJYoQ62Cxg==", - "dev": true - }, - "global-prefix": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/global-prefix/-/global-prefix-1.0.2.tgz", - "integrity": "sha1-2/dDxsFJklk8ZVVoy2btMsASLr4=", - "dev": true, - "requires": { - "expand-tilde": "^2.0.2", - "homedir-polyfill": "^1.0.1", - "ini": "^1.3.4", - "is-windows": "^1.0.1", - "which": "^1.2.14" - } - }, - "globals": { - "version": "11.10.0", - "resolved": "https://registry.npmjs.org/globals/-/globals-11.10.0.tgz", - "integrity": "sha512-0GZF1RiPKU97IHUO5TORo9w1PwrH/NBPl+fS7oMLdaTRiYmYbwK4NWoZWrAdd0/abG9R2BU+OiwyQpTpE6pdfQ==", - "dev": true - }, - "graceful-fs": { - "version": "4.1.15", - "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.1.15.tgz", - "integrity": "sha512-6uHUhOPEBgQ24HM+r6b/QwWfZq+yiFcipKFrOFiBEnWdy5sdzYoi+pJeQaPI5qOLRFqWmAXUPQNsielzdLoecA==", - "dev": true - }, - "has": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/has/-/has-1.0.3.tgz", - "integrity": "sha512-f2dvO0VU6Oej7RkWJGrehjbzMAjFp5/VKPp5tTpWIV4JHHZK1/BxbFRtf/siA2SWTe09caDmVtYYzWEIbBS4zw==", - "dev": true, - "requires": { - "function-bind": "^1.1.1" - } - }, - "has-flag": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", - "integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0=", - "dev": true - }, - "has-symbols": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.0.tgz", - "integrity": "sha1-uhqPGvKg/DllD1yFA2dwQSIGO0Q=", - "dev": true - }, - "has-unicode": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/has-unicode/-/has-unicode-2.0.1.tgz", - "integrity": "sha1-4Ob+aijPUROIVeCG0Wkedx3iqLk=", - "dev": true, - "optional": true - }, - "has-value": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/has-value/-/has-value-1.0.0.tgz", - "integrity": "sha1-GLKB2lhbHFxR3vJMkw7SmgvmsXc=", - "dev": true, - "requires": { - "get-value": "^2.0.6", - "has-values": "^1.0.0", - "isobject": "^3.0.0" - } - }, - "has-values": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/has-values/-/has-values-1.0.0.tgz", - "integrity": "sha1-lbC2P+whRmGab+V/51Yo1aOe/k8=", - "dev": true, - "requires": { - "is-number": "^3.0.0", - "kind-of": "^4.0.0" - }, - "dependencies": { - "kind-of": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/kind-of/-/kind-of-4.0.0.tgz", - "integrity": "sha1-IIE989cSkosgc3hpGkUGb65y3Vc=", - "dev": true, - "requires": { - "is-buffer": "^1.1.5" - } - } - } - }, - "hash-base": { - "version": "3.0.4", - "resolved": "https://registry.npmjs.org/hash-base/-/hash-base-3.0.4.tgz", - "integrity": "sha1-X8hoaEfs1zSZQDMZprCj8/auSRg=", - "dev": true, - "requires": { - "inherits": "^2.0.1", - "safe-buffer": "^5.0.1" - } - }, - "hash.js": { - "version": "1.1.7", - "resolved": "https://registry.npmjs.org/hash.js/-/hash.js-1.1.7.tgz", - "integrity": "sha512-taOaskGt4z4SOANNseOviYDvjEJinIkRgmp7LbKP2YTTmVxWBl87s/uzK9r+44BclBSp2X7K1hqeNfz9JbBeXA==", - "dev": true, - "requires": { - "inherits": "^2.0.3", - "minimalistic-assert": "^1.0.1" - } - }, - "hmac-drbg": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/hmac-drbg/-/hmac-drbg-1.0.1.tgz", - "integrity": "sha1-0nRXAQJabHdabFRXk+1QL8DGSaE=", - "dev": true, - "requires": { - "hash.js": "^1.0.3", - "minimalistic-assert": "^1.0.0", - "minimalistic-crypto-utils": "^1.0.1" - } - }, - "homedir-polyfill": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/homedir-polyfill/-/homedir-polyfill-1.0.1.tgz", - "integrity": "sha1-TCu8inWJmP7r9e1oWA921GdotLw=", - "dev": true, - "requires": { - "parse-passwd": "^1.0.0" - } - }, - "https-browserify": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/https-browserify/-/https-browserify-1.0.0.tgz", - "integrity": "sha1-7AbBDgo0wPL68Zn3/X/Hj//QPHM=", - "dev": true - }, - "iconv-lite": { - "version": "0.4.24", - "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz", - "integrity": "sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==", - "dev": true, - "optional": true, - "requires": { - "safer-buffer": ">= 2.1.2 < 3" - } - }, - "ieee754": { - "version": "1.1.12", - "resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.1.12.tgz", - "integrity": "sha512-GguP+DRY+pJ3soyIiGPTvdiVXjZ+DbXOxGpXn3eMvNW4x4irjqXm4wHKscC+TfxSJ0yw/S1F24tqdMNsMZTiLA==", - "dev": true - }, - "iferr": { - "version": "0.1.5", - "resolved": "https://registry.npmjs.org/iferr/-/iferr-0.1.5.tgz", - "integrity": "sha1-xg7taebY/bazEEofy8ocGS3FtQE=", - "dev": true - }, - "ignore-walk": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/ignore-walk/-/ignore-walk-3.0.1.tgz", - "integrity": "sha512-DTVlMx3IYPe0/JJcYP7Gxg7ttZZu3IInhuEhbchuqneY9wWe5Ojy2mXLBaQFUQmo0AW2r3qG7m1mg86js+gnlQ==", - "dev": true, - "optional": true, - "requires": { - "minimatch": "^3.0.4" - } - }, - "import-local": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/import-local/-/import-local-2.0.0.tgz", - "integrity": "sha512-b6s04m3O+s3CGSbqDIyP4R6aAwAeYlVq9+WUWep6iHa8ETRf9yei1U48C5MmfJmV9AiLYYBKPMq/W+/WRpQmCQ==", - "dev": true, - "requires": { - "pkg-dir": "^3.0.0", - "resolve-cwd": "^2.0.0" - } - }, - "imurmurhash": { - "version": "0.1.4", - "resolved": "https://registry.npmjs.org/imurmurhash/-/imurmurhash-0.1.4.tgz", - "integrity": "sha1-khi5srkoojixPcT7a21XbyMUU+o=", - "dev": true - }, - "indexof": { - "version": "0.0.1", - "resolved": "https://registry.npmjs.org/indexof/-/indexof-0.0.1.tgz", - "integrity": "sha1-gtwzbSMrkGIXnQWrMpOmYFn9Q10=", - "dev": true - }, - "inflight": { - "version": "1.0.6", - "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", - "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=", - "dev": true, - "requires": { - "once": "^1.3.0", - "wrappy": "1" - } - }, - "inherits": { - "version": "2.0.3", - "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", - "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=", - "dev": true - }, - "ini": { - "version": "1.3.5", - "resolved": "https://registry.npmjs.org/ini/-/ini-1.3.5.tgz", - "integrity": "sha512-RZY5huIKCMRWDUqZlEi72f/lmXKMvuszcMBduliQ3nnWbx9X/ZBQO7DijMEYS9EhHBb2qacRUMtC7svLwe0lcw==", - "dev": true - }, - "interpret": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/interpret/-/interpret-1.2.0.tgz", - "integrity": "sha512-mT34yGKMNceBQUoVn7iCDKDntA7SC6gycMAWzGx1z/CMCTV7b2AAtXlo3nRyHZ1FelRkQbQjprHSYGwzLtkVbw==", - "dev": true - }, - "invariant": { - "version": "2.2.4", - "resolved": "https://registry.npmjs.org/invariant/-/invariant-2.2.4.tgz", - "integrity": "sha512-phJfQVBuaJM5raOpJjSfkiD6BpbCE4Ns//LaXl6wGYtUBY83nWS6Rf9tXm2e8VaK60JEjYldbPif/A2B1C2gNA==", - "dev": true, - "requires": { - "loose-envify": "^1.0.0" - } - }, - "invert-kv": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/invert-kv/-/invert-kv-2.0.0.tgz", - "integrity": "sha512-wPVv/y/QQ/Uiirj/vh3oP+1Ww+AWehmi1g5fFWGPF6IpCBCDVrhgHRMvrLfdYcwDh3QJbGXDW4JAuzxElLSqKA==", - "dev": true - }, - "is-accessor-descriptor": { - "version": "0.1.6", - "resolved": "https://registry.npmjs.org/is-accessor-descriptor/-/is-accessor-descriptor-0.1.6.tgz", - "integrity": "sha1-qeEss66Nh2cn7u84Q/igiXtcmNY=", - "dev": true, - "requires": { - "kind-of": "^3.0.2" - }, - "dependencies": { - "kind-of": { - "version": "3.2.2", - "resolved": "https://registry.npmjs.org/kind-of/-/kind-of-3.2.2.tgz", - "integrity": "sha1-MeohpzS6ubuw8yRm2JOupR5KPGQ=", - "dev": true, - "requires": { - "is-buffer": "^1.1.5" - } - } - } - }, - "is-binary-path": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/is-binary-path/-/is-binary-path-1.0.1.tgz", - "integrity": "sha1-dfFmQrSA8YenEcgUFh/TpKdlWJg=", - "dev": true, - "requires": { - "binary-extensions": "^1.0.0" - } - }, - "is-buffer": { - "version": "1.1.6", - "resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-1.1.6.tgz", - "integrity": "sha512-NcdALwpXkTm5Zvvbk7owOUSvVvBKDgKP5/ewfXEznmQFfs4ZRmanOeKBTjRVjka3QFoN6XJ+9F3USqfHqTaU5w==", - "dev": true - }, - "is-callable": { - "version": "1.1.4", - "resolved": "https://registry.npmjs.org/is-callable/-/is-callable-1.1.4.tgz", - "integrity": "sha512-r5p9sxJjYnArLjObpjA4xu5EKI3CuKHkJXMhT7kwbpUyIFD1n5PMAsoPvWnvtZiNz7LjkYDRZhd7FlI0eMijEA==", - "dev": true - }, - "is-data-descriptor": { - "version": "0.1.4", - "resolved": "https://registry.npmjs.org/is-data-descriptor/-/is-data-descriptor-0.1.4.tgz", - "integrity": "sha1-C17mSDiOLIYCgueT8YVv7D8wG1Y=", - "dev": true, - "requires": { - "kind-of": "^3.0.2" - }, - "dependencies": { - "kind-of": { - "version": "3.2.2", - "resolved": "https://registry.npmjs.org/kind-of/-/kind-of-3.2.2.tgz", - "integrity": "sha1-MeohpzS6ubuw8yRm2JOupR5KPGQ=", - "dev": true, - "requires": { - "is-buffer": "^1.1.5" - } - } - } - }, - "is-date-object": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/is-date-object/-/is-date-object-1.0.1.tgz", - "integrity": "sha1-mqIOtq7rv/d/vTPnTKAbM1gdOhY=", - "dev": true - }, - "is-descriptor": { - "version": "0.1.6", - "resolved": "https://registry.npmjs.org/is-descriptor/-/is-descriptor-0.1.6.tgz", - "integrity": "sha512-avDYr0SB3DwO9zsMov0gKCESFYqCnE4hq/4z3TdUlukEy5t9C0YRq7HLrsN52NAcqXKaepeCD0n+B0arnVG3Hg==", - "dev": true, - "requires": { - "is-accessor-descriptor": "^0.1.6", - "is-data-descriptor": "^0.1.4", - "kind-of": "^5.0.0" - }, - "dependencies": { - "kind-of": { - "version": "5.1.0", - "resolved": "https://registry.npmjs.org/kind-of/-/kind-of-5.1.0.tgz", - "integrity": "sha512-NGEErnH6F2vUuXDh+OlbcKW7/wOcfdRHaZ7VWtqCztfHri/++YKmP51OdWeGPuqCOba6kk2OTe5d02VmTB80Pw==", - "dev": true - } - } - }, - "is-extendable": { - "version": "0.1.1", - "resolved": "https://registry.npmjs.org/is-extendable/-/is-extendable-0.1.1.tgz", - "integrity": "sha1-YrEQ4omkcUGOPsNqYX1HLjAd/Ik=", - "dev": true - }, - "is-extglob": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-2.1.1.tgz", - "integrity": "sha1-qIwCU1eR8C7TfHahueqXc8gz+MI=", - "dev": true - }, - "is-fullwidth-code-point": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-1.0.0.tgz", - "integrity": "sha1-754xOG8DGn8NZDr4L95QxFfvAMs=", - "dev": true, - "requires": { - "number-is-nan": "^1.0.0" - } - }, - "is-glob": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/is-glob/-/is-glob-4.0.0.tgz", - "integrity": "sha1-lSHHaEXMJhCoUgPd8ICpWML/q8A=", - "dev": true, - "requires": { - "is-extglob": "^2.1.1" - } - }, - "is-number": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/is-number/-/is-number-3.0.0.tgz", - "integrity": "sha1-JP1iAaR4LPUFYcgQJ2r8fRLXEZU=", - "dev": true, - "requires": { - "kind-of": "^3.0.2" - }, - "dependencies": { - "kind-of": { - "version": "3.2.2", - "resolved": "https://registry.npmjs.org/kind-of/-/kind-of-3.2.2.tgz", - "integrity": "sha1-MeohpzS6ubuw8yRm2JOupR5KPGQ=", - "dev": true, - "requires": { - "is-buffer": "^1.1.5" - } - } - } - }, - "is-plain-object": { - "version": "2.0.4", - "resolved": "https://registry.npmjs.org/is-plain-object/-/is-plain-object-2.0.4.tgz", - "integrity": "sha512-h5PpgXkWitc38BBMYawTYMWJHFZJVnBquFE57xFpjB8pJFiF6gZ+bU+WyI/yqXiFR5mdLsgYNaPe8uao6Uv9Og==", - "dev": true, - "requires": { - "isobject": "^3.0.1" - } - }, - "is-regex": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/is-regex/-/is-regex-1.0.4.tgz", - "integrity": "sha1-VRdIm1RwkbCTDglWVM7SXul+lJE=", - "dev": true, - "requires": { - "has": "^1.0.1" - } - }, - "is-stream": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-1.1.0.tgz", - "integrity": "sha1-EtSj3U5o4Lec6428hBc66A2RykQ=", - "dev": true - }, - "is-symbol": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/is-symbol/-/is-symbol-1.0.2.tgz", - "integrity": "sha512-HS8bZ9ox60yCJLH9snBpIwv9pYUAkcuLhSA1oero1UB5y9aiQpRA8y2ex945AOtCZL1lJDeIk3G5LthswI46Lw==", - "dev": true, - "requires": { - "has-symbols": "^1.0.0" - } - }, - "is-windows": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/is-windows/-/is-windows-1.0.2.tgz", - "integrity": "sha512-eXK1UInq2bPmjyX6e3VHIzMLobc4J94i4AWn+Hpq3OU5KkrRC96OAcR3PRJ/pGu6m8TRnBHP9dkXQVsT/COVIA==", - "dev": true - }, - "isarray": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", - "integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=", - "dev": true - }, - "isexe": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", - "integrity": "sha1-6PvzdNxVb/iUehDcsFctYz8s+hA=", - "dev": true - }, - "isobject": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/isobject/-/isobject-3.0.1.tgz", - "integrity": "sha1-TkMekrEalzFjaqH5yNHMvP2reN8=", - "dev": true - }, - "js-levenshtein": { - "version": "1.1.6", - "resolved": "https://registry.npmjs.org/js-levenshtein/-/js-levenshtein-1.1.6.tgz", - "integrity": "sha512-X2BB11YZtrRqY4EnQcLX5Rh373zbK4alC1FW7D7MBhL2gtcC17cTnr6DmfHZeS0s2rTHjUTMMHfG7gO8SSdw+g==", - "dev": true - }, - "js-tokens": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz", - "integrity": "sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==", - "dev": true - }, - "jsesc": { - "version": "2.5.2", - "resolved": "https://registry.npmjs.org/jsesc/-/jsesc-2.5.2.tgz", - "integrity": "sha512-OYu7XEzjkCQ3C5Ps3QIZsQfNpqoJyZZA99wd9aWd05NCtC5pWOkShK2mkL6HXQR6/Cy2lbNdPlZBpuQHXE63gA==", - "dev": true - }, - "json-parse-better-errors": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/json-parse-better-errors/-/json-parse-better-errors-1.0.2.tgz", - "integrity": "sha512-mrqyZKfX5EhL7hvqcV6WG1yYjnjeuYDzDhhcAAUrq8Po85NBQBJP+ZDUT75qZQ98IkUoBqdkExkukOU7Ts2wrw==", - "dev": true - }, - "json-schema-traverse": { - "version": "0.4.1", - "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz", - "integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==", - "dev": true - }, - "json5": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/json5/-/json5-2.1.0.tgz", - "integrity": "sha512-8Mh9h6xViijj36g7Dxi+Y4S6hNGV96vcJZr/SrlHh1LR/pEn/8j/+qIBbs44YKl69Lrfctp4QD+AdWLTMqEZAQ==", - "dev": true, - "requires": { - "minimist": "^1.2.0" - } - }, - "kind-of": { - "version": "6.0.2", - "resolved": "https://registry.npmjs.org/kind-of/-/kind-of-6.0.2.tgz", - "integrity": "sha512-s5kLOcnH0XqDO+FvuaLX8DDjZ18CGFk7VygH40QoKPUQhW4e2rvM0rwUq0t8IQDOwYSeLK01U90OjzBTme2QqA==", - "dev": true - }, - "lcid": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/lcid/-/lcid-2.0.0.tgz", - "integrity": "sha512-avPEb8P8EGnwXKClwsNUgryVjllcRqtMYa49NTsbQagYuT1DcXnl1915oxWjoyGrXR6zH/Y0Zc96xWsPcoDKeA==", - "dev": true, - "requires": { - "invert-kv": "^2.0.0" - } - }, - "lightercollective": { - "version": "0.1.0", - "resolved": "https://registry.npmjs.org/lightercollective/-/lightercollective-0.1.0.tgz", - "integrity": "sha512-J9tg5uraYoQKaWbmrzDDexbG6hHnMcWS1qLYgJSWE+mpA3U5OCSeMUhb+K55otgZJ34oFdR0ECvdIb3xuO5JOQ==", - "dev": true - }, - "loader-runner": { - "version": "2.4.0", - "resolved": "https://registry.npmjs.org/loader-runner/-/loader-runner-2.4.0.tgz", - "integrity": "sha512-Jsmr89RcXGIwivFY21FcRrisYZfvLMTWx5kOLc+JTxtpBOG6xML0vzbc6SEQG2FO9/4Fc3wW4LVcB5DmGflaRw==", - "dev": true - }, - "loader-utils": { - "version": "1.2.3", - "resolved": "https://registry.npmjs.org/loader-utils/-/loader-utils-1.2.3.tgz", - "integrity": "sha512-fkpz8ejdnEMG3s37wGL07iSBDg99O9D5yflE9RGNH3hRdx9SOwYfnGYdZOUIZitN8E+E2vkq3MUMYMvPYl5ZZA==", - "dev": true, - "requires": { - "big.js": "^5.2.2", - "emojis-list": "^2.0.0", - "json5": "^1.0.1" - }, - "dependencies": { - "json5": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/json5/-/json5-1.0.1.tgz", - "integrity": "sha512-aKS4WQjPenRxiQsC93MNfjx+nbF4PAdYzmd/1JIj8HYzqfbu86beTuNgXDzPknWk0n0uARlyewZo4s++ES36Ow==", - "dev": true, - "requires": { - "minimist": "^1.2.0" - } - } - } - }, - "locate-path": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-3.0.0.tgz", - "integrity": "sha512-7AO748wWnIhNqAuaty2ZWHkQHRSNfPVIsPIfwEOWO22AmaoVrWavlOcMR5nzTLNYvp36X220/maaRsrec1G65A==", - "dev": true, - "requires": { - "p-locate": "^3.0.0", - "path-exists": "^3.0.0" - } - }, - "lodash": { - "version": "4.17.11", - "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.11.tgz", - "integrity": "sha512-cQKh8igo5QUhZ7lg38DYWAxMvjSAKG0A8wGSVimP07SIUEK2UO+arSRKbRZWtelMtN5V0Hkwh5ryOto/SshYIg==", - "dev": true - }, - "lodash.debounce": { - "version": "4.0.8", - "resolved": "https://registry.npmjs.org/lodash.debounce/-/lodash.debounce-4.0.8.tgz", - "integrity": "sha1-gteb/zCmfEAF/9XiUVMArZyk168=", - "dev": true - }, - "loose-envify": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/loose-envify/-/loose-envify-1.4.0.tgz", - "integrity": "sha512-lyuxPGr/Wfhrlem2CL/UcnUc1zcqKAImBDzukY7Y5F/yQiNdko6+fRLevlw1HgMySw7f611UIY408EtxRSoK3Q==", - "dev": true, - "requires": { - "js-tokens": "^3.0.0 || ^4.0.0" - } - }, - "lru-cache": { - "version": "5.1.1", - "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-5.1.1.tgz", - "integrity": "sha512-KpNARQA3Iwv+jTA0utUVVbrh+Jlrr1Fv0e56GGzAFOXN7dk/FviaDW8LHmK52DlcH4WP2n6gI8vN1aesBFgo9w==", - "dev": true, - "requires": { - "yallist": "^3.0.2" - } - }, - "luaparse": { - "version": "0.2.1", - "resolved": "https://registry.npmjs.org/luaparse/-/luaparse-0.2.1.tgz", - "integrity": "sha1-qo9WEysN6X0388mRqd9C4OF/ZWw=" - }, - "make-dir": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/make-dir/-/make-dir-1.3.0.tgz", - "integrity": "sha512-2w31R7SJtieJJnQtGc7RVL2StM2vGYVfqUOvUDxH6bC6aJTxPxTF0GnIgCyu7tjockiUWAYQRbxa7vKn34s5sQ==", - "dev": true, - "requires": { - "pify": "^3.0.0" - } - }, - "map-age-cleaner": { - "version": "0.1.3", - "resolved": "https://registry.npmjs.org/map-age-cleaner/-/map-age-cleaner-0.1.3.tgz", - "integrity": "sha512-bJzx6nMoP6PDLPBFmg7+xRKeFZvFboMrGlxmNj9ClvX53KrmvM5bXFXEWjbz4cz1AFn+jWJ9z/DJSz7hrs0w3w==", - "dev": true, - "requires": { - "p-defer": "^1.0.0" - } - }, - "map-cache": { - "version": "0.2.2", - "resolved": "https://registry.npmjs.org/map-cache/-/map-cache-0.2.2.tgz", - "integrity": "sha1-wyq9C9ZSXZsFFkW7TyasXcmKDb8=", - "dev": true - }, - "map-visit": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/map-visit/-/map-visit-1.0.0.tgz", - "integrity": "sha1-7Nyo8TFE5mDxtb1B8S80edmN+48=", - "dev": true, - "requires": { - "object-visit": "^1.0.0" - } - }, - "md5.js": { - "version": "1.3.5", - "resolved": "https://registry.npmjs.org/md5.js/-/md5.js-1.3.5.tgz", - "integrity": "sha512-xitP+WxNPcTTOgnTJcrhM0xvdPepipPSf3I8EIpGKeFLjt3PlJLIDG3u8EX53ZIubkb+5U2+3rELYpEhHhzdkg==", - "dev": true, - "requires": { - "hash-base": "^3.0.0", - "inherits": "^2.0.1", - "safe-buffer": "^5.1.2" - } - }, - "mem": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/mem/-/mem-4.0.0.tgz", - "integrity": "sha512-WQxG/5xYc3tMbYLXoXPm81ET2WDULiU5FxbuIoNbJqLOOI8zehXFdZuiUEgfdrU2mVB1pxBZUGlYORSrpuJreA==", - "dev": true, - "requires": { - "map-age-cleaner": "^0.1.1", - "mimic-fn": "^1.0.0", - "p-is-promise": "^1.1.0" - } - }, - "memory-fs": { - "version": "0.4.1", - "resolved": "https://registry.npmjs.org/memory-fs/-/memory-fs-0.4.1.tgz", - "integrity": "sha1-OpoguEYlI+RHz7x+i7gO1me/xVI=", - "dev": true, - "requires": { - "errno": "^0.1.3", - "readable-stream": "^2.0.1" - } - }, - "micromatch": { - "version": "3.1.10", - "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-3.1.10.tgz", - "integrity": "sha512-MWikgl9n9M3w+bpsY3He8L+w9eF9338xRl8IAO5viDizwSzziFEyUzo2xrrloB64ADbTf8uA8vRqqttDTOmccg==", - "dev": true, - "requires": { - "arr-diff": "^4.0.0", - "array-unique": "^0.3.2", - "braces": "^2.3.1", - "define-property": "^2.0.2", - "extend-shallow": "^3.0.2", - "extglob": "^2.0.4", - "fragment-cache": "^0.2.1", - "kind-of": "^6.0.2", - "nanomatch": "^1.2.9", - "object.pick": "^1.3.0", - "regex-not": "^1.0.0", - "snapdragon": "^0.8.1", - "to-regex": "^3.0.2" - } - }, - "miller-rabin": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/miller-rabin/-/miller-rabin-4.0.1.tgz", - "integrity": "sha512-115fLhvZVqWwHPbClyntxEVfVDfl9DLLTuJvq3g2O/Oxi8AiNouAHvDSzHS0viUJc+V5vm3eq91Xwqn9dp4jRA==", - "dev": true, - "requires": { - "bn.js": "^4.0.0", - "brorand": "^1.0.1" - } - }, - "mimic-fn": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-1.2.0.tgz", - "integrity": "sha512-jf84uxzwiuiIVKiOLpfYk7N46TSy8ubTonmneY9vrpHNAnp0QBt2BxWV9dO3/j+BoVAb+a5G6YDPW3M5HOdMWQ==", - "dev": true - }, - "minimalistic-assert": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/minimalistic-assert/-/minimalistic-assert-1.0.1.tgz", - "integrity": "sha512-UtJcAD4yEaGtjPezWuO9wC4nwUnVH/8/Im3yEHQP4b67cXlD/Qr9hdITCU1xDbSEXg2XKNaP8jsReV7vQd00/A==", - "dev": true - }, - "minimalistic-crypto-utils": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/minimalistic-crypto-utils/-/minimalistic-crypto-utils-1.0.1.tgz", - "integrity": "sha1-9sAMHAsIIkblxNmd+4x8CDsrWCo=", - "dev": true - }, - "minimatch": { - "version": "3.0.4", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", - "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", - "dev": true, - "requires": { - "brace-expansion": "^1.1.7" - } - }, - "minimist": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz", - "integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=", - "dev": true - }, - "minipass": { - "version": "2.3.5", - "resolved": "https://registry.npmjs.org/minipass/-/minipass-2.3.5.tgz", - "integrity": "sha512-Gi1W4k059gyRbyVUZQ4mEqLm0YIUiGYfvxhF6SIlk3ui1WVxMTGfGdQ2SInh3PDrRTVvPKgULkpJtT4RH10+VA==", - "dev": true, - "optional": true, - "requires": { - "safe-buffer": "^5.1.2", - "yallist": "^3.0.0" - } - }, - "minizlib": { - "version": "1.2.1", - "resolved": "https://registry.npmjs.org/minizlib/-/minizlib-1.2.1.tgz", - "integrity": "sha512-7+4oTUOWKg7AuL3vloEWekXY2/D20cevzsrNT2kGWm+39J9hGTCBv8VI5Pm5lXZ/o3/mdR4f8rflAPhnQb8mPA==", - "dev": true, - "optional": true, - "requires": { - "minipass": "^2.2.1" - } - }, - "mississippi": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/mississippi/-/mississippi-3.0.0.tgz", - "integrity": "sha512-x471SsVjUtBRtcvd4BzKE9kFC+/2TeWgKCgw0bZcw1b9l2X3QX5vCWgF+KaZaYm87Ss//rHnWryupDrgLvmSkA==", - "dev": true, - "requires": { - "concat-stream": "^1.5.0", - "duplexify": "^3.4.2", - "end-of-stream": "^1.1.0", - "flush-write-stream": "^1.0.0", - "from2": "^2.1.0", - "parallel-transform": "^1.1.0", - "pump": "^3.0.0", - "pumpify": "^1.3.3", - "stream-each": "^1.1.0", - "through2": "^2.0.0" - } - }, - "mixin-deep": { - "version": "1.3.1", - "resolved": "https://registry.npmjs.org/mixin-deep/-/mixin-deep-1.3.1.tgz", - "integrity": "sha512-8ZItLHeEgaqEvd5lYBXfm4EZSFCX29Jb9K+lAHhDKzReKBQKj3R+7NOF6tjqYi9t4oI8VUfaWITJQm86wnXGNQ==", - "dev": true, - "requires": { - "for-in": "^1.0.2", - "is-extendable": "^1.0.1" - }, - "dependencies": { - "is-extendable": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/is-extendable/-/is-extendable-1.0.1.tgz", - "integrity": "sha512-arnXMxT1hhoKo9k1LZdmlNyJdDDfy2v0fXjFlmok4+i8ul/6WlbVge9bhM74OpNPQPMGUToDtz+KXa1PneJxOA==", - "dev": true, - "requires": { - "is-plain-object": "^2.0.4" - } - } - } - }, - "mkdirp": { - "version": "0.5.1", - "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz", - "integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=", - "dev": true, - "requires": { - "minimist": "0.0.8" - }, - "dependencies": { - "minimist": { - "version": "0.0.8", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz", - "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=", - "dev": true - } - } - }, - "move-concurrently": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/move-concurrently/-/move-concurrently-1.0.1.tgz", - "integrity": "sha1-viwAX9oy4LKa8fBdfEszIUxwH5I=", - "dev": true, - "requires": { - "aproba": "^1.1.1", - "copy-concurrently": "^1.0.0", - "fs-write-stream-atomic": "^1.0.8", - "mkdirp": "^0.5.1", - "rimraf": "^2.5.4", - "run-queue": "^1.0.3" - } - }, - "ms": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.1.tgz", - "integrity": "sha512-tgp+dl5cGk28utYktBsrFqA7HKgrhgPsg6Z/EfhWI4gl1Hwq8B/GmY/0oXZ6nF8hDVesS/FpnYaD/kOWhYQvyg==", - "dev": true - }, - "nan": { - "version": "2.12.1", - "resolved": "https://registry.npmjs.org/nan/-/nan-2.12.1.tgz", - "integrity": "sha512-JY7V6lRkStKcKTvHO5NVSQRv+RV+FIL5pvDoLiAtSL9pKlC5x9PKQcZDsq7m4FO4d57mkhC6Z+QhAh3Jdk5JFw==", - "dev": true, - "optional": true - }, - "nanomatch": { - "version": "1.2.13", - "resolved": "https://registry.npmjs.org/nanomatch/-/nanomatch-1.2.13.tgz", - "integrity": "sha512-fpoe2T0RbHwBTBUOftAfBPaDEi06ufaUai0mE6Yn1kacc3SnTErfb/h+X94VXzI64rKFHYImXSvdwGGCmwOqCA==", - "dev": true, - "requires": { - "arr-diff": "^4.0.0", - "array-unique": "^0.3.2", - "define-property": "^2.0.2", - "extend-shallow": "^3.0.2", - "fragment-cache": "^0.2.1", - "is-windows": "^1.0.2", - "kind-of": "^6.0.2", - "object.pick": "^1.3.0", - "regex-not": "^1.0.0", - "snapdragon": "^0.8.1", - "to-regex": "^3.0.1" - } - }, - "needle": { - "version": "2.2.4", - "resolved": "https://registry.npmjs.org/needle/-/needle-2.2.4.tgz", - "integrity": "sha512-HyoqEb4wr/rsoaIDfTH2aVL9nWtQqba2/HvMv+++m8u0dz808MaagKILxtfeSN7QU7nvbQ79zk3vYOJp9zsNEA==", - "dev": true, - "optional": true, - "requires": { - "debug": "^2.1.2", - "iconv-lite": "^0.4.4", - "sax": "^1.2.4" - }, - "dependencies": { - "debug": { - "version": "2.6.9", - "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", - "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", - "dev": true, - "optional": true, - "requires": { - "ms": "2.0.0" - } - }, - "ms": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", - "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=", - "dev": true, - "optional": true - } - } - }, - "neo-async": { - "version": "2.6.0", - "resolved": "https://registry.npmjs.org/neo-async/-/neo-async-2.6.0.tgz", - "integrity": "sha512-MFh0d/Wa7vkKO3Y3LlacqAEeHK0mckVqzDieUKTT+KGxi+zIpeVsFxymkIiRpbpDziHc290Xr9A1O4Om7otoRA==", - "dev": true - }, - "nice-try": { - "version": "1.0.5", - "resolved": "https://registry.npmjs.org/nice-try/-/nice-try-1.0.5.tgz", - "integrity": "sha512-1nh45deeb5olNY7eX82BkPO7SSxR5SSYJiPTrTdFUVYwAl8CKMA5N9PjTYkHiRjisVcxcQ1HXdLhx2qxxJzLNQ==", - "dev": true - }, - "node-libs-browser": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/node-libs-browser/-/node-libs-browser-2.1.0.tgz", - "integrity": "sha512-5AzFzdoIMb89hBGMZglEegffzgRg+ZFoUmisQ8HI4j1KDdpx13J0taNp2y9xPbur6W61gepGDDotGBVQ7mfUCg==", - "dev": true, - "requires": { - "assert": "^1.1.1", - "browserify-zlib": "^0.2.0", - "buffer": "^4.3.0", - "console-browserify": "^1.1.0", - "constants-browserify": "^1.0.0", - "crypto-browserify": "^3.11.0", - "domain-browser": "^1.1.1", - "events": "^1.0.0", - "https-browserify": "^1.0.0", - "os-browserify": "^0.3.0", - "path-browserify": "0.0.0", - "process": "^0.11.10", - "punycode": "^1.2.4", - "querystring-es3": "^0.2.0", - "readable-stream": "^2.3.3", - "stream-browserify": "^2.0.1", - "stream-http": "^2.7.2", - "string_decoder": "^1.0.0", - "timers-browserify": "^2.0.4", - "tty-browserify": "0.0.0", - "url": "^0.11.0", - "util": "^0.10.3", - "vm-browserify": "0.0.4" - }, - "dependencies": { - "punycode": { - "version": "1.4.1", - "resolved": "https://registry.npmjs.org/punycode/-/punycode-1.4.1.tgz", - "integrity": "sha1-wNWmOycYgArY4esPpSachN1BhF4=", - "dev": true - } - } - }, - "node-pre-gyp": { - "version": "0.10.3", - "resolved": "https://registry.npmjs.org/node-pre-gyp/-/node-pre-gyp-0.10.3.tgz", - "integrity": "sha512-d1xFs+C/IPS8Id0qPTZ4bUT8wWryfR/OzzAFxweG+uLN85oPzyo2Iw6bVlLQ/JOdgNonXLCoRyqDzDWq4iw72A==", - "dev": true, - "optional": true, - "requires": { - "detect-libc": "^1.0.2", - "mkdirp": "^0.5.1", - "needle": "^2.2.1", - "nopt": "^4.0.1", - "npm-packlist": "^1.1.6", - "npmlog": "^4.0.2", - "rc": "^1.2.7", - "rimraf": "^2.6.1", - "semver": "^5.3.0", - "tar": "^4" - } - }, - "node-releases": { - "version": "1.1.3", - "resolved": "https://registry.npmjs.org/node-releases/-/node-releases-1.1.3.tgz", - "integrity": "sha512-6VrvH7z6jqqNFY200kdB6HdzkgM96Oaj9v3dqGfgp6mF+cHmU4wyQKZ2/WPDRVoR0Jz9KqbamaBN0ZhdUaysUQ==", - "dev": true, - "requires": { - "semver": "^5.3.0" - } - }, - "nopt": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/nopt/-/nopt-4.0.1.tgz", - "integrity": "sha1-0NRoWv1UFRk8jHUFYC0NF81kR00=", - "dev": true, - "optional": true, - "requires": { - "abbrev": "1", - "osenv": "^0.1.4" - } - }, - "normalize-path": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-2.1.1.tgz", - "integrity": "sha1-GrKLVW4Zg2Oowab35vogE3/mrtk=", - "dev": true, - "requires": { - "remove-trailing-separator": "^1.0.1" - } - }, - "npm-bundled": { - "version": "1.0.5", - "resolved": "https://registry.npmjs.org/npm-bundled/-/npm-bundled-1.0.5.tgz", - "integrity": "sha512-m/e6jgWu8/v5niCUKQi9qQl8QdeEduFA96xHDDzFGqly0OOjI7c+60KM/2sppfnUU9JJagf+zs+yGhqSOFj71g==", - "dev": true, - "optional": true - }, - "npm-packlist": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/npm-packlist/-/npm-packlist-1.2.0.tgz", - "integrity": "sha512-7Mni4Z8Xkx0/oegoqlcao/JpPCPEMtUvsmB0q7mgvlMinykJLSRTYuFqoQLYgGY8biuxIeiHO+QNJKbCfljewQ==", - "dev": true, - "optional": true, - "requires": { - "ignore-walk": "^3.0.1", - "npm-bundled": "^1.0.1" - } - }, - "npm-run-path": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/npm-run-path/-/npm-run-path-2.0.2.tgz", - "integrity": "sha1-NakjLfo11wZ7TLLd8jV7GHFTbF8=", - "dev": true, - "requires": { - "path-key": "^2.0.0" - } - }, - "npmlog": { - "version": "4.1.2", - "resolved": "https://registry.npmjs.org/npmlog/-/npmlog-4.1.2.tgz", - "integrity": "sha512-2uUqazuKlTaSI/dC8AzicUck7+IrEaOnN/e0jd3Xtt1KcGpwx30v50mL7oPyr/h9bL3E4aZccVwpwP+5W9Vjkg==", - "dev": true, - "optional": true, - "requires": { - "are-we-there-yet": "~1.1.2", - "console-control-strings": "~1.1.0", - "gauge": "~2.7.3", - "set-blocking": "~2.0.0" - } - }, - "number-is-nan": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/number-is-nan/-/number-is-nan-1.0.1.tgz", - "integrity": "sha1-CXtgK1NCKlIsGvuHkDGDNpQaAR0=", - "dev": true - }, - "object-assign": { - "version": "4.1.1", - "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", - "integrity": "sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM=", - "dev": true, - "optional": true - }, - "object-copy": { - "version": "0.1.0", - "resolved": "https://registry.npmjs.org/object-copy/-/object-copy-0.1.0.tgz", - "integrity": "sha1-fn2Fi3gb18mRpBupde04EnVOmYw=", - "dev": true, - "requires": { - "copy-descriptor": "^0.1.0", - "define-property": "^0.2.5", - "kind-of": "^3.0.3" - }, - "dependencies": { - "define-property": { - "version": "0.2.5", - "resolved": "https://registry.npmjs.org/define-property/-/define-property-0.2.5.tgz", - "integrity": "sha1-w1se+RjsPJkPmlvFe+BKrOxcgRY=", - "dev": true, - "requires": { - "is-descriptor": "^0.1.0" - } - }, - "kind-of": { - "version": "3.2.2", - "resolved": "https://registry.npmjs.org/kind-of/-/kind-of-3.2.2.tgz", - "integrity": "sha1-MeohpzS6ubuw8yRm2JOupR5KPGQ=", - "dev": true, - "requires": { - "is-buffer": "^1.1.5" - } - } - } - }, - "object-keys": { - "version": "1.0.12", - "resolved": "https://registry.npmjs.org/object-keys/-/object-keys-1.0.12.tgz", - "integrity": "sha512-FTMyFUm2wBcGHnH2eXmz7tC6IwlqQZ6mVZ+6dm6vZ4IQIHjs6FdNsQBuKGPuUUUY6NfJw2PshC08Tn6LzLDOag==", - "dev": true - }, - "object-visit": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/object-visit/-/object-visit-1.0.1.tgz", - "integrity": "sha1-95xEk68MU3e1n+OdOV5BBC3QRbs=", - "dev": true, - "requires": { - "isobject": "^3.0.0" - } - }, - "object.getownpropertydescriptors": { - "version": "2.0.3", - "resolved": "https://registry.npmjs.org/object.getownpropertydescriptors/-/object.getownpropertydescriptors-2.0.3.tgz", - "integrity": "sha1-h1jIRvW0B62rDyNuCYbxSwUcqhY=", - "dev": true, - "requires": { - "define-properties": "^1.1.2", - "es-abstract": "^1.5.1" - } - }, - "object.pick": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/object.pick/-/object.pick-1.3.0.tgz", - "integrity": "sha1-h6EKxMFpS9Lhy/U1kaZhQftd10c=", - "dev": true, - "requires": { - "isobject": "^3.0.1" - } - }, - "once": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", - "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", - "dev": true, - "requires": { - "wrappy": "1" - } - }, - "os-browserify": { - "version": "0.3.0", - "resolved": "https://registry.npmjs.org/os-browserify/-/os-browserify-0.3.0.tgz", - "integrity": "sha1-hUNzx/XCMVkU/Jv8a9gjj92h7Cc=", - "dev": true - }, - "os-homedir": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/os-homedir/-/os-homedir-1.0.2.tgz", - "integrity": "sha1-/7xJiDNuDoM94MFox+8VISGqf7M=", - "dev": true, - "optional": true - }, - "os-locale": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/os-locale/-/os-locale-3.1.0.tgz", - "integrity": "sha512-Z8l3R4wYWM40/52Z+S265okfFj8Kt2cC2MKY+xNi3kFs+XGI7WXu/I309QQQYbRW4ijiZ+yxs9pqEhJh0DqW3Q==", - "dev": true, - "requires": { - "execa": "^1.0.0", - "lcid": "^2.0.0", - "mem": "^4.0.0" - } - }, - "os-tmpdir": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/os-tmpdir/-/os-tmpdir-1.0.2.tgz", - "integrity": "sha1-u+Z0BseaqFxc/sdm/lc0VV36EnQ=", - "dev": true, - "optional": true - }, - "osenv": { - "version": "0.1.5", - "resolved": "https://registry.npmjs.org/osenv/-/osenv-0.1.5.tgz", - "integrity": "sha512-0CWcCECdMVc2Rw3U5w9ZjqX6ga6ubk1xDVKxtBQPK7wis/0F2r9T6k4ydGYhecl7YUBxBVxhL5oisPsNxAPe2g==", - "dev": true, - "optional": true, - "requires": { - "os-homedir": "^1.0.0", - "os-tmpdir": "^1.0.0" - } - }, - "p-defer": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/p-defer/-/p-defer-1.0.0.tgz", - "integrity": "sha1-n26xgvbJqozXQwBKfU+WsZaw+ww=", - "dev": true - }, - "p-finally": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/p-finally/-/p-finally-1.0.0.tgz", - "integrity": "sha1-P7z7FbiZpEEjs0ttzBi3JDNqLK4=", - "dev": true - }, - "p-is-promise": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/p-is-promise/-/p-is-promise-1.1.0.tgz", - "integrity": "sha1-nJRWmJ6fZYgBewQ01WCXZ1w9oF4=", - "dev": true - }, - "p-limit": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-2.1.0.tgz", - "integrity": "sha512-NhURkNcrVB+8hNfLuysU8enY5xn2KXphsHBaC2YmRNTZRc7RWusw6apSpdEj3jo4CMb6W9nrF6tTnsJsJeyu6g==", - "dev": true, - "requires": { - "p-try": "^2.0.0" - } - }, - "p-locate": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-3.0.0.tgz", - "integrity": "sha512-x+12w/To+4GFfgJhBEpiDcLozRJGegY+Ei7/z0tSLkMmxGZNybVMSfWj9aJn8Z5Fc7dBUNJOOVgPv2H7IwulSQ==", - "dev": true, - "requires": { - "p-limit": "^2.0.0" - } - }, - "p-try": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/p-try/-/p-try-2.0.0.tgz", - "integrity": "sha512-hMp0onDKIajHfIkdRk3P4CdCmErkYAxxDtP3Wx/4nZ3aGlau2VKh3mZpcuFkH27WQkL/3WBCPOktzA9ZOAnMQQ==", - "dev": true - }, - "pako": { - "version": "1.0.8", - "resolved": "https://registry.npmjs.org/pako/-/pako-1.0.8.tgz", - "integrity": "sha512-6i0HVbUfcKaTv+EG8ZTr75az7GFXcLYk9UyLEg7Notv/Ma+z/UG3TCoz6GiNeOrn1E/e63I0X/Hpw18jHOTUnA==", - "dev": true - }, - "parallel-transform": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/parallel-transform/-/parallel-transform-1.1.0.tgz", - "integrity": "sha1-1BDwZbBdojCB/NEPKIVMKb2jOwY=", - "dev": true, - "requires": { - "cyclist": "~0.2.2", - "inherits": "^2.0.3", - "readable-stream": "^2.1.5" - } - }, - "parse-asn1": { - "version": "5.1.1", - "resolved": "https://registry.npmjs.org/parse-asn1/-/parse-asn1-5.1.1.tgz", - "integrity": "sha512-KPx7flKXg775zZpnp9SxJlz00gTd4BmJ2yJufSc44gMCRrRQ7NSzAcSJQfifuOLgW6bEi+ftrALtsgALeB2Adw==", - "dev": true, - "requires": { - "asn1.js": "^4.0.0", - "browserify-aes": "^1.0.0", - "create-hash": "^1.1.0", - "evp_bytestokey": "^1.0.0", - "pbkdf2": "^3.0.3" - } - }, - "parse-passwd": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/parse-passwd/-/parse-passwd-1.0.0.tgz", - "integrity": "sha1-bVuTSkVpk7I9N/QKOC1vFmao5cY=", - "dev": true - }, - "pascalcase": { - "version": "0.1.1", - "resolved": "https://registry.npmjs.org/pascalcase/-/pascalcase-0.1.1.tgz", - "integrity": "sha1-s2PlXoAGym/iF4TS2yK9FdeRfxQ=", - "dev": true - }, - "path-browserify": { - "version": "0.0.0", - "resolved": "https://registry.npmjs.org/path-browserify/-/path-browserify-0.0.0.tgz", - "integrity": "sha1-oLhwcpquIUAFt9UDLsLLuw+0RRo=", - "dev": true - }, - "path-dirname": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/path-dirname/-/path-dirname-1.0.2.tgz", - "integrity": "sha1-zDPSTVJeCZpTiMAzbG4yuRYGCeA=", - "dev": true - }, - "path-exists": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-3.0.0.tgz", - "integrity": "sha1-zg6+ql94yxiSXqfYENe1mwEP1RU=", - "dev": true - }, - "path-is-absolute": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", - "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=", - "dev": true - }, - "path-key": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/path-key/-/path-key-2.0.1.tgz", - "integrity": "sha1-QRyttXTFoUDTpLGRDUDYDMn0C0A=", - "dev": true - }, - "path-parse": { - "version": "1.0.6", - "resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.6.tgz", - "integrity": "sha512-GSmOT2EbHrINBf9SR7CDELwlJ8AENk3Qn7OikK4nFYAu3Ote2+JYNVvkpAEQm3/TLNEJFD/xZJjzyxg3KBWOzw==", - "dev": true - }, - "pbkdf2": { - "version": "3.0.17", - "resolved": "https://registry.npmjs.org/pbkdf2/-/pbkdf2-3.0.17.tgz", - "integrity": "sha512-U/il5MsrZp7mGg3mSQfn742na2T+1/vHDCG5/iTI3X9MKUuYUZVLQhyRsg06mCgDBTd57TxzgZt7P+fYfjRLtA==", - "dev": true, - "requires": { - "create-hash": "^1.1.2", - "create-hmac": "^1.1.4", - "ripemd160": "^2.0.1", - "safe-buffer": "^5.0.1", - "sha.js": "^2.4.8" - } - }, - "pify": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/pify/-/pify-3.0.0.tgz", - "integrity": "sha1-5aSs0sEB/fPZpNB/DbxNtJ3SgXY=", - "dev": true - }, - "pkg-dir": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/pkg-dir/-/pkg-dir-3.0.0.tgz", - "integrity": "sha512-/E57AYkoeQ25qkxMj5PBOVgF8Kiu/h7cYS30Z5+R7WaiCCBfLq58ZI/dSeaEKb9WVJV5n/03QwrN3IeWIFllvw==", - "dev": true, - "requires": { - "find-up": "^3.0.0" - } - }, - "posix-character-classes": { - "version": "0.1.1", - "resolved": "https://registry.npmjs.org/posix-character-classes/-/posix-character-classes-0.1.1.tgz", - "integrity": "sha1-AerA/jta9xoqbAL+q7jB/vfgDqs=", - "dev": true - }, - "printf": { - "version": "0.5.1", - "resolved": "https://registry.npmjs.org/printf/-/printf-0.5.1.tgz", - "integrity": "sha512-UaE/jO0hNsrvPGQEb4LyNzcrJv9Z00tsreBduOSxMtrebvoUhxiEJ4YCHX8YHf6akwfKsC2Gyv5zv47UXhMiLg==" - }, - "private": { - "version": "0.1.8", - "resolved": "https://registry.npmjs.org/private/-/private-0.1.8.tgz", - "integrity": "sha512-VvivMrbvd2nKkiG38qjULzlc+4Vx4wm/whI9pQD35YrARNnhxeiRktSOhSukRLFNlzg6Br/cJPet5J/u19r/mg==", - "dev": true - }, - "process": { - "version": "0.11.10", - "resolved": "https://registry.npmjs.org/process/-/process-0.11.10.tgz", - "integrity": "sha1-czIwDoQBYb2j5podHZGn1LwW8YI=", - "dev": true - }, - "process-nextick-args": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.0.tgz", - "integrity": "sha512-MtEC1TqN0EU5nephaJ4rAtThHtC86dNN9qCuEhtshvpVBkAW5ZO7BASN9REnF9eoXGcRub+pFuKEpOHE+HbEMw==", - "dev": true - }, - "promise-inflight": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/promise-inflight/-/promise-inflight-1.0.1.tgz", - "integrity": "sha1-mEcocL8igTL8vdhoEputEsPAKeM=", - "dev": true - }, - "prr": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/prr/-/prr-1.0.1.tgz", - "integrity": "sha1-0/wRS6BplaRexok/SEzrHXj19HY=", - "dev": true - }, - "public-encrypt": { - "version": "4.0.3", - "resolved": "https://registry.npmjs.org/public-encrypt/-/public-encrypt-4.0.3.tgz", - "integrity": "sha512-zVpa8oKZSz5bTMTFClc1fQOnyyEzpl5ozpi1B5YcvBrdohMjH2rfsBtyXcuNuwjsDIXmBYlF2N5FlJYhR29t8Q==", - "dev": true, - "requires": { - "bn.js": "^4.1.0", - "browserify-rsa": "^4.0.0", - "create-hash": "^1.1.0", - "parse-asn1": "^5.0.0", - "randombytes": "^2.0.1", - "safe-buffer": "^5.1.2" - } - }, - "pump": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/pump/-/pump-3.0.0.tgz", - "integrity": "sha512-LwZy+p3SFs1Pytd/jYct4wpv49HiYCqd9Rlc5ZVdk0V+8Yzv6jR5Blk3TRmPL1ft69TxP0IMZGJ+WPFU2BFhww==", - "dev": true, - "requires": { - "end-of-stream": "^1.1.0", - "once": "^1.3.1" - } - }, - "pumpify": { - "version": "1.5.1", - "resolved": "https://registry.npmjs.org/pumpify/-/pumpify-1.5.1.tgz", - "integrity": "sha512-oClZI37HvuUJJxSKKrC17bZ9Cu0ZYhEAGPsPUy9KlMUmv9dKX2o77RUmq7f3XjIxbwyGwYzbzQ1L2Ks8sIradQ==", - "dev": true, - "requires": { - "duplexify": "^3.6.0", - "inherits": "^2.0.3", - "pump": "^2.0.0" - }, - "dependencies": { - "pump": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/pump/-/pump-2.0.1.tgz", - "integrity": "sha512-ruPMNRkN3MHP1cWJc9OWr+T/xDP0jhXYCLfJcBuX54hhfIBnaQmAUMfDcG4DM5UMWByBbJY69QSphm3jtDKIkA==", - "dev": true, - "requires": { - "end-of-stream": "^1.1.0", - "once": "^1.3.1" - } - } - } - }, - "punycode": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.1.1.tgz", - "integrity": "sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A==", - "dev": true - }, - "querystring": { - "version": "0.2.0", - "resolved": "https://registry.npmjs.org/querystring/-/querystring-0.2.0.tgz", - "integrity": "sha1-sgmEkgO7Jd+CDadW50cAWHhSFiA=", - "dev": true - }, - "querystring-es3": { - "version": "0.2.1", - "resolved": "https://registry.npmjs.org/querystring-es3/-/querystring-es3-0.2.1.tgz", - "integrity": "sha1-nsYfeQSYdXB9aUFFlv2Qek1xHnM=", - "dev": true - }, - "randombytes": { - "version": "2.0.6", - "resolved": "https://registry.npmjs.org/randombytes/-/randombytes-2.0.6.tgz", - "integrity": "sha512-CIQ5OFxf4Jou6uOKe9t1AOgqpeU5fd70A8NPdHSGeYXqXsPe6peOwI0cUl88RWZ6sP1vPMV3avd/R6cZ5/sP1A==", - "dev": true, - "requires": { - "safe-buffer": "^5.1.0" - } - }, - "randomfill": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/randomfill/-/randomfill-1.0.4.tgz", - "integrity": "sha512-87lcbR8+MhcWcUiQ+9e+Rwx8MyR2P7qnt15ynUlbm3TU/fjbgz4GsvfSUDTemtCCtVCqb4ZcEFlyPNTh9bBTLw==", - "dev": true, - "requires": { - "randombytes": "^2.0.5", - "safe-buffer": "^5.1.0" - } - }, - "rc": { - "version": "1.2.8", - "resolved": "https://registry.npmjs.org/rc/-/rc-1.2.8.tgz", - "integrity": "sha512-y3bGgqKj3QBdxLbLkomlohkvsA8gdAiUQlSBJnBhfn+BPxg4bc62d8TcBW15wavDfgexCgccckhcZvywyQYPOw==", - "dev": true, - "optional": true, - "requires": { - "deep-extend": "^0.6.0", - "ini": "~1.3.0", - "minimist": "^1.2.0", - "strip-json-comments": "~2.0.1" - } - }, - "readable-stream": { - "version": "2.3.6", - "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.6.tgz", - "integrity": "sha512-tQtKA9WIAhBF3+VLAseyMqZeBjW0AHJoxOtYqSUZNJxauErmLbVm2FW1y+J/YA9dUrAC39ITejlZWhVIwawkKw==", - "dev": true, - "requires": { - "core-util-is": "~1.0.0", - "inherits": "~2.0.3", - "isarray": "~1.0.0", - "process-nextick-args": "~2.0.0", - "safe-buffer": "~5.1.1", - "string_decoder": "~1.1.1", - "util-deprecate": "~1.0.1" - } - }, - "readdirp": { - "version": "2.2.1", - "resolved": "https://registry.npmjs.org/readdirp/-/readdirp-2.2.1.tgz", - "integrity": "sha512-1JU/8q+VgFZyxwrJ+SVIOsh+KywWGpds3NTqikiKpDMZWScmAYyKIgqkO+ARvNWJfXeXR1zxz7aHF4u4CyH6vQ==", - "dev": true, - "requires": { - "graceful-fs": "^4.1.11", - "micromatch": "^3.1.10", - "readable-stream": "^2.0.2" - } - }, - "regenerate": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/regenerate/-/regenerate-1.4.0.tgz", - "integrity": "sha512-1G6jJVDWrt0rK99kBjvEtziZNCICAuvIPkSiUFIQxVP06RCVpq3dmDo2oi6ABpYaDYaTRr67BEhL8r1wgEZZKg==", - "dev": true - }, - "regenerate-unicode-properties": { - "version": "7.0.0", - "resolved": "https://registry.npmjs.org/regenerate-unicode-properties/-/regenerate-unicode-properties-7.0.0.tgz", - "integrity": "sha512-s5NGghCE4itSlUS+0WUj88G6cfMVMmH8boTPNvABf8od+2dhT9WDlWu8n01raQAJZMOK8Ch6jSexaRO7swd6aw==", - "dev": true, - "requires": { - "regenerate": "^1.4.0" - } - }, - "regenerator-transform": { - "version": "0.13.3", - "resolved": "https://registry.npmjs.org/regenerator-transform/-/regenerator-transform-0.13.3.tgz", - "integrity": "sha512-5ipTrZFSq5vU2YoGoww4uaRVAK4wyYC4TSICibbfEPOruUu8FFP7ErV0BjmbIOEpn3O/k9na9UEdYR/3m7N6uA==", - "dev": true, - "requires": { - "private": "^0.1.6" - } - }, - "regex-not": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/regex-not/-/regex-not-1.0.2.tgz", - "integrity": "sha512-J6SDjUgDxQj5NusnOtdFxDwN/+HWykR8GELwctJ7mdqhcyy1xEc4SRFHUXvxTp661YaVKAjfRLZ9cCqS6tn32A==", - "dev": true, - "requires": { - "extend-shallow": "^3.0.2", - "safe-regex": "^1.1.0" - } - }, - "regexpu-core": { - "version": "4.4.0", - "resolved": "https://registry.npmjs.org/regexpu-core/-/regexpu-core-4.4.0.tgz", - "integrity": "sha512-eDDWElbwwI3K0Lo6CqbQbA6FwgtCz4kYTarrri1okfkRLZAqstU+B3voZBCjg8Fl6iq0gXrJG6MvRgLthfvgOA==", - "dev": true, - "requires": { - "regenerate": "^1.4.0", - "regenerate-unicode-properties": "^7.0.0", - "regjsgen": "^0.5.0", - "regjsparser": "^0.6.0", - "unicode-match-property-ecmascript": "^1.0.4", - "unicode-match-property-value-ecmascript": "^1.0.2" - } - }, - "regjsgen": { - "version": "0.5.0", - "resolved": "https://registry.npmjs.org/regjsgen/-/regjsgen-0.5.0.tgz", - "integrity": "sha512-RnIrLhrXCX5ow/E5/Mh2O4e/oa1/jW0eaBKTSy3LaCj+M3Bqvm97GWDp2yUtzIs4LEn65zR2yiYGFqb2ApnzDA==", - "dev": true - }, - "regjsparser": { - "version": "0.6.0", - "resolved": "https://registry.npmjs.org/regjsparser/-/regjsparser-0.6.0.tgz", - "integrity": "sha512-RQ7YyokLiQBomUJuUG8iGVvkgOLxwyZM8k6d3q5SAXpg4r5TZJZigKFvC6PpD+qQ98bCDC5YelPeA3EucDoNeQ==", - "dev": true, - "requires": { - "jsesc": "~0.5.0" - }, - "dependencies": { - "jsesc": { - "version": "0.5.0", - "resolved": "https://registry.npmjs.org/jsesc/-/jsesc-0.5.0.tgz", - "integrity": "sha1-597mbjXW/Bb3EP6R1c9p9w8IkR0=", - "dev": true - } - } - }, - "remove-trailing-separator": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/remove-trailing-separator/-/remove-trailing-separator-1.1.0.tgz", - "integrity": "sha1-wkvOKig62tW8P1jg1IJJuSN52O8=", - "dev": true - }, - "repeat-element": { - "version": "1.1.3", - "resolved": "https://registry.npmjs.org/repeat-element/-/repeat-element-1.1.3.tgz", - "integrity": "sha512-ahGq0ZnV5m5XtZLMb+vP76kcAM5nkLqk0lpqAuojSKGgQtn4eRi4ZZGm2olo2zKFH+sMsWaqOCW1dqAnOru72g==", - "dev": true - }, - "repeat-string": { - "version": "1.6.1", - "resolved": "https://registry.npmjs.org/repeat-string/-/repeat-string-1.6.1.tgz", - "integrity": "sha1-jcrkcOHIirwtYA//Sndihtp15jc=", - "dev": true - }, - "require-directory": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz", - "integrity": "sha1-jGStX9MNqxyXbiNE/+f3kqam30I=", - "dev": true - }, - "require-main-filename": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/require-main-filename/-/require-main-filename-1.0.1.tgz", - "integrity": "sha1-l/cXtp1IeE9fUmpsWqj/3aBVpNE=", - "dev": true - }, - "resolve": { - "version": "1.9.0", - "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.9.0.tgz", - "integrity": "sha512-TZNye00tI67lwYvzxCxHGjwTNlUV70io54/Ed4j6PscB8xVfuBJpRenI/o6dVk0cY0PYTY27AgCoGGxRnYuItQ==", - "dev": true, - "requires": { - "path-parse": "^1.0.6" - } - }, - "resolve-cwd": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/resolve-cwd/-/resolve-cwd-2.0.0.tgz", - "integrity": "sha1-AKn3OHVW4nA46uIyyqNypqWbZlo=", - "dev": true, - "requires": { - "resolve-from": "^3.0.0" - } - }, - "resolve-dir": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/resolve-dir/-/resolve-dir-1.0.1.tgz", - "integrity": "sha1-eaQGRMNivoLybv/nOcm7U4IEb0M=", - "dev": true, - "requires": { - "expand-tilde": "^2.0.0", - "global-modules": "^1.0.0" - } - }, - "resolve-from": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-3.0.0.tgz", - "integrity": "sha1-six699nWiBvItuZTM17rywoYh0g=", - "dev": true - }, - "resolve-url": { - "version": "0.2.1", - "resolved": "https://registry.npmjs.org/resolve-url/-/resolve-url-0.2.1.tgz", - "integrity": "sha1-LGN/53yJOv0qZj/iGqkIAGjiBSo=", - "dev": true - }, - "ret": { - "version": "0.1.15", - "resolved": "https://registry.npmjs.org/ret/-/ret-0.1.15.tgz", - "integrity": "sha512-TTlYpa+OL+vMMNG24xSlQGEJ3B/RzEfUlLct7b5G/ytav+wPrplCpVMFuwzXbkecJrb6IYo1iFb0S9v37754mg==", - "dev": true - }, - "rimraf": { - "version": "2.6.3", - "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.6.3.tgz", - "integrity": "sha512-mwqeW5XsA2qAejG46gYdENaxXjx9onRNCfn7L0duuP4hCuTIi/QO7PDK07KJfp1d+izWPrzEJDcSqBa0OZQriA==", - "dev": true, - "requires": { - "glob": "^7.1.3" - } - }, - "ripemd160": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/ripemd160/-/ripemd160-2.0.2.tgz", - "integrity": "sha512-ii4iagi25WusVoiC4B4lq7pbXfAp3D9v5CwfkY33vffw2+pkDjY1D8GaN7spsxvCSx8dkPqOZCEZyfxcmJG2IA==", - "dev": true, - "requires": { - "hash-base": "^3.0.0", - "inherits": "^2.0.1" - } - }, - "run-queue": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/run-queue/-/run-queue-1.0.3.tgz", - "integrity": "sha1-6Eg5bwV9Ij8kOGkkYY4laUFh7Ec=", - "dev": true, - "requires": { - "aproba": "^1.1.1" - } - }, - "safe-buffer": { - "version": "5.1.2", - "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", - "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==", - "dev": true - }, - "safe-regex": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/safe-regex/-/safe-regex-1.1.0.tgz", - "integrity": "sha1-QKNmnzsHfR6UPURinhV91IAjvy4=", - "dev": true, - "requires": { - "ret": "~0.1.10" - } - }, - "safer-buffer": { - "version": "2.1.2", - "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", - "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==", - "dev": true, - "optional": true - }, - "sax": { - "version": "1.2.4", - "resolved": "https://registry.npmjs.org/sax/-/sax-1.2.4.tgz", - "integrity": "sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw==", - "dev": true, - "optional": true - }, - "schema-utils": { - "version": "0.4.7", - "resolved": "https://registry.npmjs.org/schema-utils/-/schema-utils-0.4.7.tgz", - "integrity": "sha512-v/iwU6wvwGK8HbU9yi3/nhGzP0yGSuhQMzL6ySiec1FSrZZDkhm4noOSWzrNFo/jEc+SJY6jRTwuwbSXJPDUnQ==", - "dev": true, - "requires": { - "ajv": "^6.1.0", - "ajv-keywords": "^3.1.0" - } - }, - "semver": { - "version": "5.6.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-5.6.0.tgz", - "integrity": "sha512-RS9R6R35NYgQn++fkDWaOmqGoj4Ek9gGs+DPxNUZKuwE183xjJroKvyo1IzVFeXvUrvmALy6FWD5xrdJT25gMg==", - "dev": true - }, - "serialize-javascript": { - "version": "1.6.1", - "resolved": "https://registry.npmjs.org/serialize-javascript/-/serialize-javascript-1.6.1.tgz", - "integrity": "sha512-A5MOagrPFga4YaKQSWHryl7AXvbQkEqpw4NNYMTNYUNV51bA8ABHgYFpqKx+YFFrw59xMV1qGH1R4AgoNIVgCw==", - "dev": true - }, - "set-blocking": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/set-blocking/-/set-blocking-2.0.0.tgz", - "integrity": "sha1-BF+XgtARrppoA93TgrJDkrPYkPc=", - "dev": true - }, - "set-value": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/set-value/-/set-value-2.0.0.tgz", - "integrity": "sha512-hw0yxk9GT/Hr5yJEYnHNKYXkIA8mVJgd9ditYZCe16ZczcaELYYcfvaXesNACk2O8O0nTiPQcQhGUQj8JLzeeg==", - "dev": true, - "requires": { - "extend-shallow": "^2.0.1", - "is-extendable": "^0.1.1", - "is-plain-object": "^2.0.3", - "split-string": "^3.0.1" - }, - "dependencies": { - "extend-shallow": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/extend-shallow/-/extend-shallow-2.0.1.tgz", - "integrity": "sha1-Ua99YUrZqfYQ6huvu5idaxxWiQ8=", - "dev": true, - "requires": { - "is-extendable": "^0.1.0" - } - } - } - }, - "setimmediate": { - "version": "1.0.5", - "resolved": "https://registry.npmjs.org/setimmediate/-/setimmediate-1.0.5.tgz", - "integrity": "sha1-KQy7Iy4waULX1+qbg3Mqt4VvgoU=", - "dev": true - }, - "sha.js": { - "version": "2.4.11", - "resolved": "https://registry.npmjs.org/sha.js/-/sha.js-2.4.11.tgz", - "integrity": "sha512-QMEp5B7cftE7APOjk5Y6xgrbWu+WkLVQwk8JNjZ8nKRciZaByEW6MubieAiToS7+dwvrjGhH8jRXz3MVd0AYqQ==", - "dev": true, - "requires": { - "inherits": "^2.0.1", - "safe-buffer": "^5.0.1" - } - }, - "shebang-command": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-1.2.0.tgz", - "integrity": "sha1-RKrGW2lbAzmJaMOfNj/uXer98eo=", - "dev": true, - "requires": { - "shebang-regex": "^1.0.0" - } - }, - "shebang-regex": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-1.0.0.tgz", - "integrity": "sha1-2kL0l0DAtC2yypcoVxyxkMmO/qM=", - "dev": true - }, - "signal-exit": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.2.tgz", - "integrity": "sha1-tf3AjxKH6hF4Yo5BXiUTK3NkbG0=", - "dev": true - }, - "snapdragon": { - "version": "0.8.2", - "resolved": "https://registry.npmjs.org/snapdragon/-/snapdragon-0.8.2.tgz", - "integrity": "sha512-FtyOnWN/wCHTVXOMwvSv26d+ko5vWlIDD6zoUJ7LW8vh+ZBC8QdljveRP+crNrtBwioEUWy/4dMtbBjA4ioNlg==", - "dev": true, - "requires": { - "base": "^0.11.1", - "debug": "^2.2.0", - "define-property": "^0.2.5", - "extend-shallow": "^2.0.1", - "map-cache": "^0.2.2", - "source-map": "^0.5.6", - "source-map-resolve": "^0.5.0", - "use": "^3.1.0" - }, - "dependencies": { - "debug": { - "version": "2.6.9", - "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", - "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", - "dev": true, - "requires": { - "ms": "2.0.0" - } - }, - "define-property": { - "version": "0.2.5", - "resolved": "https://registry.npmjs.org/define-property/-/define-property-0.2.5.tgz", - "integrity": "sha1-w1se+RjsPJkPmlvFe+BKrOxcgRY=", - "dev": true, - "requires": { - "is-descriptor": "^0.1.0" - } - }, - "extend-shallow": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/extend-shallow/-/extend-shallow-2.0.1.tgz", - "integrity": "sha1-Ua99YUrZqfYQ6huvu5idaxxWiQ8=", - "dev": true, - "requires": { - "is-extendable": "^0.1.0" - } - }, - "ms": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", - "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=", - "dev": true - } - } - }, - "snapdragon-node": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/snapdragon-node/-/snapdragon-node-2.1.1.tgz", - "integrity": "sha512-O27l4xaMYt/RSQ5TR3vpWCAB5Kb/czIcqUFOM/C4fYcLnbZUc1PkjTAMjof2pBWaSTwOUd6qUHcFGVGj7aIwnw==", - "dev": true, - "requires": { - "define-property": "^1.0.0", - "isobject": "^3.0.0", - "snapdragon-util": "^3.0.1" - }, - "dependencies": { - "define-property": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/define-property/-/define-property-1.0.0.tgz", - "integrity": "sha1-dp66rz9KY6rTr56NMEybvnm/sOY=", - "dev": true, - "requires": { - "is-descriptor": "^1.0.0" - } - }, - "is-accessor-descriptor": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/is-accessor-descriptor/-/is-accessor-descriptor-1.0.0.tgz", - "integrity": "sha512-m5hnHTkcVsPfqx3AKlyttIPb7J+XykHvJP2B9bZDjlhLIoEq4XoK64Vg7boZlVWYK6LUY94dYPEE7Lh0ZkZKcQ==", - "dev": true, - "requires": { - "kind-of": "^6.0.0" - } - }, - "is-data-descriptor": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/is-data-descriptor/-/is-data-descriptor-1.0.0.tgz", - "integrity": "sha512-jbRXy1FmtAoCjQkVmIVYwuuqDFUbaOeDjmed1tOGPrsMhtJA4rD9tkgA0F1qJ3gRFRXcHYVkdeaP50Q5rE/jLQ==", - "dev": true, - "requires": { - "kind-of": "^6.0.0" - } - }, - "is-descriptor": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/is-descriptor/-/is-descriptor-1.0.2.tgz", - "integrity": "sha512-2eis5WqQGV7peooDyLmNEPUrps9+SXX5c9pL3xEB+4e9HnGuDa7mB7kHxHw4CbqS9k1T2hOH3miL8n8WtiYVtg==", - "dev": true, - "requires": { - "is-accessor-descriptor": "^1.0.0", - "is-data-descriptor": "^1.0.0", - "kind-of": "^6.0.2" - } - } - } - }, - "snapdragon-util": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/snapdragon-util/-/snapdragon-util-3.0.1.tgz", - "integrity": "sha512-mbKkMdQKsjX4BAL4bRYTj21edOf8cN7XHdYUJEe+Zn99hVEYcMvKPct1IqNe7+AZPirn8BCDOQBHQZknqmKlZQ==", - "dev": true, - "requires": { - "kind-of": "^3.2.0" - }, - "dependencies": { - "kind-of": { - "version": "3.2.2", - "resolved": "https://registry.npmjs.org/kind-of/-/kind-of-3.2.2.tgz", - "integrity": "sha1-MeohpzS6ubuw8yRm2JOupR5KPGQ=", - "dev": true, - "requires": { - "is-buffer": "^1.1.5" - } - } - } - }, - "source-list-map": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/source-list-map/-/source-list-map-2.0.1.tgz", - "integrity": "sha512-qnQ7gVMxGNxsiL4lEuJwe/To8UnK7fAnmbGEEH8RpLouuKbeEm0lhbQVFIrNSuB+G7tVrAlVsZgETT5nljf+Iw==", - "dev": true - }, - "source-map": { - "version": "0.5.7", - "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.5.7.tgz", - "integrity": "sha1-igOdLRAh0i0eoUyA2OpGi6LvP8w=", - "dev": true - }, - "source-map-resolve": { - "version": "0.5.2", - "resolved": "https://registry.npmjs.org/source-map-resolve/-/source-map-resolve-0.5.2.tgz", - "integrity": "sha512-MjqsvNwyz1s0k81Goz/9vRBe9SZdB09Bdw+/zYyO+3CuPk6fouTaxscHkgtE8jKvf01kVfl8riHzERQ/kefaSA==", - "dev": true, - "requires": { - "atob": "^2.1.1", - "decode-uri-component": "^0.2.0", - "resolve-url": "^0.2.1", - "source-map-url": "^0.4.0", - "urix": "^0.1.0" - } - }, - "source-map-support": { - "version": "0.5.10", - "resolved": "https://registry.npmjs.org/source-map-support/-/source-map-support-0.5.10.tgz", - "integrity": "sha512-YfQ3tQFTK/yzlGJuX8pTwa4tifQj4QS2Mj7UegOu8jAz59MqIiMGPXxQhVQiIMNzayuUSF/jEuVnfFF5JqybmQ==", - "dev": true, - "requires": { - "buffer-from": "^1.0.0", - "source-map": "^0.6.0" - }, - "dependencies": { - "source-map": { - "version": "0.6.1", - "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", - "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==", - "dev": true - } - } - }, - "source-map-url": { - "version": "0.4.0", - "resolved": "https://registry.npmjs.org/source-map-url/-/source-map-url-0.4.0.tgz", - "integrity": "sha1-PpNdfd1zYxuXZZlW1VEo6HtQhKM=", - "dev": true - }, - "split-string": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/split-string/-/split-string-3.1.0.tgz", - "integrity": "sha512-NzNVhJDYpwceVVii8/Hu6DKfD2G+NrQHlS/V/qgv763EYudVwEcMQNxd2lh+0VrUByXN/oJkl5grOhYWvQUYiw==", - "dev": true, - "requires": { - "extend-shallow": "^3.0.0" - } - }, - "ssri": { - "version": "6.0.1", - "resolved": "https://registry.npmjs.org/ssri/-/ssri-6.0.1.tgz", - "integrity": "sha512-3Wge10hNcT1Kur4PDFwEieXSCMCJs/7WvSACcrMYrNp+b8kDL1/0wJch5Ni2WrtwEa2IO8OsVfeKIciKCDx/QA==", - "dev": true, - "requires": { - "figgy-pudding": "^3.5.1" - } - }, - "static-extend": { - "version": "0.1.2", - "resolved": "https://registry.npmjs.org/static-extend/-/static-extend-0.1.2.tgz", - "integrity": "sha1-YICcOcv/VTNyJv1eC1IPNB8ftcY=", - "dev": true, - "requires": { - "define-property": "^0.2.5", - "object-copy": "^0.1.0" - }, - "dependencies": { - "define-property": { - "version": "0.2.5", - "resolved": "https://registry.npmjs.org/define-property/-/define-property-0.2.5.tgz", - "integrity": "sha1-w1se+RjsPJkPmlvFe+BKrOxcgRY=", - "dev": true, - "requires": { - "is-descriptor": "^0.1.0" - } - } - } - }, - "stream-browserify": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/stream-browserify/-/stream-browserify-2.0.1.tgz", - "integrity": "sha1-ZiZu5fm9uZQKTkUUyvtDu3Hlyds=", - "dev": true, - "requires": { - "inherits": "~2.0.1", - "readable-stream": "^2.0.2" - } - }, - "stream-each": { - "version": "1.2.3", - "resolved": "https://registry.npmjs.org/stream-each/-/stream-each-1.2.3.tgz", - "integrity": "sha512-vlMC2f8I2u/bZGqkdfLQW/13Zihpej/7PmSiMQsbYddxuTsJp8vRe2x2FvVExZg7FaOds43ROAuFJwPR4MTZLw==", - "dev": true, - "requires": { - "end-of-stream": "^1.1.0", - "stream-shift": "^1.0.0" - } - }, - "stream-http": { - "version": "2.8.3", - "resolved": "https://registry.npmjs.org/stream-http/-/stream-http-2.8.3.tgz", - "integrity": "sha512-+TSkfINHDo4J+ZobQLWiMouQYB+UVYFttRA94FpEzzJ7ZdqcL4uUUQ7WkdkI4DSozGmgBUE/a47L+38PenXhUw==", - "dev": true, - "requires": { - "builtin-status-codes": "^3.0.0", - "inherits": "^2.0.1", - "readable-stream": "^2.3.6", - "to-arraybuffer": "^1.0.0", - "xtend": "^4.0.0" - } - }, - "stream-shift": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/stream-shift/-/stream-shift-1.0.0.tgz", - "integrity": "sha1-1cdSgl5TZ+eG944Y5EXqIjoVWVI=", - "dev": true - }, - "string-width": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/string-width/-/string-width-1.0.2.tgz", - "integrity": "sha1-EYvfW4zcUaKn5w0hHgfisLmxB9M=", - "dev": true, - "requires": { - "code-point-at": "^1.0.0", - "is-fullwidth-code-point": "^1.0.0", - "strip-ansi": "^3.0.0" - } - }, - "string_decoder": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz", - "integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==", - "dev": true, - "requires": { - "safe-buffer": "~5.1.0" - } - }, - "strip-ansi": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz", - "integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=", - "dev": true, - "requires": { - "ansi-regex": "^2.0.0" - } - }, - "strip-eof": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/strip-eof/-/strip-eof-1.0.0.tgz", - "integrity": "sha1-u0P/VZim6wXYm1n80SnJgzE2Br8=", - "dev": true - }, - "strip-json-comments": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-2.0.1.tgz", - "integrity": "sha1-PFMZQukIwml8DsNEhYwobHygpgo=", - "dev": true, - "optional": true - }, - "supports-color": { - "version": "5.5.0", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz", - "integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==", - "dev": true, - "requires": { - "has-flag": "^3.0.0" - } - }, - "tapable": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/tapable/-/tapable-1.1.1.tgz", - "integrity": "sha512-9I2ydhj8Z9veORCw5PRm4u9uebCn0mcCa6scWoNcbZ6dAtoo2618u9UUzxgmsCOreJpqDDuv61LvwofW7hLcBA==", - "dev": true - }, - "tar": { - "version": "4.4.8", - "resolved": "https://registry.npmjs.org/tar/-/tar-4.4.8.tgz", - "integrity": "sha512-LzHF64s5chPQQS0IYBn9IN5h3i98c12bo4NCO7e0sGM2llXQ3p2FGC5sdENN4cTW48O915Sh+x+EXx7XW96xYQ==", - "dev": true, - "optional": true, - "requires": { - "chownr": "^1.1.1", - "fs-minipass": "^1.2.5", - "minipass": "^2.3.4", - "minizlib": "^1.1.1", - "mkdirp": "^0.5.0", - "safe-buffer": "^5.1.2", - "yallist": "^3.0.2" - } - }, - "terser": { - "version": "3.14.1", - "resolved": "https://registry.npmjs.org/terser/-/terser-3.14.1.tgz", - "integrity": "sha512-NSo3E99QDbYSMeJaEk9YW2lTg3qS9V0aKGlb+PlOrei1X02r1wSBHCNX/O+yeTRFSWPKPIGj6MqvvdqV4rnVGw==", - "dev": true, - "requires": { - "commander": "~2.17.1", - "source-map": "~0.6.1", - "source-map-support": "~0.5.6" - }, - "dependencies": { - "source-map": { - "version": "0.6.1", - "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", - "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==", - "dev": true - } - } - }, - "terser-webpack-plugin": { - "version": "1.2.1", - "resolved": "https://registry.npmjs.org/terser-webpack-plugin/-/terser-webpack-plugin-1.2.1.tgz", - "integrity": "sha512-GGSt+gbT0oKcMDmPx4SRSfJPE1XaN3kQRWG4ghxKQw9cn5G9x6aCKSsgYdvyM0na9NJ4Drv0RG6jbBByZ5CMjw==", - "dev": true, - "requires": { - "cacache": "^11.0.2", - "find-cache-dir": "^2.0.0", - "schema-utils": "^1.0.0", - "serialize-javascript": "^1.4.0", - "source-map": "^0.6.1", - "terser": "^3.8.1", - "webpack-sources": "^1.1.0", - "worker-farm": "^1.5.2" - }, - "dependencies": { - "schema-utils": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/schema-utils/-/schema-utils-1.0.0.tgz", - "integrity": "sha512-i27Mic4KovM/lnGsy8whRCHhc7VicJajAjTrYg11K9zfZXnYIt4k5F+kZkwjnrhKzLic/HLU4j11mjsz2G/75g==", - "dev": true, - "requires": { - "ajv": "^6.1.0", - "ajv-errors": "^1.0.0", - "ajv-keywords": "^3.1.0" - } - }, - "source-map": { - "version": "0.6.1", - "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", - "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==", - "dev": true - } - } - }, - "through2": { - "version": "2.0.5", - "resolved": "https://registry.npmjs.org/through2/-/through2-2.0.5.tgz", - "integrity": "sha512-/mrRod8xqpA+IHSLyGCQ2s8SPHiCDEeQJSep1jqLYeEUClOFG2Qsh+4FU6G9VeqpZnGW/Su8LQGc4YKni5rYSQ==", - "dev": true, - "requires": { - "readable-stream": "~2.3.6", - "xtend": "~4.0.1" - } - }, - "timers-browserify": { - "version": "2.0.10", - "resolved": "https://registry.npmjs.org/timers-browserify/-/timers-browserify-2.0.10.tgz", - "integrity": "sha512-YvC1SV1XdOUaL6gx5CoGroT3Gu49pK9+TZ38ErPldOWW4j49GI1HKs9DV+KGq/w6y+LZ72W1c8cKz2vzY+qpzg==", - "dev": true, - "requires": { - "setimmediate": "^1.0.4" - } - }, - "to-arraybuffer": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/to-arraybuffer/-/to-arraybuffer-1.0.1.tgz", - "integrity": "sha1-fSKbH8xjfkZsoIEYCDanqr/4P0M=", - "dev": true - }, - "to-fast-properties": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/to-fast-properties/-/to-fast-properties-2.0.0.tgz", - "integrity": "sha1-3F5pjL0HkmW8c+A3doGk5Og/YW4=", - "dev": true - }, - "to-object-path": { - "version": "0.3.0", - "resolved": "https://registry.npmjs.org/to-object-path/-/to-object-path-0.3.0.tgz", - "integrity": "sha1-KXWIt7Dn4KwI4E5nL4XB9JmeF68=", - "dev": true, - "requires": { - "kind-of": "^3.0.2" - }, - "dependencies": { - "kind-of": { - "version": "3.2.2", - "resolved": "https://registry.npmjs.org/kind-of/-/kind-of-3.2.2.tgz", - "integrity": "sha1-MeohpzS6ubuw8yRm2JOupR5KPGQ=", - "dev": true, - "requires": { - "is-buffer": "^1.1.5" - } - } - } - }, - "to-regex": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/to-regex/-/to-regex-3.0.2.tgz", - "integrity": "sha512-FWtleNAtZ/Ki2qtqej2CXTOayOH9bHDQF+Q48VpWyDXjbYxA4Yz8iDB31zXOBUlOHHKidDbqGVrTUvQMPmBGBw==", - "dev": true, - "requires": { - "define-property": "^2.0.2", - "extend-shallow": "^3.0.2", - "regex-not": "^1.0.2", - "safe-regex": "^1.1.0" - } - }, - "to-regex-range": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-2.1.1.tgz", - "integrity": "sha1-fIDBe53+vlmeJzZ+DU3VWQFB2zg=", - "dev": true, - "requires": { - "is-number": "^3.0.0", - "repeat-string": "^1.6.1" - } - }, - "trim-right": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/trim-right/-/trim-right-1.0.1.tgz", - "integrity": "sha1-yy4SAwZ+DI3h9hQJS5/kVwTqYAM=", - "dev": true - }, - "tslib": { - "version": "1.9.3", - "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.9.3.tgz", - "integrity": "sha512-4krF8scpejhaOgqzBEcGM7yDIEfi0/8+8zDRZhNZZ2kjmHJ4hv3zCbQWxoJGz1iw5U0Jl0nma13xzHXcncMavQ==", - "dev": true - }, - "tty-browserify": { - "version": "0.0.0", - "resolved": "https://registry.npmjs.org/tty-browserify/-/tty-browserify-0.0.0.tgz", - "integrity": "sha1-oVe6QC2iTpv5V/mqadUk7tQpAaY=", - "dev": true - }, - "typedarray": { - "version": "0.0.6", - "resolved": "https://registry.npmjs.org/typedarray/-/typedarray-0.0.6.tgz", - "integrity": "sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=", - "dev": true - }, - "unicode-canonical-property-names-ecmascript": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/unicode-canonical-property-names-ecmascript/-/unicode-canonical-property-names-ecmascript-1.0.4.tgz", - "integrity": "sha512-jDrNnXWHd4oHiTZnx/ZG7gtUTVp+gCcTTKr8L0HjlwphROEW3+Him+IpvC+xcJEFegapiMZyZe02CyuOnRmbnQ==", - "dev": true - }, - "unicode-match-property-ecmascript": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/unicode-match-property-ecmascript/-/unicode-match-property-ecmascript-1.0.4.tgz", - "integrity": "sha512-L4Qoh15vTfntsn4P1zqnHulG0LdXgjSO035fEpdtp6YxXhMT51Q6vgM5lYdG/5X3MjS+k/Y9Xw4SFCY9IkR0rg==", - "dev": true, - "requires": { - "unicode-canonical-property-names-ecmascript": "^1.0.4", - "unicode-property-aliases-ecmascript": "^1.0.4" - } - }, - "unicode-match-property-value-ecmascript": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/unicode-match-property-value-ecmascript/-/unicode-match-property-value-ecmascript-1.0.2.tgz", - "integrity": "sha512-Rx7yODZC1L/T8XKo/2kNzVAQaRE88AaMvI1EF/Xnj3GW2wzN6fop9DDWuFAKUVFH7vozkz26DzP0qyWLKLIVPQ==", - "dev": true - }, - "unicode-property-aliases-ecmascript": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/unicode-property-aliases-ecmascript/-/unicode-property-aliases-ecmascript-1.0.4.tgz", - "integrity": "sha512-2WSLa6OdYd2ng8oqiGIWnJqyFArvhn+5vgx5GTxMbUYjCYKUcuKS62YLFF0R/BDGlB1yzXjQOLtPAfHsgirEpg==", - "dev": true - }, - "union-value": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/union-value/-/union-value-1.0.0.tgz", - "integrity": "sha1-XHHDTLW61dzr4+oM0IIHulqhrqQ=", - "dev": true, - "requires": { - "arr-union": "^3.1.0", - "get-value": "^2.0.6", - "is-extendable": "^0.1.1", - "set-value": "^0.4.3" - }, - "dependencies": { - "extend-shallow": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/extend-shallow/-/extend-shallow-2.0.1.tgz", - "integrity": "sha1-Ua99YUrZqfYQ6huvu5idaxxWiQ8=", - "dev": true, - "requires": { - "is-extendable": "^0.1.0" - } - }, - "set-value": { - "version": "0.4.3", - "resolved": "https://registry.npmjs.org/set-value/-/set-value-0.4.3.tgz", - "integrity": "sha1-fbCPnT0i3H945Trzw79GZuzfzPE=", - "dev": true, - "requires": { - "extend-shallow": "^2.0.1", - "is-extendable": "^0.1.1", - "is-plain-object": "^2.0.1", - "to-object-path": "^0.3.0" - } - } - } - }, - "unique-filename": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/unique-filename/-/unique-filename-1.1.1.tgz", - "integrity": "sha512-Vmp0jIp2ln35UTXuryvjzkjGdRyf9b2lTXuSYUiPmzRcl3FDtYqAwOnTJkAngD9SWhnoJzDbTKwaOrZ+STtxNQ==", - "dev": true, - "requires": { - "unique-slug": "^2.0.0" - } - }, - "unique-slug": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/unique-slug/-/unique-slug-2.0.1.tgz", - "integrity": "sha512-n9cU6+gITaVu7VGj1Z8feKMmfAjEAQGhwD9fE3zvpRRa0wEIx8ODYkVGfSc94M2OX00tUFV8wH3zYbm1I8mxFg==", - "dev": true, - "requires": { - "imurmurhash": "^0.1.4" - } - }, - "unset-value": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/unset-value/-/unset-value-1.0.0.tgz", - "integrity": "sha1-g3aHP30jNRef+x5vw6jtDfyKtVk=", - "dev": true, - "requires": { - "has-value": "^0.3.1", - "isobject": "^3.0.0" - }, - "dependencies": { - "has-value": { - "version": "0.3.1", - "resolved": "https://registry.npmjs.org/has-value/-/has-value-0.3.1.tgz", - "integrity": "sha1-ex9YutpiyoJ+wKIHgCVlSEWZXh8=", - "dev": true, - "requires": { - "get-value": "^2.0.3", - "has-values": "^0.1.4", - "isobject": "^2.0.0" - }, - "dependencies": { - "isobject": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/isobject/-/isobject-2.1.0.tgz", - "integrity": "sha1-8GVWEJaj8dou9GJy+BXIQNh+DIk=", - "dev": true, - "requires": { - "isarray": "1.0.0" - } - } - } - }, - "has-values": { - "version": "0.1.4", - "resolved": "https://registry.npmjs.org/has-values/-/has-values-0.1.4.tgz", - "integrity": "sha1-bWHeldkd/Km5oCCJrThL/49it3E=", - "dev": true - } - } - }, - "upath": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/upath/-/upath-1.1.0.tgz", - "integrity": "sha512-bzpH/oBhoS/QI/YtbkqCg6VEiPYjSZtrHQM6/QnJS6OL9pKUFLqb3aFh4Scvwm45+7iAgiMkLhSbaZxUqmrprw==", - "dev": true - }, - "uri-js": { - "version": "4.2.2", - "resolved": "https://registry.npmjs.org/uri-js/-/uri-js-4.2.2.tgz", - "integrity": "sha512-KY9Frmirql91X2Qgjry0Wd4Y+YTdrdZheS8TFwvkbLWf/G5KNJDCh6pKL5OZctEW4+0Baa5idK2ZQuELRwPznQ==", - "dev": true, - "requires": { - "punycode": "^2.1.0" - } - }, - "urix": { - "version": "0.1.0", - "resolved": "https://registry.npmjs.org/urix/-/urix-0.1.0.tgz", - "integrity": "sha1-2pN/emLiH+wf0Y1Js1wpNQZ6bHI=", - "dev": true - }, - "url": { - "version": "0.11.0", - "resolved": "https://registry.npmjs.org/url/-/url-0.11.0.tgz", - "integrity": "sha1-ODjpfPxgUh63PFJajlW/3Z4uKPE=", - "dev": true, - "requires": { - "punycode": "1.3.2", - "querystring": "0.2.0" - }, - "dependencies": { - "punycode": { - "version": "1.3.2", - "resolved": "https://registry.npmjs.org/punycode/-/punycode-1.3.2.tgz", - "integrity": "sha1-llOgNvt8HuQjQvIyXM7v6jkmxI0=", - "dev": true - } - } - }, - "use": { - "version": "3.1.1", - "resolved": "https://registry.npmjs.org/use/-/use-3.1.1.tgz", - "integrity": "sha512-cwESVXlO3url9YWlFW/TA9cshCEhtu7IKJ/p5soJ/gGpj7vbvFrAY/eIioQ6Dw23KjZhYgiIo8HOs1nQ2vr/oQ==", - "dev": true - }, - "util": { - "version": "0.10.4", - "resolved": "https://registry.npmjs.org/util/-/util-0.10.4.tgz", - "integrity": "sha512-0Pm9hTQ3se5ll1XihRic3FDIku70C+iHUdT/W926rSgHV5QgXsYbKZN8MSC3tJtSkhuROzvsQjAaFENRXr+19A==", - "dev": true, - "requires": { - "inherits": "2.0.3" - } - }, - "util-deprecate": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", - "integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=", - "dev": true - }, - "util.promisify": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/util.promisify/-/util.promisify-1.0.0.tgz", - "integrity": "sha512-i+6qA2MPhvoKLuxnJNpXAGhg7HphQOSUq2LKMZD0m15EiskXUkMvKdF4Uui0WYeCUGea+o2cw/ZuwehtfsrNkA==", - "dev": true, - "requires": { - "define-properties": "^1.1.2", - "object.getownpropertydescriptors": "^2.0.3" - } - }, - "v8-compile-cache": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/v8-compile-cache/-/v8-compile-cache-2.0.2.tgz", - "integrity": "sha512-1wFuMUIM16MDJRCrpbpuEPTUGmM5QMUg0cr3KFwra2XgOgFcPGDQHDh3CszSCD2Zewc/dh/pamNEW8CbfDebUw==", - "dev": true - }, - "vm-browserify": { - "version": "0.0.4", - "resolved": "https://registry.npmjs.org/vm-browserify/-/vm-browserify-0.0.4.tgz", - "integrity": "sha1-XX6kW7755Kb/ZflUOOCofDV9WnM=", - "dev": true, - "requires": { - "indexof": "0.0.1" - } - }, - "watchpack": { - "version": "1.6.0", - "resolved": "https://registry.npmjs.org/watchpack/-/watchpack-1.6.0.tgz", - "integrity": "sha512-i6dHe3EyLjMmDlU1/bGQpEw25XSjkJULPuAVKCbNRefQVq48yXKUpwg538F7AZTf9kyr57zj++pQFltUa5H7yA==", - "dev": true, - "requires": { - "chokidar": "^2.0.2", - "graceful-fs": "^4.1.2", - "neo-async": "^2.5.0" - } - }, - "webpack": { - "version": "4.28.4", - "resolved": "https://registry.npmjs.org/webpack/-/webpack-4.28.4.tgz", - "integrity": "sha512-NxjD61WsK/a3JIdwWjtIpimmvE6UrRi3yG54/74Hk9rwNj5FPkA4DJCf1z4ByDWLkvZhTZE+P3C/eh6UD5lDcw==", - "dev": true, - "requires": { - "@webassemblyjs/ast": "1.7.11", - "@webassemblyjs/helper-module-context": "1.7.11", - "@webassemblyjs/wasm-edit": "1.7.11", - "@webassemblyjs/wasm-parser": "1.7.11", - "acorn": "^5.6.2", - "acorn-dynamic-import": "^3.0.0", - "ajv": "^6.1.0", - "ajv-keywords": "^3.1.0", - "chrome-trace-event": "^1.0.0", - "enhanced-resolve": "^4.1.0", - "eslint-scope": "^4.0.0", - "json-parse-better-errors": "^1.0.2", - "loader-runner": "^2.3.0", - "loader-utils": "^1.1.0", - "memory-fs": "~0.4.1", - "micromatch": "^3.1.8", - "mkdirp": "~0.5.0", - "neo-async": "^2.5.0", - "node-libs-browser": "^2.0.0", - "schema-utils": "^0.4.4", - "tapable": "^1.1.0", - "terser-webpack-plugin": "^1.1.0", - "watchpack": "^1.5.0", - "webpack-sources": "^1.3.0" - } - }, - "webpack-cli": { - "version": "3.2.1", - "resolved": "https://registry.npmjs.org/webpack-cli/-/webpack-cli-3.2.1.tgz", - "integrity": "sha512-jeJveHwz/vwpJ3B8bxEL5a/rVKIpRNJDsKggfKnxuYeohNDW4Y/wB9N/XHJA093qZyS0r6mYL+/crLsIol4WKA==", - "dev": true, - "requires": { - "chalk": "^2.4.1", - "cross-spawn": "^6.0.5", - "enhanced-resolve": "^4.1.0", - "findup-sync": "^2.0.0", - "global-modules": "^1.0.0", - "global-modules-path": "^2.3.0", - "import-local": "^2.0.0", - "interpret": "^1.1.0", - "lightercollective": "^0.1.0", - "loader-utils": "^1.1.0", - "supports-color": "^5.5.0", - "v8-compile-cache": "^2.0.2", - "yargs": "^12.0.4" - } - }, - "webpack-sources": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/webpack-sources/-/webpack-sources-1.3.0.tgz", - "integrity": "sha512-OiVgSrbGu7NEnEvQJJgdSFPl2qWKkWq5lHMhgiToIiN9w34EBnjYzSYs+VbL5KoYiLNtFFa7BZIKxRED3I32pA==", - "dev": true, - "requires": { - "source-list-map": "^2.0.0", - "source-map": "~0.6.1" - }, - "dependencies": { - "source-map": { - "version": "0.6.1", - "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", - "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==", - "dev": true - } - } - }, - "which": { - "version": "1.3.1", - "resolved": "https://registry.npmjs.org/which/-/which-1.3.1.tgz", - "integrity": "sha512-HxJdYWq1MTIQbJ3nw0cqssHoTNU267KlrDuGZ1WYlxDStUtKUhOaJmh112/TZmHxxUfuJqPXSOm7tDyas0OSIQ==", - "dev": true, - "requires": { - "isexe": "^2.0.0" - } - }, - "which-module": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/which-module/-/which-module-2.0.0.tgz", - "integrity": "sha1-2e8H3Od7mQK4o6j6SzHD4/fm6Ho=", - "dev": true - }, - "wide-align": { - "version": "1.1.3", - "resolved": "https://registry.npmjs.org/wide-align/-/wide-align-1.1.3.tgz", - "integrity": "sha512-QGkOQc8XL6Bt5PwnsExKBPuMKBxnGxWWW3fU55Xt4feHozMUhdUMaBCk290qpm/wG5u/RSKzwdAC4i51YigihA==", - "dev": true, - "optional": true, - "requires": { - "string-width": "^1.0.2 || 2" - } - }, - "worker-farm": { - "version": "1.6.0", - "resolved": "https://registry.npmjs.org/worker-farm/-/worker-farm-1.6.0.tgz", - "integrity": "sha512-6w+3tHbM87WnSWnENBUvA2pxJPLhQUg5LKwUQHq3r+XPhIM+Gh2R5ycbwPCyuGbNg+lPgdcnQUhuC02kJCvffQ==", - "dev": true, - "requires": { - "errno": "~0.1.7" - } - }, - "wrap-ansi": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-2.1.0.tgz", - "integrity": "sha1-2Pw9KE3QV5T+hJc8rs3Rz4JP3YU=", - "dev": true, - "requires": { - "string-width": "^1.0.1", - "strip-ansi": "^3.0.1" - } - }, - "wrappy": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", - "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=", - "dev": true - }, - "xtend": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.1.tgz", - "integrity": "sha1-pcbVMr5lbiPbgg77lDofBJmNY68=", - "dev": true - }, - "y18n": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/y18n/-/y18n-4.0.0.tgz", - "integrity": "sha512-r9S/ZyXu/Xu9q1tYlpsLIsa3EeLXXk0VwlxqTcFRfg9EhMW+17kbt9G0NrgCmhGb5vT2hyhJZLfDGx+7+5Uj/w==", - "dev": true - }, - "yallist": { - "version": "3.0.3", - "resolved": "https://registry.npmjs.org/yallist/-/yallist-3.0.3.tgz", - "integrity": "sha512-S+Zk8DEWE6oKpV+vI3qWkaK+jSbIK86pCwe2IF/xwIpQ8jEuxpw9NyaGjmp9+BoJv5FV2piqCDcoCtStppiq2A==", - "dev": true - }, - "yargs": { - "version": "12.0.5", - "resolved": "https://registry.npmjs.org/yargs/-/yargs-12.0.5.tgz", - "integrity": "sha512-Lhz8TLaYnxq/2ObqHDql8dX8CJi97oHxrjUcYtzKbbykPtVW9WB+poxI+NM2UIzsMgNCZTIf0AQwsjK5yMAqZw==", - "dev": true, - "requires": { - "cliui": "^4.0.0", - "decamelize": "^1.2.0", - "find-up": "^3.0.0", - "get-caller-file": "^1.0.1", - "os-locale": "^3.0.0", - "require-directory": "^2.1.1", - "require-main-filename": "^1.0.1", - "set-blocking": "^2.0.0", - "string-width": "^2.0.0", - "which-module": "^2.0.0", - "y18n": "^3.2.1 || ^4.0.0", - "yargs-parser": "^11.1.1" - }, - "dependencies": { - "ansi-regex": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-3.0.0.tgz", - "integrity": "sha1-7QMXwyIGT3lGbAKWa922Bas32Zg=", - "dev": true - }, - "is-fullwidth-code-point": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz", - "integrity": "sha1-o7MKXE8ZkYMWeqq5O+764937ZU8=", - "dev": true - }, - "string-width": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/string-width/-/string-width-2.1.1.tgz", - "integrity": "sha512-nOqH59deCq9SRHlxq1Aw85Jnt4w6KvLKqWVik6oA9ZklXLNIOlqg4F2yrT1MVaTjAqvVwdfeZ7w7aCvJD7ugkw==", - "dev": true, - "requires": { - "is-fullwidth-code-point": "^2.0.0", - "strip-ansi": "^4.0.0" - } - }, - "strip-ansi": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-4.0.0.tgz", - "integrity": "sha1-qEeQIusaw2iocTibY1JixQXuNo8=", - "dev": true, - "requires": { - "ansi-regex": "^3.0.0" - } - } - } - }, - "yargs-parser": { - "version": "11.1.1", - "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-11.1.1.tgz", - "integrity": "sha512-C6kB/WJDiaxONLJQnF8ccx9SEeoTTLek8RVbaOIsrAUS8VrBEXfmeSnCZxygc+XC2sNMBIwOOnfcxiynjHsVSQ==", - "dev": true, - "requires": { - "camelcase": "^5.0.0", - "decamelize": "^1.2.0" - } - } - } -} diff --git a/package.json b/package.json index 430a7a3..2a82fe2 100644 --- a/package.json +++ b/package.json @@ -1,34 +1,50 @@ { - "name": "lua-in-js", - "version": "1.1.0", - "description": "A Lua to JS transpiler / runtime", - "keywords": [ - "lua", - "javascript", - "transpiler", - "runtime" - ], - "author": "Teoxoy", - "license": "MIT", - "main": "dist/lua-in-js.js", - "module": "src/index.js", - "repository": { - "type": "git", - "url": "git://github.com/teoxoy/lua-in-js.git" - }, - "scripts": { - "build": "webpack" - }, - "dependencies": { - "printf": "^0.5.1", - "luaparse": "^0.2.1" - }, - "devDependencies": { - "@babel/core": "^7.2.2", - "@babel/preset-env": "^7.2.3", - "babel-loader": "^8.0.5", - "clean-webpack-plugin": "^1.0.0", - "webpack": "^4.28.4", - "webpack-cli": "^3.2.1" - } + "name": "lua-in-js", + "version": "2.0.0", + "description": "A Lua to JS transpiler/runtime", + "keywords": [ + "lua", + "javascript", + "typescript", + "transpiler", + "runtime", + "parser" + ], + "author": "Teoxoy", + "license": "MIT", + "main": "dist/lua-in-js.cjs.js", + "module": "dist/lua-in-js.es.js", + "typings": "dist/types/index.d.ts", + "repository": { + "type": "git", + "url": "git://github.com/teoxoy/lua-in-js.git" + }, + "scripts": { + "build": "rimraf dist && rollup -c rollup.config.js", + "dev": "rimraf dist && rollup -c rollup.config.js -w", + "test": "node ./tests/test.js", + "lint": "eslint . --ignore-path .gitignore --ext .ts", + "lint:fix": "eslint . --ignore-path .gitignore --ext .ts --fix" + }, + "dependencies": { + "luaparse": "^0.2.1", + "printj": "^1.2.2" + }, + "devDependencies": { + "@types/luaparse": "^0.2.6", + "@types/node": "^12.7.4", + "@typescript-eslint/eslint-plugin": "^2.1.0", + "@typescript-eslint/parser": "^2.1.0", + "eslint": "^6.3.0", + "eslint-config-prettier": "^6.2.0", + "eslint-plugin-import": "^2.18.2", + "eslint-plugin-prettier": "^3.1.0", + "prettier": "1.18.2", + "rimraf": "^3.0.0", + "rollup": "^1.20.3", + "rollup-plugin-commonjs": "^10.1.0", + "rollup-plugin-node-resolve": "^5.2.0", + "rollup-plugin-typescript2": "^0.24.0", + "typescript": "^3.6.2" + } } diff --git a/rollup.config.js b/rollup.config.js new file mode 100644 index 0000000..ccd1454 --- /dev/null +++ b/rollup.config.js @@ -0,0 +1,33 @@ +import resolve from 'rollup-plugin-node-resolve' +import commonjs from 'rollup-plugin-commonjs' +import typescript from 'rollup-plugin-typescript2' +const pkg = require('./package.json') + +export default { + input: 'src/index.ts', + output: [ + { + file: pkg.main, + name: pkg.name, + format: 'cjs', + sourcemap: true + }, + { + file: pkg.module, + name: pkg.name, + format: 'es', + sourcemap: true + } + ], + external: Object.keys(pkg.dependencies).concat(require('module').builtinModules), + watch: { + include: 'src/**' + }, + plugins: [ + commonjs(), + resolve(), + typescript({ + useTsconfigDeclarationDir: true + }) + ] +} diff --git a/src/LuaError.ts b/src/LuaError.ts new file mode 100644 index 0000000..72991e1 --- /dev/null +++ b/src/LuaError.ts @@ -0,0 +1,10 @@ +export class LuaError extends Error { + public constructor(message: string) { + super() + this.message = message + } + + public toString(): string { + return `LuaError: ${this.message}` + } +} diff --git a/src/Scope.ts b/src/Scope.ts new file mode 100644 index 0000000..356670d --- /dev/null +++ b/src/Scope.ts @@ -0,0 +1,42 @@ +import { hasOwnProperty, LuaType } from './utils' + +export class Scope { + private parent: Scope + private _varargs: LuaType[] + private readonly _variables: Record + + public constructor(variables = {}) { + this._variables = variables + } + + public get(key: string): LuaType { + return this._variables[key] + } + + public set(key: string, value: LuaType): void { + if (hasOwnProperty(this._variables, key) || !this.parent) { + this.setLocal(key, value) + } else { + this.parent.set(key, value) + } + } + + public setLocal(key: string, value: LuaType): void { + this._variables[key] = value + } + + public setVarargs(args: LuaType[]): void { + this._varargs = args + } + + public getVarargs(): LuaType[] { + return this._varargs || (this.parent && this.parent.getVarargs()) || [] + } + + public extend(): Scope { + const innerVars = Object.create(this._variables) + const scope = new Scope(innerVars) + scope.parent = this + return scope + } +} diff --git a/src/Table.ts b/src/Table.ts new file mode 100644 index 0000000..dfcbb48 --- /dev/null +++ b/src/Table.ts @@ -0,0 +1,244 @@ +import { hasOwnProperty, LuaType, coerceArgToTable, coerceToString } from './utils' + +type MetaMethods = + // unary op + | '__unm' + | '__bnot' + | '__len' + // binary op + | '__add' + | '__sub' + | '__mul' + | '__mod' + | '__pow' + | '__div' + | '__idiv' + | '__band' + | '__bor' + | '__bxor' + | '__shl' + | '__shr' + | '__concat' + | '__eq' + | '__lt' + | '__le' + // other + | '__index' + | '__newindex' + | '__call' + | '__pairs' + | '__ipairs' + | '__tostring' + +class Table { + public numValues: LuaType[] = [undefined] + public strValues: Record = {} + public keys: string[] = [] + public values: LuaType[] = [] + public metatable: Table | null = null + public constructor(initialiser?: Record | LuaType[] | ((t: Table) => void)) { + if (initialiser === undefined) return + + if (typeof initialiser === 'function') { + initialiser(this) + return + } + + if (Array.isArray(initialiser)) { + this.insert(...initialiser) + return + } + + for (const key in initialiser) { + if (hasOwnProperty(initialiser, key)) { + let value = initialiser[key] + if (value === null) value = undefined + this.set(key, value) + } + } + } + + public get(key: LuaType): LuaType { + const value = this.rawget(key) + + if (value === undefined && this.metatable) { + const mm = this.metatable.get('__index') as Table | Function + + if (mm instanceof Table) { + return mm.get(key) + } + + if (typeof mm === 'function') { + const v = mm.call(undefined, this, key) + return v instanceof Array ? v[0] : v + } + } + + return value + } + + public rawget(key: LuaType): LuaType { + switch (typeof key) { + case 'string': + if (hasOwnProperty(this.strValues, key)) { + return this.strValues[key] + } + break + case 'number': + if (key > 0 && key % 1 === 0) { + return this.numValues[key] + } + } + + const index = this.keys.indexOf(tostring(key)) + return index === -1 ? undefined : this.values[index] + } + + public getMetaMethod(name: MetaMethods): Function { + return this.metatable && (this.metatable.rawget(name) as Function) + } + + public set(key: LuaType, value: LuaType): LuaType { + const mm = this.metatable && this.metatable.get('__newindex') + if (mm) { + const oldValue = this.rawget(key) + + if (oldValue === undefined) { + if (mm instanceof Table) { + return mm.set(key, value) + } + if (typeof mm === 'function') { + return mm(this, key, value) + } + } + } + + this.rawset(key, value) + } + + public setFn(key: string): (v: LuaType) => void { + return v => this.set(key, v) + } + + public rawset(key: LuaType, value: LuaType): void { + switch (typeof key) { + case 'string': + this.strValues[key] = value + return + + case 'number': + if (key > 0 && key % 1 === 0) { + this.numValues[key] = value + return + } + } + + const K = tostring(key) + const index = this.keys.indexOf(K) + if (index > -1) { + this.values[index] = value + return + } + + this.values[this.keys.length] = value + this.keys.push(K) + } + + public insert(...values: LuaType[]): void { + this.numValues.push(...values) + } + + public toObject(): unknown[] | Record { + const outputAsArray = Object.keys(this.strValues).length === 0 && getn(this) > 0 + const result: unknown[] | Record = outputAsArray ? [] : {} + + for (let i = 1; i < this.numValues.length; i++) { + const propValue = this.numValues[i] + const value = propValue instanceof Table ? propValue.toObject() : propValue + + if (outputAsArray) { + const res = result as unknown[] + res[i - 1] = value + } else { + const res = result as Record + res[String(i - 1)] = value + } + } + + for (const key in this.strValues) { + if (hasOwnProperty(this.strValues, key)) { + const propValue = this.strValues[key] + const value = propValue instanceof Table ? propValue.toObject() : propValue + + const res = result as Record + res[key] = value + } + } + + return result + } +} + +function tostring(v: LuaType): string { + if (v instanceof Table) { + const mm = v.getMetaMethod('__tostring') + if (mm) return mm(v)[0] + + return valToStr(v, 'table: 0x') + } + + if (v instanceof Function) { + return valToStr(v, 'function: 0x') + } + + return coerceToString(v) + + function valToStr(v: LuaType, prefix: string): string { + const s = v.toString() + if (s.indexOf(prefix) > -1) return s + + const str = prefix + Math.floor(Math.random() * 0xffffffff).toString(16) + v.toString = () => str + return str + } +} + +function getn(table: LuaType): number { + const TABLE = coerceArgToTable(table, 'getn', 1) + + const vals = TABLE.numValues + const keys: boolean[] = [] + + for (const i in vals) { + if (hasOwnProperty(vals, i)) { + keys[i] = true + } + } + + let j = 0 + while (keys[j + 1]) { + j += 1 + } + + // Following translated from ltable.c (http://www.lua.org/source/5.3/ltable.c.html) + if (j > 0 && vals[j] === undefined) { + /* there is a boundary in the array part: (binary) search for it */ + let i = 0 + + while (j - i > 1) { + const m = Math.floor((i + j) / 2) + + if (vals[m] === undefined) { + j = m + } else { + i = m + } + } + + return i + } + + return j +} + +export { MetaMethods, Table, getn, tostring } diff --git a/src/index.js b/src/index.js deleted file mode 100644 index 1b27619..0000000 --- a/src/index.js +++ /dev/null @@ -1,7 +0,0 @@ -import * as parser from './parser' -import * as runtime from './runtime' - -export { - parser, - runtime -} diff --git a/src/index.ts b/src/index.ts new file mode 100644 index 0000000..0fd4dfe --- /dev/null +++ b/src/index.ts @@ -0,0 +1,98 @@ +import { Scope } from './Scope' +import { createG } from './lib/globals' +import { operators } from './operators' +import { Table } from './Table' +import { LuaError } from './LuaError' +import { libMath } from './lib/math' +import { libTable } from './lib/table' +import { libString, metatable as stringMetatable } from './lib/string' +import { getLibOS } from './lib/os' +import { getLibPackage } from './lib/package' +import { LuaType, ensureArray, Config } from './utils' +import { parse } from './parser' + +const call = (f: Function | Table, ...args: LuaType[]): LuaType[] => { + if (f instanceof Function) return ensureArray(f(...args)) + + const mm = f instanceof Table && f.getMetaMethod('__call') + if (mm) return ensureArray(mm(f, ...args)) + + throw new LuaError(`attempt to call an uncallable type`) +} + +const stringTable = new Table() +stringTable.metatable = stringMetatable + +const get = (t: Table | string, v: LuaType): LuaType => { + if (t instanceof Table) return t.get(v) + if (typeof t === 'string') return stringTable.get(v) + + throw new LuaError(`no table or metatable found for given type`) +} + +const execChunk = (_G: Table, chunk: string, chunkName?: string): LuaType[] => { + const exec = new Function('__lua', chunk) + const globalScope = new Scope(_G.strValues).extend() + if (chunkName) globalScope.setVarargs([chunkName]) + const res = exec({ + globalScope, + ...operators, + Table, + call, + get + }) + return res === undefined ? [undefined] : res +} + +function createEnv( + config: Config = {} +): { + run: (script: string) => LuaType + runfile: (path: string) => LuaType +} { + const cfg: Config = { + LUA_PATH: './?.lua', + stdin: '', + stdout: console.log, + ...config + } + + const _G = createG(cfg, execChunk) + + const { libPackage, _require } = getLibPackage( + (content, moduleName) => execChunk(_G, parse(content), moduleName)[0], + cfg + ) + const loaded = libPackage.get('loaded') as Table + + const load = (name: string, value: Table): void => { + _G.rawset(name, value) + loaded.rawset(name, value) + } + + load('_G', _G) + load('package', libPackage) + load('math', libMath) + load('table', libTable) + load('string', libString) + load('os', getLibOS(cfg)) + + _G.rawset('require', _require) + + const run = (script: string): LuaType => execChunk(_G, parse(script))[0] + const runfile = (filename: string): LuaType => { + if (!cfg.fileExists) throw new LuaError('runfile requires the config.fileExists function') + if (!cfg.loadFile) throw new LuaError('runfile requires the config.loadFile function') + + if (!cfg.fileExists(filename)) throw new LuaError('file not found') + + return run(cfg.loadFile(filename)) + } + + return { + run, + runfile + } +} + +export { createEnv } diff --git a/src/lib/globals.ts b/src/lib/globals.ts new file mode 100644 index 0000000..4a2908d --- /dev/null +++ b/src/lib/globals.ts @@ -0,0 +1,406 @@ +import { parse } from '../parser' +import { Table, tostring, getn } from '../Table' +import { LuaError } from '../LuaError' +import { + LuaType, + Config, + type, + posrelat, + coerceToNumber, + coerceToString, + coerceToBoolean, + coerceArgToNumber, + coerceArgToString, + coerceArgToTable, + hasOwnProperty +} from '../utils' +import { metatable as stringMetatable } from './string' + +const CHARS = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ' + +function ipairsIterator(table: Table, index: number): LuaType[] { + if (index === undefined) { + throw new LuaError('Bad argument #2 to ipairs() iterator') + } + + const nextIndex = index + 1 + const numValues = table.numValues + + if (!numValues[nextIndex] || numValues[nextIndex] === undefined) return undefined + return [nextIndex, numValues[nextIndex]] +} + +const _VERSION = 'Lua 5.3' + +function assert(v: LuaType, m?: LuaType): [unknown, unknown] { + if (coerceToBoolean(v)) return [v, m] + + const msg = m === undefined ? 'Assertion failed!' : coerceArgToString(m, 'assert', 2) + throw new LuaError(msg) +} + +function collectgarbage(): [] { + // noop + return [] +} + +function error(message: LuaType): void { + const msg = coerceArgToString(message, 'error', 1) + throw new LuaError(msg) +} + +/** + * If object does not have a metatable, returns nil. + * Otherwise, if the object's metatable has a __metatable field, returns the associated value. + * Otherwise, returns the metatable of the given object. + */ +function getmetatable(table: LuaType): Table { + if (table instanceof Table && table.metatable) { + const mm = table.metatable.rawget('__metatable') as Table + return mm ? mm : table.metatable + } + if (typeof table === 'string') { + return stringMetatable + } +} + +/** + * Returns three values (an iterator function, the table t, and 0) so that the construction + * + * `for i,v in ipairs(t) do body end` + * + * will iterate over the key–value pairs (1,t[1]), (2,t[2]), ..., up to the first nil value. + */ +function ipairs(t: LuaType): [Function, Table, number] { + const table = coerceArgToTable(t, 'ipairs', 1) + const mm = table.getMetaMethod('__pairs') || table.getMetaMethod('__ipairs') + return mm ? mm(table).slice(0, 3) : [ipairsIterator, table, 0] +} + +/** + * Allows a program to traverse all fields of a table. + * Its first argument is a table and its second argument is an index in this table. + * next returns the next index of the table and its associated value. + * When called with nil as its second argument, next returns an initial index and its associated value. + * When called with the last index, or with nil in an empty table, next returns nil. + * If the second argument is absent, then it is interpreted as nil. + * In particular, you can use next(t) to check whether a table is empty. + * + * The order in which the indices are enumerated is not specified, even for numeric indices. + * (To traverse a table in numerical order, use a numerical for.) + * + * The behavior of next is undefined if, during the traversal, you assign any value to a non-existent field in the table. + * You may however modify existing fields. In particular, you may clear existing fields. + */ +function next(table: LuaType, index?: LuaType): [number | string, LuaType] { + const TABLE = coerceArgToTable(table, 'next', 1) + + // SLOOOOOOOW... + let found = index === undefined + + if (found || (typeof index === 'number' && index > 0)) { + const numValues = TABLE.numValues + const keys = Object.keys(numValues) + let i = 1 + + if (!found) { + const I = keys.indexOf(`${index}`) + if (I >= 0) { + found = true + i += I + } + } + + if (found) { + for (i; keys[i] !== undefined; i++) { + const key = Number(keys[i]) + const value = numValues[key] + if (value !== undefined) return [key, value] + } + } + } + + for (const i in TABLE.strValues) { + if (hasOwnProperty(TABLE.strValues, i)) { + if (!found) { + if (i === index) found = true + } else if (TABLE.strValues[i] !== undefined) { + return [i, TABLE.strValues[i]] + } + } + } + + for (const i in TABLE.keys) { + if (hasOwnProperty(TABLE.keys, i)) { + const key = TABLE.keys[i] + + if (!found) { + if (key === index) found = true + } else if (TABLE.values[i] !== undefined) { + return [key, TABLE.values[i]] + } + } + } +} + +/** + * If t has a metamethod __pairs, calls it with t as argument and returns the first three results from the call. + * + * Otherwise, returns three values: the next function, the table t, and nil, so that the construction + * + * `for k,v in pairs(t) do body end` + * + * will iterate over all key–value pairs of table t. + * + * See function next for the caveats of modifying the table during its traversal. + */ +function pairs(t: LuaType): [Function, Table, undefined] { + const table = coerceArgToTable(t, 'pairs', 1) + const mm = table.getMetaMethod('__pairs') + return mm ? mm(table).slice(0, 3) : [next, table, undefined] +} + +/** + * Calls function f with the given arguments in protected mode. + * This means that any error inside f is not propagated; + * instead, pcall catches the error and returns a status code. + * Its first result is the status code (a boolean), which is true if the call succeeds without errors. + * In such case, pcall also returns all results from the call, after this first result. + * In case of any error, pcall returns false plus the error message. + */ +function pcall(f: LuaType, ...args: LuaType[]): [false, string] | [true, ...LuaType[]] { + if (typeof f !== 'function') { + throw new LuaError('Attempt to call non-function') + } + + try { + return [true, ...f(...args)] + } catch (e) { + return [false, e && e.toString()] + } +} + +/** + * Checks whether v1 is equal to v2, without invoking the __eq metamethod. Returns a boolean. + */ +function rawequal(v1: LuaType, v2: LuaType): boolean { + return v1 === v2 +} + +/** + * Gets the real value of table[index], without invoking the __index metamethod. + * table must be a table; index may be any value. + */ +function rawget(table: LuaType, index: LuaType): LuaType { + const TABLE = coerceArgToTable(table, 'rawget', 1) + return TABLE.rawget(index) +} + +/** + * Returns the length of the object v, which must be a table or a string, without invoking the __len metamethod. + * Returns an integer. + */ +function rawlen(v: LuaType): number { + if (v instanceof Table) return getn(v) + + if (typeof v === 'string') return v.length + + throw new LuaError('attempt to get length of an unsupported value') +} + +/** + * Sets the real value of table[index] to value, without invoking the __newindex metamethod. + * table must be a table, index any value different from nil and NaN, and value any Lua value. + * + * This function returns table. + */ +function rawset(table: LuaType, index: LuaType, value: LuaType): Table { + const TABLE = coerceArgToTable(table, 'rawset', 1) + if (index === undefined) throw new LuaError('table index is nil') + + TABLE.rawset(index, value) + return TABLE +} + +/** + * If index is a number, returns all arguments after argument number index; + * a negative number indexes from the end (-1 is the last argument). + * Otherwise, index must be the string "#", and select returns the total number of extra arguments it received. + */ +function select(index: number | '#', ...args: LuaType[]): LuaType[] | number { + if (index === '#') { + return args.length + } + + if (typeof index === 'number') { + const pos = posrelat(Math.trunc(index), args.length) + return args.slice(pos - 1) + } + + throw new LuaError(`bad argument #1 to 'select' (number expected, got ${type(index)})`) +} + +/** + * Sets the metatable for the given table. + * (To change the metatable of other types from Lua code,you must use the debug library (§6.10).) + * If metatable is nil, removes the metatable of the given table. + * If the original metatable has a __metatable field, raises an error. + * + * This function returns table. + */ +function setmetatable(table: LuaType, metatable: LuaType): Table { + const TABLE = coerceArgToTable(table, 'setmetatable', 1) + + if (TABLE.metatable && TABLE.metatable.rawget('__metatable')) { + throw new LuaError('cannot change a protected metatable') + } + + TABLE.metatable = coerceArgToTable(metatable, 'setmetatable', 2) + return TABLE +} + +/** + * When called with no base, tonumber tries to convert its argument to a number. + * If the argument is already a number or a string convertible to a number, + * then tonumber returns this number; otherwise, it returns nil. + * + * The conversion of strings can result in integers or floats, + * according to the lexical conventions of Lua (see §3.1). + * (The string may have leading and trailing spaces and a sign.) + * + * When called with base, then e must be a string to be interpreted as an integer numeral in that base. + * The base may be any integer between 2 and 36, inclusive. + * In bases above 10, the letter 'A' (in either upper or lower case) represents 10, + * 'B' represents 11, and so forth, with 'Z' representing 35. + * If the string e is not a valid numeral in the given base, the function returns nil. + */ +function tonumber(e: LuaType, base: LuaType): number { + const E = coerceToString(e).trim() + const BASE = base === undefined ? 10 : coerceArgToNumber(base, 'tonumber', 2) + + if (BASE !== 10 && E === 'nil') { + throw new LuaError("bad argument #1 to 'tonumber' (string expected, got nil)") + } + + if (BASE < 2 || BASE > 36) { + throw new LuaError(`bad argument #2 to 'tonumber' (base out of range)`) + } + + if (E === '') return + if (BASE === 10) return coerceToNumber(E) + + const pattern = new RegExp(`^${BASE === 16 ? '(0x)?' : ''}[${CHARS.substr(0, BASE)}]*$`, 'gi') + + if (!pattern.test(E)) return // Invalid + return parseInt(E, BASE) +} + +/** + * This function is similar to pcall, except that it sets a new message handler msgh. + */ +function xpcall(f: LuaType, msgh: LuaType, ...args: LuaType[]): [false, string] | [true, ...LuaType[]] { + if (typeof f !== 'function' || typeof msgh !== 'function') { + throw new LuaError('Attempt to call non-function') + } + + try { + return [true, ...f(...args)] + } catch (e) { + return [false, msgh(e)[0]] + } +} + +function createG(cfg: Config, execChunk: (_G: Table, chunk: string) => LuaType[]): Table { + function print(...args: LuaType[]): void { + const output = args.map(arg => tostring(arg)).join('\t') + cfg.stdout(output) + } + + function load( + chunk: LuaType, + _chunkname?: string, + _mode?: 'b' | 't' | 'bt', + env?: Table + ): [undefined, string] | (() => LuaType[]) { + let C = '' + if (chunk instanceof Function) { + let ret = ' ' + while (ret !== '' && ret !== undefined) { + C += ret + ret = chunk()[0] + } + } else { + C = coerceArgToString(chunk, 'load', 1) + } + + let parsed: string + try { + parsed = parse(C) + } catch (e) { + return [undefined, e.message] + } + + return () => execChunk(env || _G, parsed) + } + + function dofile(filename?: LuaType): LuaType[] { + const res = loadfile(filename) + + if (Array.isArray(res) && res[0] === undefined) { + throw new LuaError(res[1]) + } + + const exec = res as () => LuaType[] + return exec() + } + + function loadfile( + filename?: LuaType, + mode?: 'b' | 't' | 'bt', + env?: Table + ): [undefined, string] | (() => LuaType[]) { + const FILENAME = filename === undefined ? cfg.stdin : coerceArgToString(filename, 'loadfile', 1) + + if (!cfg.fileExists) { + throw new LuaError('loadfile requires the config.fileExists function') + } + + if (!cfg.fileExists(FILENAME)) return [undefined, 'file not found'] + + if (!cfg.loadFile) { + throw new LuaError('loadfile requires the config.loadFile function') + } + + return load(cfg.loadFile(FILENAME), FILENAME, mode, env) + } + + const _G = new Table({ + _VERSION, + assert, + dofile, + collectgarbage, + error, + getmetatable, + ipairs, + load, + loadfile, + next, + pairs, + pcall, + print, + rawequal, + rawget, + rawlen, + rawset, + select, + setmetatable, + tonumber, + tostring, + type, + xpcall + }) + + return _G +} + +export { tostring, createG } diff --git a/src/lib/math.ts b/src/lib/math.ts new file mode 100644 index 0000000..641f727 --- /dev/null +++ b/src/lib/math.ts @@ -0,0 +1,241 @@ +import { Table } from '../Table' +import { coerceArgToNumber, LuaType, coerceToNumber } from '../utils' + +const maxinteger = Number.MAX_SAFE_INTEGER +const mininteger = Number.MIN_SAFE_INTEGER +const huge = Infinity +const pi = Math.PI + +let randomSeed = 1 + +function getRandom(): number { + randomSeed = (16807 * randomSeed) % 2147483647 + return randomSeed / 2147483647 +} + +function abs(x: LuaType): number { + const X = coerceArgToNumber(x, 'abs', 1) + return Math.abs(X) +} + +function acos(x: LuaType): number { + const X = coerceArgToNumber(x, 'acos', 1) + return Math.acos(X) +} + +function asin(x: LuaType): number { + const X = coerceArgToNumber(x, 'asin', 1) + return Math.asin(X) +} + +function atan(y: LuaType, x?: LuaType): number { + const Y = coerceArgToNumber(y, 'atan', 1) + const X = x === undefined ? 1 : coerceArgToNumber(x, 'atan', 2) + return Math.atan2(Y, X) +} + +function atan2(y: LuaType, x: LuaType): number { + return atan(y, x) +} + +function ceil(x: LuaType): number { + const X = coerceArgToNumber(x, 'ceil', 1) + return Math.ceil(X) +} + +function cos(x: LuaType): number { + const X = coerceArgToNumber(x, 'cos', 1) + return Math.cos(X) +} + +function cosh(x: LuaType): number { + const X = coerceArgToNumber(x, 'cosh', 1) + return (exp(X) + exp(-X)) / 2 +} + +function deg(x: LuaType): number { + const X = coerceArgToNumber(x, 'deg', 1) + return (X * 180) / Math.PI +} + +function exp(x: LuaType): number { + const X = coerceArgToNumber(x, 'exp', 1) + return Math.exp(X) +} + +function floor(x: LuaType): number { + const X = coerceArgToNumber(x, 'floor', 1) + return Math.floor(X) +} + +function fmod(x: LuaType, y: LuaType): number { + const X = coerceArgToNumber(x, 'fmod', 1) + const Y = coerceArgToNumber(y, 'fmod', 2) + return X % Y +} + +function frexp(x: LuaType): number[] { + let X = coerceArgToNumber(x, 'frexp', 1) + + if (X === 0) { + return [0, 0] + } + + const delta = X > 0 ? 1 : -1 + X *= delta + + const exponent = Math.floor(Math.log(X) / Math.log(2)) + 1 + const mantissa = X / Math.pow(2, exponent) + + return [mantissa * delta, exponent] +} + +function ldexp(m: LuaType, e: LuaType): number { + const M = coerceArgToNumber(m, 'ldexp', 1) + const E = coerceArgToNumber(e, 'ldexp', 2) + return M * Math.pow(2, E) +} + +function log(x: LuaType, base?: LuaType): number { + const X = coerceArgToNumber(x, 'log', 1) + if (base === undefined) { + return Math.log(X) + } else { + const B = coerceArgToNumber(base, 'log', 2) + return Math.log(X) / Math.log(B) + } +} + +function log10(x: LuaType): number { + const X = coerceArgToNumber(x, 'log10', 1) + // v5.2: warn ('math.log10 is deprecated. Use math.log with 10 as its second argument instead.'); + return Math.log(X) / Math.log(10) +} + +function max(...args: LuaType[]): number { + const ARGS = args.map((n, i) => coerceArgToNumber(n, 'max', i + 1)) + return Math.max(...ARGS) +} + +function min(...args: LuaType[]): number { + const ARGS = args.map((n, i) => coerceArgToNumber(n, 'min', i + 1)) + return Math.min(...ARGS) +} + +function modf(x: LuaType): number[] { + const X = coerceArgToNumber(x, 'modf', 1) + const intValue = Math.floor(X) + const mantissa = X - intValue + return [intValue, mantissa] +} + +function pow(x: LuaType, y: LuaType): number { + const X = coerceArgToNumber(x, 'pow', 1) + const Y = coerceArgToNumber(y, 'pow', 2) + return Math.pow(X, Y) +} + +function rad(x: LuaType): number { + const X = coerceArgToNumber(x, 'rad', 1) + return (Math.PI / 180) * X +} + +function random(min?: LuaType, max?: LuaType): number { + if (min === undefined && max === undefined) return getRandom() + const firstArg = coerceArgToNumber(min, 'random', 1) + const MIN = max === undefined ? firstArg : 1 + const MAX = max === undefined ? coerceArgToNumber(max, 'random', 2) : firstArg + + if (MIN > MAX) throw new Error("bad argument #2 to 'random' (interval is empty)") + return Math.floor(getRandom() * (MAX - MIN + 1) + MIN) +} + +function randomseed(x: LuaType): void { + randomSeed = coerceArgToNumber(x, 'randomseed', 1) +} + +function sin(x: LuaType): number { + const X = coerceArgToNumber(x, 'sin', 1) + return Math.sin(X) +} + +function sinh(x: LuaType): number { + const X = coerceArgToNumber(x, 'sinh', 1) + return (exp(X) - exp(-X)) / 2 +} + +function sqrt(x: LuaType): number { + const X = coerceArgToNumber(x, 'sqrt', 1) + return Math.sqrt(X) +} + +function tan(x: LuaType): number { + const X = coerceArgToNumber(x, 'tan', 1) + return Math.tan(X) +} + +function tanh(x: LuaType): number { + const X = coerceArgToNumber(x, 'tanh', 1) + return (exp(X) - exp(-X)) / (exp(X) + exp(-X)) +} + +function tointeger(x: LuaType): number { + const X = coerceToNumber(x) + if (X === undefined) return undefined + return Math.floor(X) +} + +function type(x: LuaType): string { + const X = coerceToNumber(x) + if (X === undefined) return undefined + if (tointeger(X) === X) return 'integer' + return 'float' +} + +function ult(m: LuaType, n: LuaType): boolean { + const M = coerceArgToNumber(m, 'ult', 1) + const N = coerceArgToNumber(n, 'ult', 2) + + const toUnsigned = (n: number): number => n >>> 0 + return toUnsigned(M) < toUnsigned(N) +} + +const libMath = new Table({ + abs, + acos, + asin, + atan, + atan2, + ceil, + cos, + cosh, + deg, + exp, + floor, + fmod, + frexp, + huge, + ldexp, + log, + log10, + max, + min, + maxinteger, + mininteger, + modf, + pi, + pow, + rad, + random, + randomseed, + sin, + sinh, + sqrt, + tan, + tanh, + tointeger, + type, + ult +}) + +export { libMath } diff --git a/src/lib/os.ts b/src/lib/os.ts new file mode 100644 index 0000000..6c11b02 --- /dev/null +++ b/src/lib/os.ts @@ -0,0 +1,193 @@ +import { Table } from '../Table' +import { LuaType, Config, coerceArgToNumber } from '../utils' +import { LuaError } from '../LuaError' + +const DAYS = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'] +const MONTHS = [ + 'January', + 'February', + 'March', + 'April', + 'May', + 'June', + 'July', + 'August', + 'September', + 'October', + 'November', + 'December' +] +const DAYS_IN_MONTH = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] + +// LUA uses strftime internally (https://en.cppreference.com/w/c/chrono/strftime) +type Format = + | '%' // [string] literal % + | 'Y' // [number] year (e.g. 2017) + | 'y' // [number] last 2 digits of year (range [00,99]) + | 'b' // [string] abbreviated month name (e.g. Oct) + | 'B' // [string] full month name (e.g. October) + | 'm' // [number] month (range [01,12]) + | 'U' // [number] week of the year (Sunday is the first day of the week) (range [00,53]) + | 'W' // [number] week of the year (Monday is the first day of the week) (range [00,53]) + | 'j' // [number] day of the year (range [001,366]) + | 'd' // [number] day of the month (range [01,31]) + | 'a' // [string] abbreviated weekday name (e.g. Fri) + | 'A' // [string] full weekday name (e.g. Friday) + | 'w' // [number] weekday - Sunday is 0 (range [0-6]) + | 'H' // [number] hour - 24 hour format (range [00-23]) + | 'I' // [number] hour - 12 hour format (range [01,12]) + | 'M' // [number] minute (range [00,59]) + | 'S' // [number] second (range [00,60]) + | 'c' // [string] standard date and time string (e.g. Sun Oct 17 04:41:13 2010) + | 'x' // [string] date (e.g. 09/16/98) + | 'X' // [string] time (e.g. 23:48:10) + | 'p' // [string] a.m. or p.m. + | 'Z' // [string] locale-dependent time zone name or abbreviation (e.g. UTC) + +const DATE_FORMAT_HANDLERS: Record string> = { + '%': () => '%', + Y: (date, utc) => `${utc ? date.getUTCFullYear() : date.getFullYear()}`, + y: (date, utc) => DATE_FORMAT_HANDLERS.Y(date, utc).substr(-2), + b: (date, utc) => DATE_FORMAT_HANDLERS.B(date, utc).substr(0, 3), + B: (date, utc) => MONTHS[utc ? date.getUTCMonth() : date.getMonth()], + m: (date, utc) => `0${(utc ? date.getUTCMonth() : date.getMonth()) + 1}`.substr(-2), + U: (date, utc) => getWeekOfYear(date, 0, utc), + W: (date, utc) => getWeekOfYear(date, 1, utc), + j: (date, utc) => { + let result = utc ? date.getUTCDate() : date.getDate() + const month = utc ? date.getUTCMonth() : date.getMonth() + const year = utc ? date.getUTCFullYear() : date.getFullYear() + + result += DAYS_IN_MONTH.slice(0, month).reduce((sum, n) => sum + n, 0) + + if (month > 1 && year % 4 === 0) { + result += 1 + } + + return `00${result}`.substr(-3) + }, + d: (date, utc) => `0${utc ? date.getUTCDate() : date.getDate()}`.substr(-2), + a: (date, utc) => DATE_FORMAT_HANDLERS.A(date, utc).substr(0, 3), + A: (date, utc) => DAYS[utc ? date.getUTCDay() : date.getDay()], + w: (date, utc) => `${utc ? date.getUTCDay() : date.getDay()}`, + H: (date, utc) => `0${utc ? date.getUTCHours() : date.getHours()}`.substr(-2), + I: (date, utc) => `0${(utc ? date.getUTCHours() : date.getHours()) % 12 || 12}`.substr(-2), + M: (date, utc) => `0${utc ? date.getUTCMinutes() : date.getMinutes()}`.substr(-2), + S: (date, utc) => `0${utc ? date.getUTCSeconds() : date.getSeconds()}`.substr(-2), + c: (date, utc) => date.toLocaleString(undefined, utc ? { timeZone: 'UTC' } : undefined), + x: (date, utc) => { + const m = DATE_FORMAT_HANDLERS.m(date, utc) + const d = DATE_FORMAT_HANDLERS.d(date, utc) + const y = DATE_FORMAT_HANDLERS.y(date, utc) + return `${m}/${d}/${y}` + }, + X: (date, utc) => { + const h = DATE_FORMAT_HANDLERS.H(date, utc) + const m = DATE_FORMAT_HANDLERS.M(date, utc) + const s = DATE_FORMAT_HANDLERS.S(date, utc) + return `${h}:${m}:${s}` + }, + p: (date, utc) => ((utc ? date.getUTCHours() : date.getHours()) < 12 ? 'AM' : 'PM'), + Z: (date, utc) => { + if (utc) return 'UTC' + const match = date.toString().match(/[A-Z][A-Z][A-Z]/) + return match ? match[0] : '' + } +} + +function isDST(date: Date): boolean { + const year = date.getFullYear() + const jan = new Date(year, 0) + + // ASSUMPTION: If the time offset of the date is the same as it would be in January of the same year, DST is not in effect. + return date.getTimezoneOffset() !== jan.getTimezoneOffset() +} + +function getWeekOfYear(date: Date, firstDay: number, utc: boolean): string { + const dayOfYear = parseInt(DATE_FORMAT_HANDLERS.j(date, utc), 10) + const jan1 = new Date(date.getFullYear(), 0, 1, 12) + const offset = (8 - (utc ? jan1.getUTCDay() : jan1.getDay()) + firstDay) % 7 + + return `0${Math.floor((dayOfYear - offset) / 7) + 1}`.substr(-2) +} + +function date(input = '%c', time?: number): string | Table { + const utc = input.substr(0, 1) === '!' + const string = utc ? input.substr(1) : input + const date = new Date() + + if (time) { + date.setTime(time * 1000) + } + + if (string === '*t') { + return new Table({ + year: parseInt(DATE_FORMAT_HANDLERS.Y(date, utc), 10), + month: parseInt(DATE_FORMAT_HANDLERS.m(date, utc), 10), + day: parseInt(DATE_FORMAT_HANDLERS.d(date, utc), 10), + hour: parseInt(DATE_FORMAT_HANDLERS.H(date, utc), 10), + min: parseInt(DATE_FORMAT_HANDLERS.M(date, utc), 10), + sec: parseInt(DATE_FORMAT_HANDLERS.S(date, utc), 10), + wday: parseInt(DATE_FORMAT_HANDLERS.w(date, utc), 10) + 1, + yday: parseInt(DATE_FORMAT_HANDLERS.j(date, utc), 10), + isdst: isDST(date) + }) + } + + return string.replace(/%[%YybBmUWjdaAwHIMScxXpZ]/g, f => DATE_FORMAT_HANDLERS[f[1] as Format](date, utc)) +} + +function setlocale(locale = 'C'): string { + if (locale === 'C') return 'C' + + // TODO: implement fully +} + +function time(table?: Table): number { + let now = Math.round(Date.now() / 1000) + if (!table) return now + + const year = table.rawget('year') as number + const month = table.rawget('month') as number + const day = table.rawget('day') as number + const hour = (table.rawget('hour') as number) || 12 + const min = table.rawget('min') as number + const sec = table.rawget('sec') as number + // const isdst = table.rawget('isdst') as boolean + + if (year) now += year * 31557600 + if (month) now += month * 2629800 + if (day) now += day * 86400 + if (hour) now += hour * 3600 + if (min) now += min * 60 + if (sec) now += sec + return now +} + +function difftime(t2: LuaType, t1: LuaType): number { + const T2 = coerceArgToNumber(t2, 'difftime', 1) + const T1 = coerceArgToNumber(t1, 'difftime', 2) + return T2 - T1 +} + +const getLibOS = (cfg: Config): Table => { + function exit(code: LuaType): void { + if (!cfg.osExit) throw new LuaError('os.exit requires the config.osExit function') + + let CODE = 0 + if (typeof code === 'boolean' && code === false) CODE = 1 + else if (typeof code === 'number') CODE = code + + cfg.osExit(CODE) + } + + return new Table({ + date, + exit, + setlocale, + time, + difftime + }) +} + +export { getLibOS } diff --git a/src/lib/package.ts b/src/lib/package.ts new file mode 100644 index 0000000..e9746e6 --- /dev/null +++ b/src/lib/package.ts @@ -0,0 +1,102 @@ +import { Table } from '../Table' +import { LuaType, Config, coerceArgToString } from '../utils' +import { LuaError } from '../LuaError' + +const getLibPackage = ( + execModule: (content: string, moduleName: string) => LuaType, + cfg: Config +): { + libPackage: Table + _require: (modname: LuaType) => LuaType +} => { + const LUA_DIRSEP = '/' + const LUA_PATH_SEP = ';' + const LUA_PATH_MARK = '?' + const LUA_EXEC_DIR = '!' + const LUA_IGMARK = '-' + + const LUA_PATH = cfg.LUA_PATH + + const config = [LUA_DIRSEP, LUA_PATH_SEP, LUA_PATH_MARK, LUA_EXEC_DIR, LUA_IGMARK].join('\n') + + const loaded = new Table() + const preload = new Table() + + const searchpath = (name: LuaType, path: LuaType, sep?: LuaType, rep?: LuaType): string | [undefined, string] => { + if (!cfg.fileExists) { + throw new LuaError('package.searchpath requires the config.fileExists function') + } + + let NAME = coerceArgToString(name, 'searchpath', 1) + const PATH = coerceArgToString(path, 'searchpath', 2) + const SEP = sep === undefined ? '.' : coerceArgToString(sep, 'searchpath', 3) + const REP = rep === undefined ? '/' : coerceArgToString(rep, 'searchpath', 4) + + NAME = NAME.replace(SEP, REP) + + const paths = PATH.split(';').map(template => template.replace('?', NAME)) + + for (const path of paths) { + if (cfg.fileExists(path)) return path + } + + return [undefined, `The following files don't exist: ${paths.join(' ')}`] + } + + const searchers = new Table([ + (moduleName: string): [undefined] | [() => LuaType] => { + const res = preload.rawget(moduleName) + if (res === undefined) { + return [undefined] + } + return [res as () => LuaType] + }, + (moduleName: string): [undefined] | [string] | [(modname: string, path: string) => LuaType, string] => { + const res = searchpath(moduleName, libPackage.rawget('path')) + if (Array.isArray(res) && res[0] === undefined) { + return [res[1]] + } + + if (!cfg.loadFile) { + throw new LuaError('package.searchers requires the config.loadFile function') + } + + return [(moduleName: string, path: string) => execModule(cfg.loadFile(path), moduleName), res as string] + } + ]) + + function _require(modname: LuaType): LuaType { + const MODNAME = coerceArgToString(modname, 'require', 1) + + const module = loaded.rawget(MODNAME) + if (module) return module + + const searcherFns = searchers.numValues.filter(fn => !!fn) as Function[] + + for (const searcher of searcherFns) { + const res = searcher(MODNAME) + if (res[0] !== undefined && typeof res[0] !== 'string') { + const loader = res[0] + const result = loader(MODNAME, res[1]) + const module = result === undefined ? true : result + loaded.rawset(MODNAME, module) + return module + } + } + + throw new LuaError(`Module '${MODNAME}' not found!`) + } + + const libPackage = new Table({ + path: LUA_PATH, + config, + loaded, + preload, + searchers, + searchpath + }) + + return { libPackage, _require } +} + +export { getLibPackage } diff --git a/src/lib/string.ts b/src/lib/string.ts new file mode 100644 index 0000000..9652227 --- /dev/null +++ b/src/lib/string.ts @@ -0,0 +1,378 @@ +import printj from 'printj' +import { Table, tostring } from '../Table' +import { LuaError } from '../LuaError' +import { posrelat, coerceArgToNumber, coerceArgToString, hasOwnProperty, LuaType } from '../utils' + +const ROSETTA_STONE: Record = { + '([^a-zA-Z0-9%(])-': '$1*?', + '([^%])-([^a-zA-Z0-9?])': '$1*?$2', + '([^%])\\.': '$1[\\s\\S]', + '(.)-$': '$1*?', + '%a': '[a-zA-Z]', + '%A': '[^a-zA-Z]', + '%c': '[\x00-\x1f]', + '%C': '[^\x00-\x1f]', + '%d': '\\d', + '%D': '[^d]', + '%l': '[a-z]', + '%L': '[^a-z]', + '%p': '[.,"\'?!;:#$%&()*+-/<>=@\\[\\]\\\\^_{}|~]', + '%P': '[^.,"\'?!;:#$%&()*+-/<>=@\\[\\]\\\\^_{}|~]', + '%s': '[ \\t\\n\\f\\v\\r]', + '%S': '[^ \t\n\f\v\r]', + '%u': '[A-Z]', + '%U': '[^A-Z]', + '%w': '[a-zA-Z0-9]', + '%W': '[^a-zA-Z0-9]', + '%x': '[a-fA-F0-9]', + '%X': '[^a-fA-F0-9]', + '%([^a-zA-Z])': '\\$1' +} + +function translatePattern(pattern: string): string { + // TODO Add support for balanced character matching (not sure this is easily achieveable). + + // Replace single backslash with double backslashes + let tPattern = pattern.replace(/\\/g, '\\\\') + + for (const i in ROSETTA_STONE) { + if (hasOwnProperty(ROSETTA_STONE, i)) { + tPattern = tPattern.replace(new RegExp(i, 'g'), ROSETTA_STONE[i]) + } + } + + let nestingLevel = 0 + + for (let i = 0, l = tPattern.length; i < l; i++) { + if (i && tPattern.substr(i - 1, 1) === '\\') { + continue + } + + // Remove nested square brackets caused by substitutions + const character = tPattern.substr(i, 1) + + if (character === '[' || character === ']') { + if (character === ']') { + nestingLevel -= 1 + } + + if (nestingLevel > 0) { + tPattern = tPattern.substr(0, i) + tPattern.substr(i + 1) + i -= 1 + l -= 1 + } + + if (character === '[') { + nestingLevel += 1 + } + } + } + + return tPattern +} + +/** + * Returns the internal numeric codes of the characters s[i], s[i+1], ..., s[j]. + * The default value for i is 1; the default value for j is i. + * These indices are corrected following the same rules of function string.sub. + * + * Numeric codes are not necessarily portable across platforms. + */ +function byte(s: LuaType, i: LuaType, j: LuaType): number[] { + const S = coerceArgToString(s, 'byte', 1) + const I = i === undefined ? 1 : coerceArgToNumber(i, 'byte', 2) + const J = j === undefined ? I : coerceArgToNumber(j, 'byte', 3) + + return S.substring(I - 1, J) + .split('') + .map(c => c.charCodeAt(0)) +} + +/** + * Receives zero or more integers. Returns a string with length equal to the number of arguments, + * in which each character has the internal numeric code equal to its corresponding argument. + * + * Numeric codes are not necessarily portable across platforms. + */ +function char(...bytes: LuaType[]): string { + return bytes + .map((b, i) => { + const B = coerceArgToNumber(b, 'char', i) + return String.fromCharCode(B) + }) + .join('') +} + +/** + * Looks for the first match of pattern (see §6.4.1) in the string s. If it finds a match, then find returns + * the indices of s where this occurrence starts and ends; otherwise, it returns nil. + * A third, optional numeric argument init specifies where to start the search; its default value is 1 and can be negative. + * A value of true as a fourth, optional argument plain turns off the pattern matching facilities, + * so the function does a plain "find substring" operation, with no characters in pattern being considered magic. + * Note that if plain is given, then init must be given as well. + * + * If the pattern has captures, then in a successful match the captured values are also returned, after the two indices. + */ +function find(s: LuaType, pattern: LuaType, init: LuaType, plain: LuaType): (number | string)[] { + const S = coerceArgToString(s, 'find', 1) + const P = coerceArgToString(pattern, 'find', 2) + const INIT = init === undefined ? 1 : coerceArgToNumber(init, 'find', 3) + const PLAIN = plain === undefined ? false : coerceArgToNumber(plain, 'find', 4) + + // Regex + if (!PLAIN) { + const regex = new RegExp(translatePattern(P)) + const index = S.substr(INIT - 1).search(regex) + + if (index < 0) return + + const match = S.substr(INIT - 1).match(regex) + const result = [index + INIT, index + INIT + match[0].length - 1] + + match.shift() + return [...result, ...match] + } + + // Plain + const index = S.indexOf(P, INIT - 1) + return index === -1 ? undefined : [index + 1, index + P.length] +} + +function format(formatstring: string, ...args: LuaType[]): string { + // Pattern with all constraints: + // /%%|%([-+ #0]{0,5})?(\d{0,2})?(?:\.(\d{0,2}))?([AEGXacdefgioqsux])/g + const PATTERN = /%%|%([-+ #0]*)?(\d*)?(?:\.(\d*))?(.)/g + + let i = -1 + return formatstring.replace(PATTERN, (format, flags, width, precision, modifier) => { + if (format === '%%') return '%' + if (!modifier.match(/[AEGXacdefgioqsux]/)) { + throw new LuaError(`invalid option '%${format}' to 'format'`) + } + if (flags && flags.length > 5) { + throw new LuaError(`invalid format (repeated flags)`) + } + if (width && width.length > 2) { + throw new LuaError(`invalid format (width too long)`) + } + if (precision && precision.length > 2) { + throw new LuaError(`invalid format (precision too long)`) + } + + i += 1 + const arg = args[i] + if (arg === undefined) { + throw new LuaError(`bad argument #${i} to 'format' (no value)`) + } + if (/A|a|E|e|f|G|g/.test(modifier)) { + return printj.sprintf(format, coerceArgToNumber(arg, 'format', i)) + } + if (/c|d|i|o|u|X|x/.test(modifier)) { + return printj.sprintf(format, coerceArgToNumber(arg, 'format', i)) + } + + if (modifier === 'q') { + return `"${(arg as string).replace(/([\n"])/g, '\\$1')}"` + } + if (modifier === 's') { + return printj.sprintf(format, tostring(arg)) + } + return printj.sprintf(format, arg) + }) +} + +/** + * Returns an iterator function that, each time it is called, returns the next captures from pattern (see §6.4.1) + * over the string s. If pattern specifies no captures, then the whole match is produced in each call. + */ +function gmatch(s: LuaType, pattern: LuaType): () => string[] { + const S = coerceArgToString(s, 'gmatch', 1) + const P = translatePattern(coerceArgToString(pattern, 'gmatch', 2)) + + const reg = new RegExp(P, 'g') + const matches = S.match(reg) + + return () => { + const match = matches.shift() + if (match === undefined) return [] + + const groups = new RegExp(P).exec(match) + groups.shift() + return groups.length ? groups : [match] + } +} + +/** + * Returns a copy of s in which all (or the first n, if given) occurrences of the pattern (see §6.4.1) + * have been replaced by a replacement string specified by repl, which can be a string, a table, or a function. + * gsub also returns, as its second value, the total number of matches that occurred. + * The name gsub comes from Global SUBstitution. + * + * If repl is a string, then its value is used for replacement. The character % works as an escape character: + * any sequence in repl of the form %d, with d between 1 and 9, stands for the value of the d-th captured substring. + * The sequence %0 stands for the whole match. The sequence %% stands for a single %. + * + * If repl is a table, then the table is queried for every match, using the first capture as the key. + * + * If repl is a function, then this function is called every time a match occurs, + * with all captured substrings passed as arguments, in order. + * + * In any case, if the pattern specifies no captures, then it behaves as if the whole pattern was inside a capture. + * + * If the value returned by the table query or by the function call is a string or a number, + * then it is used as the replacement string; otherwise, if it is false or nil, then there is no replacement + * (that is, the original match is kept in the string). + */ +function gsub(s: LuaType, pattern: LuaType, repl: LuaType, n?: LuaType): string { + let S = coerceArgToString(s, 'gsub', 1) + const N = n === undefined ? Infinity : coerceArgToNumber(n, 'gsub', 3) + const P = translatePattern(coerceArgToString(pattern, 'gsub', 2)) + + const REPL = ((): ((strs: string[]) => string) => { + if (typeof repl === 'function') + return strs => { + const ret = repl(strs[0])[0] + return ret === undefined ? strs[0] : ret + } + + if (repl instanceof Table) return strs => repl.get(strs[0]).toString() + + return strs => `${repl}`.replace(/%([0-9])/g, (_, i) => strs[i]) + })() + + let result = '' + let count = 0 + let match + let lastMatch + while (count < N && S && (match = S.match(P))) { + const prefix = + // eslint-disable-next-line no-nested-ternary + match[0].length > 0 ? S.substr(0, match.index) : lastMatch === undefined ? '' : S.substr(0, 1) + + lastMatch = match[0] + result += `${prefix}${REPL(match)}` + S = S.substr(`${prefix}${lastMatch}`.length) + + count += 1 + } + + return `${result}${S}` +} + +/** + * Receives a string and returns its length. The empty string "" has length 0. + * Embedded zeros are counted, so "a\000bc\000" has length 5. + */ +function len(s: LuaType): number { + const str = coerceArgToString(s, 'len', 1) + return str.length +} + +/** + * Receives a string and returns a copy of this string with all uppercase letters changed to lowercase. + * All other characters are left unchanged. + * The definition of what an uppercase letter is depends on the current locale. + */ +function lower(s: LuaType): string { + const str = coerceArgToString(s, 'lower', 1) + return str.toLowerCase() +} + +/** + * Looks for the first match of pattern (see §6.4.1) in the string s. + * If it finds one, then match returns the captures from the pattern; otherwise it returns nil. + * If pattern specifies no captures, then the whole match is returned. + * A third, optional numeric argument init specifies where to start the search; its default value is 1 and can be negative. + */ +function match(s: LuaType, pattern: LuaType, init: LuaType = 0): string | RegExpMatchArray { + let str = coerceArgToString(s, 'match', 1) + const patt = coerceArgToString(pattern, 'match', 2) + const ini = coerceArgToNumber(init, 'match', 3) + + str = str.substr(ini) + const matches = str.match(new RegExp(translatePattern(patt))) + + if (!matches) { + return + } else if (!matches[1]) { + return matches[0] + } + + matches.shift() + return matches +} + +/** + * Returns a string that is the concatenation of n copies of the string s separated by the string sep. + * The default value for sep is the empty string (that is, no separator). + * Returns the empty string if n is not positive. + */ +function rep(s: LuaType, n: LuaType, sep?: LuaType): string { + const str = coerceArgToString(s, 'rep', 1) + const num = coerceArgToNumber(n, 'rep', 2) + const SEP = sep === undefined ? '' : coerceArgToString(sep, 'rep', 3) + return Array(num) + .fill(str) + .join(SEP) +} + +/** Returns a string that is the string s reversed. */ +function reverse(s: LuaType): string { + const str = coerceArgToString(s, 'reverse', 1) + return str + .split('') + .reverse() + .join('') +} + +/** + * Returns the substring of s that starts at i and continues until j; i and j can be negative. + * If j is absent, then it is assumed to be equal to -1 (which is the same as the string length). + * In particular, the call string.sub(s,1,j) returns a prefix of s with length j, and string.sub(s, -i) + * (for a positive j) returns a suffix of s with length i. + * + * If, after the translation of negative indices, i is less than 1, it is corrected to 1. If j is greater than + * the string length, it is corrected to that length. If, after these corrections, i is greater than j, + * the function returns the empty string. + */ +function sub(s: LuaType, i: LuaType = 1, j: LuaType = -1): string { + const S = coerceArgToString(s, 'sub', 1) + let start = posrelat(coerceArgToNumber(i, 'sub', 2), S.length) + let end = posrelat(coerceArgToNumber(j, 'sub', 3), S.length) + + if (start < 1) start = 1 + if (end > S.length) end = S.length + + if (start <= end) return S.substr(start - 1, end - start + 1) + return '' +} + +/** + * Receives a string and returns a copy of this string with all lowercase letters changed to uppercase. + * All other characters are left unchanged. + * The definition of what a lowercase letter is depends on the current locale. + */ +function upper(s: LuaType): string { + const S = coerceArgToString(s, 'upper', 1) + return S.toUpperCase() +} + +const libString = new Table({ + byte, + char, + find, + format, + gmatch, + gsub, + len, + lower, + match, + rep, + reverse, + sub, + upper +}) + +const metatable = new Table({ __index: libString }) + +export { libString, metatable } diff --git a/src/lib/table.ts b/src/lib/table.ts new file mode 100644 index 0000000..fb111d3 --- /dev/null +++ b/src/lib/table.ts @@ -0,0 +1,182 @@ +import { Table, getn } from '../Table' +import { + LuaType, + coerceToBoolean, + coerceArgToNumber, + coerceArgToString, + coerceArgToTable, + coerceArgToFunction +} from '../utils' +import { LuaError } from '../LuaError' + +/** + * Given a list where all elements are strings or numbers, returns the string list[i]..sep..list[i+1] ··· sep..list[j]. + * The default value for sep is the empty string, the default for i is 1, and the default for j is #list. + * If i is greater than j, returns the empty string. + */ +function concat(table: LuaType, sep: LuaType = '', i: LuaType = 1, j?: LuaType): string { + const TABLE = coerceArgToTable(table, 'concat', 1) + const SEP = coerceArgToString(sep, 'concat', 2) + const I = coerceArgToNumber(i, 'concat', 3) + const J = j === undefined ? maxn(TABLE) : coerceArgToNumber(j, 'concat', 4) + + return [] + .concat(TABLE.numValues) + .splice(I, J - I + 1) + .join(SEP) +} + +/** + * Inserts element value at position pos in list, shifting up the elements list[pos], list[pos+1], ···, list[#list]. + * The default value for pos is #list+1, so that a call table.insert(t,x) inserts x at the end of list t. + */ +function insert(table: LuaType, pos: LuaType, value?: LuaType): void { + const TABLE = coerceArgToTable(table, 'insert', 1) + const POS = value === undefined ? TABLE.numValues.length : coerceArgToNumber(pos, 'insert', 2) + const VALUE = value === undefined ? pos : value + + TABLE.numValues.splice(POS, 0, undefined) + TABLE.set(POS, VALUE) +} + +function maxn(table: LuaType): number { + const TABLE = coerceArgToTable(table, 'maxn', 1) + return TABLE.numValues.length - 1 +} + +/** + * Moves elements from table a1 to table a2, performing the equivalent to the following multiple assignment: + * + * `a2[t],··· = a1[f],···,a1[e].` + * + * The default for a2 is a1. + * The destination range can overlap with the source range. + * The number of elements to be moved must fit in a Lua integer. + * + * Returns the destination table a2. + */ +function move(a1: LuaType, f: LuaType, e: LuaType, t: LuaType, a2?: LuaType): Table { + const A1 = coerceArgToTable(a1, 'move', 1) + const F = coerceArgToNumber(f, 'move', 2) + const E = coerceArgToNumber(e, 'move', 3) + const T = coerceArgToNumber(t, 'move', 4) + const A2 = a2 === undefined ? A1 : coerceArgToTable(a2, 'move', 5) + + if (E >= F) { + if (F <= 0 && E >= Number.MAX_SAFE_INTEGER + F) throw new LuaError('too many elements to move') + const n = E - F + 1 // number of elements to movea + if (T > Number.MAX_SAFE_INTEGER - n + 1) throw new LuaError('destination wrap around') + + if (T > E || T <= F || A2 !== A1) { + for (let i = 0; i < n; i++) { + const v = A1.get(F + i) + A2.set(T + i, v) + } + } else { + for (let i = n - 1; i >= 0; i--) { + const v = A1.get(F + i) + A2.set(T + i, v) + } + } + } + + return A2 +} + +/** + * Returns a new table with all arguments stored into keys 1, 2, etc. and with a field "n" with the total number of arguments. + * Note that the resulting table may not be a sequence. + */ +function pack(...args: LuaType[]): Table { + const table = new Table(args) + table.rawset('n', args.length) + return table +} + +/** + * Removes from list the element at position pos, returning the value of the removed element. + * When pos is an integer between 1 and #list, it shifts down the elements list[pos+1], list[pos+2], ···, list[#list] and + * erases element list[#list]; The index pos can also be 0 when #list is 0, or #list + 1; + * in those cases, the function erases the element list[pos]. + * + * The default value for pos is #list, so that a call table.remove(l) removes the last element of list l. + */ +function remove(table: LuaType, pos?: LuaType): LuaType { + const TABLE = coerceArgToTable(table, 'remove', 1) + const max = getn(TABLE) + const POS = pos === undefined ? max : coerceArgToNumber(pos, 'remove', 2) + + if (POS > max || POS < 0) { + return + } + + const vals = TABLE.numValues + const result = vals.splice(POS, 1)[0] + + let i = POS + while (i < max && vals[i] === undefined) { + delete vals[i] + i += 1 + } + + return result +} + +/** + * Sorts list elements in a given order, in-place, from list[1] to list[#list]. + * If comp is given, then it must be a function that receives two list elements and + * returns true when the first element must come before the second in the final order + * (so that, after the sort, i < j implies not comp(list[j],list[i])). + * If comp is not given, then the standard Lua operator < is used instead. + * + * Note that the comp function must define a strict partial order over the elements in the list; + * that is, it must be asymmetric and transitive. Otherwise, no valid sort may be possible. + * + * The sort algorithm is not stable: elements considered equal by the given order may have + * their relative positions changed by the sort. + */ +function sort(table: Table, comp?: Function): void { + const TABLE = coerceArgToTable(table, 'sort', 1) + + let sortFunc: (a: LuaType, b: LuaType) => number + + if (comp) { + const COMP = coerceArgToFunction(comp, 'sort', 2) + sortFunc = (a, b) => (coerceToBoolean(COMP(a, b)[0]) ? -1 : 1) + } else { + sortFunc = (a, b) => (a < b ? -1 : 1) + } + + const arr = TABLE.numValues + arr.shift() + arr.sort(sortFunc).unshift(undefined) +} + +/** + * Returns the elements from the given list. This function is equivalent to + * + * `return list[i], list[i+1], ···, list[j]` + * + * By default, i is 1 and j is #list. + */ +function unpack(table: LuaType, i?: LuaType, j?: LuaType): LuaType[] { + const TABLE = coerceArgToTable(table, 'unpack', 1) + const I = i === undefined ? 1 : coerceArgToNumber(i, 'unpack', 2) + const J = j === undefined ? getn(TABLE) : coerceArgToNumber(j, 'unpack', 3) + + return TABLE.numValues.slice(I, J + 1) +} + +const libTable = new Table({ + getn, + concat, + insert, + maxn, + move, + pack, + remove, + sort, + unpack +}) + +export { libTable } diff --git a/src/operators.ts b/src/operators.ts new file mode 100644 index 0000000..bf6bfc6 --- /dev/null +++ b/src/operators.ts @@ -0,0 +1,184 @@ +import { MetaMethods, Table, getn } from './Table' +import { coerceToNumber, coerceToString, LuaType, coerceToBoolean } from './utils' +import { LuaError } from './LuaError' + +const binaryArithmetic = ( + left: LuaType, + right: LuaType, + metaMethodName: MetaMethods, + callback: (l: number, r: number) => R +): R => { + const mm = + (left instanceof Table && left.getMetaMethod(metaMethodName)) || + (right instanceof Table && right.getMetaMethod(metaMethodName)) + if (mm) return mm(left, right)[0] + + const L = coerceToNumber(left, 'attempt to perform arithmetic on a %type value') + const R = coerceToNumber(right, 'attempt to perform arithmetic on a %type value') + return callback(L, R) +} + +const binaryBooleanArithmetic = ( + left: LuaType, + right: LuaType, + metaMethodName: MetaMethods, + callback: (l: LuaType, r: LuaType) => boolean +): boolean => { + if ( + (typeof left === 'string' && typeof right === 'string') || + (typeof left === 'number' && typeof right === 'number') + ) { + return callback(left, right) + } + return binaryArithmetic(left, right, metaMethodName, callback) +} + +// extra +const bool = (value: LuaType): boolean => coerceToBoolean(value) + +// unary +const not = (value: LuaType): boolean => !bool(value) + +const unm = (value: LuaType): number => { + const mm = value instanceof Table && value.getMetaMethod('__unm') + if (mm) return mm(value)[0] + + return -1 * coerceToNumber(value, 'attempt to perform arithmetic on a %type value') +} + +const bnot = (value: LuaType): number => { + const mm = value instanceof Table && value.getMetaMethod('__bnot') + if (mm) return mm(value)[0] + + return ~coerceToNumber(value, 'attempt to perform arithmetic on a %type value') +} + +const len = (value: LuaType): number => { + if (value instanceof Table) { + const mm = value.getMetaMethod('__len') + if (mm) return mm(value)[0] + + return getn(value) + } + + if (typeof value === 'string') return value.length + + throw new LuaError('attempt to get length of an unsupported value') + + // if (typeof value === 'object') { + // let length = 0 + // for (const key in value) { + // if (hasOwnProperty(value, key)) { + // length += 1 + // } + // } + // return length + // } +} + +// binary +const add = (left: LuaType, right: LuaType): number => binaryArithmetic(left, right, '__add', (l, r) => l + r) + +const sub = (left: LuaType, right: LuaType): number => binaryArithmetic(left, right, '__sub', (l, r) => l - r) + +const mul = (left: LuaType, right: LuaType): number => binaryArithmetic(left, right, '__mul', (l, r) => l * r) + +const mod = (left: LuaType, right: LuaType): number => + binaryArithmetic(left, right, '__mod', (l, r) => { + if (r === 0 || r === -Infinity || r === Infinity || isNaN(l) || isNaN(r)) return NaN + + const absR = Math.abs(r) + let result = Math.abs(l) % absR + + if (l * r < 0) result = absR - result + if (r < 0) result *= -1 + + return result + }) + +const pow = (left: LuaType, right: LuaType): number => binaryArithmetic(left, right, '__pow', Math.pow) + +const div = (left: LuaType, right: LuaType): number => + binaryArithmetic(left, right, '__div', (l, r) => { + if (r === undefined) throw new LuaError('attempt to perform arithmetic on a nil value') + return l / r + }) + +const idiv = (left: LuaType, right: LuaType): number => + binaryArithmetic(left, right, '__idiv', (l, r) => { + if (r === undefined) throw new LuaError('attempt to perform arithmetic on a nil value') + return Math.floor(l / r) + }) + +const band = (left: LuaType, right: LuaType): number => binaryArithmetic(left, right, '__band', (l, r) => l & r) + +const bor = (left: LuaType, right: LuaType): number => binaryArithmetic(left, right, '__bor', (l, r) => l | r) + +const bxor = (left: LuaType, right: LuaType): number => binaryArithmetic(left, right, '__bxor', (l, r) => l ^ r) + +const shl = (left: LuaType, right: LuaType): number => binaryArithmetic(left, right, '__shl', (l, r) => l << r) + +const shr = (left: LuaType, right: LuaType): number => binaryArithmetic(left, right, '__shr', (l, r) => l >> r) + +const concat = (left: LuaType, right: LuaType): string => { + const mm = + (left instanceof Table && left.getMetaMethod('__concat')) || + (right instanceof Table && right.getMetaMethod('__concat')) + if (mm) return mm(left, right)[0] + + const L = coerceToString(left, 'attempt to concatenate a %type value') + const R = coerceToString(right, 'attempt to concatenate a %type value') + return `${L}${R}` +} + +const neq = (left: LuaType, right: LuaType): boolean => !eq(left, right) + +const eq = (left: LuaType, right: LuaType): boolean => { + const mm = + right !== left && + left instanceof Table && + right instanceof Table && + left.metatable === right.metatable && + left.getMetaMethod('__eq') + + if (mm) return !!mm(left, right)[0] + + return left === right +} + +const lt = (left: LuaType, right: LuaType): boolean => binaryBooleanArithmetic(left, right, '__lt', (l, r) => l < r) + +const le = (left: LuaType, right: LuaType): boolean => binaryBooleanArithmetic(left, right, '__le', (l, r) => l <= r) + +const gt = (left: LuaType, right: LuaType): boolean => !le(left, right) + +const ge = (left: LuaType, right: LuaType): boolean => !lt(left, right) + +const operators = { + bool, + not, + unm, + bnot, + len, + add, + sub, + mul, + mod, + pow, + div, + idiv, + band, + bor, + bxor, + shl, + shr, + concat, + neq, + eq, + lt, + le, + gt, + ge +} + +export { operators } diff --git a/src/parser.ts b/src/parser.ts new file mode 100644 index 0000000..c684156 --- /dev/null +++ b/src/parser.ts @@ -0,0 +1,752 @@ +import luaparse from 'luaparse' + +type Block = + | luaparse.IfClause + | luaparse.ElseifClause + | luaparse.ElseClause + | luaparse.WhileStatement + | luaparse.DoStatement + | luaparse.RepeatStatement + | luaparse.FunctionDeclaration + | luaparse.ForNumericStatement + | luaparse.ForGenericStatement + | luaparse.Chunk + +const isBlock = (node: luaparse.Node): node is Block => + node.type === 'IfClause' || + node.type === 'ElseifClause' || + node.type === 'ElseClause' || + node.type === 'WhileStatement' || + node.type === 'DoStatement' || + node.type === 'RepeatStatement' || + node.type === 'FunctionDeclaration' || + node.type === 'ForNumericStatement' || + node.type === 'ForGenericStatement' || + node.type === 'Chunk' + +class MemExpr extends String { + public base: string | MemExpr + public property: string | MemExpr + + public constructor(base: string | MemExpr, property: string | MemExpr) { + super() + this.base = base + this.property = property + } + + public get(): string { + return `__lua.get(${this.base}, ${this.property})` + } + + public set(value: string | MemExpr): string { + return `${this.base}.set(${this.property}, ${value})` + } + + public setFn(): string { + return `${this.base}.setFn(${this.property})` + } + + public toString(): string { + return this.get() + } + + public valueOf(): string { + return this.get() + } +} + +const UNI_OP_MAP = { + not: 'not', + '-': 'unm', + '~': 'bnot', + '#': 'len' +} + +const BIN_OP_MAP = { + '+': 'add', + '-': 'sub', + '*': 'mul', + '%': 'mod', + '^': 'pow', + '/': 'div', + '//': 'idiv', + '&': 'band', + '|': 'bor', + '~': 'bxor', + '<<': 'shl', + '>>': 'shr', + '..': 'concat', + '~=': 'neq', + '==': 'eq', + '<': 'lt', + '<=': 'le', + '>': 'gt', + '>=': 'ge' +} + +const generate = (node: luaparse.Node): string | MemExpr => { + switch (node.type) { + case 'LabelStatement': { + return `case '${node.label.name}': label = undefined` + } + + case 'BreakStatement': { + return 'break' + } + + case 'GotoStatement': { + return `label = '${node.label.name}'; continue` + } + + case 'ReturnStatement': { + const args = parseExpressions(node.arguments) + return `return ${args}` + } + + case 'IfStatement': { + const clauses = node.clauses.map(clause => generate(clause)) + return clauses.join(' else ') + } + + case 'IfClause': + case 'ElseifClause': { + const condition = expression(node.condition) + const body = parseBody(node) + return `if (__lua.bool(${condition})) {\n${body}\n}` + } + + case 'ElseClause': { + const body = parseBody(node) + return `{\n${body}\n}` + } + + case 'WhileStatement': { + const condition = expression(node.condition) + const body = parseBody(node) + return `while(${condition}) {\n${body}\n}` + } + + case 'DoStatement': { + const body = parseBody(node) + return `\n${body}\n` + } + + case 'RepeatStatement': { + const condition = expression(node.condition) + const body = parseBody(node) + return `do {\n${body}\n} while (!(${condition}))` + } + + case 'LocalStatement': { + return parseAssignments(node) + } + + case 'AssignmentStatement': { + return parseAssignments(node) + } + + case 'CallStatement': { + return generate(node.expression) + } + + case 'FunctionDeclaration': { + const getFuncDef = (params: string[]): string => { + const paramStr = params.join(';\n') + const body = parseBody(node, paramStr) + const argsStr = params.length === 0 ? '' : '...args' + const returnStr = + node.body.findIndex(node => node.type === 'ReturnStatement') === -1 ? '\nreturn []' : '' + return `(${argsStr}) => {\n${body}${returnStr}\n}` + } + + const params = node.parameters.map(param => { + if (param.type === 'VarargLiteral') { + return `$${nodeToScope.get(param)}.setVarargs(args)` + } + return `$${nodeToScope.get(param)}.setLocal('${param.name}', args.shift())` + }) + + // anonymous function + if (node.identifier === null) return getFuncDef(params) + + if (node.identifier.type === 'Identifier') { + const scope = nodeToScope.get(node.identifier) + const setStr = node.isLocal ? 'setLocal' : 'set' + return `$${scope}.${setStr}('${node.identifier.name}', ${getFuncDef(params)})` + } + + const identifier = generate(node.identifier) as MemExpr + if (node.identifier.indexer === ':') { + params.unshift(`$${nodeToScope.get(node)}.setLocal('self', args.shift())`) + } + return identifier.set(getFuncDef(params)) + } + + case 'ForNumericStatement': { + const varName = node.variable.name + const start = expression(node.start) + const end = expression(node.end) + const step = node.step === null ? 1 : expression(node.step) + const init = `let ${varName} = ${start}, end = ${end}, step = ${step}` + const cond = `step > 0 ? ${varName} <= end : ${varName} >= end` + const after = `${varName} += step` + const varInit = `$${nodeToScope.get(node.variable)}.setLocal('${varName}', ${varName});` + const body = parseBody(node, varInit) + + return `for (${init}; ${cond}; ${after}) {\n${body}\n}` + } + + case 'ForGenericStatement': { + const iterators = parseExpressions(node.iterators) + + const variables = node.variables + .map((variable, index) => { + return `$${nodeToScope.get(variable)}.setLocal('${variable.name}', res[${index}])` + }) + .join(';\n') + + const body = parseBody(node, variables) + + return `for (let [iterator, table, next] = ${iterators}, res = __lua.call(iterator, table, next); res[0] !== undefined; res = __lua.call(iterator, table, res[0])) {\n${body}\n}` + } + + case 'Chunk': { + const body = parseBody(node) + return `'use strict'\nconst $0 = __lua.globalScope\nlet vars\nlet vals\nlet label\n\n${body}` + } + + case 'Identifier': { + return `$${nodeToScope.get(node)}.get('${node.name}')` + } + + case 'StringLiteral': { + const S = node.value + .replace(/([^\\])?\\(\d{1,3})/g, (_, pre, dec) => `${pre || ''}${String.fromCharCode(dec)}`) + .replace(/\\/g, '\\\\') + + return `\`${S}\`` + } + + case 'NumericLiteral': { + return node.value.toString() + } + + case 'BooleanLiteral': { + return node.value ? 'true' : 'false' + } + + case 'NilLiteral': { + return 'undefined' + } + + case 'VarargLiteral': { + return `$${nodeToScope.get(node)}.getVarargs()` + } + + // inside TableConstructorExpression + // case 'TableKey': {} + // case 'TableKeyString': {} + // case 'TableValue': {} + + case 'TableConstructorExpression': { + if (node.fields.length === 0) return 'new __lua.Table()' + + const fields = node.fields + .map((field, index, arr) => { + if (field.type === 'TableKey') { + return `t.rawset(${generate(field.key)}, ${expression(field.value)})` + } + + if (field.type === 'TableKeyString') { + return `t.rawset('${field.key.name}', ${expression(field.value)})` + } + + if (field.type === 'TableValue') { + if (index === arr.length - 1 && ExpressionReturnsArray(field.value)) { + return `t.insert(...${generate(field.value)})` + } + return `t.insert(${expression(field.value)})` + } + }) + .join(';\n') + + return `new __lua.Table(t => {\n${fields}\n})` + } + + case 'UnaryExpression': { + const operator = UNI_OP_MAP[node.operator] + const argument = expression(node.argument) + + if (!operator) { + throw new Error(`Unhandled unary operator: ${node.operator}`) + } + + return `__lua.${operator}(${argument})` + } + + case 'BinaryExpression': { + const left = expression(node.left) + const right = expression(node.right) + const operator = BIN_OP_MAP[node.operator] + + if (!operator) { + throw new Error(`Unhandled binary operator: ${node.operator}`) + } + + return `__lua.${operator}(${left}, ${right})` + } + + case 'LogicalExpression': { + const left = expression(node.left) + const right = expression(node.right) + const operator = node.operator + + if (operator === 'and') { + return `(!__lua.bool(${left})?${left}:${right})` + } + if (operator === 'or') { + return `(__lua.bool(${left})?${left}:${right})` + } + throw new Error(`Unhandled logical operator: ${node.operator}`) + } + case 'MemberExpression': { + const base = expression(node.base) + return new MemExpr(base, `'${node.identifier.name}'`) + } + + case 'IndexExpression': { + const base = expression(node.base) + const index = expression(node.index) + return new MemExpr(base, index) + } + + case 'CallExpression': + case 'TableCallExpression': + case 'StringCallExpression': { + const functionName = expression(node.base) + const args = + node.type === 'CallExpression' + ? parseExpressionList(node.arguments).join(', ') + : expression(node.type === 'TableCallExpression' ? node.arguments : node.argument) + + if (functionName instanceof MemExpr && node.base.type === 'MemberExpression' && node.base.indexer === ':') { + return `__lua.call(${functionName}, ${functionName.base}, ${args})` + } + + return `__lua.call(${functionName}, ${args})` + } + + default: + throw new Error(`No generator found for: ${node.type}`) + } +} + +const parseBody = (node: Block, header = ''): string => { + const scope = nodeToScope.get(node) + const scopeDef = scope === undefined ? '' : `const $${scope} = $${scopeToParentScope.get(scope)}.extend();` + + const body = node.body.map(statement => generate(statement)).join(';\n') + + const goto = nodeToGoto.get(node) + if (goto === undefined) return `${scopeDef}\n${header}\n${body}` + + const gotoHeader = `L${goto}: do { switch(label) { case undefined:` + const gotoParent = gotoToParentGoto.get(goto) + const def = gotoParent === undefined ? '' : `break; default: continue L${gotoParent}\n` + const footer = `${def}} } while (label)` + + return `${scopeDef}\n${gotoHeader}\n${header}\n${body}\n${footer}` +} + +const expression = (node: luaparse.Expression): string | MemExpr => { + const v = generate(node) + if (ExpressionReturnsArray(node)) return `${v}[0]` + return v +} + +const parseExpressions = (expressions: luaparse.Expression[]): string | MemExpr => { + // return the `array` directly instead of `[...array]` + if (expressions.length === 1 && ExpressionReturnsArray(expressions[0])) { + return generate(expressions[0]) + } + + return `[${parseExpressionList(expressions).join(', ')}]` +} + +const parseExpressionList = (expressions: luaparse.Expression[]): (string | MemExpr)[] => { + return expressions.map((node, index, arr) => { + const value = generate(node) + if (ExpressionReturnsArray(node)) { + return index === arr.length - 1 ? `...${value}` : `${value}[0]` + } + return value + }) +} + +const parseAssignments = (node: luaparse.LocalStatement | luaparse.AssignmentStatement): string => { + const lines: (string | MemExpr)[] = [] + const valFns: string[] = [] + + const useTempVar = node.variables.length > 1 && node.init.length > 0 && !node.init.every(isLiteral) + + for (let i = 0; i < node.variables.length; i++) { + const K = node.variables[i] + const V = node.init[i] + + const initStr = + // eslint-disable-next-line no-nested-ternary + useTempVar ? `vars[${i}]` : V === undefined ? 'undefined' : expression(V) + + if (K.type === 'Identifier') { + const setStr = node.type === 'LocalStatement' ? 'setLocal' : 'set' + lines.push(`$${nodeToScope.get(K)}.${setStr}('${K.name}', ${initStr})`) + } else { + const name = generate(K) as MemExpr + + if (useTempVar) { + lines.push(`vals[${valFns.length}](${initStr})`) + valFns.push(name.setFn()) + } else { + lines.push(name.set(initStr)) + } + } + } + + // push remaining CallExpressions + for (let i = node.variables.length; i < node.init.length; i++) { + const init = node.init[i] + if (isCallExpression(init)) { + lines.push(generate(init)) + } + } + + if (useTempVar) { + lines.unshift(`vars = ${parseExpressions(node.init)}`) + if (valFns.length > 0) { + lines.unshift(`vals = [${valFns.join(', ')}]`) + } + } + + return lines.join(';\n') +} + +const isCallExpression = ( + node: luaparse.Expression +): node is luaparse.CallExpression | luaparse.StringCallExpression | luaparse.TableCallExpression => { + return node.type === 'CallExpression' || node.type === 'StringCallExpression' || node.type === 'TableCallExpression' +} + +const ExpressionReturnsArray = (node: luaparse.Expression): boolean => { + return isCallExpression(node) || node.type === 'VarargLiteral' +} + +const isLiteral = (node: luaparse.Expression): boolean => { + return ( + node.type === 'StringLiteral' || + node.type === 'NumericLiteral' || + node.type === 'BooleanLiteral' || + node.type === 'NilLiteral' || + node.type === 'TableConstructorExpression' + ) +} + +const checkGoto = (ast: luaparse.Chunk): void => { + const gotoInfo: { + type: 'local' | 'label' | 'goto' + name: string + scope: number + last?: boolean + }[] = [] + + let gotoScope = 0 + const gotoScopeMap = new Map() + const getNextGotoScope = (() => { + let id = 0 + return () => { + id += 1 + return id + } + })() + + const check = (node: luaparse.Node): void => { + if (isBlock(node)) { + createGotoScope() + + for (let i = 0; i < node.body.length; i++) { + const n = node.body[i] + switch (n.type) { + case 'LocalStatement': { + gotoInfo.push({ + type: 'local', + name: n.variables[0].name, + scope: gotoScope + }) + break + } + case 'LabelStatement': { + if ( + gotoInfo.find( + node => node.type === 'label' && node.name === n.label.name && node.scope === gotoScope + ) + ) { + throw new Error(`label '${n.label.name}' already defined`) + } + + gotoInfo.push({ + type: 'label', + name: n.label.name, + scope: gotoScope, + last: + node.type !== 'RepeatStatement' && + node.body.slice(i).every(n => n.type === 'LabelStatement') + }) + break + } + case 'GotoStatement': { + gotoInfo.push({ + type: 'goto', + name: n.label.name, + scope: gotoScope + }) + break + } + case 'IfStatement': { + n.clauses.forEach(n => check(n)) + break + } + default: { + check(n) + } + } + } + + destroyGotoScope() + } + } + check(ast) + + function createGotoScope(): void { + const parent = gotoScope + gotoScope = getNextGotoScope() + gotoScopeMap.set(gotoScope, parent) + } + function destroyGotoScope(): void { + gotoScope = gotoScopeMap.get(gotoScope) + } + + for (let i = 0; i < gotoInfo.length; i++) { + const goto = gotoInfo[i] + + if (goto.type === 'goto') { + const label = gotoInfo + .filter(node => node.type === 'label' && node.name === goto.name && node.scope <= goto.scope) + .sort((a, b) => Math.abs(goto.scope - a.scope) - Math.abs(goto.scope - b.scope))[0] + + if (!label) { + throw new Error(`no visible label '${goto.name}' for `) + } + + const labelI = gotoInfo.findIndex(n => n === label) + + if (labelI > i) { + const locals = gotoInfo + .slice(i, labelI) + .filter(node => node.type === 'local' && node.scope === label.scope) + + if (!label.last && locals.length > 0) { + throw new Error(` jumps into the scope of local '${locals[0].name}'`) + } + } + } + } +} + +const visitNode = ( + node: luaparse.Node, + visitProp: (node: luaparse.Node, prevScope: number, prevGoto: number) => void, + nextScope: number, + isNewScope: boolean, + nextGoto: number +): void => { + const VP = (node: luaparse.Node | luaparse.Node[], partOfBlock = true): void => { + if (!node) return + + const S = partOfBlock === false && isNewScope ? scopeToParentScope.get(nextScope) : nextScope + if (Array.isArray(node)) { + node.forEach(n => visitProp(n, S, nextGoto)) + } else { + visitProp(node, S, nextGoto) + } + } + + switch (node.type) { + case 'LocalStatement': + case 'AssignmentStatement': + VP(node.variables) + VP(node.init) + break + case 'UnaryExpression': + VP(node.argument) + break + case 'BinaryExpression': + case 'LogicalExpression': + VP(node.left) + VP(node.right) + break + case 'FunctionDeclaration': + VP(node.identifier, false) + VP(node.parameters) + VP(node.body) + break + case 'ForGenericStatement': + VP(node.variables) + VP(node.iterators, false) + VP(node.body) + break + case 'IfClause': + case 'ElseifClause': + case 'WhileStatement': + case 'RepeatStatement': + VP(node.condition, false) + /* fall through */ + case 'Chunk': + case 'ElseClause': + case 'DoStatement': + VP(node.body) + // VK(node.globals) + // VK(node.comments) + break + case 'ForNumericStatement': + VP(node.variable) + VP(node.start, false) + VP(node.end, false) + VP(node.step, false) + VP(node.body) + break + case 'ReturnStatement': + VP(node.arguments) + break + case 'IfStatement': + VP(node.clauses) + break + case 'MemberExpression': + VP(node.base) + VP(node.identifier) + break + case 'IndexExpression': + VP(node.base) + VP(node.index) + break + case 'LabelStatement': + VP(node.label) + break + case 'CallStatement': + VP(node.expression) + break + case 'GotoStatement': + VP(node.label) + break + case 'TableConstructorExpression': + VP(node.fields) + break + case 'TableKey': + case 'TableKeyString': + VP(node.key) + /* fall through */ + case 'TableValue': + VP(node.value) + break + case 'CallExpression': + VP(node.base) + VP(node.arguments) + break + case 'TableCallExpression': + VP(node.base) + VP(node.arguments) + break + case 'StringCallExpression': + VP(node.base) + VP(node.argument) + // break + // case 'Identifier': + // case 'NumericLiteral': + // case 'BooleanLiteral': + // case 'StringLiteral': + // case 'NilLiteral': + // case 'VarargLiteral': + // case 'BreakStatement': + // case 'Comment': + // break + // default: + // throw new Error(`Unhandled ${node.type}`) + } +} + +const scopeToParentScope = new Map() +const nodeToScope = new Map() + +const gotoToParentGoto = new Map() +const nodeToGoto = new Map() + +const setExtraInfo = (ast: luaparse.Chunk): void => { + let scopeID = 0 + let gotoID = 0 + + const visitProp = (node: luaparse.Node, prevScope: number, prevGoto: number): void => { + let nextScope = prevScope + let nextGoto = prevGoto + + if (isBlock(node)) { + // set scope info + if ( + node.body.findIndex( + n => n.type === 'LocalStatement' || (n.type === 'FunctionDeclaration' && n.isLocal) + ) !== -1 || + (node.type === 'FunctionDeclaration' && + (node.parameters.length > 0 || (node.identifier && node.identifier.type === 'MemberExpression'))) || + node.type === 'ForNumericStatement' || + node.type === 'ForGenericStatement' + ) { + scopeID += 1 + nextScope = scopeID + + nodeToScope.set(node, scopeID) + scopeToParentScope.set(scopeID, prevScope) + } + + // set goto info + if (node.body.findIndex(s => s.type === 'LabelStatement' || s.type === 'GotoStatement') !== -1) { + nextGoto = gotoID + + nodeToGoto.set(node, gotoID) + if (node.type !== 'Chunk' && node.type !== 'FunctionDeclaration') { + gotoToParentGoto.set(gotoID, prevGoto) + } + + gotoID += 1 + } + } + + // set scope info + else if (node.type === 'Identifier' || node.type === 'VarargLiteral') { + nodeToScope.set(node, prevScope) + } + + visitNode(node, visitProp, nextScope, prevScope !== nextScope, nextGoto) + } + + visitProp(ast, scopeID, gotoID) +} + +const parse = (data: string): string => { + const ast = luaparse.parse(data.replace(/^#.*/, ''), { + scope: false, + comments: false, + luaVersion: '5.3' + }) + checkGoto(ast) + setExtraInfo(ast) + return generate(ast).toString() +} + +export { parse } diff --git a/src/parser/index.js b/src/parser/index.js deleted file mode 100644 index 9aac55b..0000000 --- a/src/parser/index.js +++ /dev/null @@ -1,508 +0,0 @@ -import luaparse from 'luaparse' - -class MemExpr extends String { - constructor(base, property) { - super(); - this.base = base; - this.property = property; - } - - get() { - return `Tget(${this.base}, ${this.property})`; - } - - set(value) { - return `Tset(${this.base}, ${this.property}, ${value})`; - } - - toString() { - return this.get(); - } - - valueOf() { - return this.get(); - } -} - -let scopeIndex = 1; -let functionIndex = 0; -let forLoopIndex = 0; - -const UNI_OP_MAP = { - '-': 'unm', - 'not': 'not', - '#': 'len' -}; - -const BIN_OP_MAP = { - '..': 'concat', - '+': 'add', - '-': 'sub', - '*': 'mul', - '/': 'div', - '%': 'mod', - '==': 'eq', - '~=': 'neq', - '<': 'lt', - '>': 'gt', - '<=': 'lte', - '>=': 'gte', - '^': 'pow' -}; - - -const GENERATORS = { - - AssignmentStatement(node, scope) { - let assignments = node.variables.map((variable, index) => { - const name = scoped(variable, scope); - - if (name instanceof MemExpr) { - return name.set(`__star_tmp[${index}]`); - } else { - const [match, args] = [].concat(name.match(/^\$get\((.*)\)$/)); - if (!match) { - throw new Error('Unhandled'); - } - - return `$set(${args}, __star_tmp[${index}])`; - } - }).join(';\n'); - - const values = parseExpressionList(node.init, scope).join(', '); - return `__star_tmp = [${values}];${assignments}`; - }, - - - BinaryExpression(node, scope) { - let left = scoped(node.left, scope); - let right = scoped(node.right, scope); - let operator = BIN_OP_MAP[node.operator]; - - if (isCallExpression(node.left)) { - left += '[0]'; - } - - if (isCallExpression(node.right)) { - right += '[0]'; - } - - if (!operator) { - console.info(node); - throw new Error(`Unhandled binary operator: ${node.operator}`); - } - - return `__star_op_${operator}(${left}, ${right})`; - }, - - - BooleanLiteral(node) { - return node.value ? 'true' : 'false'; - }, - - - BreakStatement(node) { - return 'break'; - }, - - - CallStatement(node, scope) { - return generate(node.expression, scope); - }, - - - CallExpression(node, scope) { - let functionName = scoped(node.base, scope); - const args = parseExpressionList(node.arguments, scope); - - if (isCallExpression(node.base)) { - args.unshift(`${functionName}[0]`); - } else { - if (functionName instanceof MemExpr && node.base.indexer === ':') { - args.unshift(functionName.base); - } - args.unshift(`${functionName}`); - } - - return `__star_call(${args})`; - }, - - - Chunk(node, scope) { - let output = node.body.map(statement => generate(statement, scope) + ';'); - return output.join('\n'); - }, - - - DoStatement(node, outerScope) { - let { scope, scopeDef } = extendScope(outerScope); - let body = this.Chunk(node, scope); - scopeDef = scopeDef.replace(',', ';'); - return `${scopeDef}\n${body}\n$=$${outerScope};`; - }, - - - ElseClause(node, scope) { - let body = this.Chunk(node, scope); - return `{\n${body}\n}`; - }, - - - ElseifClause(node, scope) { - return this.IfClause(node, scope); - }, - - - ForNumericStatement(node, outerScope) { - let { scope, scopeDef } = extendScope(outerScope); - let variableName = generate(node.variable, outerScope); - let start = scoped(node.start, outerScope); - let end = scoped(node.end, outerScope); - let step = node.step === null ? 1 : generate(node.step, outerScope); - let operator = step > 0 ? '<=' : '>='; - let body = this.Chunk(node, scope); - let loopIndex = ++forLoopIndex; - - let init = `$${outerScope}._forLoop${loopIndex} = ${start}`; - let cond = `$${outerScope}._forLoop${loopIndex} ${operator} ${end}`; - let after = `$${outerScope}._forLoop${loopIndex} += ${step}`; - let varInit = `$${scope}.setLocal('${variableName}',$${outerScope}._forLoop${loopIndex});`; - return `for (${init}; ${cond}; ${after}) {\n${scopeDef}\n${varInit}\n${body}\n}`; - }, - - - ForGenericStatement(node, outerScope) { - const { scope, scopeDef } = extendScope(outerScope); - const { scope: iterationScope, scopeDef: iterationScopeDef } = extendScope(scope); - const iterators = parseExpressionList(node.iterators, outerScope).join(', '); - const body = this.Chunk(node, iterationScope); - - const variables = node.variables.map((variable, index) => { - const name = generate(variable, scope); - return `$setLocal($, '${name}', __star_tmp[${index}])`; - }).join(';\n'); - - const defs = scopeDef.split(', '); - return `${defs[0]};\n[$${scope}._iterator, $${scope}._table, $${scope}._next] = [${iterators}];\nwhile((__star_tmp = __star_call($${scope}._iterator, $${scope}._table, $${scope}._next)),__star_tmp[0] !== undefined) {\n${iterationScopeDef}\$${scope}._next = __star_tmp[0]\n${variables}\n${body}\n}`; - }, - - - FunctionDeclaration(node, outerScope) { - let { scope, scopeDef } = extendScope(outerScope); - let isAnonymous = !node.identifier; - let identifier = isAnonymous ? '' : generate(node.identifier, outerScope); - let isMemberExpr = identifier instanceof MemExpr; - - let params = node.parameters.map((param, index) => { - let name = generate(param, scope); - if (name === '...$.getVarargs()') { - return `$.setVarargs(args)`; - } else { - return `$setLocal($, '${name}', __star_shift(args))`; - } - }); - - let name; - if (isMemberExpr) { - name = identifier.property.replace(/'/g, ''); - - if (node.identifier.indexer === ':') { - params.unshift("$setLocal($, 'self', __star_shift(args))"); - } - } else { - name = identifier; - } - - let paramStr = params.join(';\n'); - let body = this.Chunk(node, scope); - let prefix = isAnonymous? '' : 'func$'; - let funcDef = `(__star_tmp = function ${prefix}${name}(...args){${scopeDef}\n${paramStr};\n${body} return [];}, __star_tmp.toString=()=>'function: 0x${(++functionIndex).toString(16)}', __star_tmp)`; - - if (isAnonymous) { - return funcDef; - } else if (isMemberExpr) { - return identifier.set(funcDef); - } else { - const local = node.isLocal ? 'Local' : ''; - return `$set${local}($, '${identifier}', ${funcDef})`; - } - }, - - - Identifier(node, scope) { - return node.name; - }, - - - IfClause(node, scope) { - let condition = scoped(node.condition, scope); - - if (isCallExpression(node.condition)) { - condition += '[0]'; - } - - let body = this.Chunk(node, scope); - return `if (__star_op_bool(${condition})) {\n${body}\n}`; - }, - - - IfStatement(node, scope) { - let clauses = node.clauses.map((clause) => generate(clause, scope)); - return clauses.join (' else '); - }, - - - IndexExpression(node, scope) { - let base = scoped(node.base, scope); - let index = scoped(node.index, scope); - - if (isCallExpression(node.base)) { - base += '[0]'; - } - - if (isCallExpression(node.index)) { - index += '[0]'; - } - - return new MemExpr(base, index); - }, - - - LocalStatement(node, scope) { - let assignments = node.variables.map((variable, index) => { - let name = generate(variable, scope); - return `$setLocal($, '${name}', __star_tmp[${index}])`; - }).join(';\n'); - - const values = parseExpressionList(node.init, scope).join(', '); - return `__star_tmp = [${values}];${assignments}`; - }, - - - LogicalExpression(node, scope) { - let left = scoped(node.left, scope); - let right = scoped(node.right, scope); - let operator = node.operator; - - if (isCallExpression(node.left)) { - left += '[0]'; - } - - if (isCallExpression(node.right)) { - right += '[0]'; - } - - if (operator === 'and') { - return `(!__star.op.bool(${left})?${left}:${right})` - - } else if (operator === 'or') { - return `(__star.op.bool(${left})?${left}:${right})` - - } else { - console.info(node); - throw new Error(`Unhandled logical operator: ${node.operator}`); - } - }, - - - MemberExpression(node, scope) { - let base = scoped(node.base, scope); - let identifier = generate(node.identifier, scope); - - if (isCallExpression(node.base)) { - base += '[0]'; - } - - return new MemExpr(base, `'${identifier}'`); - }, - - - NilLiteral(node) { - return 'undefined'; - }, - - - NumericLiteral(node) { - return node.value.toString(); - }, - - - RepeatStatement(node, outerScope) { - let { scope, scopeDef } = extendScope(outerScope); - let condition = scoped(node.condition, outerScope); - let body = this.Chunk(node, scope); - - return `do{\n${scopeDef}\n${body}\n}while(!(${condition}))`; - }, - - - ReturnStatement(node, scope) { - const args = parseExpressionList(node.arguments, scope).join(', '); - return `return [${args}];`; - }, - - - StringCallExpression(node, scope) { - node.arguments = node.argument; - return this.TableCallExpression(node, scope); - }, - - - StringLiteral(node) { - let raw = node.raw; - if (/^\[\[[^]*]$/m.test(raw)) { - return `\`${raw.substr(2, raw.length - 4).replace(/\\/g, '\\\\')}\``; - } else { - raw = raw.replace(/([^\\])\\(\d{1,3})/g, (_, pre, dec) => `${pre}\\u${('000' + parseInt(dec, 10).toString(16)).substr(-4)}`); - return raw; - } - }, - - - TableCallExpression(node, scope) { - let functionName = scoped(node.base, scope); - let args = [generate(node.arguments, scope)]; - - if (isCallExpression(node.base)) { - return `__star_call(${functionName}[0],${args})`; - } else { - if (functionName instanceof MemExpr && node.base.indexer === ':') { - args.unshift(functionName.base); - } - return `__star_call(${functionName},${args})`; - } - }, - - - TableConstructorExpression(node, scope) { - let fields = node.fields.map((field, index, arr) => { - if (field.type == 'TableValue') { - const isLastItem = index === arr.length - 1; - return this.TableValue(field, scope, isLastItem); - } - return generate(field, scope); - }).join(';\n'); - - return `new __star_T(t => {${fields}})`; - }, - - - TableKeyString(node, scope) { - let name = generate(node.key, scope); - let value = scoped(node.value, scope); - return `Tset(t, '${name}', ${value})`; - }, - - - TableKey(node, scope) { - let name = scoped(node.key, scope); - let value = scoped(node.value, scope); - return `Tset(t, ${name}, ${value})`; - }, - - - TableValue(node, scope, isLastItem) { - let value = scoped(node.value, scope); - if (isCallExpression(node.value)) { - value = isLastItem ? `...${value}` : `${value}[0]`; - } - return `Tins(t, ${value})`; - }, - - - UnaryExpression(node, scope) { - let operator = UNI_OP_MAP[node.operator]; - let argument = scoped(node.argument, scope); - - if (isCallExpression(node.argument)) { - argument += '[0]'; - } - - if (!operator) { - console.info(node); - throw new Error(`Unhandled unary operator: ${node.operator}`); - } - - return `__star_op_${operator}(${argument})`; - }, - - - VarargLiteral(node) { - return '...$.getVarargs()'; - }, - - - WhileStatement(node, outerScope) { - let { scope, scopeDef } = extendScope(outerScope); - let condition = scoped(node.condition, outerScope); - let body = this.Chunk(node, scope); - - return `while(${condition}) {\n${scopeDef}\n${body}\n}`; - }, - -}; - - - -function parseExpressionList(expressionNodeArray, scope) { - return expressionNodeArray.map((node, index, arr) => { - let value = scoped(node, scope); - if (isCallExpression(node)) { - if (index == arr.length - 1) { - return `...${value}`; - } - return `${value}[0]`; - } - return value; - }); -} - - -function extendScope(outerIndex) { - let scope = scopeIndex++; - let scopeDef = `let $${scope} = $${outerIndex}.extend(), $ = $${scope};`; - return { scope, scopeDef }; -} - - -function scoped(node, scope) { - let value = generate(node, scope); - return node.type === 'Identifier' ? `$get($, '${value}')` : value; -} - - -function isCallExpression(node) { - return !!node.type.match(/CallExpression$/); -} - - -function generate(ast, scope) { - let generator = GENERATORS[ast.type]; - - if (!generator) { - console.info(ast); - throw new Error(`No generator found for: ${ast.type}`); - } - - return generator.call(GENERATORS, ast, scope); -} - -export function parse(data) { - let ast = luaparse.parse(data); - let js = generate(ast, 0); - return ` - "use strict"; if (typeof global === \'undefined\' && typeof window !== \'undefined\') { window.global = window; } - let __star = global.starlight.runtime, $0 = __star.globalScope, $ = $0, __star_tmp; - let __star_call = __star.call, __star_T = __star.T, __star_op_bool = __star.op.bool; - let __star_op_unm = __star.op.unm, __star_op_not = __star.op.not, __star_op_len = __star.op.len, __star_op_concat = __star.op.concat, __star_op_add = __star.op.add, __star_op_sub = __star.op.sub, __star_op_mul = __star.op.mul, __star_op_div = __star.op.div, __star_op_mod = __star.op.mod, __star_op_eq = __star.op.eq, __star_op_neq = __star.op.neq, __star_op_lt = __star.op.lt, __star_op_gt = __star.op.gt, __star_op_lte = __star.op.lte, __star_op_gte = __star.op.gte, __star_op_pow = __star.op.pow; - let __star_op_and = __star.op.and, __star_op_or = __star.op.or; - let Tget, Tset, Tins, $get, $set, $setLocal, __star_shift; - (()=>{ - let call = Function.prototype.call, bind = call.bind.bind(call), Tproto = __star_T.prototype, $proto = __star.globalScope.constructor.prototype; - Tget = bind(Tproto.get), Tset = bind(Tproto.set), Tins = bind(Tproto.insert); - $get = bind($proto.get), $set = bind($proto.set), $setLocal = bind($proto.setLocal); - __star_shift = bind(Array.prototype.shift); - })(); - ${js} - ` -} diff --git a/src/runtime/LuaError.js b/src/runtime/LuaError.js deleted file mode 100644 index f455764..0000000 --- a/src/runtime/LuaError.js +++ /dev/null @@ -1,10 +0,0 @@ -export default class LuaError extends Error { - constructor(message) { - super(); - this.message = message; - } - - toString() { - return `LuaError: ${this.message}`; - } -} diff --git a/src/runtime/Scope.js b/src/runtime/Scope.js deleted file mode 100644 index 89c998c..0000000 --- a/src/runtime/Scope.js +++ /dev/null @@ -1,44 +0,0 @@ -const hasOwnProperty = Object.prototype.hasOwnProperty; - -export default class Scope { - constructor(variables = {}) { - this._variables = variables; - } - - get(key) { - return this._variables[key]; - } - - set(key, value) { - let vars = this._variables; - - if (hasOwnProperty.call(this._variables, key) || !this.parent) { - vars[key] = value; - } else { - this.parent.set(key, value); - } - } - - setLocal(key, value) { - this._variables[key] = value; - } - - setVarargs(value) { - this._varargs = value; - } - - getVarargs() { - return this._varargs || this.parent && this.parent.getVarargs(); - } - - add(key, value) { - this._variables[key] += value; - } - - extend(outerScope) { - let innerVars = Object.create(this._variables); - let scope = new Scope(innerVars); - scope.parent = this; - return scope; - } -} \ No newline at end of file diff --git a/src/runtime/Table.js b/src/runtime/Table.js deleted file mode 100644 index 3d5e8f8..0000000 --- a/src/runtime/Table.js +++ /dev/null @@ -1,214 +0,0 @@ -import { default as LuaError } from './LuaError'; -import { type } from './lib/globals'; - -let count = 0; -let stringLib, getn; - -export function registerLibs(libs) { - // Can't import directly because they'll create a circular dependencies. :( - stringLib = libs.string; - getn = libs.getn; -}; - - -export default class Table { - - constructor(initialiser) { - this.index = ++count; - this.numValues = [undefined]; - this.strValues = {}; - this.keys = []; - this.values = []; - this.metatable = null; - - if (!initialiser) { - // noop - } else if (typeof initialiser === 'function') { - initialiser(this); - } else { - let isArr = initialiser instanceof Array; - - for (let i in initialiser) { - if (initialiser.hasOwnProperty(i)) { - let value = initialiser[i]; - if (value === null) value = undefined; - let key = isArr? parseInt(i, 10) + 1: i; - - let iterate = (typeof value == 'object' && value.constructor === Object) || value instanceof Array; - this.set(key, iterate? new Table(value) : value); - } - } - } - } - - - get(key) { - if (!(this instanceof Table)) { - if (type(this) == 'string') { - return stringLib.get(key); - - } else if ( - type(this) === 'userdata' - || (type(this) === 'function' && key === 'new') // exception for DOMAPI compat with Moonshine - ) { - if (key in this) { - return this[key]; - } - } - throw new LuaError(`attempt to index a ${type(this)} value`); - } - - let value = this.rawget(key); - - if (value === void 0) { - let mt, mm; - if ( - (mt = this.metatable) - && (mm = mt.get('__index')) - ) { - switch (mm.constructor) { - case Table: return mm.get(key); - case Function: - value = mm.call(undefined, this, key); - return (value instanceof Array)? value[0] : value; - } - } - } - - return value; - } - - - rawget(key) { - switch (typeof key) { - case 'string': return Object.prototype.hasOwnProperty.call(this.strValues, key) ? this.strValues[key] : void 0; - case 'number': - if (key > 0 && key == key >> 0) { - return this.numValues[key]; - } - /* fallthrough */ - default: - let index = this.keys.indexOf(key); - return (index >= 0) ? this.values[index] : void 0; - } - } - - - set(key, value) { - if (!(this instanceof Table)) { - if (type(this) == 'userdata') { - this[key] = value; - return; - } - throw new LuaError(`attempt to index a ${type(this)} value`); - } - - let mt, mm; - if ( - (mt = this.metatable) - && (mm = mt.get('__newindex')) - ) { - let oldValue; - - switch (typeof key) { - case 'string': - oldValue = this.strValues[key]; - break; - - case 'number': - let positiveIntegerKey = key > 0 && key == key >> 0; - if (positiveIntegerKey) { - oldValue = this.numValues[key]; - break; - } - - default: - let keys = this.keys; - let index = keys.indexOf(key); - oldValue = index == -1? undefined : this.values[index]; - } - - if (oldValue === undefined) { - switch (mm.constructor) { - case Table: return mm.set(key, value); - case Function: return mm(this, key, value); - } - } - } - this.rawset(key, value); - } - - - rawset(key, value) { - if (value instanceof Array) { - value = value[0]; - } - - switch (typeof key) { - case 'string': - this.strValues[key] = value; - break; - - case 'number': - let positiveIntegerKey = key > 0 && key == key >> 0; - if (positiveIntegerKey) { - this.numValues[key] = value; - break; - } - - default: - let keys = this.keys; - let index = keys.indexOf(key); - if (index < 0) { - index = keys.length; - keys[index] = key; - } - - this.values[index] = value; - } - } - - - insert(...values) { - this.numValues.push(...values); - } - - - toString() { - let mt, mm; - if ( - (mt = this.metatable) - && (mm = mt.get('__tostring')) - ) { - return mm(this)[0]; - } else { - return 'table: 0x' + this.index.toString(16); - } - } - - - toObject() { - const isArr = getn(this) > 0; - const result = isArr? [] : {}; - const numValues = this.numValues; - const strValues = this.strValues; - - let i; - const l = numValues.length; - - for (i = 1; i < l; i++) { - const propValue = numValues[i]; - result[i - 1] = (propValue instanceof Table)? propValue.toObject() : propValue; - } - - for (i in strValues) { - if (strValues.hasOwnProperty(i)) { - const propValue = strValues[i]; - result[i] = (propValue instanceof Table)? propValue.toObject() : propValue; - } - } - - return result; - } - -}; diff --git a/src/runtime/index.js b/src/runtime/index.js deleted file mode 100644 index 56d4049..0000000 --- a/src/runtime/index.js +++ /dev/null @@ -1,78 +0,0 @@ -import { default as Scope } from './Scope'; -import { default as globals, type } from './lib/globals'; -import { default as operators } from './operators'; -import { default as Table, registerLibs } from './Table'; -import { default as LuaError } from './LuaError'; - - -function ensureArray(value) { - return (value instanceof Array) ? value : [value]; -} - -function call(f, ...args) { - if (!(f instanceof Function)) { - if (f instanceof Table) { - let mt, mm; - if ( - (mt = f.metatable) - && (mm = mt.rawget('__call')) - ) { - args.unshift(f); - f = mm; - } - } - if (!(f instanceof Function)) { - let typ = type(f); - throw new LuaError(`attempt to call a ${typ} value`); - } - } - - return ensureArray(f(...args)); -} - -let namespace = global.starlight = global.starlight || {}; -let _G = globals; - -function init () { - let userEnv = namespace.config && namespace.config.env; - if (userEnv) { - for (let key in userEnv) { - globals.set(key, userEnv[key]); - } - } -} - - -init(); - -let runtime = namespace.runtime = { - globalScope: new Scope(globals.strValues), - _G, - op: operators, - T: Table, - LuaError, - call -}; - - - - -// The following should be configurable - -import { default as math } from './lib/math'; -_G.set('math', math); - -import { default as table, getn } from './lib/table'; -_G.set('table', table); - -import { default as string } from './lib/string'; -_G.set('string', string); - -import { default as os } from './lib/os'; -_G.set('os', os); - -import { default as _package } from './lib/package'; -_G.set('package', _package); - -registerLibs({ string, getn }); - diff --git a/src/runtime/lib/globals.js b/src/runtime/lib/globals.js deleted file mode 100644 index 300dafc..0000000 --- a/src/runtime/lib/globals.js +++ /dev/null @@ -1,454 +0,0 @@ -import { default as T } from '../Table'; -import { default as LuaError } from '../LuaError'; -import { default as stringLib, metatable as stringMetatable } from './string'; -import { getn } from './table'; - -import { - stdout, - coerceToNumber, - coerceToString, - coerceToBoolean, - coerceArgToNumber, - coerceArgToString, - coerceArgToTable -} from '../utils'; - - -const CHARS = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'; - - - -function getPackageMethods() { - let packageLib = global.starlight.runtime._G.rawget('package'); - if (packageLib === void 0) { - throw new LuaError('error during require(), package lib not found.'); - } - let methods = [packageLib.rawget('preload'), packageLib.rawget('loaded')]; - getPackageMethods = ()=>methods; - return methods; -} - - -function ipairsIterator(table, index) { - if (index === void 0) { - throw new LuaError('Bad argument #2 to ipairs() iterator'); - } - - var nextIndex = index + 1, - numValues = table.numValues; - - if (!numValues.hasOwnProperty(nextIndex) || numValues[nextIndex] === void 0) return void 0; - return [nextIndex, numValues[nextIndex]]; -} - - - -export const _VERSION = 'Lua 5.1'; - - -export function assert(v, m) { - if (!coerceToBoolean(v)) { - m = coerceArgToString(m, 'assert', 2); - throw new LuaError(m || 'Assertion failed!'); - } - return [v, m]; -} - - -// TODO dofile([filename]) - - -export function error(message) { - if ( - typeof message !== 'string' - && typeof message !== 'number' - ) { - message = '(error object is not a string)'; - } - throw new LuaError(message); -} - - -// TODO getfenv([f]) - - -export function getmetatable(table) { - if (table && table instanceof T) { - let mt = table.metatable; - if (mt) { - let mm; - return (mm = mt.rawget('__metatable')) ? mm : mt; - } - } else if (typeof table == 'string') { - return stringMetatable; - } -} - - -export function ipairs(t) { - t = coerceArgToTable(t, 'ipairs', 1); - const mt = getmetatable(t); - const mm = mt && mt.get('__ipairs'); - return mm ? mm(t).slice(0, 3) : [ipairsIterator, t, 0]; -} - - -// TODO load(func [, chunkname]) -// TODO loadfile([filename]) - - -export function loadstring(str, chunkname) { - str = coerceArgToString(str, 'loadstring', 1); - let parser = global.starlight.parser; - - if (!parser) { - throw new Error('Starlight parser not found in call to loadstring(). The parser is required to execute Lua strings at runtime.'); - } - - try { - return parser.parse(str); - } catch (e) { - return [undefined, e.message]; - } -} - - -export function next(table, index) { - table = coerceArgToTable(table, 'next', 1); - - // SLOOOOOOOW... - let found = (index === void 0), - key, value, - i, l; - - if (found || (typeof index == 'number' && index > 0 && index == index >> 0)) { - let numValues = table.numValues; - - if ('keys' in Object) { - // Use Object.keys, if available. - let keys = Object['keys'](numValues); - - if (found) { - // First pass - i = 1; - - } else if (i = keys.indexOf('' + index) + 1) { - found = true; - } - - if (found) { - while ((key = keys[i]) !== void 0 && (value = numValues[key]) === void 0) i++; - if (value !== void 0) return [key >>= 0, value]; - } - - } else { - // Else use for-in (faster than for loop on tables with large holes) - - for (l in numValues) { - i = l >> 0; - - if (!found) { - if (i === index) found = true; - - } else if (numValues[i] !== void 0) { - return [i, numValues[i]]; - } - } - } - } - - for (i in table.strValues) { - if (table.strValues.hasOwnProperty(i)) { - if (!found) { - if (i == index) found = true; - - } else if (table.strValues[i] !== void 0) { - return [i, table.strValues[i]]; - } - } - } - - for (i in table.keys) { - if (table.keys.hasOwnProperty(i)) { - let key = table.keys[i]; - - if (!found) { - if (key === index) found = true; - - } else if (table.values[i] !== void 0) { - return [key, table.values[i]]; - } - } - } - - return []; -} - - -export function pairs(table) { - table = coerceArgToTable(table, 'pairs', 1); - const mt = getmetatable(table); - const mm = mt && mt.get('__pairs'); - return mm ? mm(table).slice(0, 3) : [next, table]; -} - - -export function pcall(func, ...args) { - let result; - - try { - if (typeof func == 'function') { - result = func(...args); - } else { - throw new LuaError('Attempt to call non-function'); - } - - } catch (e) { - return [false, e && e.toString()]; - } - - result = [].concat(result); - return [true, ...result]; -} - - -export function print(...args) { - let output = args.map(arg => tostring(arg)).join('\t'); - stdout.writeln(output); -} - - -export function rawequal(v1, v2) { - return v1 === v2; -} - - -export function rawget(table, index) { - table = coerceArgToTable(table, 'rawget', 1); - return table.rawget(index); -} - - -export function rawset(table, index, value) { - table = coerceArgToTable(table, 'rawset', 1); - if (index === void 0) throw new LuaError('table index is nil'); - - table.rawset(index, value); - return table; -} - - -export function _require(modname) { - modname = coerceArgToString(modname, 'require', 1); - modname = modname.replace(/\//g, '.'); - - let [preload, loaded] = getPackageMethods(); - let mod = loaded.rawget(modname); - - if (mod) { - return mod; - } - - let modinit = preload.rawget(modname); - - if (modinit === void 0) { - throw new LuaError(`module '${modname}' not found:\n\tno field package.preload['${modname}']`); - } - - let modResult = modinit(modname); - mod = (modResult instanceof Array) ? modResult[0] : modResult; - - loaded.rawset(modname, mod !== void 0 ? mod : true); - return mod; -} - - -export function select(index, ...args) { - if (index === '#') { - return args.length; - - } else if (index = parseInt(index, 10)) { - return args.slice(index - 1); - - } else { - let typ = type(index); - throw new LuaError(`bad argument #1 to 'select' (number expected, got ${typ})`); - } -} - - -// TODO setfenv(f, table) - - -export function setmetatable(table, metatable) { - table = coerceArgToTable(table, 'setmetatable', 1); - if (metatable !== void 0) { - metatable = coerceArgToTable(metatable, 'setmetatable', 2); - } - - let mt; - if ( - (mt = table.metatable) - && mt.rawget('__metatable') - ) { - throw new LuaError('cannot change a protected metatable'); - } - - table.metatable = metatable; - return table; -} - - -export function tonumber(e, base = 10) { - base = coerceArgToNumber(base, 'tonumber', 2); - - if (e === '') return; - - if (base < 2 || base > 36) { - throw new LuaError(`bad argument #2 to 'tonumber' (base out of range)`); - } - - if (base == 10 && (e === Infinity || e === -Infinity || (typeof e == 'number' && global.isNaN(e)))) { - return e; - } - - if (base != 10 && e === void 0) { - throw new LuaError("bad argument #1 to 'tonumber' (string expected, got nil)"); - } - - e = `${e}`.trim(); - - // If using base 10, use normal coercion. - if (base === 10) { - return coerceToNumber(e); - } - - e = coerceToString(e); - - // If using base 16, ingore any "0x" prefix - let match; - if ( - base === 16 - && (match = e.match(/^(\-)?0[xX](.+)$/)) - ) { - e = `${match[1] || ''}${match[2]}`; - } - - let pattern = new RegExp('^[' + CHARS.substr(0, base) + ']*$', 'gi'); - - if (!pattern.test(e)) return; // Invalid - return parseInt(e, base); -} - - -export function tostring(e) { - let mt, mm; - - if ( - e !== void 0 - && e instanceof T - && (mt = e.metatable) - && (mm = mt.rawget('__tostring')) - ) { - return mm.call(mm, e); - } - - if (e instanceof T) { - return e.toString(); - } else if (e instanceof Function) { - return e.hasOwnProperty('toString')? `${e}` : 'function: [host code]'; - } - - return coerceToString(e); -} - - -export function type(v) { - let t = typeof v; - - switch (t) { - case 'undefined': - return 'nil'; - - case 'number': - case 'string': - case 'boolean': - case 'function': - return t; - - case 'object': - if (v.constructor === T) return 'table'; - if (v && v instanceof Function) return 'function'; - - return 'userdata'; - } -} - - -export function unpack(table, i = 1, j) { - table = coerceArgToTable(table, 'unpack', 1); - i = coerceArgToNumber(i, 'unpack', 2); - - if (j === void 0) { - j = getn(table); - } else { - j = coerceArgToNumber(j, 'unpack', 3); - } - - return table.numValues.slice(i, j + 1); -} - - -export function xpcall(func, err) { - let result, success, invalid; - - try { - if (typeof func === 'function') { - result = func(); - } else { - invalid = true; - } - success = true; - - } catch (e) { - result = err(void 0, true)[0]; - success = false; - } - - if (invalid) throw new LuaError('Attempt to call non-function'); - - if (!(result && result instanceof Array)) result = [result]; - result.unshift(success); - - return result; -} - - - -export const _G = new T({ - _VERSION, - assert, - error, - getmetatable, - ipairs, - loadstring, - next, - pairs, - pcall, - print, - rawequal, - rawget, - rawset, - require: _require, - select, - setmetatable, - tonumber, - tostring, - type, - unpack, - xpcall, -}); - - -_G.rawset('_G', _G); -export default _G; \ No newline at end of file diff --git a/src/runtime/lib/math.js b/src/runtime/lib/math.js deleted file mode 100644 index 682da06..0000000 --- a/src/runtime/lib/math.js +++ /dev/null @@ -1,253 +0,0 @@ -import { default as T } from '../Table'; -import { coerceArgToNumber } from '../utils'; - - -const RANDOM_MULTIPLIER = 16807; -const RANDOM_MODULUS = 2147483647; - -let randomSeed = 1; - - -function getRandom () { - randomSeed = (RANDOM_MULTIPLIER * randomSeed) % RANDOM_MODULUS; - return randomSeed / RANDOM_MODULUS; -} - - - -export function abs(x) { - x = coerceArgToNumber(x, 'abs', 1); - return Math.abs(x); -} - - -export function acos(x) { - x = coerceArgToNumber(x, 'acos', 1); - return Math.acos(x); -} - - -export function asin(x) { - x = coerceArgToNumber(x, 'asin', 1); - return Math.asin(x); -} - - -export function atan(x) { - x = coerceArgToNumber(x, 'atan', 1); - return Math.atan(x); -} - - -export function atan2(y, x) { - y = coerceArgToNumber(y, 'atan2', 1); - x = coerceArgToNumber(x, 'atan2', 2); - return Math.atan2(y, x); -} - - -export function ceil(x) { - x = coerceArgToNumber(x, 'ceil', 1); - return Math.ceil(x); -} - - -export function cos(x) { - x = coerceArgToNumber(x, 'cos', 1); - return Math.cos(x); -} - - -export function cosh(x) { - x = coerceArgToNumber(x, 'cosh', 1); - return (exp(x) + exp(-x)) / 2; -} - - -export function deg(x) { - x = coerceArgToNumber(x, 'deg', 1); - return x * 180 / Math.PI; -} - - -export function exp(x) { - x = coerceArgToNumber(x, 'exp', 1); - return Math.exp(x); -} - - -export function floor(x) { - x = coerceArgToNumber(x, 'floor', 1); - return Math.floor(x); -} - - -export function fmod(x, y) { - x = coerceArgToNumber(x, 'fmod', 1); - y = coerceArgToNumber(y, 'fmod', 2); - return x % y; -} - - -export function frexp(x) { - x = coerceArgToNumber(x, 'frexp', 1); - - if (x === 0) { - return [0, 0]; - } - - let delta = x > 0? 1 : -1; - x *= delta; - - let exponent = Math.floor(Math.log(x) / Math.log(2)) + 1; - let mantissa = x / Math.pow(2, exponent); - - return [mantissa * delta, exponent]; -} - - -export const huge = Infinity; - - -export function ldexp(m, e) { - m = coerceArgToNumber(m, 'ldexp', 1); - e = coerceArgToNumber(e, 'ldexp', 2); - return m * Math.pow(2, e); -} - - -export function log(x, base) { - x = coerceArgToNumber(x, 'log', 1); - if (base === void 0) { - return Math.log(x); - } else { - y = coerceArgToNumber(y, 'log', 2); - return Math.log(x) / Math.log(base); - } -} - - -export function log10(x) { - x = coerceArgToNumber(x, 'log10', 1); - // v5.2: shine.warn ('math.log10 is deprecated. Use math.log with 10 as its second argument instead.'); - return Math.log(x) / Math.log(10); -} - - -export function max(...args) { - return Math.max(...args); -} - - -export function min(...args) { - return Math.min(...args); -} - - -export function modf(x) { - x = coerceArgToNumber(x, 'modf', 1); - let intValue = Math.floor(x); - let mantissa = x - intValue; - return [intValue, mantissa]; -} - - -export const pi = Math.PI; - - -export function pow(x, y) { - x = coerceArgToNumber(x, 'pow', 1); - y = coerceArgToNumber(y, 'pow', 2); - return Math.pow(x, y); -} - - -export function rad(x) { - x = coerceArgToNumber(x, 'rad', 1); - return (Math.PI / 180) * x; -} - - -export function random(min, max) { - if (min === void 0 && max === void 0) return getRandom(); - min = coerceArgToNumber(min, 'random', 1); - - if (max === void 0) { - max = min; - min = 1; - } else { - max = coerceArgToNumber(max, 'random', 2); - } - if (min > max) throw new shine.Error("bad argument #2 to 'random' (interval is empty)"); - return Math.floor(getRandom() * (max - min + 1) + min); -} - - -export function randomseed(x) { - x = coerceArgToNumber(x, 'randomseed', 1); - randomSeed = x; -} - - -export function sin(x) { - x = coerceArgToNumber(x, 'sin', 1); - return Math.sin(x); -} - - -export function sinh(x) { - x = coerceArgToNumber(x, 'sinh', 1); - return (exp(x) - exp(-x)) / 2; -} - - -export function sqrt(x) { - x = coerceArgToNumber(x, 'sqrt', 1); - return Math.sqrt(x); -} - - -export function tan(x) { - x = coerceArgToNumber(x, 'tan', 1); - return Math.tan(x); -} - - -export function tanh(x) { - x = coerceArgToNumber(x, 'tanh', 1); - return (exp(x) - exp(-x))/(exp(x) + exp(-x)); -} - - -export default new T({ - abs, - acos, - asin, - atan, - atan2, - ceil, - cos, - cosh, - deg, - exp, - floor, - fmod, - frexp, - huge, - ldexp, - log, - log10, - max, - min, - modf, - pi, - pow, - rad, - random, - randomseed, - sin, - sinh, - sqrt, - tan, - tanh -}); diff --git a/src/runtime/lib/os.js b/src/runtime/lib/os.js deleted file mode 100644 index 1d89a6e..0000000 --- a/src/runtime/lib/os.js +++ /dev/null @@ -1,115 +0,0 @@ -import { default as T } from '../Table'; - - -const DAYS = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']; -const MONTHS = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']; -const DAYS_IN_MONTH = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]; - -const DATE_FORMAT_HANDLERS = { - '%a': (d, utc) => DAYS[d['get' + (utc? 'UTC' : '') + 'Day']()].substr(0, 3), - '%A': (d, utc) => DAYS[d['get' + (utc? 'UTC' : '') + 'Day']()], - '%b': (d, utc) => MONTHS[d['get' + (utc? 'UTC' : '') + 'Month']()].substr(0, 3), - '%B': (d, utc) => MONTHS[d['get' + (utc? 'UTC' : '') + 'Month']()], - '%c': (d, utc) => d['to' + (utc? 'UTC' : '') + 'LocaleString'](), - '%d': (d, utc) => ('0' + d['get' + (utc? 'UTC' : '') + 'Date']()).substr(-2), - '%H': (d, utc) => ('0' + d['get' + (utc? 'UTC' : '') + 'Hours']()).substr(-2), - '%I': (d, utc) => ('0' + ((d['get' + (utc? 'UTC' : '') + 'Hours']() + 11) % 12 + 1)).substr(-2), - '%j': (d, utc) => { - let result = d['get' + (utc? 'UTC' : '') + 'Date'](); - let m = d['get' + (utc? 'UTC' : '') + 'Month'](); - - for (let i = 0; i < m; i++) { - result += DAYS_IN_MONTH[i]; - } - - if (m > 1 && d['get' + (utc? 'UTC' : '') + 'FullYear']() % 4 === 0) { - result +=1; - } - - return ('00' + result).substr(-3); - }, - '%m': (d, utc) => ('0' + (d['get' + (utc? 'UTC' : '') + 'Month']() + 1)).substr(-2), - '%M': (d, utc) => ('0' + d['get' + (utc? 'UTC' : '') + 'Minutes']()).substr(-2), - '%p': (d, utc) => (d['get' + (utc? 'UTC' : '') + 'Hours']() < 12)? 'AM' : 'PM', - '%S': (d, utc) => ('0' + d['get' + (utc? 'UTC' : '') + 'Seconds']()).substr(-2), - '%U': (d, utc) => getWeekOfYear(d, 0, utc), - '%w': (d, utc) => '' + (d['get' + (utc? 'UTC' : '') + 'Day']()), - '%W': (d, utc) => getWeekOfYear(d, 1, utc), - '%x': (d, utc) => DATE_FORMAT_HANDLERS['%m'](d, utc) + '/' + DATE_FORMAT_HANDLERS['%d'](d, utc) + '/' + DATE_FORMAT_HANDLERS['%y'](d, utc), - '%X': (d, utc) => DATE_FORMAT_HANDLERS['%H'](d, utc) + ':' + DATE_FORMAT_HANDLERS['%M'](d, utc) + ':' + DATE_FORMAT_HANDLERS['%S'](d, utc), - '%y': (d, utc) => DATE_FORMAT_HANDLERS['%Y'](d, utc).substr (-2), - '%Y': (d, utc) => '' + d['get' + (utc? 'UTC' : '') + 'FullYear'](), - '%Z': (d, utc) => { let m; return (utc && 'UTC') || ((m = d.toString().match(/[A-Z][A-Z][A-Z]/)) && m[0]); }, - '%%': () => '%' -} - - -function isDST(date) { - let year = date.getFullYear(); - let jan = new Date(year, 0); - - // ASSUMPTION: If the time offset of the date is the same as it would be in January of the same year, DST is not in effect. - return (date.getTimezoneOffset() !== jan.getTimezoneOffset()); -} - - -function getWeekOfYear (d, firstDay, utc) { - let dayOfYear = parseInt(DATE_FORMAT_HANDLERS['%j'](d), 10); - let jan1 = new Date(d.getFullYear (), 0, 1, 12); - let offset = (8 - jan1['get' + (utc? 'UTC' : '') + 'Day']() + firstDay) % 7; - - return ('0' + (Math.floor((dayOfYear - offset) / 7) + 1)).substr(-2); -} - - -export function date(format = '%c', time) { - let utc, - date = new Date(); - - if (time) { - date.setTime(time * 1000); - } - - if (format.substr(0, 1) === '!') { - format = format.substr(1); - utc = true; - } - - if (format === '*t') { - return new T ({ - year: parseInt(DATE_FORMAT_HANDLERS['%Y'](date, utc), 10), - month: parseInt(DATE_FORMAT_HANDLERS['%m'](date, utc), 10), - day: parseInt(DATE_FORMAT_HANDLERS['%d'](date, utc), 10), - hour: parseInt(DATE_FORMAT_HANDLERS['%H'](date, utc), 10), - min: parseInt(DATE_FORMAT_HANDLERS['%M'](date, utc), 10), - sec: parseInt(DATE_FORMAT_HANDLERS['%S'](date, utc), 10), - wday: parseInt(DATE_FORMAT_HANDLERS['%w'](date, utc), 10) + 1, - yday: parseInt(DATE_FORMAT_HANDLERS['%j'](date, utc), 10), - isdst: isDST(date) - }); - } - - for (let i in DATE_FORMAT_HANDLERS) { - if (DATE_FORMAT_HANDLERS.hasOwnProperty(i) && format.indexOf(i) >= 0) { - format = format.replace(i, DATE_FORMAT_HANDLERS[i](date, utc)); - } - } - - return format; -} - - -export function exit(code = 0) { - var process = global.process; - if (process && process.exit) { - process.exit(code); - } else { - throw new Error(`Exit with code: ${code}`); - } -} - - -export default new T({ - date, - exit -}); diff --git a/src/runtime/lib/package.js b/src/runtime/lib/package.js deleted file mode 100644 index d205743..0000000 --- a/src/runtime/lib/package.js +++ /dev/null @@ -1,7 +0,0 @@ -import { default as T } from '../Table'; - - -export default new T({ - preload: new T(), - loaded: new T() -}); diff --git a/src/runtime/lib/string.js b/src/runtime/lib/string.js deleted file mode 100644 index dad5b7b..0000000 --- a/src/runtime/lib/string.js +++ /dev/null @@ -1,319 +0,0 @@ -import { default as T } from '../Table'; -import { default as LuaError } from '../LuaError'; -import { tostring } from './string'; -import printf from 'printf'; - -import { - coerceToNumber, - coerceToString, - coerceToBoolean, - coerceArgToNumber, - coerceArgToString, - coerceArgToFunction -} from '../utils'; - - -const ROSETTA_STONE = { - '([^a-zA-Z0-9%(])-': '$1*?', - '([^%])-([^a-zA-Z0-9?])': '$1*?$2', - '(.)-$': '$1*?', - '%a': '[a-zA-Z]', - '%A': '[^a-zA-Z]', - '%c': '[\x00-\x1f]', - '%C': '[^\x00-\x1f]', - '%d': '\\d', - '%D': '[^\d]', - '%l': '[a-z]', - '%L': '[^a-z]', - '%p': '[\.\,\"\'\?\!\;\:\#\$\%\&\(\)\*\+\-\/\<\>\=\@\\[\\]\\\\^\_\{\}\|\~]', - '%P': '[^\.\,\"\'\?\!\;\:\#\$\%\&\(\)\*\+\-\/\<\>\=\@\\[\\]\\\\^\_\{\}\|\~]', - '%s': '[ \\t\\n\\f\\v\\r]', - '%S': '[^ \t\n\f\v\r]', - '%u': '[A-Z]', - '%U': '[^A-Z]', - '%w': '[a-zA-Z0-9]', - '%W': '[^a-zA-Z0-9]', - '%x': '[a-fA-F0-9]', - '%X': '[^a-fA-F0-9]', - '%([^a-zA-Z])': '\\$1' -}; - - -function translatePattern (pattern) { - // TODO Add support for balanced character matching (not sure this is easily achieveable). - pattern = '' + pattern; - - // Replace single backslash with double backslashes - pattern = pattern.replace(new RegExp('\\\\', 'g'), '\\\\'); - - for (let i in ROSETTA_STONE) { - if (ROSETTA_STONE.hasOwnProperty(i)) { - pattern = pattern.replace(new RegExp(i, 'g'), ROSETTA_STONE[i]); - } - } - - let l = pattern.length; - let n = 0; - - for (let i = 0; i < l; i++) { - const character = pattern.substr(i, 1); - if (i && pattern.substr(i - 1, 1) == '\\') { - continue; - } - - let addSlash = false; - - if (character == '[') { - if (n) addSlash = true; - n++; - - } else if (character == ']' && pattern.substr(i - 1, 1) !== '\\') { - n--; - if (n) addSlash = true; - } - - if (addSlash) { - pattern = pattern.substr(0, i) + pattern.substr(i++ + 1); - l++; - } - } - - return pattern; -} - - - -export function byte(s, i = 1, j) { - s = coerceArgToString(s, 'byte', 1); - i = coerceArgToNumber(i, 'byte', 2); - if (j === void 0) { - j = i; - } else { - j = coerceArgToNumber(j, 'byte', 3); - } - - return s.substring(i - 1, j).split('').map(c => c.charCodeAt(0)); -} - - -export function char(...bytes) { - return bytes.map((b, i) => { - b = coerceArgToNumber(b, 'char', i); - return String.fromCharCode(b); - }).join(''); -} - - -export function dump(func) { - func = coerceArgToFunction(func, 'dump', 1); - throw new LuaError('string.dump() is not supported'); -} - - -export function find(s, pattern, init = 1, plain = false) { - s = coerceArgToString(s, 'find', 1); - pattern = coerceArgToString(pattern, 'find', 2); - init = coerceArgToNumber(init, 'find', 3); - plain = coerceToBoolean(plain); - - // Regex - if (!plain) { - pattern = translatePattern(pattern); - let reg = new RegExp(pattern); - let index = s.substr(init - 1).search(reg); - - if (index < 0) return; - - let match = s.substr(init - 1).match(reg); - let result = [index + init, index + init + match[0].length - 1]; - - match.shift(); - return result.concat(match); - } - - // Plain - let index = s.indexOf(pattern, init - 1); - return (index === -1)? void 0 : [index + 1, index + pattern.length]; -} - - -// TODO string.format (formatstring, ···) -export function format(formatstring, ...args) { - return printf(formatstring, ...args); -} - - -export function gmatch(s, pattern) { - s = coerceArgToString(s, 'gmatch', 1); - pattern = coerceArgToString(pattern, 'gmatch', 2); - pattern = translatePattern(pattern); - - let reg = new RegExp(pattern, 'g'), - matches = s.match(reg); - - return () => { - let match = matches.shift(), - groups = new RegExp(pattern).exec(match); - - if (match === void 0) { - return; - } - - groups.shift(); - return groups.length? groups : match; - }; -} - - -export function gsub(s, pattern, repl, n = Infinity) { - s = coerceArgToString(s, 'gsub', 1); - pattern = coerceArgToString(pattern, 'gsub', 2); - n = coerceArgToNumber(n, 'gsub', 3); - - pattern = translatePattern('' + pattern); - let replIsFunction = (typeof repl == 'function'); - - let count = 0, - result = '', - str, - prefix, - match, - lastMatch; - - while ( - count < n - && s - && (match = s.match(pattern)) - ) { - if (replIsFunction) { - str = repl(match[0]); - if (str instanceof Array) str = str[0]; - if (str === void 0) str = match[0]; - - } else if (repl instanceof T) { - str = repl.get(match[0]); - - } else if (typeof repl == 'object') { - str = repl[match]; - - } else { - str = `${repl}`.replace(/%([0-9])/g, (m, i) => match[i]); - - } - - if (match[0].length === 0) { - if (lastMatch === void 0) { - prefix = ''; - } else { - prefix = s.substr(0, 1); - } - - } else { - prefix = s.substr(0, match.index); - } - - lastMatch = match[0]; - result += `${prefix}${str}`; - s = s.substr(`${prefix}${lastMatch}`.length); - - count++; - } - - return [`${result}${s}`, count]; -} - - -export function len(s) { - s = coerceArgToString(s, 'len', 1); - return s.length; -} - - -export function lower (s) { - s = coerceArgToString(s, 'lower', 1); - return s.toLowerCase(); -} - - -export function match(s, pattern, init = 0) { - s = coerceArgToString(s, 'match', 1); - pattern = coerceArgToString(pattern, 'match', 2); - init = coerceArgToNumber(init, 'match', 3); - - s = s.substr(init); - let matches = s.match(new RegExp(translatePattern (pattern))); - - if (!matches) { - return; - } else if (!matches[1]) { - return matches[0]; - } - - matches.shift(); - return matches; -} - - -export function rep(s, n) { - s = coerceArgToString(s, 'rep', 1); - n = coerceArgToNumber(n, 'rep', 2); - return Array(n + 1).join(s); -} - - -export function reverse(s) { - s = coerceArgToString(s, 'reverse', 1); - return Array.prototype.map.call(s, l => l).reverse().join(''); -} - - -export function sub(s, i = 1, j) { - s = coerceArgToString(s, 'sub', 1); - i = coerceArgToNumber(i, 'sub', 2); - - if (j === void 0) { - s.length; - } else { - j = coerceArgToNumber(j, 'sub', 3); - } - - if (i > 0) { - i = i - 1; - } else if (i < 0) { - i = s.length + i; - } - - if (j < 0) { - j = s.length + j + 1; - } - - return s.substring(i, j); -} - - -export function upper(s) { - s = coerceArgToString(s, 'upper', 1); - return s.toUpperCase(); -} - - - -const string = new T({ - byte, - char, - dump, - find, - format, - gmatch, - gsub, - len, - lower, - match, - rep, - reverse, - sub, - upper -}); - -export default string; -export const metatable = new T({ __index: string }); diff --git a/src/runtime/lib/table.js b/src/runtime/lib/table.js deleted file mode 100644 index 6f7583e..0000000 --- a/src/runtime/lib/table.js +++ /dev/null @@ -1,136 +0,0 @@ -import { default as T } from '../Table'; -import { default as LuaError } from '../LuaError'; -import { - coerceToNumber, - coerceToBoolean, - coerceArgToNumber, - coerceArgToString, - coerceArgToTable, - coerceArgToFunction -} from '../utils'; - - - -export function concat(table, sep = '', i = 1, j) { - table = coerceArgToTable(table, 'concat', 1); - sep = coerceArgToString(sep, 'concat', 2); - i = coerceArgToNumber(i, 'concat', 3); - - if (j === void 0) { - j = maxn(table); - } else { - j = coerceArgToNumber(j, 'concat', 4); - } - - return [].concat(table.numValues).splice(i, j - i + 1).join(sep); -} - - -export function getn(table) { - table = coerceArgToTable(table, 'getn', 1); - - let vals = table.numValues, - keys = [], - j = 0; - - for (let i in vals) { - if (vals.hasOwnProperty(i)) { - keys[i] = true; - } - } - - while (keys[j + 1]) j++; - - // Following translated from ltable.c (http://www.lua.org/source/5.1/ltable.c.html) - if (j > 0 && vals[j] === void 0) { - /* there is a boundary in the array part: (binary) search for it */ - let i = 0; - - while (j - i > 1) { - let m = Math.floor((i + j) / 2); - - if (vals[m] === void 0) { - j = m; - } else { - i = m; - } - } - - return i; - } - - return j; -} - - -export function insert(table, index, obj) { - table = coerceArgToTable(table, 'insert', 1); - - if (obj === void 0) { - obj = index; - index = table.numValues.length; - } else { - index = coerceArgToNumber(index, 'insert', 2); - } - - table.numValues.splice(index, 0, void 0); - table.set(index, obj); -} - - -export function maxn(table) { - table = coerceArgToTable(table, 'maxn', 1); - return table.numValues.length - 1; -} - - -export function remove(table, index) { - table = coerceArgToTable(table, 'remove', 1); - index = coerceArgToNumber(index, 'remove', 2); - - let max = getn(table); - let vals = table.numValues; - - if (index > max) { - return; - } - - if (index === void 0) { - index = max; - } - - let result = vals.splice(index, 1); - while (index < max && vals[index] === void 0) { - delete vals[index++]; - } - - return result; -} - - -export function sort(table, comp) { - table = coerceArgToTable(table, 'sort', 1); - - let sortFunc; - let arr = table.numValues; - - if (comp) { - comp = coerceArgToFunction(comp, 'sort', 2); - sortFunc = (a, b) => coerceToBoolean(comp(a, b)[0])? -1 : 1; - } else { - sortFunc = (a, b) => a < b? -1 : 1; - } - - arr.shift(); - arr.sort(sortFunc).unshift(void 0); -} - - -export default new T({ - concat, - getn, - insert, - maxn, - remove, - sort -}); diff --git a/src/runtime/operators.js b/src/runtime/operators.js deleted file mode 100644 index e1b9133..0000000 --- a/src/runtime/operators.js +++ /dev/null @@ -1,157 +0,0 @@ -import { default as T } from './Table'; -import { coerceToNumber, coerceToBoolean, coerceToString } from './utils'; -import { getn } from './lib/table'; -import { default as LuaError } from './LuaError'; - - -function binaryArithmetic(left, right, metaMethodName, callback) { - let mt, f; - - if ((left && left instanceof T && (mt = left.metatable) && (f = mt.rawget(metaMethodName))) - || (right && right instanceof T && (mt = right.metatable) && (f = mt.rawget(metaMethodName)))) { - return f(left, right)[0]; - } - - if (typeof left !== 'number') { - left = coerceToNumber(left, 'attempt to perform arithmetic on a %type value'); - } - - if (typeof right !== 'number') { - right = coerceToNumber(right, 'attempt to perform arithmetic on a %type value'); - } - - return callback(left, right); -} - - -function binaryStringArithmetic(left, right, metaMethodName, callback) { - if (typeof left == 'string' && typeof right == 'string') { - return callback(left, right); - } - return binaryArithmetic(left, right, metaMethodName, callback); -} - - -function concat(left, right) { - let mt, f; - - if ( - (left && left instanceof T && (mt = left.metatable) && (f = mt.rawget('__concat'))) - || (right && right instanceof T && (mt = right.metatable) && (f = mt.rawget('__concat'))) - ) { - return f(left, right)[0]; - } else { - right = coerceToString(right, 'attempt to concatenate a %type value'); - left = coerceToString(left, 'attempt to concatenate a %type value'); - return `${left}${right}`; - } -} - - -function equal(left, right) { - var mtl, mtr, f, result; - - if (right !== left - && left && left instanceof T - && right && right instanceof T - && (mtl = left.metatable) - && (mtr = right.metatable) - && mtl === mtr - && (f = mtl.rawget('__eq')) - ) { - return !!f(left, right)[0]; - } - - return (left === right); -} - - -function mod(left, right) { - if ( - right === 0 - || right === -Infinity - || right === Infinity - || global.isNaN(left) - || global.isNaN(right) - ) { - return NaN; - } - - let absRight = Math.abs(right); - let result = Math.abs(left) % absRight; - - if (left * right < 0) result = absRight - result; - if (right < 0) result *= -1; - - return result; -} - - -function len(value) { - let length, i; - - if (value === undefined) throw new LuaError('attempt to get length of a nil value'); - if (value instanceof T) return getn(value); - - if (typeof value == 'object') { - let length = 0; - for (let key in value) { - if (value.hasOwnProperty(key)) { - length++; - } - } - return length; - } - - return value.length; -} - - -function unaryMinus(value) { - var mt, f, result; - - if (value && value instanceof T && (mt = value.metatable) && (f = mt.rawget('__unm'))) { - return f(value)[0]; - } - - if (typeof value !== 'number') { - value = coerceToNumber(value, 'attempt to perform arithmetic on a %type value'); - } - - return -value; -} - - -const op = { - concat, - len, - - eq: equal, - unm: unaryMinus, - bool: coerceToBoolean, - - neq: (...args) => !equal(...args), - not: (...args) => !coerceToBoolean(...args), - - add: (left, right) => binaryArithmetic(left, right, '__add', (l, r) => l + r), - sub: (left, right) => binaryArithmetic(left, right, '__sub', (l, r) => l - r), - mul: (left, right) => binaryArithmetic(left, right, '__mul', (l, r) => l * r), - div: (left, right) => { - if (right === undefined) throw new LuaError('attempt to perform arithmetic on a nil value'); - return binaryArithmetic(left, right, '__div', (l, r) => l / r); - }, - mod: (left, right) => binaryArithmetic(left, right, '__mod', mod), - pow: (left, right) => binaryArithmetic(left, right, '__pow', Math.pow), - lt: (left, right) => binaryStringArithmetic(left, right, '__lt', (l, r) => l < r), - lte: (left, right) => binaryStringArithmetic(left, right, '__le', (l, r) => l <= r), - - gt(left, right) { - return !op.lte(left, right); - }, - - gte(left, right) { - return !op.lt(left, right); - } -}; - -export default op; \ No newline at end of file diff --git a/src/runtime/utils.js b/src/runtime/utils.js deleted file mode 100644 index 52ec0e4..0000000 --- a/src/runtime/utils.js +++ /dev/null @@ -1,173 +0,0 @@ -import { type } from './lib/globals'; -import { default as LuaError } from './LuaError'; -import { default as T } from './Table'; - - -/** - * Pattern to identify a float string value that can validly be converted to a number in Lua. - * @type RegExp - * @constant - */ -const FLOATING_POINT_PATTERN = /^[-+]?[0-9]*\.?([0-9]+([eE][-+]?[0-9]+)?)?$/; - - -/** - * Pattern to identify a hex string value that can validly be converted to a number in Lua. - * @type RegExp - * @constant - */ -const HEXIDECIMAL_CONSTANT_PATTERN = /^(\-)?0x([0-9a-fA-F]*)\.?([0-9a-fA-F]*)$/; - - -function defaultWriteln (...args) { - console.log(...args); -} - - -/******************** - * Stdout - ********************/ - -export const stdout = { - writeln: (() => { - let namespace, config, stdout; - return (namespace = global.starlight) - && (config = namespace.config) - && (stdout = config.stdout) - && stdout.writeln - || defaultWriteln; - })() -}; - - - -/******************** - * Coercion - ********************/ - -/** - * Thows an error with the type of a variable included in the message - * @param {Object} val The value whise type is to be inspected. - * @param {String} errorMessage The error message to throw. - * @throws {LuaError} - */ -function throwCoerceError (val, errorMessage) { - if (!errorMessage) return; - errorMessage = ('' + errorMessage).replace(/\%type/gi, type(val)); - throw new LuaError(errorMessage); -} - - -/** - * Coerces a value from its current type to a boolean in the same manner as Lua. - * @param {Object} val The value to be converted. - * @returns {Boolean} The converted value. - */ -export function coerceToBoolean(val) { - return !(val === false || val === void 0); -} - - -/** - * Coerces a value from its current type to a number in the same manner as Lua. - * @param {Object} val The value to be converted. - * @param {String} [errorMessage] The error message to throw if the conversion fails. - * @returns {Number} The converted value. - */ -export function coerceToNumber(val, errorMessage) { - let n, match, mantissa; - - switch (true) { - case typeof val == 'number': return val; - case val === void 0: return; - case val === 'inf': return Infinity; - case val === '-inf': return -Infinity; - case val === 'nan': return NaN; - - default: - if (('' + val).match(FLOATING_POINT_PATTERN)) { - n = parseFloat(val); - - } else if (match = ('' + val).match(HEXIDECIMAL_CONSTANT_PATTERN)) { - mantissa = match[3]; - - if ((n = match[2]) || mantissa) { - n = parseInt(n, 16) || 0; - if (mantissa) n += parseInt(mantissa, 16) / Math.pow(16, mantissa.length); - if (match[1]) n *= -1; - } - } - - if (n === void 0) { - throwCoerceError(val, errorMessage); - } - - return n; - } -} - - -/** - * Coerces a value from its current type to a string in the same manner as Lua. - * @param {Object} val The value to be converted. - * @param {String} [errorMessage] The error message to throw if the conversion fails. - * @returns {String} The converted value. - */ -export function coerceToString(val, errorMessage) { - switch(true) { - case typeof val == 'string': - return val; - - case val === void 0: - case val === null: - return 'nil'; - - case val === Infinity: - return 'inf'; - - case val === -Infinity: - return '-inf'; - - case typeof val == 'number': - case typeof val == 'boolean': - return global.isNaN(val)? 'nan' : `${val}`; - - default: - return throwCoerceError(val, errorMessage) || 'userdata'; - } -} - - - -function coerceArg(value, coerceFunc, typ, funcName, index) { - return coerceFunc(value, `bad argument #${index} to '${funcName}' (${typ} expected, got %type)`); -} - -export function coerceArgToNumber(value, funcName, index) { - return coerceArg(value, coerceToNumber, 'number', funcName, index); -} - -export function coerceArgToString(value, funcName, index) { - return coerceArg(value, coerceToString, 'string', funcName, index); -} - -export function coerceArgToTable(value, funcName, index) { - if (value instanceof T) { - return value; - } else { - let typ = type(value); - throw new LuaError(`bad argument #${index} to '${funcName}' (table expected, got ${typ})`); - } -} - -export function coerceArgToFunction(value, funcName, index) { - if (value instanceof Function) { - return value; - } else { - let typ = type(value); - throw new LuaError(`bad argument #${index} to '${funcName}' (function expected, got ${typ})`); - } -} - - - diff --git a/src/utils.ts b/src/utils.ts new file mode 100644 index 0000000..c0a90f3 --- /dev/null +++ b/src/utils.ts @@ -0,0 +1,191 @@ +import { LuaError } from './LuaError' +import { Table } from './Table' + +type LuaType = undefined | boolean | number | string | Function | Table // thread | userdata + +interface Config { + LUA_PATH?: string + fileExists?: (path: string) => boolean + loadFile?: (path: string) => string + stdin?: string + stdout?: (data: string) => void + osExit?: (code: number) => void +} + +/** Pattern to identify a float string value that can validly be converted to a number in Lua */ +const FLOATING_POINT_PATTERN = /^[-+]?[0-9]*\.?([0-9]+([eE][-+]?[0-9]+)?)?$/ + +/** Pattern to identify a hex string value that can validly be converted to a number in Lua */ +const HEXIDECIMAL_CONSTANT_PATTERN = /^(-)?0x([0-9a-fA-F]*)\.?([0-9a-fA-F]*)$/ + +function type(v: LuaType): 'string' | 'number' | 'boolean' | 'function' | 'nil' | 'table' { + const t = typeof v + + switch (t) { + case 'undefined': + return 'nil' + + case 'number': + case 'string': + case 'boolean': + case 'function': + return t + + case 'object': + if (v instanceof Table) return 'table' + if (v instanceof Function) return 'function' + } +} + +/* translate a relative string position: negative means back from end */ +function posrelat(pos: number, len: number): number { + if (pos >= 0) return pos + if (-pos > len) return 0 + return len + pos + 1 +} + +/** + * Thows an error with the type of a variable included in the message + * @param {Object} val The value whise type is to be inspected. + * @param {String} errorMessage The error message to throw. + * @throws {LuaError} + */ +function throwCoerceError(val: LuaType, errorMessage?: string): undefined { + if (!errorMessage) return undefined + throw new LuaError(`${errorMessage}`.replace(/%type/gi, type(val))) +} + +/** + * Coerces a value from its current type to a boolean in the same manner as Lua. + * @param {Object} val The value to be converted. + * @returns {Boolean} The converted value. + */ +function coerceToBoolean(val: LuaType): boolean { + return !(val === false || val === undefined) +} + +/** + * Coerces a value from its current type to a number in the same manner as Lua. + * @param {Object} val The value to be converted. + * @param {String} [errorMessage] The error message to throw if the conversion fails. + * @returns {Number} The converted value. + */ +function coerceToNumber(val: LuaType, errorMessage?: string): number { + if (typeof val === 'number') return val + + switch (val) { + case undefined: + return undefined + case 'inf': + return Infinity + case '-inf': + return -Infinity + case 'nan': + return NaN + } + + const V = `${val}` + if (V.match(FLOATING_POINT_PATTERN)) { + return parseFloat(V) + } + + const match = V.match(HEXIDECIMAL_CONSTANT_PATTERN) + if (match) { + const [, sign, exponent, mantissa] = match + let n = parseInt(exponent, 16) || 0 + if (mantissa) n += parseInt(mantissa, 16) / Math.pow(16, mantissa.length) + if (sign) n *= -1 + return n + } + + if (errorMessage === undefined) return undefined + throwCoerceError(val, errorMessage) +} + +/** + * Coerces a value from its current type to a string in the same manner as Lua. + * @param {Object} val The value to be converted. + * @param {String} [errorMessage] The error message to throw if the conversion fails. + * @returns {String} The converted value. + */ +function coerceToString(val: LuaType, errorMessage?: string): string { + if (typeof val === 'string') return val + + switch (val) { + case undefined: + case null: + return 'nil' + case Infinity: + return 'inf' + case -Infinity: + return '-inf' + } + + if (typeof val === 'number') { + return Number.isNaN(val) ? 'nan' : `${val}` + } + + if (typeof val === 'boolean') { + return `${val}` + } + + if (errorMessage === undefined) return 'nil' + throwCoerceError(val, errorMessage) +} + +function coerceArg( + value: LuaType, + coerceFunc: (val: LuaType, errorMessage?: string) => T, + typ: 'number' | 'string', + funcName: string, + index: number +): T { + return coerceFunc(value, `bad argument #${index} to '${funcName}' (${typ} expected, got %type)`) +} + +function coerceArgToNumber(value: LuaType, funcName: string, index: number): number { + return coerceArg(value, coerceToNumber, 'number', funcName, index) +} + +function coerceArgToString(value: LuaType, funcName: string, index: number): string { + return coerceArg(value, coerceToString, 'string', funcName, index) +} + +function coerceArgToTable(value: LuaType, funcName: string, index: number): Table { + if (value instanceof Table) { + return value + } else { + const typ = type(value) + throw new LuaError(`bad argument #${index} to '${funcName}' (table expected, got ${typ})`) + } +} + +function coerceArgToFunction(value: LuaType, funcName: string, index: number): Function { + if (value instanceof Function) { + return value + } else { + const typ = type(value) + throw new LuaError(`bad argument #${index} to '${funcName}' (function expected, got ${typ})`) + } +} + +const ensureArray = (value: T | T[]): T[] => (value instanceof Array ? value : [value]) + +const hasOwnProperty = (obj: Record | unknown[], key: string | number): boolean => + Object.prototype.hasOwnProperty.call(obj, key) + +export { + LuaType, + Config, + type, + posrelat, + coerceToBoolean, + coerceToNumber, + coerceToString, + coerceArgToNumber, + coerceArgToString, + coerceArgToTable, + coerceArgToFunction, + ensureArray, + hasOwnProperty +} diff --git a/tests/lua-5.3/all.lua b/tests/lua-5.3/all.lua new file mode 100644 index 0000000..8295197 --- /dev/null +++ b/tests/lua-5.3/all.lua @@ -0,0 +1,293 @@ +#!../lua +-- $Id: all.lua,v 1.95 2016/11/07 13:11:28 roberto Exp $ +-- See Copyright Notice at the end of this file + + +local version = "Lua 5.3" +if _VERSION ~= version then + io.stderr:write("\nThis test suite is for ", version, ", not for ", _VERSION, + "\nExiting tests\n") + return +end + + +_G._ARG = arg -- save arg for other tests + + +-- next variables control the execution of some tests +-- true means no test (so an undefined variable does not skip a test) +-- defaults are for Linux; test everything. +-- Make true to avoid long or memory consuming tests +_soft = rawget(_G, "_soft") or false +-- Make true to avoid non-portable tests +_port = rawget(_G, "_port") or false +-- Make true to avoid messages about tests not performed +_nomsg = rawget(_G, "_nomsg") or false + + +local usertests = rawget(_G, "_U") + +if usertests then + -- tests for sissies ;) Avoid problems + _soft = true + _port = true + _nomsg = true +end + +-- tests should require debug when needed +debug = nil + +if usertests then + T = nil -- no "internal" tests for user tests +else + T = rawget(_G, "T") -- avoid problems with 'strict' module +end + +math.randomseed(0) + +--[=[ + example of a long [comment], + [[spanning several [lines]]] + +]=] + +print("current path:\n****" .. package.path .. "****\n") + + +local initclock = os.clock() +local lastclock = initclock +local walltime = os.time() + +local collectgarbage = collectgarbage + +do -- ( + +-- track messages for tests not performed +local msgs = {} +function Message (m) + if not _nomsg then + print(m) + msgs[#msgs+1] = string.sub(m, 3, -3) + end +end + +assert(os.setlocale"C") + +local T,print,format,write,assert,type,unpack,floor = + T,print,string.format,io.write,assert,type,table.unpack,math.floor + +-- use K for 1000 and M for 1000000 (not 2^10 -- 2^20) +local function F (m) + local function round (m) + m = m + 0.04999 + return format("%.1f", m) -- keep one decimal digit + end + if m < 1000 then return m + else + m = m / 1000 + if m < 1000 then return round(m).."K" + else + return round(m/1000).."M" + end + end +end + +local showmem +if not T then + local max = 0 + showmem = function () + local m = collectgarbage("count") * 1024 + max = (m > max) and m or max + print(format(" ---- total memory: %s, max memory: %s ----\n", + F(m), F(max))) + end +else + showmem = function () + T.checkmemory() + local total, numblocks, maxmem = T.totalmem() + local count = collectgarbage("count") + print(format( + "\n ---- total memory: %s (%.0fK), max use: %s, blocks: %d\n", + F(total), count, F(maxmem), numblocks)) + print(format("\t(strings: %d, tables: %d, functions: %d, ".. + "\n\tudata: %d, threads: %d)", + T.totalmem"string", T.totalmem"table", T.totalmem"function", + T.totalmem"userdata", T.totalmem"thread")) + end +end + + +-- +-- redefine dofile to run files through dump/undump +-- +local function report (n) print("\n***** FILE '"..n.."'*****") end +local olddofile = dofile +local dofile = function (n, strip) + showmem() + local c = os.clock() + print(string.format("time: %g (+%g)", c - initclock, c - lastclock)) + lastclock = c + report(n) + local f = assert(loadfile(n)) + local b = string.dump(f, strip) + f = assert(load(b)) + return f() +end + +-- TODO: consider implementing +-- dofile('main.lua') + +do + local next, setmetatable, stderr = next, setmetatable, io.stderr + -- track collections + local mt = {} + -- each time a table is collected, remark it for finalization + -- on next cycle + mt.__gc = function (o) + stderr:write'.' -- mark progress + local n = setmetatable(o, mt) -- remark it + end + local n = setmetatable({}, mt) -- create object +end + +report"gc.lua" +local f = assert(loadfile('gc.lua')) +f() + +dofile('db.lua') +assert(dofile('calls.lua') == deep and deep) +olddofile('strings.lua') +olddofile('literals.lua') +dofile('tpack.lua') +assert(dofile('attrib.lua') == 27) + +assert(dofile('locals.lua') == 5) +dofile('constructs.lua') +dofile('code.lua', true) +if not _G._soft then + report('big.lua') + local f = coroutine.wrap(assert(loadfile('big.lua'))) + assert(f() == 'b') + assert(f() == 'a') +end +dofile('nextvar.lua') +dofile('pm.lua') +dofile('utf8.lua') +dofile('api.lua') +assert(dofile('events.lua') == 12) +dofile('vararg.lua') +dofile('closure.lua') +dofile('coroutine.lua') +dofile('goto.lua', true) +dofile('errors.lua') +dofile('math.lua') +dofile('sort.lua', true) +dofile('bitwise.lua') +assert(dofile('verybig.lua', true) == 10); collectgarbage() +-- TODO: consider implementing +-- dofile('files.lua') + +if #msgs > 0 then + print("\ntests not performed:") + for i=1,#msgs do + print(msgs[i]) + end + print() +end + +-- no test module should define 'debug' +assert(debug == nil) + +local debug = require "debug" + +print(string.format("%d-bit integers, %d-bit floats", + string.packsize("j") * 8, string.packsize("n") * 8)) + +debug.sethook(function (a) assert(type(a) == 'string') end, "cr") + +-- to survive outside block +_G.showmem = showmem + +end --) + +local _G, showmem, print, format, clock, time, difftime, assert, open = + _G, showmem, print, string.format, os.clock, os.time, os.difftime, + assert, io.open + +-- file with time of last performed test +local fname = T and "time-debug.txt" or "time.txt" +local lasttime + +if not usertests then + -- open file with time of last performed test + local f = io.open(fname) + if f then + lasttime = assert(tonumber(f:read'a')) + f:close(); + else -- no such file; assume it is recording time for first time + lasttime = nil + end +end + +-- erase (almost) all globals +print('cleaning all!!!!') +for n in pairs(_G) do + if not ({___Glob = 1, tostring = 1})[n] then + _G[n] = nil + end +end + + +collectgarbage() +collectgarbage() +collectgarbage() +collectgarbage() +collectgarbage() +collectgarbage();showmem() + +local clocktime = clock() - initclock +walltime = difftime(time(), walltime) + +print(format("\n\ntotal time: %.2fs (wall time: %gs)\n", clocktime, walltime)) + +if not usertests then + lasttime = lasttime or clocktime -- if no last time, ignore difference + -- check whether current test time differs more than 5% from last time + local diff = (clocktime - lasttime) / lasttime + local tolerance = 0.05 -- 5% + if (diff >= tolerance or diff <= -tolerance) then + print(format("WARNING: time difference from previous test: %+.1f%%", + diff * 100)) + end + assert(open(fname, "w")):write(clocktime):close() +end + +print("final OK !!!") + + + +--[[ +***************************************************************************** +* Copyright (C) 1994-2016 Lua.org, PUC-Rio. +* +* Permission is hereby granted, free of charge, to any person obtaining +* a copy of this software and associated documentation files (the +* "Software"), to deal in the Software without restriction, including +* without limitation the rights to use, copy, modify, merge, publish, +* distribute, sublicense, and/or sell copies of the Software, and to +* permit persons to whom the Software is furnished to do so, subject to +* the following conditions: +* +* The above copyright notice and this permission notice shall be +* included in all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +***************************************************************************** +]] + diff --git a/tests/lua-5.3/api.lua b/tests/lua-5.3/api.lua new file mode 100644 index 0000000..c27ee97 --- /dev/null +++ b/tests/lua-5.3/api.lua @@ -0,0 +1,1172 @@ +-- $Id: api.lua,v 1.147 2016/11/07 13:06:25 roberto Exp $ +-- See Copyright Notice in file all.lua + +if T==nil then + (Message or print)('\n >>> testC not active: skipping API tests <<<\n') + return +end + +local debug = require "debug" + +local pack = table.pack + + +function tcheck (t1, t2) + assert(t1.n == (t2.n or #t2) + 1) + for i = 2, t1.n do assert(t1[i] == t2[i - 1]) end +end + + +local function checkerr (msg, f, ...) + local stat, err = pcall(f, ...) + assert(not stat and string.find(err, msg)) +end + + +print('testing C API') + +a = T.testC("pushvalue R; return 1") +assert(a == debug.getregistry()) + + +-- absindex +assert(T.testC("settop 10; absindex -1; return 1") == 10) +assert(T.testC("settop 5; absindex -5; return 1") == 1) +assert(T.testC("settop 10; absindex 1; return 1") == 1) +assert(T.testC("settop 10; absindex R; return 1") < -10) + +-- testing alignment +a = T.d2s(12458954321123.0) +assert(a == string.pack("d", 12458954321123.0)) +assert(T.s2d(a) == 12458954321123.0) + +a,b,c = T.testC("pushnum 1; pushnum 2; pushnum 3; return 2") +assert(a == 2 and b == 3 and not c) + +f = T.makeCfunc("pushnum 1; pushnum 2; pushnum 3; return 2") +a,b,c = f() +assert(a == 2 and b == 3 and not c) + +-- test that all trues are equal +a,b,c = T.testC("pushbool 1; pushbool 2; pushbool 0; return 3") +assert(a == b and a == true and c == false) +a,b,c = T.testC"pushbool 0; pushbool 10; pushnil;\ + tobool -3; tobool -3; tobool -3; return 3" +assert(a==false and b==true and c==false) + + +a,b,c = T.testC("gettop; return 2", 10, 20, 30, 40) +assert(a == 40 and b == 5 and not c) + +t = pack(T.testC("settop 5; return *", 2, 3)) +tcheck(t, {n=4,2,3}) + +t = pack(T.testC("settop 0; settop 15; return 10", 3, 1, 23)) +assert(t.n == 10 and t[1] == nil and t[10] == nil) + +t = pack(T.testC("remove -2; return *", 2, 3, 4)) +tcheck(t, {n=2,2,4}) + +t = pack(T.testC("insert -1; return *", 2, 3)) +tcheck(t, {n=2,2,3}) + +t = pack(T.testC("insert 3; return *", 2, 3, 4, 5)) +tcheck(t, {n=4,2,5,3,4}) + +t = pack(T.testC("replace 2; return *", 2, 3, 4, 5)) +tcheck(t, {n=3,5,3,4}) + +t = pack(T.testC("replace -2; return *", 2, 3, 4, 5)) +tcheck(t, {n=3,2,3,5}) + +t = pack(T.testC("remove 3; return *", 2, 3, 4, 5)) +tcheck(t, {n=3,2,4,5}) + +t = pack(T.testC("copy 3 4; return *", 2, 3, 4, 5)) +tcheck(t, {n=4,2,3,3,5}) + +t = pack(T.testC("copy -3 -1; return *", 2, 3, 4, 5)) +tcheck(t, {n=4,2,3,4,3}) + +do -- testing 'rotate' + local t = {10, 20, 30, 40, 50, 60} + for i = -6, 6 do + local s = string.format("rotate 2 %d; return 7", i) + local t1 = pack(T.testC(s, 10, 20, 30, 40, 50, 60)) + tcheck(t1, t) + table.insert(t, 1, table.remove(t)) + end + + t = pack(T.testC("rotate -2 1; return *", 10, 20, 30, 40)) + tcheck(t, {10, 20, 40, 30}) + t = pack(T.testC("rotate -2 -1; return *", 10, 20, 30, 40)) + tcheck(t, {10, 20, 40, 30}) + + -- some corner cases + t = pack(T.testC("rotate -1 0; return *", 10, 20, 30, 40)) + tcheck(t, {10, 20, 30, 40}) + t = pack(T.testC("rotate -1 1; return *", 10, 20, 30, 40)) + tcheck(t, {10, 20, 30, 40}) + t = pack(T.testC("rotate 5 -1; return *", 10, 20, 30, 40)) + tcheck(t, {10, 20, 30, 40}) +end + +-- testing non-function message handlers +do + local f = T.makeCfunc[[ + getglobal error + pushstring bola + pcall 1 1 1 # call 'error' with given handler + pushstatus + return 2 # return error message and status + ]] + + local msg, st = f({}) -- invalid handler + assert(st == "ERRERR" and string.find(msg, "error handling")) + local msg, st = f(nil) -- invalid handler + assert(st == "ERRERR" and string.find(msg, "error handling")) + + local a = setmetatable({}, {__call = function (_, x) return x:upper() end}) + local msg, st = f(a) -- callable handler + assert(st == "ERRRUN" and msg == "BOLA") +end + +t = pack(T.testC("insert 3; pushvalue 3; remove 3; pushvalue 2; remove 2; \ + insert 2; pushvalue 1; remove 1; insert 1; \ + insert -2; pushvalue -2; remove -3; return *", + 2, 3, 4, 5, 10, 40, 90)) +tcheck(t, {n=7,2,3,4,5,10,40,90}) + +t = pack(T.testC("concat 5; return *", "alo", 2, 3, "joao", 12)) +tcheck(t, {n=1,"alo23joao12"}) + +-- testing MULTRET +t = pack(T.testC("call 2,-1; return *", + function (a,b) return 1,2,3,4,a,b end, "alo", "joao")) +tcheck(t, {n=6,1,2,3,4,"alo", "joao"}) + +do -- test returning more results than fit in the caller stack + local a = {} + for i=1,1000 do a[i] = true end; a[999] = 10 + local b = T.testC([[pcall 1 -1 0; pop 1; tostring -1; return 1]], + table.unpack, a) + assert(b == "10") +end + + +-- testing globals +_G.a = 14; _G.b = "a31" +local a = {T.testC[[ + getglobal a; + getglobal b; + getglobal b; + setglobal a; + return * +]]} +assert(a[2] == 14 and a[3] == "a31" and a[4] == nil and _G.a == "a31") + + +-- testing arith +assert(T.testC("pushnum 10; pushnum 20; arith /; return 1") == 0.5) +assert(T.testC("pushnum 10; pushnum 20; arith -; return 1") == -10) +assert(T.testC("pushnum 10; pushnum -20; arith *; return 1") == -200) +assert(T.testC("pushnum 10; pushnum 3; arith ^; return 1") == 1000) +assert(T.testC("pushnum 10; pushstring 20; arith /; return 1") == 0.5) +assert(T.testC("pushstring 10; pushnum 20; arith -; return 1") == -10) +assert(T.testC("pushstring 10; pushstring -20; arith *; return 1") == -200) +assert(T.testC("pushstring 10; pushstring 3; arith ^; return 1") == 1000) +assert(T.testC("arith /; return 1", 2, 0) == 10.0/0) +a = T.testC("pushnum 10; pushint 3; arith \\; return 1") +assert(a == 3.0 and math.type(a) == "float") +a = T.testC("pushint 10; pushint 3; arith \\; return 1") +assert(a == 3 and math.type(a) == "integer") +a = assert(T.testC("pushint 10; pushint 3; arith +; return 1")) +assert(a == 13 and math.type(a) == "integer") +a = assert(T.testC("pushnum 10; pushint 3; arith +; return 1")) +assert(a == 13 and math.type(a) == "float") +a,b,c = T.testC([[pushnum 1; + pushstring 10; arith _; + pushstring 5; return 3]]) +assert(a == 1 and b == -10 and c == "5") +mt = {__add = function (a,b) return setmetatable({a[1] + b[1]}, mt) end, + __mod = function (a,b) return setmetatable({a[1] % b[1]}, mt) end, + __unm = function (a) return setmetatable({a[1]* 2}, mt) end} +a,b,c = setmetatable({4}, mt), + setmetatable({8}, mt), + setmetatable({-3}, mt) +x,y,z = T.testC("arith +; return 2", 10, a, b) +assert(x == 10 and y[1] == 12 and z == nil) +assert(T.testC("arith %; return 1", a, c)[1] == 4%-3) +assert(T.testC("arith _; arith +; arith %; return 1", b, a, c)[1] == + 8 % (4 + (-3)*2)) + +-- errors in arithmetic +checkerr("divide by zero", T.testC, "arith \\", 10, 0) +checkerr("%%0", T.testC, "arith %", 10, 0) + + +-- testing lessthan and lessequal +assert(T.testC("compare LT 2 5, return 1", 3, 2, 2, 4, 2, 2)) +assert(T.testC("compare LE 2 5, return 1", 3, 2, 2, 4, 2, 2)) +assert(not T.testC("compare LT 3 4, return 1", 3, 2, 2, 4, 2, 2)) +assert(T.testC("compare LE 3 4, return 1", 3, 2, 2, 4, 2, 2)) +assert(T.testC("compare LT 5 2, return 1", 4, 2, 2, 3, 2, 2)) +assert(not T.testC("compare LT 2 -3, return 1", "4", "2", "2", "3", "2", "2")) +assert(not T.testC("compare LT -3 2, return 1", "3", "2", "2", "4", "2", "2")) + +-- non-valid indices produce false +assert(not T.testC("compare LT 1 4, return 1")) +assert(not T.testC("compare LE 9 1, return 1")) +assert(not T.testC("compare EQ 9 9, return 1")) + +local b = {__lt = function (a,b) return a[1] < b[1] end} +local a1,a3,a4 = setmetatable({1}, b), + setmetatable({3}, b), + setmetatable({4}, b) +assert(T.testC("compare LT 2 5, return 1", a3, 2, 2, a4, 2, 2)) +assert(T.testC("compare LE 2 5, return 1", a3, 2, 2, a4, 2, 2)) +assert(T.testC("compare LT 5 -6, return 1", a4, 2, 2, a3, 2, 2)) +a,b = T.testC("compare LT 5 -6, return 2", a1, 2, 2, a3, 2, 20) +assert(a == 20 and b == false) +a,b = T.testC("compare LE 5 -6, return 2", a1, 2, 2, a3, 2, 20) +assert(a == 20 and b == false) +a,b = T.testC("compare LE 5 -6, return 2", a1, 2, 2, a1, 2, 20) +assert(a == 20 and b == true) + +-- testing length +local t = setmetatable({x = 20}, {__len = function (t) return t.x end}) +a,b,c = T.testC([[ + len 2; + Llen 2; + objsize 2; + return 3 +]], t) +assert(a == 20 and b == 20 and c == 0) + +t.x = "234"; t[1] = 20 +a,b,c = T.testC([[ + len 2; + Llen 2; + objsize 2; + return 3 +]], t) +assert(a == "234" and b == 234 and c == 1) + +t.x = print; t[1] = 20 +a,c = T.testC([[ + len 2; + objsize 2; + return 2 +]], t) +assert(a == print and c == 1) + + +-- testing __concat + +a = setmetatable({x="u"}, {__concat = function (a,b) return a.x..'.'..b.x end}) +x,y = T.testC([[ + pushnum 5 + pushvalue 2; + pushvalue 2; + concat 2; + pushvalue -2; + return 2; +]], a, a) +assert(x == a..a and y == 5) + +-- concat with 0 elements +assert(T.testC("concat 0; return 1") == "") + +-- concat with 1 element +assert(T.testC("concat 1; return 1", "xuxu") == "xuxu") + + + +-- testing lua_is + +function B(x) return x and 1 or 0 end + +function count (x, n) + n = n or 2 + local prog = [[ + isnumber %d; + isstring %d; + isfunction %d; + iscfunction %d; + istable %d; + isuserdata %d; + isnil %d; + isnull %d; + return 8 + ]] + prog = string.format(prog, n, n, n, n, n, n, n, n) + local a,b,c,d,e,f,g,h = T.testC(prog, x) + return B(a)+B(b)+B(c)+B(d)+B(e)+B(f)+B(g)+(100*B(h)) +end + +assert(count(3) == 2) +assert(count('alo') == 1) +assert(count('32') == 2) +assert(count({}) == 1) +assert(count(print) == 2) +assert(count(function () end) == 1) +assert(count(nil) == 1) +assert(count(io.stdin) == 1) +assert(count(nil, 15) == 100) + + +-- testing lua_to... + +function to (s, x, n) + n = n or 2 + return T.testC(string.format("%s %d; return 1", s, n), x) +end + +local hfunc = string.gmatch("", "") -- a "heavy C function" (with upvalues) +assert(debug.getupvalue(hfunc, 1)) +assert(to("tostring", {}) == nil) +assert(to("tostring", "alo") == "alo") +assert(to("tostring", 12) == "12") +assert(to("tostring", 12, 3) == nil) +assert(to("objsize", {}) == 0) +assert(to("objsize", {1,2,3}) == 3) +assert(to("objsize", "alo\0\0a") == 6) +assert(to("objsize", T.newuserdata(0)) == 0) +assert(to("objsize", T.newuserdata(101)) == 101) +assert(to("objsize", 124) == 0) +assert(to("objsize", true) == 0) +assert(to("tonumber", {}) == 0) +assert(to("tonumber", "12") == 12) +assert(to("tonumber", "s2") == 0) +assert(to("tonumber", 1, 20) == 0) +assert(to("topointer", 10) == 0) +assert(to("topointer", true) == 0) +assert(to("topointer", T.pushuserdata(20)) == 20) +assert(to("topointer", io.read) ~= 0) -- light C function +assert(to("topointer", hfunc) ~= 0) -- "heavy" C function +assert(to("topointer", function () end) ~= 0) -- Lua function +assert(to("topointer", io.stdin) ~= 0) -- full userdata +assert(to("func2num", 20) == 0) +assert(to("func2num", T.pushuserdata(10)) == 0) +assert(to("func2num", io.read) ~= 0) -- light C function +assert(to("func2num", hfunc) ~= 0) -- "heavy" C function (with upvalue) +a = to("tocfunction", math.deg) +assert(a(3) == math.deg(3) and a == math.deg) + + +print("testing panic function") +do + -- trivial error + assert(T.checkpanic("pushstring hi; error") == "hi") + + -- using the stack inside panic + assert(T.checkpanic("pushstring hi; error;", + [[checkstack 5 XX + pushstring ' alo' + pushstring ' mundo' + concat 3]]) == "hi alo mundo") + + -- "argerror" without frames + assert(T.checkpanic("loadstring 4") == + "bad argument #4 (string expected, got no value)") + + + -- memory error + T.totalmem(T.totalmem()+10000) -- set low memory limit (+10k) + assert(T.checkpanic("newuserdata 20000") == "not enough memory") + T.totalmem(0) -- restore high limit + + -- stack error + if not _soft then + local msg = T.checkpanic[[ + pushstring "function f() f() end" + loadstring -1; call 0 0 + getglobal f; call 0 0 + ]] + assert(string.find(msg, "stack overflow")) + end + +end + +-- testing deep C stack +if not _soft then + print("testing stack overflow") + collectgarbage("stop") + checkerr("XXXX", T.testC, "checkstack 1000023 XXXX") -- too deep + -- too deep (with no message) + checkerr("^stack overflow$", T.testC, "checkstack 1000023 ''") + local s = string.rep("pushnil;checkstack 1 XX;", 1000000) + checkerr("overflow", T.testC, s) + collectgarbage("restart") + print'+' +end + +local lim = _soft and 500 or 12000 +local prog = {"checkstack " .. (lim * 2 + 100) .. "msg", "newtable"} +for i = 1,lim do + prog[#prog + 1] = "pushnum " .. i + prog[#prog + 1] = "pushnum " .. i * 10 +end + +prog[#prog + 1] = "rawgeti R 2" -- get global table in registry +prog[#prog + 1] = "insert " .. -(2*lim + 2) + +for i = 1,lim do + prog[#prog + 1] = "settable " .. -(2*(lim - i + 1) + 1) +end + +prog[#prog + 1] = "return 2" + +prog = table.concat(prog, ";") +local g, t = T.testC(prog) +assert(g == _G) +for i = 1,lim do assert(t[i] == i*10); t[i] = nil end +assert(next(t) == nil) +prog, g, t = nil + +-- testing errors + +a = T.testC([[ + loadstring 2; pcall 0 1 0; + pushvalue 3; insert -2; pcall 1 1 0; + pcall 0 0 0; + return 1 +]], "x=150", function (a) assert(a==nil); return 3 end) + +assert(type(a) == 'string' and x == 150) + +function check3(p, ...) + local arg = {...} + assert(#arg == 3) + assert(string.find(arg[3], p)) +end +check3(":1:", T.testC("loadstring 2; return *", "x=")) +check3("%.", T.testC("loadfile 2; return *", ".")) +check3("xxxx", T.testC("loadfile 2; return *", "xxxx")) + +-- test errors in non protected threads +function checkerrnopro (code, msg) + local th = coroutine.create(function () end) -- create new thread + local stt, err = pcall(T.testC, th, code) -- run code there + assert(not stt and string.find(err, msg)) +end + +if not _soft then + checkerrnopro("pushnum 3; call 0 0", "attempt to call") + print"testing stack overflow in unprotected thread" + function f () f() end + checkerrnopro("getglobal 'f'; call 0 0;", "stack overflow") +end +print"+" + + +-- testing table access + +do -- getp/setp + local a = {} + T.testC("rawsetp 2 1", a, 20) + assert(a[T.pushuserdata(1)] == 20) + assert(T.testC("rawgetp 2 1; return 1", a) == 20) +end + +a = {x=0, y=12} +x, y = T.testC("gettable 2; pushvalue 4; gettable 2; return 2", + a, 3, "y", 4, "x") +assert(x == 0 and y == 12) +T.testC("settable -5", a, 3, 4, "x", 15) +assert(a.x == 15) +a[a] = print +x = T.testC("gettable 2; return 1", a) -- table and key are the same object! +assert(x == print) +T.testC("settable 2", a, "x") -- table and key are the same object! +assert(a[a] == "x") + +b = setmetatable({p = a}, {}) +getmetatable(b).__index = function (t, i) return t.p[i] end +k, x = T.testC("gettable 3, return 2", 4, b, 20, 35, "x") +assert(x == 15 and k == 35) +k = T.testC("getfield 2 y, return 1", b) +assert(k == 12) +getmetatable(b).__index = function (t, i) return a[i] end +getmetatable(b).__newindex = function (t, i,v ) a[i] = v end +y = T.testC("insert 2; gettable -5; return 1", 2, 3, 4, "y", b) +assert(y == 12) +k = T.testC("settable -5, return 1", b, 3, 4, "x", 16) +assert(a.x == 16 and k == 4) +a[b] = 'xuxu' +y = T.testC("gettable 2, return 1", b) +assert(y == 'xuxu') +T.testC("settable 2", b, 19) +assert(a[b] == 19) + +-- +do -- testing getfield/setfield with long keys + local t = {_012345678901234567890123456789012345678901234567890123456789 = 32} + local a = T.testC([[ + getfield 2 _012345678901234567890123456789012345678901234567890123456789 + return 1 + ]], t) + assert(a == 32) + local a = T.testC([[ + pushnum 33 + setglobal _012345678901234567890123456789012345678901234567890123456789 + ]]) + assert(_012345678901234567890123456789012345678901234567890123456789 == 33) + _012345678901234567890123456789012345678901234567890123456789 = nil +end + +-- testing next +a = {} +t = pack(T.testC("next; return *", a, nil)) +tcheck(t, {n=1,a}) +a = {a=3} +t = pack(T.testC("next; return *", a, nil)) +tcheck(t, {n=3,a,'a',3}) +t = pack(T.testC("next; pop 1; next; return *", a, nil)) +tcheck(t, {n=1,a}) + + + +-- testing upvalues + +do + local A = T.testC[[ pushnum 10; pushnum 20; pushcclosure 2; return 1]] + t, b, c = A([[pushvalue U0; pushvalue U1; pushvalue U2; return 3]]) + assert(b == 10 and c == 20 and type(t) == 'table') + a, b = A([[tostring U3; tonumber U4; return 2]]) + assert(a == nil and b == 0) + A([[pushnum 100; pushnum 200; replace U2; replace U1]]) + b, c = A([[pushvalue U1; pushvalue U2; return 2]]) + assert(b == 100 and c == 200) + A([[replace U2; replace U1]], {x=1}, {x=2}) + b, c = A([[pushvalue U1; pushvalue U2; return 2]]) + assert(b.x == 1 and c.x == 2) + T.checkmemory() +end + + +-- testing absent upvalues from C-function pointers +assert(T.testC[[isnull U1; return 1]] == true) +assert(T.testC[[isnull U100; return 1]] == true) +assert(T.testC[[pushvalue U1; return 1]] == nil) + +local f = T.testC[[ pushnum 10; pushnum 20; pushcclosure 2; return 1]] +assert(T.upvalue(f, 1) == 10 and + T.upvalue(f, 2) == 20 and + T.upvalue(f, 3) == nil) +T.upvalue(f, 2, "xuxu") +assert(T.upvalue(f, 2) == "xuxu") + + +-- large closures +do + local A = "checkstack 300 msg;" .. + string.rep("pushnum 10;", 255) .. + "pushcclosure 255; return 1" + A = T.testC(A) + for i=1,255 do + assert(A(("pushvalue U%d; return 1"):format(i)) == 10) + end + assert(A("isnull U256; return 1")) + assert(not A("isnil U256; return 1")) +end + + + +-- testing get/setuservalue +-- bug in 5.1.2 +checkerr("got number", debug.setuservalue, 3, {}) +checkerr("got nil", debug.setuservalue, nil, {}) +checkerr("got light userdata", debug.setuservalue, T.pushuserdata(1), {}) + +local b = T.newuserdata(0) +assert(debug.getuservalue(b) == nil) +for _, v in pairs{true, false, 4.56, print, {}, b, "XYZ"} do + assert(debug.setuservalue(b, v) == b) + assert(debug.getuservalue(b) == v) +end + +assert(debug.getuservalue(4) == nil) + +debug.setuservalue(b, function () return 10 end) +collectgarbage() -- function should not be collected +assert(debug.getuservalue(b)() == 10) + +debug.setuservalue(b, 134) +collectgarbage() -- number should not be a problem for collector +assert(debug.getuservalue(b) == 134) + +-- test barrier for uservalues +T.gcstate("atomic") +assert(T.gccolor(b) == "black") +debug.setuservalue(b, {x = 100}) +T.gcstate("pause") -- complete collection +assert(debug.getuservalue(b).x == 100) -- uvalue should be there + +-- long chain of userdata +for i = 1, 1000 do + local bb = T.newuserdata(0) + debug.setuservalue(bb, b) + b = bb +end +collectgarbage() -- nothing should not be collected +for i = 1, 1000 do + b = debug.getuservalue(b) +end +assert(debug.getuservalue(b).x == 100) +b = nil + + +-- testing locks (refs) + +-- reuse of references +local i = T.ref{} +T.unref(i) +assert(T.ref{} == i) + +Arr = {} +Lim = 100 +for i=1,Lim do -- lock many objects + Arr[i] = T.ref({}) +end + +assert(T.ref(nil) == -1 and T.getref(-1) == nil) +T.unref(-1); T.unref(-1) + +for i=1,Lim do -- unlock all them + T.unref(Arr[i]) +end + +function printlocks () + local f = T.makeCfunc("gettable R; return 1") + local n = f("n") + print("n", n) + for i=0,n do + print(i, f(i)) + end +end + + +for i=1,Lim do -- lock many objects + Arr[i] = T.ref({}) +end + +for i=1,Lim,2 do -- unlock half of them + T.unref(Arr[i]) +end + +assert(type(T.getref(Arr[2])) == 'table') + + +assert(T.getref(-1) == nil) + + +a = T.ref({}) + +collectgarbage() + +assert(type(T.getref(a)) == 'table') + + +-- colect in cl the `val' of all collected userdata +tt = {} +cl = {n=0} +A = nil; B = nil +local F +F = function (x) + local udval = T.udataval(x) + table.insert(cl, udval) + local d = T.newuserdata(100) -- cria lixo + d = nil + assert(debug.getmetatable(x).__gc == F) + assert(load("table.insert({}, {})"))() -- cria mais lixo + collectgarbage() -- forca coleta de lixo durante coleta! + assert(debug.getmetatable(x).__gc == F) -- coleta anterior nao melou isso? + local dummy = {} -- cria lixo durante coleta + if A ~= nil then + assert(type(A) == "userdata") + assert(T.udataval(A) == B) + debug.getmetatable(A) -- just acess it + end + A = x -- ressucita userdata + B = udval + return 1,2,3 +end +tt.__gc = F + +-- test whether udate collection frees memory in the right time +do + collectgarbage(); + collectgarbage(); + local x = collectgarbage("count"); + local a = T.newuserdata(5001) + assert(T.testC("objsize 2; return 1", a) == 5001) + assert(collectgarbage("count") >= x+4) + a = nil + collectgarbage(); + assert(collectgarbage("count") <= x+1) + -- udata without finalizer + x = collectgarbage("count") + collectgarbage("stop") + for i=1,1000 do T.newuserdata(0) end + assert(collectgarbage("count") > x+10) + collectgarbage() + assert(collectgarbage("count") <= x+1) + -- udata with finalizer + collectgarbage() + x = collectgarbage("count") + collectgarbage("stop") + a = {__gc = function () end} + for i=1,1000 do debug.setmetatable(T.newuserdata(0), a) end + assert(collectgarbage("count") >= x+10) + collectgarbage() -- this collection only calls TM, without freeing memory + assert(collectgarbage("count") >= x+10) + collectgarbage() -- now frees memory + assert(collectgarbage("count") <= x+1) + collectgarbage("restart") +end + + +collectgarbage("stop") + +-- create 3 userdatas with tag `tt' +a = T.newuserdata(0); debug.setmetatable(a, tt); na = T.udataval(a) +b = T.newuserdata(0); debug.setmetatable(b, tt); nb = T.udataval(b) +c = T.newuserdata(0); debug.setmetatable(c, tt); nc = T.udataval(c) + +-- create userdata without meta table +x = T.newuserdata(4) +y = T.newuserdata(0) + +checkerr("FILE%* expected, got userdata", io.input, a) +checkerr("FILE%* expected, got userdata", io.input, x) + +assert(debug.getmetatable(x) == nil and debug.getmetatable(y) == nil) + +d=T.ref(a); +e=T.ref(b); +f=T.ref(c); +t = {T.getref(d), T.getref(e), T.getref(f)} +assert(t[1] == a and t[2] == b and t[3] == c) + +t=nil; a=nil; c=nil; +T.unref(e); T.unref(f) + +collectgarbage() + +-- check that unref objects have been collected +assert(#cl == 1 and cl[1] == nc) + +x = T.getref(d) +assert(type(x) == 'userdata' and debug.getmetatable(x) == tt) +x =nil +tt.b = b -- create cycle +tt=nil -- frees tt for GC +A = nil +b = nil +T.unref(d); +n5 = T.newuserdata(0) +debug.setmetatable(n5, {__gc=F}) +n5 = T.udataval(n5) +collectgarbage() +assert(#cl == 4) +-- check order of collection +assert(cl[2] == n5 and cl[3] == nb and cl[4] == na) + +collectgarbage"restart" + + +a, na = {}, {} +for i=30,1,-1 do + a[i] = T.newuserdata(0) + debug.setmetatable(a[i], {__gc=F}) + na[i] = T.udataval(a[i]) +end +cl = {} +a = nil; collectgarbage() +assert(#cl == 30) +for i=1,30 do assert(cl[i] == na[i]) end +na = nil + + +for i=2,Lim,2 do -- unlock the other half + T.unref(Arr[i]) +end + +x = T.newuserdata(41); debug.setmetatable(x, {__gc=F}) +assert(T.testC("objsize 2; return 1", x) == 41) +cl = {} +a = {[x] = 1} +x = T.udataval(x) +collectgarbage() +-- old `x' cannot be collected (`a' still uses it) +assert(#cl == 0) +for n in pairs(a) do a[n] = nil end +collectgarbage() +assert(#cl == 1 and cl[1] == x) -- old `x' must be collected + +-- testing lua_equal +assert(T.testC("compare EQ 2 4; return 1", print, 1, print, 20)) +assert(T.testC("compare EQ 3 2; return 1", 'alo', "alo")) +assert(T.testC("compare EQ 2 3; return 1", nil, nil)) +assert(not T.testC("compare EQ 2 3; return 1", {}, {})) +assert(not T.testC("compare EQ 2 3; return 1")) +assert(not T.testC("compare EQ 2 3; return 1", 3)) + +-- testing lua_equal with fallbacks +do + local map = {} + local t = {__eq = function (a,b) return map[a] == map[b] end} + local function f(x) + local u = T.newuserdata(0) + debug.setmetatable(u, t) + map[u] = x + return u + end + assert(f(10) == f(10)) + assert(f(10) ~= f(11)) + assert(T.testC("compare EQ 2 3; return 1", f(10), f(10))) + assert(not T.testC("compare EQ 2 3; return 1", f(10), f(20))) + t.__eq = nil + assert(f(10) ~= f(10)) +end + +print'+' + + + +-- testing changing hooks during hooks +_G.t = {} +T.sethook([[ + # set a line hook after 3 count hooks + sethook 4 0 ' + getglobal t; + pushvalue -3; append -2 + pushvalue -2; append -2 + ']], "c", 3) +local a = 1 -- counting +a = 1 -- counting +a = 1 -- count hook (set line hook) +a = 1 -- line hook +a = 1 -- line hook +debug.sethook() +t = _G.t +assert(t[1] == "line") +line = t[2] +assert(t[3] == "line" and t[4] == line + 1) +assert(t[5] == "line" and t[6] == line + 2) +assert(t[7] == nil) + + +------------------------------------------------------------------------- +do -- testing errors during GC + local a = {} + for i=1,20 do + a[i] = T.newuserdata(i) -- creates several udata + end + for i=1,20,2 do -- mark half of them to raise errors during GC + debug.setmetatable(a[i], {__gc = function (x) error("error inside gc") end}) + end + for i=2,20,2 do -- mark the other half to count and to create more garbage + debug.setmetatable(a[i], {__gc = function (x) load("A=A+1")() end}) + end + _G.A = 0 + a = 0 + while 1 do + local stat, msg = pcall(collectgarbage) + if stat then + break -- stop when no more errors + else + a = a + 1 + assert(string.find(msg, "__gc")) + end + end + assert(a == 10) -- number of errors + + assert(A == 10) -- number of normal collections +end +------------------------------------------------------------------------- +-- test for userdata vals +do + local a = {}; local lim = 30 + for i=0,lim do a[i] = T.pushuserdata(i) end + for i=0,lim do assert(T.udataval(a[i]) == i) end + for i=0,lim do assert(T.pushuserdata(i) == a[i]) end + for i=0,lim do a[a[i]] = i end + for i=0,lim do a[T.pushuserdata(i)] = i end + assert(type(tostring(a[1])) == "string") +end + + +------------------------------------------------------------------------- +-- testing multiple states +T.closestate(T.newstate()); +L1 = T.newstate() +assert(L1) + +assert(T.doremote(L1, "X='a'; return 'a'") == 'a') + + +assert(#pack(T.doremote(L1, "function f () return 'alo', 3 end; f()")) == 0) + +a, b = T.doremote(L1, "return f()") +assert(a == 'alo' and b == '3') + +T.doremote(L1, "_ERRORMESSAGE = nil") +-- error: `sin' is not defined +a, _, b = T.doremote(L1, "return sin(1)") +assert(a == nil and b == 2) -- 2 == run-time error + +-- error: syntax error +a, b, c = T.doremote(L1, "return a+") +assert(a == nil and c == 3 and type(b) == "string") -- 3 == syntax error + +T.loadlib(L1) +a, b, c = T.doremote(L1, [[ + string = require'string' + a = require'_G'; assert(a == _G and require("_G") == a) + io = require'io'; assert(type(io.read) == "function") + assert(require("io") == io) + a = require'table'; assert(type(a.insert) == "function") + a = require'debug'; assert(type(a.getlocal) == "function") + a = require'math'; assert(type(a.sin) == "function") + return string.sub('okinama', 1, 2) +]]) +assert(a == "ok") + +T.closestate(L1); + + +L1 = T.newstate() +T.loadlib(L1) +T.doremote(L1, "a = {}") +T.testC(L1, [[getglobal "a"; pushstring "x"; pushint 1; + settable -3]]) +assert(T.doremote(L1, "return a.x") == "1") + +T.closestate(L1) + +L1 = nil + +print('+') + +------------------------------------------------------------------------- +-- testing memory limits +------------------------------------------------------------------------- +checkerr("block too big", T.newuserdata, math.maxinteger) +collectgarbage() +T.totalmem(T.totalmem()+5000) -- set low memory limit (+5k) +checkerr("not enough memory", load"local a={}; for i=1,100000 do a[i]=i end") +T.totalmem(0) -- restore high limit + +-- test memory errors; increase memory limit in small steps, so that +-- we get memory errors in different parts of a given task, up to there +-- is enough memory to complete the task without errors +function testamem (s, f) + collectgarbage(); collectgarbage() + local M = T.totalmem() + local oldM = M + local a,b = nil + while 1 do + M = M+7 -- increase memory limit in small steps + T.totalmem(M) + a, b = pcall(f) + T.totalmem(0) -- restore high limit + if a and b then break end -- stop when no more errors + collectgarbage() + if not a and not -- `real' error? + (string.find(b, "memory") or string.find(b, "overflow")) then + error(b, 0) -- propagate it + end + end + print("\nlimit for " .. s .. ": " .. M-oldM) + return b +end + + +-- testing memory errors when creating a new state + +b = testamem("state creation", T.newstate) +T.closestate(b); -- close new state + + +-- testing threads + +-- get main thread from registry (at index LUA_RIDX_MAINTHREAD == 1) +mt = T.testC("rawgeti R 1; return 1") +assert(type(mt) == "thread" and coroutine.running() == mt) + + + +function expand (n,s) + if n==0 then return "" end + local e = string.rep("=", n) + return string.format("T.doonnewstack([%s[ %s;\n collectgarbage(); %s]%s])\n", + e, s, expand(n-1,s), e) +end + +G=0; collectgarbage(); a =collectgarbage("count") +load(expand(20,"G=G+1"))() +assert(G==20); collectgarbage(); -- assert(gcinfo() <= a+1) + +testamem("thread creation", function () + return T.doonnewstack("x=1") == 0 -- try to create thread +end) + + +-- testing memory x compiler + +testamem("loadstring", function () + return load("x=1") -- try to do load a string +end) + + +local testprog = [[ +local function foo () return end +local t = {"x"} +a = "aaa" +for i = 1, #t do a=a..t[i] end +return true +]] + +-- testing memory x dofile +_G.a = nil +local t =os.tmpname() +local f = assert(io.open(t, "w")) +f:write(testprog) +f:close() +testamem("dofile", function () + local a = loadfile(t) + return a and a() +end) +assert(os.remove(t)) +assert(_G.a == "aaax") + + +-- other generic tests + +testamem("string creation", function () + local a, b = string.gsub("alo alo", "(a)", function (x) return x..'b' end) + return (a == 'ablo ablo') +end) + +testamem("dump/undump", function () + local a = load(testprog) + local b = a and string.dump(a) + a = b and load(b) + return a and a() +end) + +local t = os.tmpname() +testamem("file creation", function () + local f = assert(io.open(t, 'w')) + assert (not io.open"nomenaoexistente") + io.close(f); + return not loadfile'nomenaoexistente' +end) +assert(os.remove(t)) + +testamem("table creation", function () + local a, lim = {}, 10 + for i=1,lim do a[i] = i; a[i..'a'] = {} end + return (type(a[lim..'a']) == 'table' and a[lim] == lim) +end) + +testamem("constructors", function () + local a = {10, 20, 30, 40, 50; a=1, b=2, c=3, d=4, e=5} + return (type(a) == 'table' and a.e == 5) +end) + +local a = 1 +close = nil +testamem("closure creation", function () + function close (b,c) + return function (x) return a+b+c+x end + end + return (close(2,3)(4) == 10) +end) + +testamem("coroutines", function () + local a = coroutine.wrap(function () + coroutine.yield(string.rep("a", 10)) + return {} + end) + assert(string.len(a()) == 10) + return a() +end) + +do -- auxiliary buffer + local lim = 100 + local a = {}; for i = 1, lim do a[i] = "01234567890123456789" end + testamem("auxiliary buffer", function () + return (#table.concat(a, ",") == 20*lim + lim - 1) + end) +end + +print'+' + +-- testing some auxlib functions +local function gsub (a, b, c) + a, b = T.testC("gsub 2 3 4; gettop; return 2", a, b, c) + assert(b == 5) + return a +end + +assert(gsub("alo.alo.uhuh.", ".", "//") == "alo//alo//uhuh//") +assert(gsub("alo.alo.uhuh.", "alo", "//") == "//.//.uhuh.") +assert(gsub("", "alo", "//") == "") +assert(gsub("...", ".", "/.") == "/././.") +assert(gsub("...", "...", "") == "") + + +-- testing luaL_newmetatable +local mt_xuxu, res, top = T.testC("newmetatable xuxu; gettop; return 3") +assert(type(mt_xuxu) == "table" and res and top == 3) +local d, res, top = T.testC("newmetatable xuxu; gettop; return 3") +assert(mt_xuxu == d and not res and top == 3) +d, res, top = T.testC("newmetatable xuxu1; gettop; return 3") +assert(mt_xuxu ~= d and res and top == 3) + +x = T.newuserdata(0); +y = T.newuserdata(0); +T.testC("pushstring xuxu; gettable R; setmetatable 2", x) +assert(getmetatable(x) == mt_xuxu) + +-- testing luaL_testudata +-- correct metatable +local res1, res2, top = T.testC([[testudata -1 xuxu + testudata 2 xuxu + gettop + return 3]], x) +assert(res1 and res2 and top == 4) + +-- wrong metatable +res1, res2, top = T.testC([[testudata -1 xuxu1 + testudata 2 xuxu1 + gettop + return 3]], x) +assert(not res1 and not res2 and top == 4) + +-- non-existent type +res1, res2, top = T.testC([[testudata -1 xuxu2 + testudata 2 xuxu2 + gettop + return 3]], x) +assert(not res1 and not res2 and top == 4) + +-- userdata has no metatable +res1, res2, top = T.testC([[testudata -1 xuxu + testudata 2 xuxu + gettop + return 3]], y) +assert(not res1 and not res2 and top == 4) + +-- erase metatables +do + local r = debug.getregistry() + assert(r.xuxu == mt_xuxu and r.xuxu1 == d) + r.xuxu = nil; r.xuxu1 = nil +end + +print'OK' + diff --git a/tests/lua-5.3/attrib.lua b/tests/lua-5.3/attrib.lua new file mode 100644 index 0000000..993a96c --- /dev/null +++ b/tests/lua-5.3/attrib.lua @@ -0,0 +1,470 @@ +-- $Id: attrib.lua,v 1.65 2016/11/07 13:11:28 roberto Exp $ +-- See Copyright Notice in file all.lua + +print "testing require" + +assert(require"string" == string) +assert(require"math" == math) +assert(require"table" == table) +assert(require"io" == io) +assert(require"os" == os) +assert(require"coroutine" == coroutine) + +assert(type(package.path) == "string") +assert(type(package.cpath) == "string") +assert(type(package.loaded) == "table") +assert(type(package.preload) == "table") + +assert(type(package.config) == "string") +print("package config: "..string.gsub(package.config, "\n", "|")) + +do + -- create a path with 'max' templates, + -- each with 1-10 repetitions of '?' + local max = _soft and 100 or 2000 + local t = {} + for i = 1,max do t[i] = string.rep("?", i%10 + 1) end + t[#t + 1] = ";" -- empty template + local path = table.concat(t, ";") + -- use that path in a search + local s, err = package.searchpath("xuxu", path) + -- search fails; check that message has an occurence of + -- '??????????' with ? replaced by xuxu and at least 'max' lines + assert(not s and + string.find(err, string.rep("xuxu", 10)) and + #string.gsub(err, "[^\n]", "") >= max) + -- path with one very long template + local path = string.rep("?", max) + local s, err = package.searchpath("xuxu", path) + assert(not s and string.find(err, string.rep('xuxu', max))) +end + +do + local oldpath = package.path + package.path = {} + local s, err = pcall(require, "no-such-file") + assert(not s and string.find(err, "package.path")) + package.path = oldpath +end + +print('+') + + +-- The next tests for 'require' assume some specific directories and +-- libraries. + +if not _port then --[ + +local dirsep = string.match(package.config, "^([^\n]+)\n") + +-- auxiliary directory with C modules and temporary files +local DIR = "libs" .. dirsep + +-- prepend DIR to a name and correct directory separators +local function D (x) + x = string.gsub(x, "/", dirsep) + return DIR .. x +end + +-- prepend DIR and pospend proper C lib. extension to a name +local function DC (x) + local ext = (dirsep == '\\') and ".dll" or ".so" + return D(x .. ext) +end + + +local function createfiles (files, preextras, posextras) + for n,c in pairs(files) do + io.output(D(n)) + io.write(string.format(preextras, n)) + io.write(c) + io.write(string.format(posextras, n)) + io.close(io.output()) + end +end + +function removefiles (files) + for n in pairs(files) do + os.remove(D(n)) + end +end + +local files = { + ["names.lua"] = "do return {...} end\n", + ["err.lua"] = "B = 15; a = a + 1;", + ["synerr.lua"] = "B =", + ["A.lua"] = "", + ["B.lua"] = "assert(...=='B');require 'A'", + ["A.lc"] = "", + ["A"] = "", + ["L"] = "", + ["XXxX"] = "", + ["C.lua"] = "package.loaded[...] = 25; require'C'", +} + +AA = nil +local extras = [[ +NAME = '%s' +REQUIRED = ... +return AA]] + +createfiles(files, "", extras) + +-- testing explicit "dir" separator in 'searchpath' +assert(package.searchpath("C.lua", D"?", "", "") == D"C.lua") +assert(package.searchpath("C.lua", D"?", ".", ".") == D"C.lua") +assert(package.searchpath("--x-", D"?", "-", "X") == D"XXxX") +assert(package.searchpath("---xX", D"?", "---", "XX") == D"XXxX") +assert(package.searchpath(D"C.lua", "?", dirsep) == D"C.lua") +assert(package.searchpath(".\\C.lua", D"?", "\\") == D"./C.lua") + +local oldpath = package.path + +package.path = string.gsub("D/?.lua;D/?.lc;D/?;D/??x?;D/L", "D/", DIR) + +local try = function (p, n, r) + NAME = nil + local rr = require(p) + assert(NAME == n) + assert(REQUIRED == p) + assert(rr == r) +end + +a = require"names" +assert(a[1] == "names" and a[2] == D"names.lua") + +_G.a = nil +local st, msg = pcall(require, "err") +assert(not st and string.find(msg, "arithmetic") and B == 15) +st, msg = pcall(require, "synerr") +assert(not st and string.find(msg, "error loading module")) + +assert(package.searchpath("C", package.path) == D"C.lua") +assert(require"C" == 25) +assert(require"C" == 25) +AA = nil +try('B', 'B.lua', true) +assert(package.loaded.B) +assert(require"B" == true) +assert(package.loaded.A) +assert(require"C" == 25) +package.loaded.A = nil +try('B', nil, true) -- should not reload package +try('A', 'A.lua', true) +package.loaded.A = nil +os.remove(D'A.lua') +AA = {} +try('A', 'A.lc', AA) -- now must find second option +assert(package.searchpath("A", package.path) == D"A.lc") +assert(require("A") == AA) +AA = false +try('K', 'L', false) -- default option +try('K', 'L', false) -- default option (should reload it) +assert(rawget(_G, "_REQUIREDNAME") == nil) + +AA = "x" +try("X", "XXxX", AA) + + +removefiles(files) + + +-- testing require of sub-packages + +local _G = _G + +package.path = string.gsub("D/?.lua;D/?/init.lua", "D/", DIR) + +files = { + ["P1/init.lua"] = "AA = 10", + ["P1/xuxu.lua"] = "AA = 20", +} + +createfiles(files, "_ENV = {}\n", "\nreturn _ENV\n") +AA = 0 + +local m = assert(require"P1") +assert(AA == 0 and m.AA == 10) +assert(require"P1" == m) +assert(require"P1" == m) + +assert(package.searchpath("P1.xuxu", package.path) == D"P1/xuxu.lua") +m.xuxu = assert(require"P1.xuxu") +assert(AA == 0 and m.xuxu.AA == 20) +assert(require"P1.xuxu" == m.xuxu) +assert(require"P1.xuxu" == m.xuxu) +assert(require"P1" == m and m.AA == 10) + + +removefiles(files) + + +package.path = "" +assert(not pcall(require, "file_does_not_exist")) +package.path = "??\0?" +assert(not pcall(require, "file_does_not_exist1")) + +package.path = oldpath + +-- check 'require' error message +local fname = "file_does_not_exist2" +local m, err = pcall(require, fname) +for t in string.gmatch(package.path..";"..package.cpath, "[^;]+") do + t = string.gsub(t, "?", fname) + assert(string.find(err, t, 1, true)) +end + +do -- testing 'package.searchers' not being a table + local searchers = package.searchers + package.searchers = 3 + local st, msg = pcall(require, 'a') + assert(not st and string.find(msg, "must be a table")) + package.searchers = searchers +end + +local function import(...) + local f = {...} + return function (m) + for i=1, #f do m[f[i]] = _G[f[i]] end + end +end + +-- cannot change environment of a C function +assert(not pcall(module, 'XUXU')) + + + +-- testing require of C libraries + + +local p = "" -- On Mac OS X, redefine this to "_" + +-- check whether loadlib works in this system +local st, err, when = package.loadlib(DC"lib1", "*") +if not st then + local f, err, when = package.loadlib("donotexist", p.."xuxu") + assert(not f and type(err) == "string" and when == "absent") + ;(Message or print)('\n >>> cannot load dynamic library <<<\n') + print(err, when) +else + -- tests for loadlib + local f = assert(package.loadlib(DC"lib1", p.."onefunction")) + local a, b = f(15, 25) + assert(a == 25 and b == 15) + + f = assert(package.loadlib(DC"lib1", p.."anotherfunc")) + assert(f(10, 20) == "10%20\n") + + -- check error messages + local f, err, when = package.loadlib(DC"lib1", p.."xuxu") + assert(not f and type(err) == "string" and when == "init") + f, err, when = package.loadlib("donotexist", p.."xuxu") + assert(not f and type(err) == "string" and when == "open") + + -- symbols from 'lib1' must be visible to other libraries + f = assert(package.loadlib(DC"lib11", p.."luaopen_lib11")) + assert(f() == "exported") + + -- test C modules with prefixes in names + package.cpath = DC"?" + local lib2 = require"lib2-v2" + -- check correct access to global environment and correct + -- parameters + assert(_ENV.x == "lib2-v2" and _ENV.y == DC"lib2-v2") + assert(lib2.id("x") == "x") + + -- test C submodules + local fs = require"lib1.sub" + assert(_ENV.x == "lib1.sub" and _ENV.y == DC"lib1") + assert(fs.id(45) == 45) +end + +_ENV = _G + + +-- testing preload + +do + local p = package + package = {} + p.preload.pl = function (...) + local _ENV = {...} + function xuxu (x) return x+20 end + return _ENV + end + + local pl = require"pl" + assert(require"pl" == pl) + assert(pl.xuxu(10) == 30) + assert(pl[1] == "pl" and pl[2] == nil) + + package = p + assert(type(package.path) == "string") +end + +print('+') + +end --] + +print("testing assignments, logical operators, and constructors") + +local res, res2 = 27 + +a, b = 1, 2+3 +assert(a==1 and b==5) +a={} +function f() return 10, 11, 12 end +a.x, b, a[1] = 1, 2, f() +assert(a.x==1 and b==2 and a[1]==10) +a[f()], b, a[f()+3] = f(), a, 'x' +assert(a[10] == 10 and b == a and a[13] == 'x') + +do + local f = function (n) local x = {}; for i=1,n do x[i]=i end; + return table.unpack(x) end; + local a,b,c + a,b = 0, f(1) + assert(a == 0 and b == 1) + A,b = 0, f(1) + assert(A == 0 and b == 1) + a,b,c = 0,5,f(4) + assert(a==0 and b==5 and c==1) + a,b,c = 0,5,f(0) + assert(a==0 and b==5 and c==nil) +end + +a, b, c, d = 1 and nil, 1 or nil, (1 and (nil or 1)), 6 +assert(not a and b and c and d==6) + +d = 20 +a, b, c, d = f() +assert(a==10 and b==11 and c==12 and d==nil) +a,b = f(), 1, 2, 3, f() +assert(a==10 and b==1) + +assert(ab == true) +assert((10 and 2) == 2) +assert((10 or 2) == 10) +assert((10 or assert(nil)) == 10) +assert(not (nil and assert(nil))) +assert((nil or "alo") == "alo") +assert((nil and 10) == nil) +assert((false and 10) == false) +assert((true or 10) == true) +assert((false or 10) == 10) +assert(false ~= nil) +assert(nil ~= false) +assert(not nil == true) +assert(not not nil == false) +assert(not not 1 == true) +assert(not not a == true) +assert(not not (6 or nil) == true) +assert(not not (nil and 56) == false) +assert(not not (nil and true) == false) +assert(not 10 == false) +assert(not {} == false) +assert(not 0.5 == false) +assert(not "x" == false) + +assert({} ~= {}) +print('+') + +a = {} +a[true] = 20 +a[false] = 10 +assert(a[1<2] == 20 and a[1>2] == 10) + +function f(a) return a end + +local a = {} +for i=3000,-3000,-1 do a[i + 0.0] = i; end +a[10e30] = "alo"; a[true] = 10; a[false] = 20 +assert(a[10e30] == 'alo' and a[not 1] == 20 and a[10<20] == 10) +for i=3000,-3000,-1 do assert(a[i] == i); end +a[print] = assert +a[f] = print +a[a] = a +assert(a[a][a][a][a][print] == assert) +a[print](a[a[f]] == a[print]) +assert(not pcall(function () local a = {}; a[nil] = 10 end)) +assert(not pcall(function () local a = {[nil] = 10} end)) +assert(a[nil] == nil) +a = nil + +a = {10,9,8,7,6,5,4,3,2; [-3]='a', [f]=print, a='a', b='ab'} +a, a.x, a.y = a, a[-3] +assert(a[1]==10 and a[-3]==a.a and a[f]==print and a.x=='a' and not a.y) +a[1], f(a)[2], b, c = {['alo']=assert}, 10, a[1], a[f], 6, 10, 23, f(a), 2 +a[1].alo(a[2]==10 and b==10 and c==print) + + +-- test of large float/integer indices + +-- compute maximum integer where all bits fit in a float +local maxint = math.maxinteger + +while maxint - 1.0 == maxint - 0.0 do -- trim (if needed) to fit in a float + maxint = maxint // 2 +end + +maxintF = maxint + 0.0 -- float version + +assert(math.type(maxintF) == "float" and maxintF >= 2.0^14) + +-- floats and integers must index the same places +a[maxintF] = 10; a[maxintF - 1.0] = 11; +a[-maxintF] = 12; a[-maxintF + 1.0] = 13; + +assert(a[maxint] == 10 and a[maxint - 1] == 11 and + a[-maxint] == 12 and a[-maxint + 1] == 13) + +a[maxint] = 20 +a[-maxint] = 22 + +assert(a[maxintF] == 20 and a[maxintF - 1.0] == 11 and + a[-maxintF] == 22 and a[-maxintF + 1.0] == 13) + +a = nil + + +-- test conflicts in multiple assignment +do + local a,i,j,b + a = {'a', 'b'}; i=1; j=2; b=a + i, a[i], a, j, a[j], a[i+j] = j, i, i, b, j, i + assert(i == 2 and b[1] == 1 and a == 1 and j == b and b[2] == 2 and + b[3] == 1) +end + +-- repeat test with upvalues +do + local a,i,j,b + a = {'a', 'b'}; i=1; j=2; b=a + local function foo () + i, a[i], a, j, a[j], a[i+j] = j, i, i, b, j, i + end + foo() + assert(i == 2 and b[1] == 1 and a == 1 and j == b and b[2] == 2 and + b[3] == 1) + local t = {} + (function (a) t[a], a = 10, 20 end)(1); + assert(t[1] == 10) +end + +-- bug in 5.2 beta +local function foo () + local a + return function () + local b + a, b = 3, 14 -- local and upvalue have same index + return a, b + end +end + +local a, b = foo()() +assert(a == 3 and b == 14) + +print('OK') + +return res + diff --git a/tests/lua-5.3/big.lua b/tests/lua-5.3/big.lua new file mode 100644 index 0000000..1a1fa78 --- /dev/null +++ b/tests/lua-5.3/big.lua @@ -0,0 +1,82 @@ +-- $Id: big.lua,v 1.32 2016/11/07 13:11:28 roberto Exp $ +-- See Copyright Notice in file all.lua + +if _soft then + return 'a' +end + +print "testing large tables" + +local debug = require"debug" + +local lim = 2^18 + 1000 +local prog = { "local y = {0" } +for i = 1, lim do prog[#prog + 1] = i end +prog[#prog + 1] = "}\n" +prog[#prog + 1] = "X = y\n" +prog[#prog + 1] = ("assert(X[%d] == %d)"):format(lim - 1, lim - 2) +prog[#prog + 1] = "return 0" +prog = table.concat(prog, ";") + +local env = {string = string, assert = assert} +local f = assert(load(prog, nil, nil, env)) + +f() +assert(env.X[lim] == lim - 1 and env.X[lim + 1] == lim) +for k in pairs(env) do env[k] = nil end + +-- yields during accesses larger than K (in RK) +setmetatable(env, { + __index = function (t, n) coroutine.yield('g'); return _G[n] end, + __newindex = function (t, n, v) coroutine.yield('s'); _G[n] = v end, +}) + +X = nil +co = coroutine.wrap(f) +assert(co() == 's') +assert(co() == 'g') +assert(co() == 'g') +assert(co() == 0) + +assert(X[lim] == lim - 1 and X[lim + 1] == lim) + +-- errors in accesses larger than K (in RK) +getmetatable(env).__index = function () end +getmetatable(env).__newindex = function () end +local e, m = pcall(f) +assert(not e and m:find("global 'X'")) + +-- errors in metamethods +getmetatable(env).__newindex = function () error("hi") end +local e, m = xpcall(f, debug.traceback) +assert(not e and m:find("'__newindex'")) + +f, X = nil + +coroutine.yield'b' + +if 2^32 == 0 then -- (small integers) { + +print "testing string length overflow" + +local repstrings = 192 -- number of strings to be concatenated +local ssize = math.ceil(2.0^32 / repstrings) + 1 -- size of each string + +assert(repstrings * ssize > 2.0^32) -- it should be larger than maximum size + +local longs = string.rep("\0", ssize) -- create one long string + +-- create function to concatentate 'repstrings' copies of its argument +local rep = assert(load( + "local a = ...; return " .. string.rep("a", repstrings, ".."))) + +local a, b = pcall(rep, longs) -- call that function + +-- it should fail without creating string (result would be too large) +assert(not a and string.find(b, "overflow")) + +end -- } + +print'OK' + +return 'a' diff --git a/tests/lua-5.3/bitwise.lua b/tests/lua-5.3/bitwise.lua new file mode 100644 index 0000000..786679f --- /dev/null +++ b/tests/lua-5.3/bitwise.lua @@ -0,0 +1,328 @@ +-- $Id: bitwise.lua,v 1.26 2016/11/07 13:11:28 roberto Exp $ +-- See Copyright Notice in file all.lua + +print("testing bitwise operations") + +local numbits = string.packsize('j') * 8 + +assert(~0 == -1) + +assert((1 << (numbits - 1)) == math.mininteger) + +-- basic tests for bitwise operators; +-- use variables to avoid constant folding +local a, b, c, d +a = 0xFFFFFFFFFFFFFFFF +assert(a == -1 and a & -1 == a and a & 35 == 35) +a = 0xF0F0F0F0F0F0F0F0 +assert(a | -1 == -1) +assert(a ~ a == 0 and a ~ 0 == a and a ~ ~a == -1) +assert(a >> 4 == ~a) +a = 0xF0; b = 0xCC; c = 0xAA; d = 0xFD +assert(a | b ~ c & d == 0xF4) + +a = 0xF0.0; b = 0xCC.0; c = "0xAA.0"; d = "0xFD.0" +assert(a | b ~ c & d == 0xF4) + +a = 0xF0000000; b = 0xCC000000; +c = 0xAA000000; d = 0xFD000000 +assert(a | b ~ c & d == 0xF4000000) +assert(~~a == a and ~a == -1 ~ a and -d == ~d + 1) + +a = a << 32 +b = b << 32 +c = c << 32 +d = d << 32 +assert(a | b ~ c & d == 0xF4000000 << 32) +assert(~~a == a and ~a == -1 ~ a and -d == ~d + 1) + +assert(-1 >> 1 == (1 << (numbits - 1)) - 1 and 1 << 31 == 0x80000000) +assert(-1 >> (numbits - 1) == 1) +assert(-1 >> numbits == 0 and + -1 >> -numbits == 0 and + -1 << numbits == 0 and + -1 << -numbits == 0) + +assert((2^30 - 1) << 2^30 == 0) +assert((2^30 - 1) >> 2^30 == 0) + +assert(1 >> -3 == 1 << 3 and 1000 >> 5 == 1000 << -5) + + +-- coercion from strings to integers +assert("0xffffffffffffffff" | 0 == -1) +assert("0xfffffffffffffffe" & "-1" == -2) +assert(" \t-0xfffffffffffffffe\n\t" & "-1" == 2) +assert(" \n -45 \t " >> " -2 " == -45 * 4) + +-- out of range number +assert(not pcall(function () return "0xffffffffffffffff.0" | 0 end)) + +-- embedded zeros +assert(not pcall(function () return "0xffffffffffffffff\0" | 0 end)) + +print'+' + + +package.preload.bit32 = function () --{ + +-- no built-in 'bit32' library: implement it using bitwise operators + +local bit = {} + +function bit.bnot (a) + return ~a & 0xFFFFFFFF +end + + +-- +-- in all vararg functions, avoid creating 'arg' table when there are +-- only 2 (or less) parameters, as 2 parameters is the common case +-- + +function bit.band (x, y, z, ...) + if not z then + return ((x or -1) & (y or -1)) & 0xFFFFFFFF + else + local arg = {...} + local res = x & y & z + for i = 1, #arg do res = res & arg[i] end + return res & 0xFFFFFFFF + end +end + +function bit.bor (x, y, z, ...) + if not z then + return ((x or 0) | (y or 0)) & 0xFFFFFFFF + else + local arg = {...} + local res = x | y | z + for i = 1, #arg do res = res | arg[i] end + return res & 0xFFFFFFFF + end +end + +function bit.bxor (x, y, z, ...) + if not z then + return ((x or 0) ~ (y or 0)) & 0xFFFFFFFF + else + local arg = {...} + local res = x ~ y ~ z + for i = 1, #arg do res = res ~ arg[i] end + return res & 0xFFFFFFFF + end +end + +function bit.btest (...) + return bit.band(...) ~= 0 +end + +function bit.lshift (a, b) + return ((a & 0xFFFFFFFF) << b) & 0xFFFFFFFF +end + +function bit.rshift (a, b) + return ((a & 0xFFFFFFFF) >> b) & 0xFFFFFFFF +end + +function bit.arshift (a, b) + a = a & 0xFFFFFFFF + if b <= 0 or (a & 0x80000000) == 0 then + return (a >> b) & 0xFFFFFFFF + else + return ((a >> b) | ~(0xFFFFFFFF >> b)) & 0xFFFFFFFF + end +end + +function bit.lrotate (a ,b) + b = b & 31 + a = a & 0xFFFFFFFF + a = (a << b) | (a >> (32 - b)) + return a & 0xFFFFFFFF +end + +function bit.rrotate (a, b) + return bit.lrotate(a, -b) +end + +local function checkfield (f, w) + w = w or 1 + assert(f >= 0, "field cannot be negative") + assert(w > 0, "width must be positive") + assert(f + w <= 32, "trying to access non-existent bits") + return f, ~(-1 << w) +end + +function bit.extract (a, f, w) + local f, mask = checkfield(f, w) + return (a >> f) & mask +end + +function bit.replace (a, v, f, w) + local f, mask = checkfield(f, w) + v = v & mask + a = (a & ~(mask << f)) | (v << f) + return a & 0xFFFFFFFF +end + +return bit + +end --} + + +print("testing bitwise library") + +local bit32 = require'bit32' + +assert(bit32.band() == bit32.bnot(0)) +assert(bit32.btest() == true) +assert(bit32.bor() == 0) +assert(bit32.bxor() == 0) + +assert(bit32.band() == bit32.band(0xffffffff)) +assert(bit32.band(1,2) == 0) + + +-- out-of-range numbers +assert(bit32.band(-1) == 0xffffffff) +assert(bit32.band((1 << 33) - 1) == 0xffffffff) +assert(bit32.band(-(1 << 33) - 1) == 0xffffffff) +assert(bit32.band((1 << 33) + 1) == 1) +assert(bit32.band(-(1 << 33) + 1) == 1) +assert(bit32.band(-(1 << 40)) == 0) +assert(bit32.band(1 << 40) == 0) +assert(bit32.band(-(1 << 40) - 2) == 0xfffffffe) +assert(bit32.band((1 << 40) - 4) == 0xfffffffc) + +assert(bit32.lrotate(0, -1) == 0) +assert(bit32.lrotate(0, 7) == 0) +assert(bit32.lrotate(0x12345678, 0) == 0x12345678) +assert(bit32.lrotate(0x12345678, 32) == 0x12345678) +assert(bit32.lrotate(0x12345678, 4) == 0x23456781) +assert(bit32.rrotate(0x12345678, -4) == 0x23456781) +assert(bit32.lrotate(0x12345678, -8) == 0x78123456) +assert(bit32.rrotate(0x12345678, 8) == 0x78123456) +assert(bit32.lrotate(0xaaaaaaaa, 2) == 0xaaaaaaaa) +assert(bit32.lrotate(0xaaaaaaaa, -2) == 0xaaaaaaaa) +for i = -50, 50 do + assert(bit32.lrotate(0x89abcdef, i) == bit32.lrotate(0x89abcdef, i%32)) +end + +assert(bit32.lshift(0x12345678, 4) == 0x23456780) +assert(bit32.lshift(0x12345678, 8) == 0x34567800) +assert(bit32.lshift(0x12345678, -4) == 0x01234567) +assert(bit32.lshift(0x12345678, -8) == 0x00123456) +assert(bit32.lshift(0x12345678, 32) == 0) +assert(bit32.lshift(0x12345678, -32) == 0) +assert(bit32.rshift(0x12345678, 4) == 0x01234567) +assert(bit32.rshift(0x12345678, 8) == 0x00123456) +assert(bit32.rshift(0x12345678, 32) == 0) +assert(bit32.rshift(0x12345678, -32) == 0) +assert(bit32.arshift(0x12345678, 0) == 0x12345678) +assert(bit32.arshift(0x12345678, 1) == 0x12345678 // 2) +assert(bit32.arshift(0x12345678, -1) == 0x12345678 * 2) +assert(bit32.arshift(-1, 1) == 0xffffffff) +assert(bit32.arshift(-1, 24) == 0xffffffff) +assert(bit32.arshift(-1, 32) == 0xffffffff) +assert(bit32.arshift(-1, -1) == bit32.band(-1 * 2, 0xffffffff)) + +assert(0x12345678 << 4 == 0x123456780) +assert(0x12345678 << 8 == 0x1234567800) +assert(0x12345678 << -4 == 0x01234567) +assert(0x12345678 << -8 == 0x00123456) +assert(0x12345678 << 32 == 0x1234567800000000) +assert(0x12345678 << -32 == 0) +assert(0x12345678 >> 4 == 0x01234567) +assert(0x12345678 >> 8 == 0x00123456) +assert(0x12345678 >> 32 == 0) +assert(0x12345678 >> -32 == 0x1234567800000000) + +print("+") +-- some special cases +local c = {0, 1, 2, 3, 10, 0x80000000, 0xaaaaaaaa, 0x55555555, + 0xffffffff, 0x7fffffff} + +for _, b in pairs(c) do + assert(bit32.band(b) == b) + assert(bit32.band(b, b) == b) + assert(bit32.band(b, b, b, b) == b) + assert(bit32.btest(b, b) == (b ~= 0)) + assert(bit32.band(b, b, b) == b) + assert(bit32.band(b, b, b, ~b) == 0) + assert(bit32.btest(b, b, b) == (b ~= 0)) + assert(bit32.band(b, bit32.bnot(b)) == 0) + assert(bit32.bor(b, bit32.bnot(b)) == bit32.bnot(0)) + assert(bit32.bor(b) == b) + assert(bit32.bor(b, b) == b) + assert(bit32.bor(b, b, b) == b) + assert(bit32.bor(b, b, 0, ~b) == 0xffffffff) + assert(bit32.bxor(b) == b) + assert(bit32.bxor(b, b) == 0) + assert(bit32.bxor(b, b, b) == b) + assert(bit32.bxor(b, b, b, b) == 0) + assert(bit32.bxor(b, 0) == b) + assert(bit32.bnot(b) ~= b) + assert(bit32.bnot(bit32.bnot(b)) == b) + assert(bit32.bnot(b) == (1 << 32) - 1 - b) + assert(bit32.lrotate(b, 32) == b) + assert(bit32.rrotate(b, 32) == b) + assert(bit32.lshift(bit32.lshift(b, -4), 4) == bit32.band(b, bit32.bnot(0xf))) + assert(bit32.rshift(bit32.rshift(b, 4), -4) == bit32.band(b, bit32.bnot(0xf))) +end + +-- for this test, use at most 24 bits (mantissa of a single float) +c = {0, 1, 2, 3, 10, 0x800000, 0xaaaaaa, 0x555555, 0xffffff, 0x7fffff} +for _, b in pairs(c) do + for i = -40, 40 do + local x = bit32.lshift(b, i) + local y = math.floor(math.fmod(b * 2.0^i, 2.0^32)) + assert(math.fmod(x - y, 2.0^32) == 0) + end +end + +assert(not pcall(bit32.band, {})) +assert(not pcall(bit32.bnot, "a")) +assert(not pcall(bit32.lshift, 45)) +assert(not pcall(bit32.lshift, 45, print)) +assert(not pcall(bit32.rshift, 45, print)) + +print("+") + + +-- testing extract/replace + +assert(bit32.extract(0x12345678, 0, 4) == 8) +assert(bit32.extract(0x12345678, 4, 4) == 7) +assert(bit32.extract(0xa0001111, 28, 4) == 0xa) +assert(bit32.extract(0xa0001111, 31, 1) == 1) +assert(bit32.extract(0x50000111, 31, 1) == 0) +assert(bit32.extract(0xf2345679, 0, 32) == 0xf2345679) + +assert(not pcall(bit32.extract, 0, -1)) +assert(not pcall(bit32.extract, 0, 32)) +assert(not pcall(bit32.extract, 0, 0, 33)) +assert(not pcall(bit32.extract, 0, 31, 2)) + +assert(bit32.replace(0x12345678, 5, 28, 4) == 0x52345678) +assert(bit32.replace(0x12345678, 0x87654321, 0, 32) == 0x87654321) +assert(bit32.replace(0, 1, 2) == 2^2) +assert(bit32.replace(0, -1, 4) == 2^4) +assert(bit32.replace(-1, 0, 31) == (1 << 31) - 1) +assert(bit32.replace(-1, 0, 1, 2) == (1 << 32) - 7) + + +-- testing conversion of floats + +assert(bit32.bor(3.0) == 3) +assert(bit32.bor(-4.0) == 0xfffffffc) + +-- large floats and large-enough integers? +if 2.0^50 < 2.0^50 + 1.0 and 2.0^50 < (-1 >> 1) then + assert(bit32.bor(2.0^32 - 5.0) == 0xfffffffb) + assert(bit32.bor(-2.0^32 - 6.0) == 0xfffffffa) + assert(bit32.bor(2.0^48 - 5.0) == 0xfffffffb) + assert(bit32.bor(-2.0^48 - 6.0) == 0xfffffffa) +end + +print'OK' + diff --git a/tests/lua-5.3/bwcoercion.lua b/tests/lua-5.3/bwcoercion.lua new file mode 100644 index 0000000..cd735ab --- /dev/null +++ b/tests/lua-5.3/bwcoercion.lua @@ -0,0 +1,78 @@ +local tonumber, tointeger = tonumber, math.tointeger +local type, getmetatable, rawget, error = type, getmetatable, rawget, error +local strsub = string.sub + +local print = print + +_ENV = nil + +-- Try to convert a value to an integer, without assuming any coercion. +local function toint (x) + x = tonumber(x) -- handle numerical strings + if not x then + return false -- not coercible to a number + end + return tointeger(x) +end + + +-- If operation fails, maybe second operand has a metamethod that should +-- have been called if not for this string metamethod, so try to +-- call it. +local function trymt (x, y, mtname) + if type(y) ~= "string" then -- avoid recalling original metamethod + local mt = getmetatable(y) + local mm = mt and rawget(mt, mtname) + if mm then + return mm(x, y) + end + end + -- if any test fails, there is no other metamethod to be called + error("attempt to '" .. strsub(mtname, 3) .. + "' a " .. type(x) .. " with a " .. type(y), 4) +end + + +local function checkargs (x, y, mtname) + local xi = toint(x) + local yi = toint(y) + if xi and yi then + return xi, yi + else + return trymt(x, y, mtname), nil + end +end + + +local smt = getmetatable("") + +smt.__band = function (x, y) + local x, y = checkargs(x, y, "__band") + return y and x & y or x +end + +smt.__bor = function (x, y) + local x, y = checkargs(x, y, "__bor") + return y and x | y or x +end + +smt.__bxor = function (x, y) + local x, y = checkargs(x, y, "__bxor") + return y and x ~ y or x +end + +smt.__shl = function (x, y) + local x, y = checkargs(x, y, "__shl") + return y and x << y or x +end + +smt.__shr = function (x, y) + local x, y = checkargs(x, y, "__shr") + return y and x >> y or x +end + +smt.__bnot = function (x) + local x, y = checkargs(x, x, "__bnot") + return y and ~x or x +end + diff --git a/tests/lua-5.3/calls.lua b/tests/lua-5.3/calls.lua new file mode 100644 index 0000000..6d6fb7b --- /dev/null +++ b/tests/lua-5.3/calls.lua @@ -0,0 +1,401 @@ +-- $Id: calls.lua,v 1.60 2016/11/07 13:11:28 roberto Exp $ +-- See Copyright Notice in file all.lua + +print("testing functions and calls") + +local debug = require "debug" + +-- get the opportunity to test 'type' too ;) + +assert(type(1<2) == 'boolean') +assert(type(true) == 'boolean' and type(false) == 'boolean') +assert(type(nil) == 'nil' + and type(-3) == 'number' + and type'x' == 'string' + and type{} == 'table' + and type(type) == 'function') + +assert(type(assert) == type(print)) +function f (x) return a:x (x) end +assert(type(f) == 'function') +assert(not pcall(type)) + + +do -- test error in 'print' too... + local tostring = _ENV.tostring + + _ENV.tostring = nil + local st, msg = pcall(print, 1) + assert(st == false and string.find(msg, "attempt to call a nil value")) + + _ENV.tostring = function () return {} end + local st, msg = pcall(print, 1) + assert(st == false and string.find(msg, "must return a string")) + + _ENV.tostring = tostring +end + + +-- testing local-function recursion +fact = false +do + local res = 1 + local function fact (n) + if n==0 then return res + else return n*fact(n-1) + end + end + assert(fact(5) == 120) +end +assert(fact == false) + +-- testing declarations +a = {i = 10} +self = 20 +function a:x (x) return x+self.i end +function a.y (x) return x+self end + +assert(a:x(1)+10 == a.y(1)) + +a.t = {i=-100} +a["t"].x = function (self, a,b) return self.i+a+b end + +assert(a.t:x(2,3) == -95) + +do + local a = {x=0} + function a:add (x) self.x, a.y = self.x+x, 20; return self end + assert(a:add(10):add(20):add(30).x == 60 and a.y == 20) +end + +local a = {b={c={}}} + +function a.b.c.f1 (x) return x+1 end +function a.b.c:f2 (x,y) self[x] = y end +assert(a.b.c.f1(4) == 5) +a.b.c:f2('k', 12); assert(a.b.c.k == 12) + +print('+') + +t = nil -- 'declare' t +function f(a,b,c) local d = 'a'; t={a,b,c,d} end + +f( -- this line change must be valid + 1,2) +assert(t[1] == 1 and t[2] == 2 and t[3] == nil and t[4] == 'a') +f(1,2, -- this one too + 3,4) +assert(t[1] == 1 and t[2] == 2 and t[3] == 3 and t[4] == 'a') + +function fat(x) + if x <= 1 then return 1 + else return x*load("return fat(" .. x-1 .. ")", "")() + end +end + +assert(load "load 'assert(fat(6)==720)' () ")() +a = load('return fat(5), 3') +a,b = a() +assert(a == 120 and b == 3) +print('+') + +function err_on_n (n) + if n==0 then error(); exit(1); + else err_on_n (n-1); exit(1); + end +end + +do + function dummy (n) + if n > 0 then + assert(not pcall(err_on_n, n)) + dummy(n-1) + end + end +end + +dummy(10) + +function deep (n) + if n>0 then deep(n-1) end +end +deep(10) +deep(200) + +-- testing tail call +function deep (n) if n>0 then return deep(n-1) else return 101 end end +assert(deep(30000) == 101) +a = {} +function a:deep (n) if n>0 then return self:deep(n-1) else return 101 end end +assert(a:deep(30000) == 101) + +print('+') + + +a = nil +(function (x) a=x end)(23) +assert(a == 23 and (function (x) return x*2 end)(20) == 40) + + +-- testing closures + +-- fixed-point operator +Z = function (le) + local function a (f) + return le(function (x) return f(f)(x) end) + end + return a(a) + end + + +-- non-recursive factorial + +F = function (f) + return function (n) + if n == 0 then return 1 + else return n*f(n-1) end + end + end + +fat = Z(F) + +assert(fat(0) == 1 and fat(4) == 24 and Z(F)(5)==5*Z(F)(4)) + +local function g (z) + local function f (a,b,c,d) + return function (x,y) return a+b+c+d+a+x+y+z end + end + return f(z,z+1,z+2,z+3) +end + +f = g(10) +assert(f(9, 16) == 10+11+12+13+10+9+16+10) + +Z, F, f = nil +print('+') + +-- testing multiple returns + +function unlpack (t, i) + i = i or 1 + if (i <= #t) then + return t[i], unlpack(t, i+1) + end +end + +function equaltab (t1, t2) + assert(#t1 == #t2) + for i = 1, #t1 do + assert(t1[i] == t2[i]) + end +end + +local pack = function (...) return (table.pack(...)) end + +function f() return 1,2,30,4 end +function ret2 (a,b) return a,b end + +local a,b,c,d = unlpack{1,2,3} +assert(a==1 and b==2 and c==3 and d==nil) +a = {1,2,3,4,false,10,'alo',false,assert} +equaltab(pack(unlpack(a)), a) +equaltab(pack(unlpack(a), -1), {1,-1}) +a,b,c,d = ret2(f()), ret2(f()) +assert(a==1 and b==1 and c==2 and d==nil) +a,b,c,d = unlpack(pack(ret2(f()), ret2(f()))) +assert(a==1 and b==1 and c==2 and d==nil) +a,b,c,d = unlpack(pack(ret2(f()), (ret2(f())))) +assert(a==1 and b==1 and c==nil and d==nil) + +a = ret2{ unlpack{1,2,3}, unlpack{3,2,1}, unlpack{"a", "b"}} +assert(a[1] == 1 and a[2] == 3 and a[3] == "a" and a[4] == "b") + + +-- testing calls with 'incorrect' arguments +rawget({}, "x", 1) +rawset({}, "x", 1, 2) +assert(math.sin(1,2) == math.sin(1)) +table.sort({10,9,8,4,19,23,0,0}, function (a,b) return a 10 or a[i]() ~= x +assert(i == 11 and a[1]() == 1 and a[3]() == 3 and i == 4) + + +-- testing closures created in 'then' and 'else' parts of 'if's +a = {} +for i = 1, 10 do + if i % 3 == 0 then + local y = 0 + a[i] = function (x) local t = y; y = x; return t end + elseif i % 3 == 1 then + goto L1 + error'not here' + ::L1:: + local y = 1 + a[i] = function (x) local t = y; y = x; return t end + elseif i % 3 == 2 then + local t + goto l4 + ::l4a:: a[i] = t; goto l4b + error("should never be here!") + ::l4:: + local y = 2 + t = function (x) local t = y; y = x; return t end + goto l4a + error("should never be here!") + ::l4b:: + end +end + +for i = 1, 10 do + assert(a[i](i * 10) == i % 3 and a[i]() == i * 10) +end + +print'+' + + +-- test for correctly closing upvalues in tail calls of vararg functions +local function t () + local function c(a,b) assert(a=="test" and b=="OK") end + local function v(f, ...) c("test", f() ~= 1 and "FAILED" or "OK") end + local x = 1 + return v(function() return x end) +end +t() + + +-- test for debug manipulation of upvalues +local debug = require'debug' + +do + local a , b, c = 3, 5, 7 + foo1 = function () return a+b end; + foo2 = function () return b+a end; + do + local a = 10 + foo3 = function () return a+b end; + end +end + +assert(debug.upvalueid(foo1, 1)) +assert(debug.upvalueid(foo1, 2)) +assert(not pcall(debug.upvalueid, foo1, 3)) +assert(debug.upvalueid(foo1, 1) == debug.upvalueid(foo2, 2)) +assert(debug.upvalueid(foo1, 2) == debug.upvalueid(foo2, 1)) +assert(debug.upvalueid(foo3, 1)) +assert(debug.upvalueid(foo1, 1) ~= debug.upvalueid(foo3, 1)) +assert(debug.upvalueid(foo1, 2) == debug.upvalueid(foo3, 2)) + +assert(debug.upvalueid(string.gmatch("x", "x"), 1) ~= nil) + +assert(foo1() == 3 + 5 and foo2() == 5 + 3) +debug.upvaluejoin(foo1, 2, foo2, 2) +assert(foo1() == 3 + 3 and foo2() == 5 + 3) +assert(foo3() == 10 + 5) +debug.upvaluejoin(foo3, 2, foo2, 1) +assert(foo3() == 10 + 5) +debug.upvaluejoin(foo3, 2, foo2, 2) +assert(foo3() == 10 + 3) + +assert(not pcall(debug.upvaluejoin, foo1, 3, foo2, 1)) +assert(not pcall(debug.upvaluejoin, foo1, 1, foo2, 3)) +assert(not pcall(debug.upvaluejoin, foo1, 0, foo2, 1)) +assert(not pcall(debug.upvaluejoin, print, 1, foo2, 1)) +assert(not pcall(debug.upvaluejoin, {}, 1, foo2, 1)) +assert(not pcall(debug.upvaluejoin, foo1, 1, print, 1)) + +print'OK' diff --git a/tests/lua-5.3/code.lua b/tests/lua-5.3/code.lua new file mode 100644 index 0000000..0b9d142 --- /dev/null +++ b/tests/lua-5.3/code.lua @@ -0,0 +1,239 @@ +-- $Id: code.lua,v 1.42 2016/11/07 13:04:32 roberto Exp $ +-- See Copyright Notice in file all.lua + +if T==nil then + (Message or print)('\n >>> testC not active: skipping opcode tests <<<\n') + return +end +print "testing code generation and optimizations" + + +-- this code gave an error for the code checker +do + local function f (a) + for k,v,w in a do end + end +end + + +-- testing reuse in constant table +local function checkKlist (func, list) + local k = T.listk(func) + assert(#k == #list) + for i = 1, #k do + assert(k[i] == list[i] and math.type(k[i]) == math.type(list[i])) + end +end + +local function foo () + local a + a = 3; + a = 0; a = 0.0; a = -7 + 7 + a = 3.78/4; a = 3.78/4 + a = -3.78/4; a = 3.78/4; a = -3.78/4 + a = -3.79/4; a = 0.0; a = -0; + a = 3; a = 3.0; a = 3; a = 3.0 +end + +checkKlist(foo, {3, 0, 0.0, 3.78/4, -3.78/4, -3.79/4, 3.0}) + + +-- testing opcodes + +function check (f, ...) + local arg = {...} + local c = T.listcode(f) + for i=1, #arg do + -- print(arg[i], c[i]) + assert(string.find(c[i], '- '..arg[i]..' *%d')) + end + assert(c[#arg+2] == nil) +end + + +function checkequal (a, b) + a = T.listcode(a) + b = T.listcode(b) + for i = 1, #a do + a[i] = string.gsub(a[i], '%b()', '') -- remove line number + b[i] = string.gsub(b[i], '%b()', '') -- remove line number + assert(a[i] == b[i]) + end +end + + +-- some basic instructions +check(function () + (function () end){f()} +end, 'CLOSURE', 'NEWTABLE', 'GETTABUP', 'CALL', 'SETLIST', 'CALL', 'RETURN') + + +-- sequence of LOADNILs +check(function () + local a,b,c + local d; local e; + local f,g,h; + d = nil; d=nil; b=nil; a=nil; c=nil; +end, 'LOADNIL', 'RETURN') + +check(function () + local a,b,c,d = 1,1,1,1 + d=nil;c=nil;b=nil;a=nil +end, 'LOADK', 'LOADK', 'LOADK', 'LOADK', 'LOADNIL', 'RETURN') + +do + local a,b,c,d = 1,1,1,1 + d=nil;c=nil;b=nil;a=nil + assert(a == nil and b == nil and c == nil and d == nil) +end + + +-- single return +check (function (a,b,c) return a end, 'RETURN') + + +-- infinite loops +check(function () while true do local a = -1 end end, +'LOADK', 'JMP', 'RETURN') + +check(function () while 1 do local a = -1 end end, +'LOADK', 'JMP', 'RETURN') + +check(function () repeat local x = 1 until true end, +'LOADK', 'RETURN') + + +-- concat optimization +check(function (a,b,c,d) return a..b..c..d end, + 'MOVE', 'MOVE', 'MOVE', 'MOVE', 'CONCAT', 'RETURN') + +-- not +check(function () return not not nil end, 'LOADBOOL', 'RETURN') +check(function () return not not false end, 'LOADBOOL', 'RETURN') +check(function () return not not true end, 'LOADBOOL', 'RETURN') +check(function () return not not 1 end, 'LOADBOOL', 'RETURN') + +-- direct access to locals +check(function () + local a,b,c,d + a = b*2 + c[2], a[b] = -((a + d/2 - a[b]) ^ a.x), b +end, + 'LOADNIL', + 'MUL', + 'DIV', 'ADD', 'GETTABLE', 'SUB', 'GETTABLE', 'POW', + 'UNM', 'SETTABLE', 'SETTABLE', 'RETURN') + + +-- direct access to constants +check(function () + local a,b + a.x = 3.2 + a.x = b + a[b] = 'x' +end, + 'LOADNIL', 'SETTABLE', 'SETTABLE', 'SETTABLE', 'RETURN') + +check(function () + local a,b + a = 1 - a + b = 1/a + b = 5-4 +end, + 'LOADNIL', 'SUB', 'DIV', 'LOADK', 'RETURN') + +check(function () + local a,b + a[true] = false +end, + 'LOADNIL', 'SETTABLE', 'RETURN') + + +-- constant folding +local function checkK (func, val) + check(func, 'LOADK', 'RETURN') + local k = T.listk(func) + assert(#k == 1 and k[1] == val and math.type(k[1]) == math.type(val)) + assert(func() == val) +end +checkK(function () return 0.0 end, 0.0) +checkK(function () return 0 end, 0) +checkK(function () return -0//1 end, 0) +checkK(function () return 3^-1 end, 1/3) +checkK(function () return (1 + 1)^(50 + 50) end, 2^100) +checkK(function () return (-2)^(31 - 2) end, -0x20000000 + 0.0) +checkK(function () return (-3^0 + 5) // 3.0 end, 1.0) +checkK(function () return -3 % 5 end, 2) +checkK(function () return -((2.0^8 + -(-1)) % 8)/2 * 4 - 3 end, -5.0) +checkK(function () return -((2^8 + -(-1)) % 8)//2 * 4 - 3 end, -7.0) +checkK(function () return 0xF0.0 | 0xCC.0 ~ 0xAA & 0xFD end, 0xF4) +checkK(function () return ~(~0xFF0 | 0xFF0) end, 0) +checkK(function () return ~~-100024.0 end, -100024) +checkK(function () return ((100 << 6) << -4) >> 2 end, 100) + + +-- no foldings +check(function () return -0.0 end, 'LOADK', 'UNM', 'RETURN') +check(function () return 3/0 end, 'DIV', 'RETURN') +check(function () return 0%0 end, 'MOD', 'RETURN') +check(function () return -4//0 end, 'IDIV', 'RETURN') + +-- bug in constant folding for 5.1 +check(function () return -nil end, 'LOADNIL', 'UNM', 'RETURN') + + +check(function () + local a,b,c + b[c], a = c, b + b[a], a = c, b + a, b = c, a + a = a +end, + 'LOADNIL', + 'MOVE', 'MOVE', 'SETTABLE', + 'MOVE', 'MOVE', 'MOVE', 'SETTABLE', + 'MOVE', 'MOVE', 'MOVE', + -- no code for a = a + 'RETURN') + + +-- x == nil , x ~= nil +checkequal(function () if (a==nil) then a=1 end; if a~=nil then a=1 end end, + function () if (a==9) then a=1 end; if a~=9 then a=1 end end) + +check(function () if a==nil then a='a' end end, +'GETTABUP', 'EQ', 'JMP', 'SETTABUP', 'RETURN') + +-- de morgan +checkequal(function () local a; if not (a or b) then b=a end end, + function () local a; if (not a and not b) then b=a end end) + +checkequal(function (l) local a; return 0 <= a and a <= l end, + function (l) local a; return not (not(a >= 0) or not(a <= l)) end) + + +-- if-goto optimizations +check(function (a, b, c, d, e) + if a == b then goto l1 + elseif a == c then goto l2 + elseif a == d then goto l2 + else if a == e then goto l3 + else goto l3 + end + end + ::l1:: ::l2:: ::l3:: ::l4:: +end, 'EQ', 'JMP', 'EQ', 'JMP', 'EQ', 'JMP', 'EQ', 'JMP', 'JMP', 'RETURN') + +checkequal( +function (a) while a < 10 do a = a + 1 end end, +function (a) ::L2:: if not(a < 10) then goto L1 end; a = a + 1; + goto L2; ::L1:: end +) + +checkequal( +function (a) while a < 10 do a = a + 1 end end, +function (a) while true do if not(a < 10) then break end; a = a + 1; end end +) + +print 'OK' + diff --git a/tests/lua-5.3/constructs.lua b/tests/lua-5.3/constructs.lua new file mode 100644 index 0000000..cebd257 --- /dev/null +++ b/tests/lua-5.3/constructs.lua @@ -0,0 +1,313 @@ +-- $Id: constructs.lua,v 1.41 2016/11/07 13:11:28 roberto Exp $ +-- See Copyright Notice in file all.lua + +;;print "testing syntax";; + +local debug = require "debug" + + +local function checkload (s, msg) + assert(string.find(select(2, load(s)), msg)) +end + +-- testing semicollons +do ;;; end +; do ; a = 3; assert(a == 3) end; +; + + +-- invalid operations should not raise errors when not executed +if false then a = 3 // 0; a = 0 % 0 end + + +-- testing priorities + +assert(2^3^2 == 2^(3^2)); +assert(2^3*4 == (2^3)*4); +assert(2.0^-2 == 1/4 and -2^- -2 == - - -4); +assert(not nil and 2 and not(2>3 or 3<2)); +assert(-3-1-5 == 0+0-9); +assert(-2^2 == -4 and (-2)^2 == 4 and 2*2-3-1 == 0); +assert(-3%5 == 2 and -3+5 == 2) +assert(2*1+3/3 == 3 and 1+2 .. 3*1 == "33"); +assert(not(2+1 > 3*1) and "a".."b" > "a"); + +assert("7" .. 3 << 1 == 146) +assert(10 >> 1 .. "9" == 0) +assert(10 | 1 .. "9" == 27) + +assert(0xF0 | 0xCC ~ 0xAA & 0xFD == 0xF4) +assert(0xFD & 0xAA ~ 0xCC | 0xF0 == 0xF4) +assert(0xF0 & 0x0F + 1 == 0x10) + +assert(3^4//2^3//5 == 2) + +assert(-3+4*5//2^3^2//9+4%10/3 == (-3)+(((4*5)//(2^(3^2)))//9)+((4%10)/3)) + +assert(not ((true or false) and nil)) +assert( true or false and nil) + +-- old bug +assert((((1 or false) and true) or false) == true) +assert((((nil and true) or false) and true) == false) + +local a,b = 1,nil; +assert(-(1 or 2) == -1 and (1 and 2)+(-1.25 or -4) == 0.75); +x = ((b or a)+1 == 2 and (10 or a)+1 == 11); assert(x); +x = (((2<3) or 1) == true and (2<3 and 4) == 4); assert(x); + +x,y=1,2; +assert((x>y) and x or y == 2); +x,y=2,1; +assert((x>y) and x or y == 2); + +assert(1234567890 == tonumber('1234567890') and 1234567890+1 == 1234567891) + + +-- silly loops +repeat until 1; repeat until true; +while false do end; while nil do end; + +do -- test old bug (first name could not be an `upvalue') + local a; function f(x) x={a=1}; x={x=1}; x={G=1} end +end + +function f (i) + if type(i) ~= 'number' then return i,'jojo'; end; + if i > 0 then return i, f(i-1); end; +end + +x = {f(3), f(5), f(10);}; +assert(x[1] == 3 and x[2] == 5 and x[3] == 10 and x[4] == 9 and x[12] == 1); +assert(x[nil] == nil) +x = {f'alo', f'xixi', nil}; +assert(x[1] == 'alo' and x[2] == 'xixi' and x[3] == nil); +x = {f'alo'..'xixi'}; +assert(x[1] == 'aloxixi') +x = {f{}} +assert(x[2] == 'jojo' and type(x[1]) == 'table') + + +local f = function (i) + if i < 10 then return 'a'; + elseif i < 20 then return 'b'; + elseif i < 30 then return 'c'; + end; +end + +assert(f(3) == 'a' and f(12) == 'b' and f(26) == 'c' and f(100) == nil) + +for i=1,1000 do break; end; +n=100; +i=3; +t = {}; +a=nil +while not a do + a=0; for i=1,n do for i=i,1,-1 do a=a+1; t[i]=1; end; end; +end +assert(a == n*(n+1)/2 and i==3); +assert(t[1] and t[n] and not t[0] and not t[n+1]) + +function f(b) + local x = 1; + repeat + local a; + if b==1 then local b=1; x=10; break + elseif b==2 then x=20; break; + elseif b==3 then x=30; + else local a,b,c,d=math.sin(1); x=x+1; + end + until x>=12; + return x; +end; + +assert(f(1) == 10 and f(2) == 20 and f(3) == 30 and f(4)==12) + + +local f = function (i) + if i < 10 then return 'a' + elseif i < 20 then return 'b' + elseif i < 30 then return 'c' + else return 8 + end +end + +assert(f(3) == 'a' and f(12) == 'b' and f(26) == 'c' and f(100) == 8) + +local a, b = nil, 23 +x = {f(100)*2+3 or a, a or b+2} +assert(x[1] == 19 and x[2] == 25) +x = {f=2+3 or a, a = b+2} +assert(x.f == 5 and x.a == 25) + +a={y=1} +x = {a.y} +assert(x[1] == 1) + +function f(i) + while 1 do + if i>0 then i=i-1; + else return; end; + end; +end; + +function g(i) + while 1 do + if i>0 then i=i-1 + else return end + end +end + +f(10); g(10); + +do + function f () return 1,2,3; end + local a, b, c = f(); + assert(a==1 and b==2 and c==3) + a, b, c = (f()); + assert(a==1 and b==nil and c==nil) +end + +local a,b = 3 and f(); +assert(a==1 and b==nil) + +function g() f(); return; end; +assert(g() == nil) +function g() return nil or f() end +a,b = g() +assert(a==1 and b==nil) + +print'+'; + + +f = [[ +return function ( a , b , c , d , e ) + local x = a >= b or c or ( d and e ) or nil + return x +end , { a = 1 , b = 2 >= 1 , } or { 1 }; +]] +f = string.gsub(f, "%s+", "\n"); -- force a SETLINE between opcodes +f,a = load(f)(); +assert(a.a == 1 and a.b) + +function g (a,b,c,d,e) + if not (a>=b or c or d and e or nil) then return 0; else return 1; end; +end + +function h (a,b,c,d,e) + while (a>=b or c or (d and e) or nil) do return 1; end; + return 0; +end; + +assert(f(2,1) == true and g(2,1) == 1 and h(2,1) == 1) +assert(f(1,2,'a') == 'a' and g(1,2,'a') == 1 and h(1,2,'a') == 1) +assert(f(1,2,'a') +~= -- force SETLINE before nil +nil, "") +assert(f(1,2,'a') == 'a' and g(1,2,'a') == 1 and h(1,2,'a') == 1) +assert(f(1,2,nil,1,'x') == 'x' and g(1,2,nil,1,'x') == 1 and + h(1,2,nil,1,'x') == 1) +assert(f(1,2,nil,nil,'x') == nil and g(1,2,nil,nil,'x') == 0 and + h(1,2,nil,nil,'x') == 0) +assert(f(1,2,nil,1,nil) == nil and g(1,2,nil,1,nil) == 0 and + h(1,2,nil,1,nil) == 0) + +assert(1 and 2<3 == true and 2<3 and 'a'<'b' == true) +x = 2<3 and not 3; assert(x==false) +x = 2<1 or (2>1 and 'a'); assert(x=='a') + + +do + local a; if nil then a=1; else a=2; end; -- this nil comes as PUSHNIL 2 + assert(a==2) +end + +function F(a) + assert(debug.getinfo(1, "n").name == 'F') + return a,2,3 +end + +a,b = F(1)~=nil; assert(a == true and b == nil); +a,b = F(nil)==nil; assert(a == true and b == nil) + +---------------------------------------------------------------- +------------------------------------------------------------------ + +-- sometimes will be 0, sometimes will not... +_ENV.GLOB1 = math.floor(os.time()) % 2 + +-- basic expressions with their respective values +local basiccases = { + {"nil", nil}, + {"false", false}, + {"true", true}, + {"10", 10}, + {"(0==_ENV.GLOB1)", 0 == _ENV.GLOB1}, +} + +print('testing short-circuit optimizations (' .. _ENV.GLOB1 .. ')') + + +-- operators with their respective values +local binops = { + {" and ", function (a,b) if not a then return a else return b end end}, + {" or ", function (a,b) if a then return a else return b end end}, +} + +local cases = {} + +-- creates all combinations of '(cases[i] op cases[n-i])' plus +-- 'not(cases[i] op cases[n-i])' (syntax + value) +local function createcases (n) + local res = {} + for i = 1, n - 1 do + for _, v1 in ipairs(cases[i]) do + for _, v2 in ipairs(cases[n - i]) do + for _, op in ipairs(binops) do + local t = { + "(" .. v1[1] .. op[1] .. v2[1] .. ")", + op[2](v1[2], v2[2]) + } + res[#res + 1] = t + res[#res + 1] = {"not" .. t[1], not t[2]} + end + end + end + end + return res +end + +-- do not do too many combinations for soft tests +local level = _soft and 3 or 4 + +cases[1] = basiccases +for i = 2, level do cases[i] = createcases(i) end +print("+") + +local prog = [[if %s then IX = true end; return %s]] + +local i = 0 +for n = 1, level do + for _, v in pairs(cases[n]) do + local s = v[1] + local p = load(string.format(prog, s, s), "") + IX = false + assert(p() == v[2] and IX == not not v[2]) + i = i + 1 + if i % 60000 == 0 then print('+') end + end +end +------------------------------------------------------------------ + +-- testing some syntax errors (chosen through 'gcov') +checkload("for x do", "expected") +checkload("x:call", "expected") + +if not _soft then + -- control structure too long + local s = string.rep("a = a + 1\n", 2^18) + s = "while true do " .. s .. "end" + checkload(s, "too long") +end + +print'OK' diff --git a/tests/lua-5.3/coroutine.lua b/tests/lua-5.3/coroutine.lua new file mode 100644 index 0000000..c8fc857 --- /dev/null +++ b/tests/lua-5.3/coroutine.lua @@ -0,0 +1,874 @@ +-- $Id: coroutine.lua,v 1.42 2016/11/07 13:03:20 roberto Exp $ +-- See Copyright Notice in file all.lua + +print "testing coroutines" + +local debug = require'debug' + +local f + +local main, ismain = coroutine.running() +assert(type(main) == "thread" and ismain) +assert(not coroutine.resume(main)) +assert(not coroutine.isyieldable()) +assert(not pcall(coroutine.yield)) + + +-- trivial errors +assert(not pcall(coroutine.resume, 0)) +assert(not pcall(coroutine.status, 0)) + + +-- tests for multiple yield/resume arguments + +local function eqtab (t1, t2) + assert(#t1 == #t2) + for i = 1, #t1 do + local v = t1[i] + assert(t2[i] == v) + end +end + +_G.x = nil -- declare x +function foo (a, ...) + local x, y = coroutine.running() + assert(x == f and y == false) + -- next call should not corrupt coroutine (but must fail, + -- as it attempts to resume the running coroutine) + assert(coroutine.resume(f) == false) + assert(coroutine.status(f) == "running") + local arg = {...} + assert(coroutine.isyieldable()) + for i=1,#arg do + _G.x = {coroutine.yield(table.unpack(arg[i]))} + end + return table.unpack(a) +end + +f = coroutine.create(foo) +assert(type(f) == "thread" and coroutine.status(f) == "suspended") +assert(string.find(tostring(f), "thread")) +local s,a,b,c,d +s,a,b,c,d = coroutine.resume(f, {1,2,3}, {}, {1}, {'a', 'b', 'c'}) +assert(s and a == nil and coroutine.status(f) == "suspended") +s,a,b,c,d = coroutine.resume(f) +eqtab(_G.x, {}) +assert(s and a == 1 and b == nil) +s,a,b,c,d = coroutine.resume(f, 1, 2, 3) +eqtab(_G.x, {1, 2, 3}) +assert(s and a == 'a' and b == 'b' and c == 'c' and d == nil) +s,a,b,c,d = coroutine.resume(f, "xuxu") +eqtab(_G.x, {"xuxu"}) +assert(s and a == 1 and b == 2 and c == 3 and d == nil) +assert(coroutine.status(f) == "dead") +s, a = coroutine.resume(f, "xuxu") +assert(not s and string.find(a, "dead") and coroutine.status(f) == "dead") + + +-- yields in tail calls +local function foo (i) return coroutine.yield(i) end +f = coroutine.wrap(function () + for i=1,10 do + assert(foo(i) == _G.x) + end + return 'a' +end) +for i=1,10 do _G.x = i; assert(f(i) == i) end +_G.x = 'xuxu'; assert(f('xuxu') == 'a') + +-- recursive +function pf (n, i) + coroutine.yield(n) + pf(n*i, i+1) +end + +f = coroutine.wrap(pf) +local s=1 +for i=1,10 do + assert(f(1, 1) == s) + s = s*i +end + +-- sieve +function gen (n) + return coroutine.wrap(function () + for i=2,n do coroutine.yield(i) end + end) +end + + +function filter (p, g) + return coroutine.wrap(function () + while 1 do + local n = g() + if n == nil then return end + if math.fmod(n, p) ~= 0 then coroutine.yield(n) end + end + end) +end + +local x = gen(100) +local a = {} +while 1 do + local n = x() + if n == nil then break end + table.insert(a, n) + x = filter(n, x) +end + +assert(#a == 25 and a[#a] == 97) +x, a = nil + +-- yielding across C boundaries + +co = coroutine.wrap(function() + assert(not pcall(table.sort,{1,2,3}, coroutine.yield)) + assert(coroutine.isyieldable()) + coroutine.yield(20) + return 30 + end) + +assert(co() == 20) +assert(co() == 30) + + +local f = function (s, i) return coroutine.yield(i) end + +local f1 = coroutine.wrap(function () + return xpcall(pcall, function (...) return ... end, + function () + local s = 0 + for i in f, nil, 1 do pcall(function () s = s + i end) end + error({s}) + end) + end) + +f1() +for i = 1, 10 do assert(f1(i) == i) end +local r1, r2, v = f1(nil) +assert(r1 and not r2 and v[1] == (10 + 1)*10/2) + + +function f (a, b) a = coroutine.yield(a); error{a + b} end +function g(x) return x[1]*2 end + +co = coroutine.wrap(function () + coroutine.yield(xpcall(f, g, 10, 20)) + end) + +assert(co() == 10) +r, msg = co(100) +assert(not r and msg == 240) + + +-- unyieldable C call +do + local function f (c) + assert(not coroutine.isyieldable()) + return c .. c + end + + local co = coroutine.wrap(function (c) + assert(coroutine.isyieldable()) + local s = string.gsub("a", ".", f) + return s + end) + assert(co() == "aa") +end + + +-- errors in coroutines +function foo () + assert(debug.getinfo(1).currentline == debug.getinfo(foo).linedefined + 1) + assert(debug.getinfo(2).currentline == debug.getinfo(goo).linedefined) + coroutine.yield(3) + error(foo) +end + +function goo() foo() end +x = coroutine.wrap(goo) +assert(x() == 3) +local a,b = pcall(x) +assert(not a and b == foo) + +x = coroutine.create(goo) +a,b = coroutine.resume(x) +assert(a and b == 3) +a,b = coroutine.resume(x) +assert(not a and b == foo and coroutine.status(x) == "dead") +a,b = coroutine.resume(x) +assert(not a and string.find(b, "dead") and coroutine.status(x) == "dead") + + +-- co-routines x for loop +function all (a, n, k) + if k == 0 then coroutine.yield(a) + else + for i=1,n do + a[k] = i + all(a, n, k-1) + end + end +end + +local a = 0 +for t in coroutine.wrap(function () all({}, 5, 4) end) do + a = a+1 +end +assert(a == 5^4) + + +-- access to locals of collected corroutines +local C = {}; setmetatable(C, {__mode = "kv"}) +local x = coroutine.wrap (function () + local a = 10 + local function f () a = a+10; return a end + while true do + a = a+1 + coroutine.yield(f) + end + end) + +C[1] = x; + +local f = x() +assert(f() == 21 and x()() == 32 and x() == f) +x = nil +collectgarbage() +assert(C[1] == nil) +assert(f() == 43 and f() == 53) + + +-- old bug: attempt to resume itself + +function co_func (current_co) + assert(coroutine.running() == current_co) + assert(coroutine.resume(current_co) == false) + coroutine.yield(10, 20) + assert(coroutine.resume(current_co) == false) + coroutine.yield(23) + return 10 +end + +local co = coroutine.create(co_func) +local a,b,c = coroutine.resume(co, co) +assert(a == true and b == 10 and c == 20) +a,b = coroutine.resume(co, co) +assert(a == true and b == 23) +a,b = coroutine.resume(co, co) +assert(a == true and b == 10) +assert(coroutine.resume(co, co) == false) +assert(coroutine.resume(co, co) == false) + + +-- other old bug when attempting to resume itself +-- (trigger C-code assertions) +do + local A = coroutine.running() + local B = coroutine.create(function() return coroutine.resume(A) end) + local st, res = coroutine.resume(B) + assert(st == true and res == false) + + A = coroutine.wrap(function() return pcall(A, 1) end) + st, res = A() + assert(not st and string.find(res, "non%-suspended")) +end + + +-- attempt to resume 'normal' coroutine +local co1, co2 +co1 = coroutine.create(function () return co2() end) +co2 = coroutine.wrap(function () + assert(coroutine.status(co1) == 'normal') + assert(not coroutine.resume(co1)) + coroutine.yield(3) + end) + +a,b = coroutine.resume(co1) +assert(a and b == 3) +assert(coroutine.status(co1) == 'dead') + +-- infinite recursion of coroutines +a = function(a) coroutine.wrap(a)(a) end +assert(not pcall(a, a)) +a = nil + + +-- access to locals of erroneous coroutines +local x = coroutine.create (function () + local a = 10 + _G.f = function () a=a+1; return a end + error('x') + end) + +assert(not coroutine.resume(x)) +-- overwrite previous position of local `a' +assert(not coroutine.resume(x, 1, 1, 1, 1, 1, 1, 1)) +assert(_G.f() == 11) +assert(_G.f() == 12) + + +if not T then + (Message or print)('\n >>> testC not active: skipping yield/hook tests <<<\n') +else + print "testing yields inside hooks" + + local turn + + function fact (t, x) + assert(turn == t) + if x == 0 then return 1 + else return x*fact(t, x-1) + end + end + + local A, B = 0, 0 + + local x = coroutine.create(function () + T.sethook("yield 0", "", 2) + A = fact("A", 6) + end) + + local y = coroutine.create(function () + T.sethook("yield 0", "", 3) + B = fact("B", 7) + end) + + while A==0 or B==0 do -- A ~= 0 when 'x' finishes (similar for 'B','y') + if A==0 then turn = "A"; assert(T.resume(x)) end + if B==0 then turn = "B"; assert(T.resume(y)) end + end + + assert(B // A == 7) -- fact(7) // fact(6) + + local line = debug.getinfo(1, "l").currentline + 2 -- get line number + local function foo () + local x = 10 --<< this line is 'line' + x = x + 10 + _G.XX = x + end + + -- testing yields in line hook + local co = coroutine.wrap(function () + T.sethook("setglobal X; yield 0", "l", 0); foo(); return 10 end) + + _G.XX = nil; + _G.X = nil; co(); assert(_G.X == line) + _G.X = nil; co(); assert(_G.X == line + 1) + _G.X = nil; co(); assert(_G.X == line + 2 and _G.XX == nil) + _G.X = nil; co(); assert(_G.X == line + 3 and _G.XX == 20) + assert(co() == 10) + + -- testing yields in count hook + co = coroutine.wrap(function () + T.sethook("yield 0", "", 1); foo(); return 10 end) + + _G.XX = nil; + local c = 0 + repeat c = c + 1; local a = co() until a == 10 + assert(_G.XX == 20 and c >= 5) + + co = coroutine.wrap(function () + T.sethook("yield 0", "", 2); foo(); return 10 end) + + _G.XX = nil; + local c = 0 + repeat c = c + 1; local a = co() until a == 10 + assert(_G.XX == 20 and c >= 5) + _G.X = nil; _G.XX = nil + + do + -- testing debug library on a coroutine suspended inside a hook + -- (bug in 5.2/5.3) + c = coroutine.create(function (a, ...) + T.sethook("yield 0", "l") -- will yield on next two lines + assert(a == 10) + return ... + end) + + assert(coroutine.resume(c, 1, 2, 3)) -- start coroutine + local n,v = debug.getlocal(c, 0, 1) -- check its local + assert(n == "a" and v == 1) + n,v = debug.getlocal(c, 0, -1) -- check varargs + assert(v == 2) + n,v = debug.getlocal(c, 0, -2) + assert(v == 3) + assert(debug.setlocal(c, 0, 1, 10)) -- test 'setlocal' + assert(debug.setlocal(c, 0, -2, 20)) + local t = debug.getinfo(c, 0) -- test 'getinfo' + assert(t.currentline == t.linedefined + 1) + assert(not debug.getinfo(c, 1)) -- no other level + assert(coroutine.resume(c)) -- run next line + v = {coroutine.resume(c)} -- finish coroutine + assert(v[1] == true and v[2] == 2 and v[3] == 20 and v[4] == nil) + assert(not coroutine.resume(c)) + end + + do + -- testing debug library on last function in a suspended coroutine + -- (bug in 5.2/5.3) + local c = coroutine.create(function () T.testC("yield 1", 10, 20) end) + local a, b = coroutine.resume(c) + assert(a and b == 20) + assert(debug.getinfo(c, 0).linedefined == -1) + a, b = debug.getlocal(c, 0, 2) + assert(b == 10) + end + + + print "testing coroutine API" + + -- reusing a thread + assert(T.testC([[ + newthread # create thread + pushvalue 2 # push body + pushstring 'a a a' # push argument + xmove 0 3 2 # move values to new thread + resume -1, 1 # call it first time + pushstatus + xmove 3 0 0 # move results back to stack + setglobal X # result + setglobal Y # status + pushvalue 2 # push body (to call it again) + pushstring 'b b b' + xmove 0 3 2 + resume -1, 1 # call it again + pushstatus + xmove 3 0 0 + return 1 # return result + ]], function (...) return ... end) == 'b b b') + + assert(X == 'a a a' and Y == 'OK') + + + -- resuming running coroutine + C = coroutine.create(function () + return T.testC([[ + pushnum 10; + pushnum 20; + resume -3 2; + pushstatus + gettop; + return 3]], C) + end) + local a, b, c, d = coroutine.resume(C) + assert(a == true and string.find(b, "non%-suspended") and + c == "ERRRUN" and d == 4) + + a, b, c, d = T.testC([[ + rawgeti R 1 # get main thread + pushnum 10; + pushnum 20; + resume -3 2; + pushstatus + gettop; + return 4]]) + assert(a == coroutine.running() and string.find(b, "non%-suspended") and + c == "ERRRUN" and d == 4) + + + -- using a main thread as a coroutine + local state = T.newstate() + T.loadlib(state) + + assert(T.doremote(state, [[ + coroutine = require'coroutine'; + X = function (x) coroutine.yield(x, 'BB'); return 'CC' end; + return 'ok']])) + + t = table.pack(T.testC(state, [[ + rawgeti R 1 # get main thread + pushstring 'XX' + getglobal X # get function for body + pushstring AA # arg + resume 1 1 # 'resume' shadows previous stack! + gettop + setglobal T # top + setglobal B # second yielded value + setglobal A # fist yielded value + rawgeti R 1 # get main thread + pushnum 5 # arg (noise) + resume 1 1 # after coroutine ends, previous stack is back + pushstatus + return * + ]])) + assert(t.n == 4 and t[2] == 'XX' and t[3] == 'CC' and t[4] == 'OK') + assert(T.doremote(state, "return T") == '2') + assert(T.doremote(state, "return A") == 'AA') + assert(T.doremote(state, "return B") == 'BB') + + T.closestate(state) + + print'+' + +end + + +-- leaving a pending coroutine open +_X = coroutine.wrap(function () + local a = 10 + local x = function () a = a+1 end + coroutine.yield() + end) + +_X() + + +if not _soft then + -- bug (stack overflow) + local j = 2^9 + local lim = 1000000 -- (C stack limit; assume 32-bit machine) + local t = {lim - 10, lim - 5, lim - 1, lim, lim + 1} + for i = 1, #t do + local j = t[i] + co = coroutine.create(function() + local t = {} + for i = 1, j do t[i] = i end + return table.unpack(t) + end) + local r, msg = coroutine.resume(co) + assert(not r) + end + co = nil +end + + +assert(coroutine.running() == main) + +print"+" + + +print"testing yields inside metamethods" + +local mt = { + __eq = function(a,b) coroutine.yield(nil, "eq"); return a.x == b.x end, + __lt = function(a,b) coroutine.yield(nil, "lt"); return a.x < b.x end, + __le = function(a,b) coroutine.yield(nil, "le"); return a - b <= 0 end, + __add = function(a,b) coroutine.yield(nil, "add"); return a.x + b.x end, + __sub = function(a,b) coroutine.yield(nil, "sub"); return a.x - b.x end, + __mod = function(a,b) coroutine.yield(nil, "mod"); return a.x % b.x end, + __unm = function(a,b) coroutine.yield(nil, "unm"); return -a.x end, + __bnot = function(a,b) coroutine.yield(nil, "bnot"); return ~a.x end, + __shl = function(a,b) coroutine.yield(nil, "shl"); return a.x << b.x end, + __shr = function(a,b) coroutine.yield(nil, "shr"); return a.x >> b.x end, + __band = function(a,b) + a = type(a) == "table" and a.x or a + b = type(b) == "table" and b.x or b + coroutine.yield(nil, "band") + return a & b + end, + __bor = function(a,b) coroutine.yield(nil, "bor"); return a.x | b.x end, + __bxor = function(a,b) coroutine.yield(nil, "bxor"); return a.x ~ b.x end, + + __concat = function(a,b) + coroutine.yield(nil, "concat"); + a = type(a) == "table" and a.x or a + b = type(b) == "table" and b.x or b + return a .. b + end, + __index = function (t,k) coroutine.yield(nil, "idx"); return t.k[k] end, + __newindex = function (t,k,v) coroutine.yield(nil, "nidx"); t.k[k] = v end, +} + + +local function new (x) + return setmetatable({x = x, k = {}}, mt) +end + + +local a = new(10) +local b = new(12) +local c = new"hello" + +local function run (f, t) + local i = 1 + local c = coroutine.wrap(f) + while true do + local res, stat = c() + if res then assert(t[i] == nil); return res, t end + assert(stat == t[i]) + i = i + 1 + end +end + + +assert(run(function () if (a>=b) then return '>=' else return '<' end end, + {"le", "sub"}) == "<") +-- '<=' using '<' +mt.__le = nil +assert(run(function () if (a<=b) then return '<=' else return '>' end end, + {"lt"}) == "<=") +assert(run(function () if (a==b) then return '==' else return '~=' end end, + {"eq"}) == "~=") + +assert(run(function () return a & b + a end, {"add", "band"}) == 2) + +assert(run(function () return a % b end, {"mod"}) == 10) + +assert(run(function () return ~a & b end, {"bnot", "band"}) == ~10 & 12) +assert(run(function () return a | b end, {"bor"}) == 10 | 12) +assert(run(function () return a ~ b end, {"bxor"}) == 10 ~ 12) +assert(run(function () return a << b end, {"shl"}) == 10 << 12) +assert(run(function () return a >> b end, {"shr"}) == 10 >> 12) + +assert(run(function () return a..b end, {"concat"}) == "1012") + +assert(run(function() return a .. b .. c .. a end, + {"concat", "concat", "concat"}) == "1012hello10") + +assert(run(function() return "a" .. "b" .. a .. "c" .. c .. b .. "x" end, + {"concat", "concat", "concat"}) == "ab10chello12x") + + +do -- a few more tests for comparsion operators + local mt1 = { + __le = function (a,b) + coroutine.yield(10) + return + (type(a) == "table" and a.x or a) <= (type(b) == "table" and b.x or b) + end, + __lt = function (a,b) + coroutine.yield(10) + return + (type(a) == "table" and a.x or a) < (type(b) == "table" and b.x or b) + end, + } + local mt2 = { __lt = mt1.__lt } -- no __le + + local function run (f) + local co = coroutine.wrap(f) + local res + repeat + res = co() + until res ~= 10 + return res + end + + local function test () + local a1 = setmetatable({x=1}, mt1) + local a2 = setmetatable({x=2}, mt2) + assert(a1 < a2) + assert(a1 <= a2) + assert(1 < a2) + assert(1 <= a2) + assert(2 > a1) + assert(2 >= a2) + return true + end + + run(test) + +end + +assert(run(function () + a.BB = print + return a.BB + end, {"nidx", "idx"}) == print) + +-- getuptable & setuptable +do local _ENV = _ENV + f = function () AAA = BBB + 1; return AAA end +end +g = new(10); g.k.BBB = 10; +debug.setupvalue(f, 1, g) +assert(run(f, {"idx", "nidx", "idx"}) == 11) +assert(g.k.AAA == 11) + +print"+" + +print"testing yields inside 'for' iterators" + +local f = function (s, i) + if i%2 == 0 then coroutine.yield(nil, "for") end + if i < s then return i + 1 end + end + +assert(run(function () + local s = 0 + for i in f, 4, 0 do s = s + i end + return s + end, {"for", "for", "for"}) == 10) + + + +-- tests for coroutine API +if T==nil then + (Message or print)('\n >>> testC not active: skipping coroutine API tests <<<\n') + return +end + +print('testing coroutine API') + +local function apico (...) + local x = {...} + return coroutine.wrap(function () + return T.testC(table.unpack(x)) + end) +end + +local a = {apico( +[[ + pushstring errorcode + pcallk 1 0 2; + invalid command (should not arrive here) +]], +[[return *]], +"stackmark", +error +)()} +assert(#a == 4 and + a[3] == "stackmark" and + a[4] == "errorcode" and + _G.status == "ERRRUN" and + _G.ctx == 2) -- 'ctx' to pcallk + +local co = apico( + "pushvalue 2; pushnum 10; pcallk 1 2 3; invalid command;", + coroutine.yield, + "getglobal status; getglobal ctx; pushvalue 2; pushstring a; pcallk 1 0 4; invalid command", + "getglobal status; getglobal ctx; return *") + +assert(co() == 10) +assert(co(20, 30) == 'a') +a = {co()} +assert(#a == 10 and + a[2] == coroutine.yield and + a[5] == 20 and a[6] == 30 and + a[7] == "YIELD" and a[8] == 3 and + a[9] == "YIELD" and a[10] == 4) +assert(not pcall(co)) -- coroutine is dead now + + +f = T.makeCfunc("pushnum 3; pushnum 5; yield 1;") +co = coroutine.wrap(function () + assert(f() == 23); assert(f() == 23); return 10 +end) +assert(co(23,16) == 5) +assert(co(23,16) == 5) +assert(co(23,16) == 10) + + +-- testing coroutines with C bodies +f = T.makeCfunc([[ + pushnum 102 + yieldk 1 U2 + cannot be here! +]], +[[ # continuation + pushvalue U3 # accessing upvalues inside a continuation + pushvalue U4 + return * +]], 23, "huu") + +x = coroutine.wrap(f) +assert(x() == 102) +eqtab({x()}, {23, "huu"}) + + +f = T.makeCfunc[[pushstring 'a'; pushnum 102; yield 2; ]] + +a, b, c, d = T.testC([[newthread; pushvalue 2; xmove 0 3 1; resume 3 0; + pushstatus; xmove 3 0 0; resume 3 0; pushstatus; + return 4; ]], f) + +assert(a == 'YIELD' and b == 'a' and c == 102 and d == 'OK') + + +-- testing chain of suspendable C calls + +local count = 3 -- number of levels + +f = T.makeCfunc([[ + remove 1; # remove argument + pushvalue U3; # get selection function + call 0 1; # call it (result is 'f' or 'yield') + pushstring hello # single argument for selected function + pushupvalueindex 2; # index of continuation program + callk 1 -1 .; # call selected function + errorerror # should never arrive here +]], +[[ + # continuation program + pushnum 34 # return value + return * # return all results +]], +function () -- selection function + count = count - 1 + if count == 0 then return coroutine.yield + else return f + end +end +) + +co = coroutine.wrap(function () return f(nil) end) +assert(co() == "hello") -- argument to 'yield' +a = {co()} +-- three '34's (one from each pending C call) +assert(#a == 3 and a[1] == a[2] and a[2] == a[3] and a[3] == 34) + + +-- testing yields with continuations + +co = coroutine.wrap(function (...) return + T.testC([[ # initial function + yieldk 1 2 + cannot be here! + ]], + [[ # 1st continuation + yieldk 0 3 + cannot be here! + ]], + [[ # 2nd continuation + yieldk 0 4 + cannot be here! + ]], + [[ # 3th continuation + pushvalue 6 # function which is last arg. to 'testC' here + pushnum 10; pushnum 20; + pcall 2 0 0 # call should throw an error and return to next line + pop 1 # remove error message + pushvalue 6 + getglobal status; getglobal ctx + pcallk 2 2 5 # call should throw an error and jump to continuation + cannot be here! + ]], + [[ # 4th (and last) continuation + return * + ]], + -- function called by 3th continuation + function (a,b) x=a; y=b; error("errmsg") end, + ... +) +end) + +local a = {co(3,4,6)} +assert(a[1] == 6 and a[2] == nil) +a = {co()}; assert(a[1] == nil and _G.status == "YIELD" and _G.ctx == 2) +a = {co()}; assert(a[1] == nil and _G.status == "YIELD" and _G.ctx == 3) +a = {co(7,8)}; +-- original arguments +assert(type(a[1]) == 'string' and type(a[2]) == 'string' and + type(a[3]) == 'string' and type(a[4]) == 'string' and + type(a[5]) == 'string' and type(a[6]) == 'function') +-- arguments left from fist resume +assert(a[7] == 3 and a[8] == 4) +-- arguments to last resume +assert(a[9] == 7 and a[10] == 8) +-- error message and nothing more +assert(a[11]:find("errmsg") and #a == 11) +-- check arguments to pcallk +assert(x == "YIELD" and y == 4) + +assert(not pcall(co)) -- coroutine should be dead + + +-- bug in nCcalls +local co = coroutine.wrap(function () + local a = {pcall(pcall,pcall,pcall,pcall,pcall,pcall,pcall,error,"hi")} + return pcall(assert, table.unpack(a)) +end) + +local a = {co()} +assert(a[10] == "hi") + +print'OK' diff --git a/tests/lua-5.3/db.lua b/tests/lua-5.3/db.lua new file mode 100644 index 0000000..004f57a --- /dev/null +++ b/tests/lua-5.3/db.lua @@ -0,0 +1,857 @@ +-- $Id: db.lua,v 1.79 2016/11/07 13:02:34 roberto Exp $ +-- See Copyright Notice in file all.lua + +-- testing debug library + +local debug = require "debug" + +local function dostring(s) return assert(load(s))() end + +print"testing debug library and debug information" + +do +local a=1 +end + +assert(not debug.gethook()) + +local testline = 19 -- line where 'test' is defined +function test (s, l, p) -- this must be line 19 + collectgarbage() -- avoid gc during trace + local function f (event, line) + assert(event == 'line') + local l = table.remove(l, 1) + if p then print(l, line) end + assert(l == line, "wrong trace!!") + end + debug.sethook(f,"l"); load(s)(); debug.sethook() + assert(#l == 0) +end + + +do + assert(not pcall(debug.getinfo, print, "X")) -- invalid option + assert(not debug.getinfo(1000)) -- out of range level + assert(not debug.getinfo(-1)) -- out of range level + local a = debug.getinfo(print) + assert(a.what == "C" and a.short_src == "[C]") + a = debug.getinfo(print, "L") + assert(a.activelines == nil) + local b = debug.getinfo(test, "SfL") + assert(b.name == nil and b.what == "Lua" and b.linedefined == testline and + b.lastlinedefined == b.linedefined + 10 and + b.func == test and not string.find(b.short_src, "%[")) + assert(b.activelines[b.linedefined + 1] and + b.activelines[b.lastlinedefined]) + assert(not b.activelines[b.linedefined] and + not b.activelines[b.lastlinedefined + 1]) +end + + +-- test file and string names truncation +a = "function f () end" +local function dostring (s, x) return load(s, x)() end +dostring(a) +assert(debug.getinfo(f).short_src == string.format('[string "%s"]', a)) +dostring(a..string.format("; %s\n=1", string.rep('p', 400))) +assert(string.find(debug.getinfo(f).short_src, '^%[string [^\n]*%.%.%."%]$')) +dostring(a..string.format("; %s=1", string.rep('p', 400))) +assert(string.find(debug.getinfo(f).short_src, '^%[string [^\n]*%.%.%."%]$')) +dostring("\n"..a) +assert(debug.getinfo(f).short_src == '[string "..."]') +dostring(a, "") +assert(debug.getinfo(f).short_src == '[string ""]') +dostring(a, "@xuxu") +assert(debug.getinfo(f).short_src == "xuxu") +dostring(a, "@"..string.rep('p', 1000)..'t') +assert(string.find(debug.getinfo(f).short_src, "^%.%.%.p*t$")) +dostring(a, "=xuxu") +assert(debug.getinfo(f).short_src == "xuxu") +dostring(a, string.format("=%s", string.rep('x', 500))) +assert(string.find(debug.getinfo(f).short_src, "^x*$")) +dostring(a, "=") +assert(debug.getinfo(f).short_src == "") +a = nil; f = nil; + + +repeat + local g = {x = function () + local a = debug.getinfo(2) + assert(a.name == 'f' and a.namewhat == 'local') + a = debug.getinfo(1) + assert(a.name == 'x' and a.namewhat == 'field') + return 'xixi' + end} + local f = function () return 1+1 and (not 1 or g.x()) end + assert(f() == 'xixi') + g = debug.getinfo(f) + assert(g.what == "Lua" and g.func == f and g.namewhat == "" and not g.name) + + function f (x, name) -- local! + name = name or 'f' + local a = debug.getinfo(1) + assert(a.name == name and a.namewhat == 'local') + return x + end + + -- breaks in different conditions + if 3>4 then break end; f() + if 3<4 then a=1 else break end; f() + while 1 do local x=10; break end; f() + local b = 1 + if 3>4 then return math.sin(1) end; f() + a = 3<4; f() + a = 3<4 or 1; f() + repeat local x=20; if 4>3 then f() else break end; f() until 1 + g = {} + f(g).x = f(2) and f(10)+f(9) + assert(g.x == f(19)) + function g(x) if not x then return 3 end return (x('a', 'x')) end + assert(g(f) == 'a') +until 1 + +test([[if +math.sin(1) +then + a=1 +else + a=2 +end +]], {2,3,4,7}) + +test([[-- +if nil then + a=1 +else + a=2 +end +]], {2,5,6}) + +test([[a=1 +repeat + a=a+1 +until a==3 +]], {1,3,4,3,4}) + +test([[ do + return +end +]], {2}) + +test([[local a +a=1 +while a<=3 do + a=a+1 +end +]], {1,2,3,4,3,4,3,4,3,5}) + +test([[while math.sin(1) do + if math.sin(1) + then break + end +end +a=1]], {1,2,3,6}) + +test([[for i=1,3 do + a=i +end +]], {1,2,1,2,1,2,1,3}) + +test([[for i,v in pairs{'a','b'} do + a=tostring(i) .. v +end +]], {1,2,1,2,1,3}) + +test([[for i=1,4 do a=1 end]], {1,1,1,1,1}) + + + +print'+' + +-- invalid levels in [gs]etlocal +assert(not pcall(debug.getlocal, 20, 1)) +assert(not pcall(debug.setlocal, -1, 1, 10)) + + +-- parameter names +local function foo (a,b,...) local d, e end +local co = coroutine.create(foo) + +assert(debug.getlocal(foo, 1) == 'a') +assert(debug.getlocal(foo, 2) == 'b') +assert(not debug.getlocal(foo, 3)) +assert(debug.getlocal(co, foo, 1) == 'a') +assert(debug.getlocal(co, foo, 2) == 'b') +assert(not debug.getlocal(co, foo, 3)) + +assert(not debug.getlocal(print, 1)) + + +-- varargs +local function foo (a, ...) + local t = table.pack(...) + for i = 1, t.n do + local n, v = debug.getlocal(1, -i) + assert(n == "(*vararg)" and v == t[i]) + end + assert(not debug.getlocal(1, -(t.n + 1))) + assert(not debug.setlocal(1, -(t.n + 1), 30)) + if t.n > 0 then + (function (x) + assert(debug.setlocal(2, -1, x) == "(*vararg)") + assert(debug.setlocal(2, -t.n, x) == "(*vararg)") + end)(430) + assert(... == 430) + end +end + +foo() +foo(print) +foo(200, 3, 4) +local a = {} +for i = 1, (_soft and 100 or 1000) do a[i] = i end +foo(table.unpack(a)) +a = nil + +-- access to vararg in non-vararg function +local function foo () return debug.getlocal(1, -1) end +assert(not foo(10)) + + +do -- test hook presence in debug info + assert(not debug.gethook()) + local count = 0 + local function f () + assert(debug.getinfo(1).namewhat == "hook") + local sndline = string.match(debug.traceback(), "\n(.-)\n") + assert(string.find(sndline, "hook")) + count = count + 1 + end + debug.sethook(f, "l") + local a = 0 + _ENV.a = a + a = 1 + debug.sethook() + assert(count == 4) +end + + +a = {}; L = nil +local glob = 1 +local oldglob = glob +debug.sethook(function (e,l) + collectgarbage() -- force GC during a hook + local f, m, c = debug.gethook() + assert(m == 'crl' and c == 0) + if e == "line" then + if glob ~= oldglob then + L = l-1 -- get the first line where "glob" has changed + oldglob = glob + end + elseif e == "call" then + local f = debug.getinfo(2, "f").func + a[f] = 1 + else assert(e == "return") + end +end, "crl") + + +function f(a,b) + collectgarbage() + local _, x = debug.getlocal(1, 1) + local _, y = debug.getlocal(1, 2) + assert(x == a and y == b) + assert(debug.setlocal(2, 3, "pera") == "AA".."AA") + assert(debug.setlocal(2, 4, "maçã") == "B") + x = debug.getinfo(2) + assert(x.func == g and x.what == "Lua" and x.name == 'g' and + x.nups == 2 and string.find(x.source, "^@.*db%.lua$")) + glob = glob+1 + assert(debug.getinfo(1, "l").currentline == L+1) + assert(debug.getinfo(1, "l").currentline == L+2) +end + +function foo() + glob = glob+1 + assert(debug.getinfo(1, "l").currentline == L+1) +end; foo() -- set L +-- check line counting inside strings and empty lines + +_ = 'alo\ +alo' .. [[ + +]] +--[[ +]] +assert(debug.getinfo(1, "l").currentline == L+11) -- check count of lines + + +function g(...) + local arg = {...} + do local a,b,c; a=math.sin(40); end + local feijao + local AAAA,B = "xuxu", "mamão" + f(AAAA,B) + assert(AAAA == "pera" and B == "maçã") + do + local B = 13 + local x,y = debug.getlocal(1,5) + assert(x == 'B' and y == 13) + end +end + +g() + + +assert(a[f] and a[g] and a[assert] and a[debug.getlocal] and not a[print]) + + +-- tests for manipulating non-registered locals (C and Lua temporaries) + +local n, v = debug.getlocal(0, 1) +assert(v == 0 and n == "(*temporary)") +local n, v = debug.getlocal(0, 2) +assert(v == 2 and n == "(*temporary)") +assert(not debug.getlocal(0, 3)) +assert(not debug.getlocal(0, 0)) + +function f() + assert(select(2, debug.getlocal(2,3)) == 1) + assert(not debug.getlocal(2,4)) + debug.setlocal(2, 3, 10) + return 20 +end + +function g(a,b) return (a+1) + f() end + +assert(g(0,0) == 30) + + +debug.sethook(nil); +assert(debug.gethook() == nil) + + +-- testing access to function arguments + +local function collectlocals (level) + local tab = {} + for i = 1, math.huge do + local n, v = debug.getlocal(level + 1, i) + if not (n and string.find(n, "^[a-zA-Z0-9_]+$")) then + break -- consider only real variables + end + tab[n] = v + end + return tab +end + + +X = nil +a = {} +function a:f (a, b, ...) local arg = {...}; local c = 13 end +debug.sethook(function (e) + assert(e == "call") + dostring("XX = 12") -- test dostring inside hooks + -- testing errors inside hooks + assert(not pcall(load("a='joao'+1"))) + debug.sethook(function (e, l) + assert(debug.getinfo(2, "l").currentline == l) + local f,m,c = debug.gethook() + assert(e == "line") + assert(m == 'l' and c == 0) + debug.sethook(nil) -- hook is called only once + assert(not X) -- check that + X = collectlocals(2) + end, "l") +end, "c") + +a:f(1,2,3,4,5) +assert(X.self == a and X.a == 1 and X.b == 2 and X.c == nil) +assert(XX == 12) +assert(debug.gethook() == nil) + + +-- testing access to local variables in return hook (bug in 5.2) +do + local function foo (a, b) + do local x,y,z end + local c, d = 10, 20 + return + end + + local function aux () + if debug.getinfo(2).name == "foo" then + foo = nil -- to signal that it found 'foo' + local tab = {a = 100, b = 200, c = 10, d = 20} + for n, v in pairs(collectlocals(2)) do + assert(tab[n] == v) + tab[n] = nil + end + assert(next(tab) == nil) -- 'tab' must be empty + end + end + + debug.sethook(aux, "r"); foo(100, 200); debug.sethook() + assert(foo == nil) +end + +-- testing upvalue access +local function getupvalues (f) + local t = {} + local i = 1 + while true do + local name, value = debug.getupvalue(f, i) + if not name then break end + assert(not t[name]) + t[name] = value + i = i + 1 + end + return t +end + +local a,b,c = 1,2,3 +local function foo1 (a) b = a; return c end +local function foo2 (x) a = x; return c+b end +assert(not debug.getupvalue(foo1, 3)) +assert(not debug.getupvalue(foo1, 0)) +assert(not debug.setupvalue(foo1, 3, "xuxu")) +local t = getupvalues(foo1) +assert(t.a == nil and t.b == 2 and t.c == 3) +t = getupvalues(foo2) +assert(t.a == 1 and t.b == 2 and t.c == 3) +assert(debug.setupvalue(foo1, 1, "xuxu") == "b") +assert(({debug.getupvalue(foo2, 3)})[2] == "xuxu") +-- upvalues of C functions are allways "called" "" (the empty string) +assert(debug.getupvalue(string.gmatch("x", "x"), 1) == "") + + +-- testing count hooks +local a=0 +debug.sethook(function (e) a=a+1 end, "", 1) +a=0; for i=1,1000 do end; assert(1000 < a and a < 1012) +debug.sethook(function (e) a=a+1 end, "", 4) +a=0; for i=1,1000 do end; assert(250 < a and a < 255) +local f,m,c = debug.gethook() +assert(m == "" and c == 4) +debug.sethook(function (e) a=a+1 end, "", 4000) +a=0; for i=1,1000 do end; assert(a == 0) + +do + debug.sethook(print, "", 2^24 - 1) -- count upperbound + local f,m,c = debug.gethook() + assert(({debug.gethook()})[3] == 2^24 - 1) +end + +debug.sethook() + + +-- tests for tail calls +local function f (x) + if x then + assert(debug.getinfo(1, "S").what == "Lua") + assert(debug.getinfo(1, "t").istailcall == true) + local tail = debug.getinfo(2) + assert(tail.func == g1 and tail.istailcall == true) + assert(debug.getinfo(3, "S").what == "main") + print"+" + end +end + +function g(x) return f(x) end + +function g1(x) g(x) end + +local function h (x) local f=g1; return f(x) end + +h(true) + +local b = {} +debug.sethook(function (e) table.insert(b, e) end, "cr") +h(false) +debug.sethook() +local res = {"return", -- first return (from sethook) + "call", "tail call", "call", "tail call", + "return", "return", + "call", -- last call (to sethook) +} +for i = 1, #res do assert(res[i] == table.remove(b, 1)) end + +b = 0 +debug.sethook(function (e) + if e == "tail call" then + b = b + 1 + assert(debug.getinfo(2, "t").istailcall == true) + else + assert(debug.getinfo(2, "t").istailcall == false) + end + end, "c") +h(false) +debug.sethook() +assert(b == 2) -- two tail calls + +lim = _soft and 3000 or 30000 +local function foo (x) + if x==0 then + assert(debug.getinfo(2).what == "main") + local info = debug.getinfo(1) + assert(info.istailcall == true and info.func == foo) + else return foo(x-1) + end +end + +foo(lim) + + +print"+" + + +-- testing local function information +co = load[[ + local A = function () + return x + end + return +]] + +local a = 0 +-- 'A' should be visible to debugger only after its complete definition +debug.sethook(function (e, l) + if l == 3 then a = a + 1; assert(debug.getlocal(2, 1) == "(*temporary)") + elseif l == 4 then a = a + 1; assert(debug.getlocal(2, 1) == "A") + end +end, "l") +co() -- run local function definition +debug.sethook() -- turn off hook +assert(a == 2) -- ensure all two lines where hooked + +-- testing traceback + +assert(debug.traceback(print) == print) +assert(debug.traceback(print, 4) == print) +assert(string.find(debug.traceback("hi", 4), "^hi\n")) +assert(string.find(debug.traceback("hi"), "^hi\n")) +assert(not string.find(debug.traceback("hi"), "'debug.traceback'")) +assert(string.find(debug.traceback("hi", 0), "'debug.traceback'")) +assert(string.find(debug.traceback(), "^stack traceback:\n")) + +do -- C-function names in traceback + local st, msg = (function () return pcall end)()(debug.traceback) + assert(st == true and string.find(msg, "pcall")) +end + + +-- testing nparams, nups e isvararg +local t = debug.getinfo(print, "u") +assert(t.isvararg == true and t.nparams == 0 and t.nups == 0) + +t = debug.getinfo(function (a,b,c) end, "u") +assert(t.isvararg == false and t.nparams == 3 and t.nups == 0) + +t = debug.getinfo(function (a,b,...) return t[a] end, "u") +assert(t.isvararg == true and t.nparams == 2 and t.nups == 1) + +t = debug.getinfo(1) -- main +assert(t.isvararg == true and t.nparams == 0 and t.nups == 1 and + debug.getupvalue(t.func, 1) == "_ENV") + + + + +-- testing debugging of coroutines + +local function checktraceback (co, p, level) + local tb = debug.traceback(co, nil, level) + local i = 0 + for l in string.gmatch(tb, "[^\n]+\n?") do + assert(i == 0 or string.find(l, p[i])) + i = i+1 + end + assert(p[i] == nil) +end + + +local function f (n) + if n > 0 then f(n-1) + else coroutine.yield() end +end + +local co = coroutine.create(f) +coroutine.resume(co, 3) +checktraceback(co, {"yield", "db.lua", "db.lua", "db.lua", "db.lua"}) +checktraceback(co, {"db.lua", "db.lua", "db.lua", "db.lua"}, 1) +checktraceback(co, {"db.lua", "db.lua", "db.lua"}, 2) +checktraceback(co, {"db.lua"}, 4) +checktraceback(co, {}, 40) + + +co = coroutine.create(function (x) + local a = 1 + coroutine.yield(debug.getinfo(1, "l")) + coroutine.yield(debug.getinfo(1, "l").currentline) + return a + end) + +local tr = {} +local foo = function (e, l) if l then table.insert(tr, l) end end +debug.sethook(co, foo, "lcr") + +local _, l = coroutine.resume(co, 10) +local x = debug.getinfo(co, 1, "lfLS") +assert(x.currentline == l.currentline and x.activelines[x.currentline]) +assert(type(x.func) == "function") +for i=x.linedefined + 1, x.lastlinedefined do + assert(x.activelines[i]) + x.activelines[i] = nil +end +assert(next(x.activelines) == nil) -- no 'extra' elements +assert(not debug.getinfo(co, 2)) +local a,b = debug.getlocal(co, 1, 1) +assert(a == "x" and b == 10) +a,b = debug.getlocal(co, 1, 2) +assert(a == "a" and b == 1) +debug.setlocal(co, 1, 2, "hi") +assert(debug.gethook(co) == foo) +assert(#tr == 2 and + tr[1] == l.currentline-1 and tr[2] == l.currentline) + +a,b,c = pcall(coroutine.resume, co) +assert(a and b and c == l.currentline+1) +checktraceback(co, {"yield", "in function <"}) + +a,b = coroutine.resume(co) +assert(a and b == "hi") +assert(#tr == 4 and tr[4] == l.currentline+2) +assert(debug.gethook(co) == foo) +assert(not debug.gethook()) +checktraceback(co, {}) + + +-- check get/setlocal in coroutines +co = coroutine.create(function (x) + local a, b = coroutine.yield(x) + assert(a == 100 and b == nil) + return x +end) +a, b = coroutine.resume(co, 10) +assert(a and b == 10) +a, b = debug.getlocal(co, 1, 1) +assert(a == "x" and b == 10) +assert(not debug.getlocal(co, 1, 5)) +assert(debug.setlocal(co, 1, 1, 30) == "x") +assert(not debug.setlocal(co, 1, 5, 40)) +a, b = coroutine.resume(co, 100) +assert(a and b == 30) + + +-- check traceback of suspended (or dead with error) coroutines + +function f(i) if i==0 then error(i) else coroutine.yield(); f(i-1) end end + +co = coroutine.create(function (x) f(x) end) +a, b = coroutine.resume(co, 3) +t = {"'coroutine.yield'", "'f'", "in function <"} +while coroutine.status(co) == "suspended" do + checktraceback(co, t) + a, b = coroutine.resume(co) + table.insert(t, 2, "'f'") -- one more recursive call to 'f' +end +t[1] = "'error'" +checktraceback(co, t) + + +-- test acessing line numbers of a coroutine from a resume inside +-- a C function (this is a known bug in Lua 5.0) + +local function g(x) + coroutine.yield(x) +end + +local function f (i) + debug.sethook(function () end, "l") + for j=1,1000 do + g(i+j) + end +end + +local co = coroutine.wrap(f) +co(10) +pcall(co) +pcall(co) + + +assert(type(debug.getregistry()) == "table") + + +-- test tagmethod information +local a = {} +local function f (t) + local info = debug.getinfo(1); + assert(info.namewhat == "metamethod") + a.op = info.name + return info.name +end +setmetatable(a, { + __index = f; __add = f; __div = f; __mod = f; __concat = f; __pow = f; + __mul = f; __idiv = f; __unm = f; __len = f; __sub = f; + __shl = f; __shr = f; __bor = f; __bxor = f; + __eq = f; __le = f; __lt = f; __unm = f; __len = f; __band = f; + __bnot = f; +}) + +local b = setmetatable({}, getmetatable(a)) + +assert(a[3] == "__index" and a^3 == "__pow" and a..a == "__concat") +assert(a/3 == "__div" and 3%a == "__mod") +assert(a+3 == "__add" and 3-a == "__sub" and a*3 == "__mul" and + -a == "__unm" and #a == "__len" and a&3 == "__band") +assert(a|3 == "__bor" and 3~a == "__bxor" and a<<3 == "__shl" and + a>>1 == "__shr") +assert (a==b and a.op == "__eq") +assert (a>=b and a.op == "__le") +assert (a>b and a.op == "__lt") +assert(~a == "__bnot") + +do -- testing for-iterator name + local function f() + assert(debug.getinfo(1).name == "for iterator") + end + + for i in f do end +end + + +do -- testing debug info for finalizers + local name = nil + + -- create a piece of garbage with a finalizer + setmetatable({}, {__gc = function () + local t = debug.getinfo(2) -- get callee information + assert(t.namewhat == "metamethod") + name = t.name + end}) + + -- repeat until previous finalizer runs (setting 'name') + repeat local a = {} until name + assert(name == "__gc") +end + + +do + print("testing traceback sizes") + + local function countlines (s) + return select(2, string.gsub(s, "\n", "")) + end + + local function deep (lvl, n) + if lvl == 0 then + return (debug.traceback("message", n)) + else + return (deep(lvl-1, n)) + end + end + + local function checkdeep (total, start) + local s = deep(total, start) + local rest = string.match(s, "^message\nstack traceback:\n(.*)$") + local cl = countlines(rest) + -- at most 10 lines in first part, 11 in second, plus '...' + assert(cl <= 10 + 11 + 1) + local brk = string.find(rest, "%.%.%.") + if brk then -- does message have '...'? + local rest1 = string.sub(rest, 1, brk) + local rest2 = string.sub(rest, brk, #rest) + assert(countlines(rest1) == 10 and countlines(rest2) == 11) + else + assert(cl == total - start + 2) + end + end + + for d = 1, 51, 10 do + for l = 1, d do + -- use coroutines to ensure complete control of the stack + coroutine.wrap(checkdeep)(d, l) + end + end + +end + + +print("testing debug functions on chunk without debug info") +prog = [[-- program to be loaded without debug information +local debug = require'debug' +local a = 12 -- a local variable + +local n, v = debug.getlocal(1, 1) +assert(n == "(*temporary)" and v == debug) -- unkown name but known value +n, v = debug.getlocal(1, 2) +assert(n == "(*temporary)" and v == 12) -- unkown name but known value + +-- a function with an upvalue +local f = function () local x; return a end +n, v = debug.getupvalue(f, 1) +assert(n == "(*no name)" and v == 12) +assert(debug.setupvalue(f, 1, 13) == "(*no name)") +assert(a == 13) + +local t = debug.getinfo(f) +assert(t.name == nil and t.linedefined > 0 and + t.lastlinedefined == t.linedefined and + t.short_src == "?") +assert(debug.getinfo(1).currentline == -1) + +t = debug.getinfo(f, "L").activelines +assert(next(t) == nil) -- active lines are empty + +-- dump/load a function without debug info +f = load(string.dump(f)) + +t = debug.getinfo(f) +assert(t.name == nil and t.linedefined > 0 and + t.lastlinedefined == t.linedefined and + t.short_src == "?") +assert(debug.getinfo(1).currentline == -1) + +return a +]] + + +-- load 'prog' without debug info +local f = assert(load(string.dump(load(prog), true))) + +assert(f() == 13) + +do -- tests for 'source' in binary dumps + local prog = [[ + return function (x) + return function (y) + return x + y + end + end + ]] + local name = string.rep("x", 1000) + local p = assert(load(prog, name)) + -- load 'p' as a binary chunk with debug information + local c = string.dump(p) + assert(#c > 1000 and #c < 2000) -- no repetition of 'source' in dump + local f = assert(load(c)) + local g = f() + local h = g(3) + assert(h(5) == 8) + assert(debug.getinfo(f).source == name and -- all functions have 'source' + debug.getinfo(g).source == name and + debug.getinfo(h).source == name) + -- again, without debug info + local c = string.dump(p, true) + assert(#c < 500) -- no 'source' in dump + local f = assert(load(c)) + local g = f() + local h = g(30) + assert(h(50) == 80) + assert(debug.getinfo(f).source == '=?' and -- no function has 'source' + debug.getinfo(g).source == '=?' and + debug.getinfo(h).source == '=?') +end + +print"OK" + diff --git a/tests/lua-5.3/errors.lua b/tests/lua-5.3/errors.lua new file mode 100644 index 0000000..79d746c --- /dev/null +++ b/tests/lua-5.3/errors.lua @@ -0,0 +1,537 @@ +-- $Id: errors.lua,v 1.94 2016/12/21 19:23:02 roberto Exp $ +-- See Copyright Notice in file all.lua + +print("testing errors") + +local debug = require"debug" + +-- avoid problems with 'strict' module (which may generate other error messages) +local mt = getmetatable(_G) or {} +local oldmm = mt.__index +mt.__index = nil + +local function checkerr (msg, f, ...) + local st, err = pcall(f, ...) + assert(not st and string.find(err, msg)) +end + + +local function doit (s) + local f, msg = load(s) + if f == nil then return msg end + local cond, msg = pcall(f) + return (not cond) and msg +end + + +local function checkmessage (prog, msg) + local m = doit(prog) + assert(string.find(m, msg, 1, true)) +end + +local function checksyntax (prog, extra, token, line) + local msg = doit(prog) + if not string.find(token, "^<%a") and not string.find(token, "^char%(") + then token = "'"..token.."'" end + token = string.gsub(token, "(%p)", "%%%1") + local pt = string.format([[^%%[string ".*"%%]:%d: .- near %s$]], + line, token) + assert(string.find(msg, pt)) + assert(string.find(msg, msg, 1, true)) +end + + +-- test error message with no extra info +assert(doit("error('hi', 0)") == 'hi') + +-- test error message with no info +assert(doit("error()") == nil) + + +-- test common errors/errors that crashed in the past +assert(doit("table.unpack({}, 1, n=2^30)")) +assert(doit("a=math.sin()")) +assert(not doit("tostring(1)") and doit("tostring()")) +assert(doit"tonumber()") +assert(doit"repeat until 1; a") +assert(doit"return;;") +assert(doit"assert(false)") +assert(doit"assert(nil)") +assert(doit("function a (... , ...) end")) +assert(doit("function a (, ...) end")) +assert(doit("local t={}; t = t[#t] + 1")) + +checksyntax([[ + local a = {4 + +]], "'}' expected (to close '{' at line 1)", "", 3) + + +-- tests for better error messages + +checkmessage("a = {} + 1", "arithmetic") +checkmessage("a = {} | 1", "bitwise operation") +checkmessage("a = {} < 1", "attempt to compare") +checkmessage("a = {} <= 1", "attempt to compare") + +checkmessage("a=1; bbbb=2; a=math.sin(3)+bbbb(3)", "global 'bbbb'") +checkmessage("a={}; do local a=1 end a:bbbb(3)", "method 'bbbb'") +checkmessage("local a={}; a.bbbb(3)", "field 'bbbb'") +assert(not string.find(doit"a={13}; local bbbb=1; a[bbbb](3)", "'bbbb'")) +checkmessage("a={13}; local bbbb=1; a[bbbb](3)", "number") +checkmessage("a=(1)..{}", "a table value") + +checkmessage("a = #print", "length of a function value") +checkmessage("a = #3", "length of a number value") + +aaa = nil +checkmessage("aaa.bbb:ddd(9)", "global 'aaa'") +checkmessage("local aaa={bbb=1}; aaa.bbb:ddd(9)", "field 'bbb'") +checkmessage("local aaa={bbb={}}; aaa.bbb:ddd(9)", "method 'ddd'") +checkmessage("local a,b,c; (function () a = b+1 end)()", "upvalue 'b'") +assert(not doit"local aaa={bbb={ddd=next}}; aaa.bbb:ddd(nil)") + +-- upvalues being indexed do not go to the stack +checkmessage("local a,b,cc; (function () a = cc[1] end)()", "upvalue 'cc'") +checkmessage("local a,b,cc; (function () a.x = 1 end)()", "upvalue 'a'") + +checkmessage("local _ENV = {x={}}; a = a + 1", "global 'a'") + +checkmessage("b=1; local aaa='a'; x=aaa+b", "local 'aaa'") +checkmessage("aaa={}; x=3/aaa", "global 'aaa'") +checkmessage("aaa='2'; b=nil;x=aaa*b", "global 'b'") +checkmessage("aaa={}; x=-aaa", "global 'aaa'") + +-- short circuit +checkmessage("a=1; local a,bbbb=2,3; a = math.sin(1) and bbbb(3)", + "local 'bbbb'") +checkmessage("a=1; local a,bbbb=2,3; a = bbbb(1) or a(3)", "local 'bbbb'") +checkmessage("local a,b,c,f = 1,1,1; f((a and b) or c)", "local 'f'") +checkmessage("local a,b,c = 1,1,1; ((a and b) or c)()", "call a number value") +assert(not string.find(doit"aaa={}; x=(aaa or aaa)+(aaa and aaa)", "'aaa'")) +assert(not string.find(doit"aaa={}; (aaa or aaa)()", "'aaa'")) + +checkmessage("print(print < 10)", "function with number") +checkmessage("print(print < print)", "two function values") +checkmessage("print('10' < 10)", "string with number") +checkmessage("print(10 < '23')", "number with string") + +-- float->integer conversions +checkmessage("local a = 2.0^100; x = a << 2", "local a") +checkmessage("local a = 1 >> 2.0^100", "has no integer representation") +checkmessage("local a = '10' << 2.0^100", "has no integer representation") +checkmessage("local a = 2.0^100 & 1", "has no integer representation") +checkmessage("local a = 2.0^100 & '1'", "has no integer representation") +checkmessage("local a = 2.0 | 1e40", "has no integer representation") +checkmessage("local a = 2e100 ~ 1", "has no integer representation") +checkmessage("string.sub('a', 2.0^100)", "has no integer representation") +checkmessage("string.rep('a', 3.3)", "has no integer representation") +checkmessage("return 6e40 & 7", "has no integer representation") +checkmessage("return 34 << 7e30", "has no integer representation") +checkmessage("return ~-3e40", "has no integer representation") +checkmessage("return ~-3.009", "has no integer representation") +checkmessage("return 3.009 & 1", "has no integer representation") +checkmessage("return 34 >> {}", "table value") +checkmessage("a = 24 // 0", "divide by zero") +checkmessage("a = 1 % 0", "'n%0'") + + +-- passing light userdata instead of full userdata +_G.D = debug +checkmessage([[ + -- create light udata + local x = D.upvalueid(function () return debug end, 1) + D.setuservalue(x, {}) +]], "light userdata") +_G.D = nil + +do -- named objects (field '__name') + checkmessage("math.sin(io.input())", "(number expected, got FILE*)") + _G.XX = setmetatable({}, {__name = "My Type"}) + assert(string.find(tostring(XX), "^My Type")) + checkmessage("io.input(XX)", "(FILE* expected, got My Type)") + checkmessage("return XX + 1", "on a My Type value") + checkmessage("return ~io.stdin", "on a FILE* value") + checkmessage("return XX < XX", "two My Type values") + checkmessage("return {} < XX", "table with My Type") + checkmessage("return XX < io.stdin", "My Type with FILE*") + _G.XX = nil +end + +-- global functions +checkmessage("(io.write or print){}", "io.write") +checkmessage("(collectgarbage or print){}", "collectgarbage") + +-- errors in functions without debug info +do + local f = function (a) return a + 1 end + f = assert(load(string.dump(f, true))) + assert(f(3) == 4) + checkerr("^%?:%-1:", f, {}) + + -- code with a move to a local var ('OP_MOV A B' with A3+1, + {d = x and aaa[x or y]}} +]], "global 'aaa'") + +checkmessage([[ +local x,y = {},1 +if math.sin(1) == 0 then return 3 end -- return +x.a()]], "field 'a'") + +checkmessage([[ +prefix = nil +insert = nil +while 1 do + local a + if nil then break end + insert(prefix, a) +end]], "global 'insert'") + +checkmessage([[ -- tail call + return math.sin("a") +]], "'sin'") + +checkmessage([[collectgarbage("nooption")]], "invalid option") + +checkmessage([[x = print .. "a"]], "concatenate") +checkmessage([[x = "a" .. false]], "concatenate") +checkmessage([[x = {} .. 2]], "concatenate") + +checkmessage("getmetatable(io.stdin).__gc()", "no value") + +checkmessage([[ +local Var +local function main() + NoSuchName (function() Var=0 end) +end +main() +]], "global 'NoSuchName'") +print'+' + +a = {}; setmetatable(a, {__index = string}) +checkmessage("a:sub()", "bad self") +checkmessage("string.sub('a', {})", "#2") +checkmessage("('a'):sub{}", "#1") + +checkmessage("table.sort({1,2,3}, table.sort)", "'table.sort'") +checkmessage("string.gsub('s', 's', setmetatable)", "'setmetatable'") + +-- tests for errors in coroutines + +local function f (n) + local c = coroutine.create(f) + local a,b = coroutine.resume(c) + return b +end +assert(string.find(f(), "C stack overflow")) + +checkmessage("coroutine.yield()", "outside a coroutine") + +f = coroutine.wrap(function () table.sort({1,2,3}, coroutine.yield) end) +checkerr("yield across", f) + + +-- testing size of 'source' info; size of buffer for that info is +-- LUA_IDSIZE, declared as 60 in luaconf. Get one position for '\0'. +idsize = 60 - 1 +local function checksize (source) + -- syntax error + local _, msg = load("x", source) + msg = string.match(msg, "^([^:]*):") -- get source (1st part before ':') + assert(msg:len() <= idsize) +end + +for i = 60 - 10, 60 + 10 do -- check border cases around 60 + checksize("@" .. string.rep("x", i)) -- file names + checksize(string.rep("x", i - 10)) -- string sources + checksize("=" .. string.rep("x", i)) -- exact sources +end + + +-- testing line error + +local function lineerror (s, l) + local err,msg = pcall(load(s)) + local line = string.match(msg, ":(%d+):") + assert((line and line+0) == l) +end + +lineerror("local a\n for i=1,'a' do \n print(i) \n end", 2) +lineerror("\n local a \n for k,v in 3 \n do \n print(k) \n end", 3) +lineerror("\n\n for k,v in \n 3 \n do \n print(k) \n end", 4) +lineerror("function a.x.y ()\na=a+1\nend", 1) + +lineerror("a = \na\n+\n{}", 3) +lineerror("a = \n3\n+\n(\n4\n/\nprint)", 6) +lineerror("a = \nprint\n+\n(\n4\n/\n7)", 3) + +lineerror("a\n=\n-\n\nprint\n;", 3) + +lineerror([[ +a +( +23) +]], 1) + +lineerror([[ +local a = {x = 13} +a +. +x +( +23 +) +]], 2) + +lineerror([[ +local a = {x = 13} +a +. +x +( +23 + a +) +]], 6) + +local p = [[ + function g() f() end + function f(x) error('a', X) end +g() +]] +X=3;lineerror((p), 3) +X=0;lineerror((p), nil) +X=1;lineerror((p), 2) +X=2;lineerror((p), 1) + + +if not _soft then + -- several tests that exaust the Lua stack + collectgarbage() + print"testing stack overflow" + C = 0 + local l = debug.getinfo(1, "l").currentline; function y () C=C+1; y() end + + local function checkstackmessage (m) + return (string.find(m, "^.-:%d+: stack overflow")) + end + -- repeated stack overflows (to check stack recovery) + assert(checkstackmessage(doit('y()'))) + print('+') + assert(checkstackmessage(doit('y()'))) + print('+') + assert(checkstackmessage(doit('y()'))) + print('+') + + + -- error lines in stack overflow + C = 0 + local l1 + local function g(x) + l1 = debug.getinfo(x, "l").currentline; y() + end + local _, stackmsg = xpcall(g, debug.traceback, 1) + print('+') + local stack = {} + for line in string.gmatch(stackmsg, "[^\n]*") do + local curr = string.match(line, ":(%d+):") + if curr then table.insert(stack, tonumber(curr)) end + end + local i=1 + while stack[i] ~= l1 do + assert(stack[i] == l) + i = i+1 + end + assert(i > 15) + + + -- error in error handling + local res, msg = xpcall(error, error) + assert(not res and type(msg) == 'string') + print('+') + + local function f (x) + if x==0 then error('a\n') + else + local aux = function () return f(x-1) end + local a,b = xpcall(aux, aux) + return a,b + end + end + f(3) + + local function loop (x,y,z) return 1 + loop(x, y, z) end + + local res, msg = xpcall(loop, function (m) + assert(string.find(m, "stack overflow")) + checkerr("error handling", loop) + assert(math.sin(0) == 0) + return 15 + end) + assert(msg == 15) + + local f = function () + for i = 999900, 1000000, 1 do table.unpack({}, 1, i) end + end + checkerr("too many results", f) + +end + + +do + -- non string messages + local t = {} + local res, msg = pcall(function () error(t) end) + assert(not res and msg == t) + + res, msg = pcall(function () error(nil) end) + assert(not res and msg == nil) + + local function f() error{msg='x'} end + res, msg = xpcall(f, function (r) return {msg=r.msg..'y'} end) + assert(msg.msg == 'xy') + + -- 'assert' with extra arguments + res, msg = pcall(assert, false, "X", t) + assert(not res and msg == "X") + + -- 'assert' with no message + res, msg = pcall(function () assert(false) end) + local line = string.match(msg, "%w+%.lua:(%d+): assertion failed!$") + assert(tonumber(line) == debug.getinfo(1, "l").currentline - 2) + + -- 'assert' with non-string messages + res, msg = pcall(assert, false, t) + assert(not res and msg == t) + + res, msg = pcall(assert, nil, nil) + assert(not res and msg == nil) + + -- 'assert' without arguments + res, msg = pcall(assert) + assert(not res and string.find(msg, "value expected")) +end + +-- xpcall with arguments +a, b, c = xpcall(string.find, error, "alo", "al") +assert(a and b == 1 and c == 2) +a, b, c = xpcall(string.find, function (x) return {} end, true, "al") +assert(not a and type(b) == "table" and c == nil) + + +print("testing tokens in error messages") +checksyntax("syntax error", "", "error", 1) +checksyntax("1.000", "", "1.000", 1) +checksyntax("[[a]]", "", "[[a]]", 1) +checksyntax("'aa'", "", "'aa'", 1) +checksyntax("while << do end", "", "<<", 1) +checksyntax("for >> do end", "", ">>", 1) + +-- test invalid non-printable char in a chunk +checksyntax("a\1a = 1", "", "<\\1>", 1) + +-- test 255 as first char in a chunk +checksyntax("\255a = 1", "", "<\\255>", 1) + +doit('I = load("a=9+"); a=3') +assert(a==3 and I == nil) +print('+') + +lim = 1000 +if _soft then lim = 100 end +for i=1,lim do + doit('a = ') + doit('a = 4+nil') +end + + +-- testing syntax limits + +local maxClevel = 200 -- LUAI_MAXCCALLS (in llimits.h) + +local function testrep (init, rep, close, repc) + local s = init .. string.rep(rep, maxClevel - 10) .. close .. + string.rep(repc, maxClevel - 10) + assert(load(s)) -- 190 levels is OK + s = init .. string.rep(rep, maxClevel + 1) + checkmessage(s, "too many C levels") +end + +testrep("local a; a", ",a", "= 1", ",1") -- multiple assignment +testrep("local a; a=", "{", "0", "}") +testrep("local a; a=", "(", "2", ")") +testrep("local a; ", "a(", "2", ")") +testrep("", "do ", "", " end") +testrep("", "while a do ", "", " end") +testrep("local a; ", "if a then else ", "", " end") +testrep("", "function foo () ", "", " end") +testrep("local a; a=", "a..", "a", "") +testrep("local a; a=", "a^", "a", "") + +checkmessage("a = f(x" .. string.rep(",x", 260) .. ")", "too many registers") + + +-- testing other limits + +-- upvalues +local lim = 127 +local s = "local function fooA ()\n local " +for j = 1,lim do + s = s.."a"..j..", " +end +s = s.."b,c\n" +s = s.."local function fooB ()\n local " +for j = 1,lim do + s = s.."b"..j..", " +end +s = s.."b\n" +s = s.."function fooC () return b+c" +local c = 1+2 +for j = 1,lim do + s = s.."+a"..j.."+b"..j + c = c + 2 +end +s = s.."\nend end end" +local a,b = load(s) +assert(c > 255 and string.find(b, "too many upvalues") and + string.find(b, "line 5")) + +-- local variables +s = "\nfunction foo ()\n local " +for j = 1,300 do + s = s.."a"..j..", " +end +s = s.."b\n" +local a,b = load(s) +assert(string.find(b, "line 2") and string.find(b, "too many local variables")) + +mt.__index = oldmm + +print('OK') diff --git a/tests/lua-5.3/events.lua b/tests/lua-5.3/events.lua new file mode 100644 index 0000000..463d97d --- /dev/null +++ b/tests/lua-5.3/events.lua @@ -0,0 +1,456 @@ +-- $Id: events.lua,v 1.45 2016/12/21 19:23:02 roberto Exp $ +-- See Copyright Notice in file all.lua + +print('testing metatables') + +-- local debug = require'debug' + +X = 20; B = 30 + +_ENV = setmetatable({}, {__index=_G}) + +collectgarbage() + +X = X+10 +assert(X == 30 and _G.X == 20) +B = false +assert(B == false) +B = nil +assert(B == 30) + +assert(getmetatable{} == nil) +assert(getmetatable(4) == nil) +assert(getmetatable(nil) == nil) +a={name = "NAME"}; setmetatable(a, {__metatable = "xuxu", + __tostring=function(x) return x.name end}) +assert(getmetatable(a) == "xuxu") +assert(tostring(a) == "NAME") +-- cannot change a protected metatable +assert(pcall(setmetatable, a, {}) == false) +a.name = "gororoba" +assert(tostring(a) == "gororoba") + +local a, t = {10,20,30; x="10", y="20"}, {} +assert(setmetatable(a,t) == a) +assert(getmetatable(a) == t) +assert(setmetatable(a,nil) == a) +assert(getmetatable(a) == nil) +assert(setmetatable(a,t) == a) + + +function f (t, i, e) + assert(not e) + local p = rawget(t, "parent") + return (p and p[i]+3), "dummy return" +end + +t.__index = f + +a.parent = {z=25, x=12, [4] = 24} +assert(a[1] == 10 and a.z == 28 and a[4] == 27 and a.x == "10") + +collectgarbage() + +a = setmetatable({}, t) +function f(t, i, v) rawset(t, i, v-3) end +setmetatable(t, t) -- causes a bug in 5.1 ! +t.__newindex = f +a[1] = 30; a.x = "101"; a[5] = 200 +assert(a[1] == 27 and a.x == 98 and a[5] == 197) + +do -- bug in Lua 5.3.2 + local mt = {} + mt.__newindex = mt + local t = setmetatable({}, mt) + t[1] = 10 -- will segfault on some machines + assert(mt[1] == 10) +end + + +local c = {} +a = setmetatable({}, t) +t.__newindex = c +a[1] = 10; a[2] = 20; a[3] = 90 +assert(c[1] == 10 and c[2] == 20 and c[3] == 90) + + +do + local a; + a = setmetatable({}, {__index = setmetatable({}, + {__index = setmetatable({}, + {__index = function (_,n) return a[n-3]+4, "lixo" end})})}) + a[0] = 20 + for i=0,10 do + assert(a[i*3] == 20 + i*4) + end +end + + +do -- newindex + local foi + local a = {} + for i=1,10 do a[i] = 0; a['a'..i] = 0; end + setmetatable(a, {__newindex = function (t,k,v) foi=true; rawset(t,k,v) end}) + foi = false; a[1]=0; assert(not foi) + foi = false; a['a1']=0; assert(not foi) + foi = false; a['a11']=0; assert(foi) + foi = false; a[11]=0; assert(foi) + foi = false; a[1]=nil; assert(not foi) + foi = false; a[1]=nil; assert(foi) +end + + +setmetatable(t, nil) +function f (t, ...) return t, {...} end +t.__call = f + +do + local x,y = a(table.unpack{'a', 1}) + assert(x==a and y[1]=='a' and y[2]==1 and y[3]==nil) + x,y = a() + assert(x==a and y[1]==nil) +end + + +local b = setmetatable({}, t) +setmetatable(b,t) + +function f(op) + return function (...) cap = {[0] = op, ...} ; return (...) end +end +t.__add = f("add") +t.__sub = f("sub") +t.__mul = f("mul") +t.__div = f("div") +t.__idiv = f("idiv") +t.__mod = f("mod") +t.__unm = f("unm") +t.__pow = f("pow") +t.__len = f("len") +t.__band = f("band") +t.__bor = f("bor") +t.__bxor = f("bxor") +t.__shl = f("shl") +t.__shr = f("shr") +t.__bnot = f("bnot") + +assert(b+5 == b) +assert(cap[0] == "add" and cap[1] == b and cap[2] == 5 and cap[3]==nil) +assert(b+'5' == b) +assert(cap[0] == "add" and cap[1] == b and cap[2] == '5' and cap[3]==nil) +assert(5+b == 5) +assert(cap[0] == "add" and cap[1] == 5 and cap[2] == b and cap[3]==nil) +assert('5'+b == '5') +assert(cap[0] == "add" and cap[1] == '5' and cap[2] == b and cap[3]==nil) +b=b-3; assert(getmetatable(b) == t) +assert(5-a == 5) +assert(cap[0] == "sub" and cap[1] == 5 and cap[2] == a and cap[3]==nil) +assert('5'-a == '5') +assert(cap[0] == "sub" and cap[1] == '5' and cap[2] == a and cap[3]==nil) +assert(a*a == a) +assert(cap[0] == "mul" and cap[1] == a and cap[2] == a and cap[3]==nil) +assert(a/0 == a) +assert(cap[0] == "div" and cap[1] == a and cap[2] == 0 and cap[3]==nil) +assert(a%2 == a) +assert(cap[0] == "mod" and cap[1] == a and cap[2] == 2 and cap[3]==nil) +assert(a // (1/0) == a) +assert(cap[0] == "idiv" and cap[1] == a and cap[2] == 1/0 and cap[3]==nil) +assert(a & "hi" == a) +assert(cap[0] == "band" and cap[1] == a and cap[2] == "hi" and cap[3]==nil) +assert(a | "hi" == a) +assert(cap[0] == "bor" and cap[1] == a and cap[2] == "hi" and cap[3]==nil) +assert("hi" ~ a == "hi") +assert(cap[0] == "bxor" and cap[1] == "hi" and cap[2] == a and cap[3]==nil) +assert(-a == a) +assert(cap[0] == "unm" and cap[1] == a) +assert(a^4 == a) +assert(cap[0] == "pow" and cap[1] == a and cap[2] == 4 and cap[3]==nil) +assert(a^'4' == a) +assert(cap[0] == "pow" and cap[1] == a and cap[2] == '4' and cap[3]==nil) +assert(4^a == 4) +assert(cap[0] == "pow" and cap[1] == 4 and cap[2] == a and cap[3]==nil) +assert('4'^a == '4') +assert(cap[0] == "pow" and cap[1] == '4' and cap[2] == a and cap[3]==nil) +assert(#a == a) +assert(cap[0] == "len" and cap[1] == a) +assert(~a == a) +assert(cap[0] == "bnot" and cap[1] == a) +assert(a << 3 == a) +assert(cap[0] == "shl" and cap[1] == a and cap[2] == 3) +assert(1.5 >> a == 1.5) +assert(cap[0] == "shr" and cap[1] == 1.5 and cap[2] == a) + + +-- test for rawlen +t = setmetatable({1,2,3}, {__len = function () return 10 end}) +assert(#t == 10 and rawlen(t) == 3) +assert(rawlen"abc" == 3) +assert(not pcall(rawlen, io.stdin)) +assert(not pcall(rawlen, 34)) +assert(not pcall(rawlen)) + +-- rawlen for long strings +assert(rawlen(string.rep('a', 1000)) == 1000) + + +t = {} +t.__lt = function (a,b,c) + collectgarbage() + assert(c == nil) + if type(a) == 'table' then a = a.x end + if type(b) == 'table' then b = b.x end + return aOp(1)) and not(Op(1)>Op(2)) and (Op(2)>Op(1))) + assert(not(Op('a')>Op('a')) and not(Op('a')>Op('b')) and (Op('b')>Op('a'))) + assert((Op(1)>=Op(1)) and not(Op(1)>=Op(2)) and (Op(2)>=Op(1))) + assert((1 >= Op(1)) and not(1 >= Op(2)) and (Op(2) >= 1)) + assert((Op('a')>=Op('a')) and not(Op('a')>=Op('b')) and (Op('b')>=Op('a'))) + assert(('a' >= Op('a')) and not(Op('a') >= 'b') and (Op('b') >= Op('a'))) +end + +test() + +t.__le = function (a,b,c) + assert(c == nil) + if type(a) == 'table' then a = a.x end + if type(b) == 'table' then b = b.x end + return a<=b, "dummy" +end + +test() -- retest comparisons, now using both `lt' and `le' + + +-- test `partial order' + +local function rawSet(x) + local y = {} + for _,k in pairs(x) do y[k] = 1 end + return y +end + +local function Set(x) + return setmetatable(rawSet(x), t) +end + +t.__lt = function (a,b) + for k in pairs(a) do + if not b[k] then return false end + b[k] = nil + end + return next(b) ~= nil +end + +t.__le = nil + +assert(Set{1,2,3} < Set{1,2,3,4}) +assert(not(Set{1,2,3,4} < Set{1,2,3,4})) +assert((Set{1,2,3,4} <= Set{1,2,3,4})) +assert((Set{1,2,3,4} >= Set{1,2,3,4})) +assert((Set{1,3} <= Set{3,5})) -- wrong!! model needs a `le' method ;-) + +t.__le = function (a,b) + for k in pairs(a) do + if not b[k] then return false end + end + return true +end + +assert(not (Set{1,3} <= Set{3,5})) -- now its OK! +assert(not(Set{1,3} <= Set{3,5})) +assert(not(Set{1,3} >= Set{3,5})) + +t.__eq = function (a,b) + for k in pairs(a) do + if not b[k] then return false end + b[k] = nil + end + return next(b) == nil +end + +local s = Set{1,3,5} +assert(s == Set{3,5,1}) +assert(not rawequal(s, Set{3,5,1})) +assert(rawequal(s, s)) +assert(Set{1,3,5,1} == rawSet{3,5,1}) +assert(rawSet{1,3,5,1} == Set{3,5,1}) +assert(Set{1,3,5} ~= Set{3,5,1,6}) + +-- '__eq' is not used for table accesses +t[Set{1,3,5}] = 1 +assert(t[Set{1,3,5}] == nil) + + +if not T then + (Message or print)('\n >>> testC not active: skipping tests for \z +userdata equality <<<\n') +else + local u1 = T.newuserdata(0) + local u2 = T.newuserdata(0) + local u3 = T.newuserdata(0) + assert(u1 ~= u2 and u1 ~= u3) + -- debug.setuservalue(u1, 1); + -- debug.setuservalue(u2, 2); + -- debug.setuservalue(u3, 1); + -- debug.setmetatable(u1, {__eq = function (a, b) + -- return debug.getuservalue(a) == debug.getuservalue(b) + -- end}) + -- debug.setmetatable(u2, {__eq = function (a, b) + -- return true + -- end}) + -- assert(u1 == u3 and u3 == u1 and u1 ~= u2) + -- assert(u2 == u1 and u2 == u3 and u3 == u2) + -- assert(u2 ~= {}) -- different types cannot be equal +end + + +t.__concat = function (a,b,c) + assert(c == nil) + if type(a) == 'table' then a = a.val end + if type(b) == 'table' then b = b.val end + if A then return a..b + else + return setmetatable({val=a..b}, t) + end +end + +c = {val="c"}; setmetatable(c, t) +d = {val="d"}; setmetatable(d, t) + +A = true +assert(c..d == 'cd') +assert(0 .."a".."b"..c..d.."e".."f"..(5+3).."g" == "0abcdef8g") + +A = false +assert((c..d..c..d).val == 'cdcd') +x = c..d +assert(getmetatable(x) == t and x.val == 'cd') +x = 0 .."a".."b"..c..d.."e".."f".."g" +assert(x.val == "0abcdefg") + + +-- concat metamethod x numbers (bug in 5.1.1) +c = {} +local x +setmetatable(c, {__concat = function (a,b) + assert(type(a) == "number" and b == c or type(b) == "number" and a == c) + return c +end}) +assert(c..5 == c and 5 .. c == c) +assert(4 .. c .. 5 == c and 4 .. 5 .. 6 .. 7 .. c == c) + + +-- test comparison compatibilities +local t1, t2, c, d +t1 = {}; c = {}; setmetatable(c, t1) +d = {} +t1.__eq = function () return true end +t1.__lt = function () return true end +setmetatable(d, t1) +assert(c == d and c < d and not(d <= c)) +t2 = {} +t2.__eq = t1.__eq +t2.__lt = t1.__lt +setmetatable(d, t2) +assert(c == d and c < d and not(d <= c)) + + + +-- test for several levels of calls +local i +local tt = { + __call = function (t, ...) + i = i+1 + if t.f then return t.f(...) + else return {...} + end + end +} + +local a = setmetatable({}, tt) +local b = setmetatable({f=a}, tt) +local c = setmetatable({f=b}, tt) + +i = 0 +x = c(3,4,5) +assert(i == 3 and x[1] == 3 and x[3] == 5) + + +assert(_G.X == 20) + +print'+' + +local _g = _G +_ENV = setmetatable({}, {__index=function (_,k) return _g[k] end}) + + +a = {} +rawset(a, "x", 1, 2, 3) +assert(a.x == 1 and rawget(a, "x", 3) == 1) + +print '+' + +-- testing metatables for basic types +-- mt = {__index = function (a,b) return a+b end, +-- __len = function (x) return math.floor(x) end} +-- debug.setmetatable(10, mt) +-- assert(getmetatable(-2) == mt) +-- assert((10)[3] == 13) +-- assert((10)["3"] == 13) +-- assert(#3.45 == 3) +-- debug.setmetatable(23, nil) +-- assert(getmetatable(-2) == nil) + +-- debug.setmetatable(true, mt) +-- assert(getmetatable(false) == mt) +-- mt.__index = function (a,b) return a or b end +-- assert((true)[false] == true) +-- assert((false)[false] == false) +-- debug.setmetatable(false, nil) +-- assert(getmetatable(true) == nil) + +-- debug.setmetatable(nil, mt) +-- assert(getmetatable(nil) == mt) +-- mt.__add = function (a,b) return (a or 0) + (b or 0) end +-- assert(10 + nil == 10) +-- assert(nil + 23 == 23) +-- assert(nil + nil == 0) +-- debug.setmetatable(nil, nil) +-- assert(getmetatable(nil) == nil) + +-- debug.setmetatable(nil, {}) + + +-- loops in delegation +a = {}; setmetatable(a, a); a.__index = a; a.__newindex = a +assert(not pcall(function (a,b) return a[b] end, a, 10)) +assert(not pcall(function (a,b,c) a[b] = c end, a, 10, true)) + +-- bug in 5.1 +T, K, V = nil +grandparent = {} +grandparent.__newindex = function(t,k,v) T=t; K=k; V=v end + +parent = {} +parent.__newindex = parent +setmetatable(parent, grandparent) + +child = setmetatable({}, parent) +child.foo = 10 --> CRASH (on some machines) +assert(T == parent and K == "foo" and V == 10) + +print 'OK' + +return 12 + + diff --git a/tests/lua-5.3/files.lua b/tests/lua-5.3/files.lua new file mode 100644 index 0000000..3cfe12d --- /dev/null +++ b/tests/lua-5.3/files.lua @@ -0,0 +1,793 @@ +-- $Id: files.lua,v 1.95 2016/11/07 13:11:28 roberto Exp $ +-- See Copyright Notice in file all.lua + +local debug = require "debug" + +local maxint = math.maxinteger + +assert(type(os.getenv"PATH") == "string") + +assert(io.input(io.stdin) == io.stdin) +assert(not pcall(io.input, "non-existent-file")) +assert(io.output(io.stdout) == io.stdout) + + +local function testerr (msg, f, ...) + local stat, err = pcall(f, ...) + return (not stat and string.find(err, msg, 1, true)) +end + + +local function checkerr (msg, f, ...) + assert(testerr(msg, f, ...)) +end + + +-- cannot close standard files +assert(not io.close(io.stdin) and + not io.stdout:close() and + not io.stderr:close()) + + +assert(type(io.input()) == "userdata" and io.type(io.output()) == "file") +assert(type(io.stdin) == "userdata" and io.type(io.stderr) == "file") +assert(not io.type(8)) +local a = {}; setmetatable(a, {}) +assert(not io.type(a)) + +assert(getmetatable(io.input()).__name == "FILE*") + +local a,b,c = io.open('xuxu_nao_existe') +assert(not a and type(b) == "string" and type(c) == "number") + +a,b,c = io.open('/a/b/c/d', 'w') +assert(not a and type(b) == "string" and type(c) == "number") + +local file = os.tmpname() +local f, msg = io.open(file, "w") +if not f then + (Message or print)("'os.tmpname' file cannot be open; skipping file tests") + +else --{ most tests here need tmpname +f:close() + +print('testing i/o') + +local otherfile = os.tmpname() + +checkerr("invalid mode", io.open, file, "rw") +checkerr("invalid mode", io.open, file, "rb+") +checkerr("invalid mode", io.open, file, "r+bk") +checkerr("invalid mode", io.open, file, "") +checkerr("invalid mode", io.open, file, "+") +checkerr("invalid mode", io.open, file, "b") +assert(io.open(file, "r+b")):close() +assert(io.open(file, "r+")):close() +assert(io.open(file, "rb")):close() + +assert(os.setlocale('C', 'all')) + +io.input(io.stdin); io.output(io.stdout); + +os.remove(file) +assert(not loadfile(file)) +checkerr("", dofile, file) +assert(not io.open(file)) +io.output(file) +assert(io.output() ~= io.stdout) + +if not _port then -- invalid seek + local status, msg, code = io.stdin:seek("set", 1000) + assert(not status and type(msg) == "string" and type(code) == "number") +end + +assert(io.output():seek() == 0) +assert(io.write("alo alo"):seek() == string.len("alo alo")) +assert(io.output():seek("cur", -3) == string.len("alo alo")-3) +assert(io.write("joao")) +assert(io.output():seek("end") == string.len("alo joao")) + +assert(io.output():seek("set") == 0) + +assert(io.write('"álo"', "{a}\n", "second line\n", "third line \n")) +assert(io.write('çfourth_line')) +io.output(io.stdout) +collectgarbage() -- file should be closed by GC +assert(io.input() == io.stdin and rawequal(io.output(), io.stdout)) +print('+') + +-- test GC for files +collectgarbage() +for i=1,120 do + for i=1,5 do + io.input(file) + assert(io.open(file, 'r')) + io.lines(file) + end + collectgarbage() +end + +io.input():close() +io.close() + +assert(os.rename(file, otherfile)) +assert(not os.rename(file, otherfile)) + +io.output(io.open(otherfile, "ab")) +assert(io.write("\n\n\t\t ", 3450, "\n")); +io.close() + +-- test writing/reading numbers +f = assert(io.open(file, "w")) +f:write(maxint, '\n') +f:write(string.format("0X%x\n", maxint)) +f:write("0xABCp-3", '\n') +f:write(0, '\n') +f:write(-maxint, '\n') +f:write(string.format("0x%X\n", -maxint)) +f:write("-0xABCp-3", '\n') +assert(f:close()) +f = assert(io.open(file, "r")) +assert(f:read("n") == maxint) +assert(f:read("n") == maxint) +assert(f:read("n") == 0xABCp-3) +assert(f:read("n") == 0) +assert(f:read("*n") == -maxint) -- test old format (with '*') +assert(f:read("n") == -maxint) +assert(f:read("*n") == -0xABCp-3) -- test old format (with '*') +assert(f:close()) +assert(os.remove(file)) + +-- test yielding during 'dofile' +f = assert(io.open(file, "w")) +f:write[[ +local x, z = coroutine.yield(10) +local y = coroutine.yield(20) +return x + y * z +]] +assert(f:close()) +f = coroutine.wrap(dofile) +assert(f(file) == 10) +print(f(100, 101) == 20) +assert(f(200) == 100 + 200 * 101) +assert(os.remove(file)) + + +f = assert(io.open(file, "w")) +-- test number termination +f:write[[ +-12.3- -0xffff+ .3|5.E-3X +234e+13E 0xDEADBEEFDEADBEEFx +0x1.13Ap+3e +]] +-- very long number +f:write("1234"); for i = 1, 1000 do f:write("0") end; f:write("\n") +-- invalid sequences (must read and discard valid prefixes) +f:write[[ +.e+ 0.e; --; 0xX; +]] +assert(f:close()) +f = assert(io.open(file, "r")) +assert(f:read("n") == -12.3); assert(f:read(1) == "-") +assert(f:read("n") == -0xffff); assert(f:read(2) == "+ ") +assert(f:read("n") == 0.3); assert(f:read(1) == "|") +assert(f:read("n") == 5e-3); assert(f:read(1) == "X") +assert(f:read("n") == 234e13); assert(f:read(1) == "E") +assert(f:read("n") == 0Xdeadbeefdeadbeef); assert(f:read(2) == "x\n") +assert(f:read("n") == 0x1.13aP3); assert(f:read(1) == "e") + +do -- attempt to read too long number + assert(f:read("n") == nil) -- fails + local s = f:read("L") -- read rest of line + assert(string.find(s, "^00*\n$")) -- lots of 0's left +end + +assert(not f:read("n")); assert(f:read(2) == "e+") +assert(not f:read("n")); assert(f:read(1) == ";") +assert(not f:read("n")); assert(f:read(2) == "-;") +assert(not f:read("n")); assert(f:read(1) == "X") +assert(not f:read("n")); assert(f:read(1) == ";") +assert(not f:read("n")); assert(not f:read(0)) -- end of file +assert(f:close()) +assert(os.remove(file)) + + +-- test line generators +assert(not pcall(io.lines, "non-existent-file")) +assert(os.rename(otherfile, file)) +io.output(otherfile) +local n = 0 +local f = io.lines(file) +while f() do n = n + 1 end; +assert(n == 6) -- number of lines in the file +checkerr("file is already closed", f) +checkerr("file is already closed", f) +-- copy from file to otherfile +n = 0 +for l in io.lines(file) do io.write(l, "\n"); n = n + 1 end +io.close() +assert(n == 6) +-- copy from otherfile back to file +local f = assert(io.open(otherfile)) +assert(io.type(f) == "file") +io.output(file) +assert(not io.output():read()) +n = 0 +for l in f:lines() do io.write(l, "\n"); n = n + 1 end +assert(tostring(f):sub(1, 5) == "file ") +assert(f:close()); io.close() +assert(n == 6) +checkerr("closed file", io.close, f) +assert(tostring(f) == "file (closed)") +assert(io.type(f) == "closed file") +io.input(file) +f = io.open(otherfile):lines() +n = 0 +for l in io.lines() do assert(l == f()); n = n + 1 end +f = nil; collectgarbage() +assert(n == 6) +assert(os.remove(otherfile)) + +do -- bug in 5.3.1 + io.output(otherfile) + io.write(string.rep("a", 300), "\n") + io.close() + local t ={}; for i = 1, 250 do t[i] = 1 end + t = {io.lines(otherfile, table.unpack(t))()} + -- everything ok here + assert(#t == 250 and t[1] == 'a' and t[#t] == 'a') + t[#t + 1] = 1 -- one too many + checkerr("too many arguments", io.lines, otherfile, table.unpack(t)) + collectgarbage() -- ensure 'otherfile' is closed + assert(os.remove(otherfile)) +end + +io.input(file) +do -- test error returns + local a,b,c = io.input():write("xuxu") + assert(not a and type(b) == "string" and type(c) == "number") +end +checkerr("invalid format", io.read, "x") +assert(io.read(0) == "") -- not eof +assert(io.read(5, 'l') == '"álo"') +assert(io.read(0) == "") +assert(io.read() == "second line") +local x = io.input():seek() +assert(io.read() == "third line ") +assert(io.input():seek("set", x)) +assert(io.read('L') == "third line \n") +assert(io.read(1) == "ç") +assert(io.read(string.len"fourth_line") == "fourth_line") +assert(io.input():seek("cur", -string.len"fourth_line")) +assert(io.read() == "fourth_line") +assert(io.read() == "") -- empty line +assert(io.read('n') == 3450) +assert(io.read(1) == '\n') +assert(io.read(0) == nil) -- end of file +assert(io.read(1) == nil) -- end of file +assert(io.read(30000) == nil) -- end of file +assert(({io.read(1)})[2] == nil) +assert(io.read() == nil) -- end of file +assert(({io.read()})[2] == nil) +assert(io.read('n') == nil) -- end of file +assert(({io.read('n')})[2] == nil) +assert(io.read('a') == '') -- end of file (OK for 'a') +assert(io.read('a') == '') -- end of file (OK for 'a') +collectgarbage() +print('+') +io.close(io.input()) +checkerr(" input file is closed", io.read) + +assert(os.remove(file)) + +local t = '0123456789' +for i=1,10 do t = t..t; end +assert(string.len(t) == 10*2^10) + +io.output(file) +io.write("alo"):write("\n") +io.close() +checkerr(" output file is closed", io.write) +local f = io.open(file, "a+b") +io.output(f) +collectgarbage() + +assert(io.write(' ' .. t .. ' ')) +assert(io.write(';', 'end of file\n')) +f:flush(); io.flush() +f:close() +print('+') + +io.input(file) +assert(io.read() == "alo") +assert(io.read(1) == ' ') +assert(io.read(string.len(t)) == t) +assert(io.read(1) == ' ') +assert(io.read(0)) +assert(io.read('a') == ';end of file\n') +assert(io.read(0) == nil) +assert(io.close(io.input())) + + +-- test errors in read/write +do + local function ismsg (m) + -- error message is not a code number + return (type(m) == "string" and tonumber(m) == nil) + end + + -- read + local f = io.open(file, "w") + local r, m, c = f:read() + assert(not r and ismsg(m) and type(c) == "number") + assert(f:close()) + -- write + f = io.open(file, "r") + r, m, c = f:write("whatever") + assert(not r and ismsg(m) and type(c) == "number") + assert(f:close()) + -- lines + f = io.open(file, "w") + r, m = pcall(f:lines()) + assert(r == false and ismsg(m)) + assert(f:close()) +end + +assert(os.remove(file)) + +-- test for L format +io.output(file); io.write"\n\nline\nother":close() +io.input(file) +assert(io.read"L" == "\n") +assert(io.read"L" == "\n") +assert(io.read"L" == "line\n") +assert(io.read"L" == "other") +assert(io.read"L" == nil) +io.input():close() + +local f = assert(io.open(file)) +local s = "" +for l in f:lines("L") do s = s .. l end +assert(s == "\n\nline\nother") +f:close() + +io.input(file) +s = "" +for l in io.lines(nil, "L") do s = s .. l end +assert(s == "\n\nline\nother") +io.input():close() + +s = "" +for l in io.lines(file, "L") do s = s .. l end +assert(s == "\n\nline\nother") + +s = "" +for l in io.lines(file, "l") do s = s .. l end +assert(s == "lineother") + +io.output(file); io.write"a = 10 + 34\na = 2*a\na = -a\n":close() +local t = {} +load(io.lines(file, "L"), nil, nil, t)() +assert(t.a == -((10 + 34) * 2)) + + +-- test for multipe arguments in 'lines' +io.output(file); io.write"0123456789\n":close() +for a,b in io.lines(file, 1, 1) do + if a == "\n" then assert(b == nil) + else assert(tonumber(a) == tonumber(b) - 1) + end +end + +for a,b,c in io.lines(file, 1, 2, "a") do + assert(a == "0" and b == "12" and c == "3456789\n") +end + +for a,b,c in io.lines(file, "a", 0, 1) do + if a == "" then break end + assert(a == "0123456789\n" and b == nil and c == nil) +end +collectgarbage() -- to close file in previous iteration + +io.output(file); io.write"00\n10\n20\n30\n40\n":close() +for a, b in io.lines(file, "n", "n") do + if a == 40 then assert(b == nil) + else assert(a == b - 10) + end +end + + +-- test load x lines +io.output(file); +io.write[[ +local y += X +X = +X * +2 + +X; +X = +X +- y; +]]:close() +_G.X = 1 +assert(not load(io.lines(file))) +collectgarbage() -- to close file in previous iteration +load(io.lines(file, "L"))() +assert(_G.X == 2) +load(io.lines(file, 1))() +assert(_G.X == 4) +load(io.lines(file, 3))() +assert(_G.X == 8) + +print('+') + +local x1 = "string\n\n\\com \"\"''coisas [[estranhas]] ]]'" +io.output(file) +assert(io.write(string.format("x2 = %q\n-- comment without ending EOS", x1))) +io.close() +assert(loadfile(file))() +assert(x1 == x2) +print('+') +assert(os.remove(file)) +assert(not os.remove(file)) +assert(not os.remove(otherfile)) + +-- testing loadfile +local function testloadfile (s, expres) + io.output(file) + if s then io.write(s) end + io.close() + local res = assert(loadfile(file))() + assert(os.remove(file)) + assert(res == expres) +end + +-- loading empty file +testloadfile(nil, nil) + +-- loading file with initial comment without end of line +testloadfile("# a non-ending comment", nil) + + +-- checking Unicode BOM in files +testloadfile("\xEF\xBB\xBF# some comment\nreturn 234", 234) +testloadfile("\xEF\xBB\xBFreturn 239", 239) +testloadfile("\xEF\xBB\xBF", nil) -- empty file with a BOM + + +-- checking line numbers in files with initial comments +testloadfile("# a comment\nreturn require'debug'.getinfo(1).currentline", 2) + + +-- loading binary file +io.output(io.open(file, "wb")) +assert(io.write(string.dump(function () return 10, '\0alo\255', 'hi' end))) +io.close() +a, b, c = assert(loadfile(file))() +assert(a == 10 and b == "\0alo\255" and c == "hi") +assert(os.remove(file)) + +-- bug in 5.2.1 +do + io.output(io.open(file, "wb")) + -- save function with no upvalues + assert(io.write(string.dump(function () return 1 end))) + io.close() + f = assert(loadfile(file, "b", {})) + assert(type(f) == "function" and f() == 1) + assert(os.remove(file)) +end + +-- loading binary file with initial comment +io.output(io.open(file, "wb")) +assert(io.write("#this is a comment for a binary file\0\n", + string.dump(function () return 20, '\0\0\0' end))) +io.close() +a, b, c = assert(loadfile(file))() +assert(a == 20 and b == "\0\0\0" and c == nil) +assert(os.remove(file)) + + +-- 'loadfile' with 'env' +do + local f = io.open(file, 'w') + f:write[[ + if (...) then a = 15; return b, c, d + else return _ENV + end + ]] + f:close() + local t = {b = 12, c = "xuxu", d = print} + local f = assert(loadfile(file, 't', t)) + local b, c, d = f(1) + assert(t.a == 15 and b == 12 and c == t.c and d == print) + assert(f() == t) + f = assert(loadfile(file, 't', nil)) + assert(f() == nil) + f = assert(loadfile(file)) + assert(f() == _G) + assert(os.remove(file)) +end + + +-- 'loadfile' x modes +do + io.open(file, 'w'):write("return 10"):close() + local s, m = loadfile(file, 'b') + assert(not s and string.find(m, "a text chunk")) + io.open(file, 'w'):write("\27 return 10"):close() + local s, m = loadfile(file, 't') + assert(not s and string.find(m, "a binary chunk")) + assert(os.remove(file)) +end + + +io.output(file) +assert(io.write("qualquer coisa\n")) +assert(io.write("mais qualquer coisa")) +io.close() +assert(io.output(assert(io.open(otherfile, 'wb'))) + :write("outra coisa\0\1\3\0\0\0\0\255\0") + :close()) + +local filehandle = assert(io.open(file, 'r+')) +local otherfilehandle = assert(io.open(otherfile, 'rb')) +assert(filehandle ~= otherfilehandle) +assert(type(filehandle) == "userdata") +assert(filehandle:read('l') == "qualquer coisa") +io.input(otherfilehandle) +assert(io.read(string.len"outra coisa") == "outra coisa") +assert(filehandle:read('l') == "mais qualquer coisa") +filehandle:close(); +assert(type(filehandle) == "userdata") +io.input(otherfilehandle) +assert(io.read(4) == "\0\1\3\0") +assert(io.read(3) == "\0\0\0") +assert(io.read(0) == "") -- 255 is not eof +assert(io.read(1) == "\255") +assert(io.read('a') == "\0") +assert(not io.read(0)) +assert(otherfilehandle == io.input()) +otherfilehandle:close() +assert(os.remove(file)) +assert(os.remove(otherfile)) +collectgarbage() + +io.output(file) + :write[[ + 123.4 -56e-2 not a number +second line +third line + +and the rest of the file +]] + :close() +io.input(file) +local _,a,b,c,d,e,h,__ = io.read(1, 'n', 'n', 'l', 'l', 'l', 'a', 10) +assert(io.close(io.input())) +assert(_ == ' ' and __ == nil) +assert(type(a) == 'number' and a==123.4 and b==-56e-2) +assert(d=='second line' and e=='third line') +assert(h==[[ + +and the rest of the file +]]) +assert(os.remove(file)) +collectgarbage() + +-- testing buffers +do + local f = assert(io.open(file, "w")) + local fr = assert(io.open(file, "r")) + assert(f:setvbuf("full", 2000)) + f:write("x") + assert(fr:read("all") == "") -- full buffer; output not written yet + f:close() + fr:seek("set") + assert(fr:read("all") == "x") -- `close' flushes it + f = assert(io.open(file), "w") + assert(f:setvbuf("no")) + f:write("x") + fr:seek("set") + assert(fr:read("all") == "x") -- no buffer; output is ready + f:close() + f = assert(io.open(file, "a")) + assert(f:setvbuf("line")) + f:write("x") + fr:seek("set", 1) + assert(fr:read("all") == "") -- line buffer; no output without `\n' + f:write("a\n"):seek("set", 1) + assert(fr:read("all") == "xa\n") -- now we have a whole line + f:close(); fr:close() + assert(os.remove(file)) +end + + +if not _soft then + print("testing large files (> BUFSIZ)") + io.output(file) + for i=1,5001 do io.write('0123456789123') end + io.write('\n12346'):close() + io.input(file) + local x = io.read('a') + io.input():seek('set', 0) + local y = io.read(30001)..io.read(1005)..io.read(0).. + io.read(1)..io.read(100003) + assert(x == y and string.len(x) == 5001*13 + 6) + io.input():seek('set', 0) + y = io.read() -- huge line + assert(x == y..'\n'..io.read()) + assert(io.read() == nil) + io.close(io.input()) + assert(os.remove(file)) + x = nil; y = nil +end + +if not _port then + local progname + do -- get name of running executable + local arg = arg or _ARG + local i = 0 + while arg[i] do i = i - 1 end + progname = '"' .. arg[i + 1] .. '"' + end + print("testing popen/pclose and execute") + local tests = { + -- command, what, code + {"ls > /dev/null", "ok"}, + {"not-to-be-found-command", "exit"}, + {"exit 3", "exit", 3}, + {"exit 129", "exit", 129}, + {"kill -s HUP $$", "signal", 1}, + {"kill -s KILL $$", "signal", 9}, + {"sh -c 'kill -s HUP $$'", "exit"}, + {progname .. ' -e " "', "ok"}, + {progname .. ' -e "os.exit(0, true)"', "ok"}, + {progname .. ' -e "os.exit(20, true)"', "exit", 20}, + } + print("\n(some error messages are expected now)") + for _, v in ipairs(tests) do + local x, y, z = io.popen(v[1]):close() + local x1, y1, z1 = os.execute(v[1]) + assert(x == x1 and y == y1 and z == z1) + if v[2] == "ok" then + assert(x and y == 'exit' and z == 0) + else + assert(not x and y == v[2]) -- correct status and 'what' + -- correct code if known (but always different from 0) + assert((v[3] == nil and z > 0) or v[3] == z) + end + end +end + + +-- testing tmpfile +f = io.tmpfile() +assert(io.type(f) == "file") +f:write("alo") +f:seek("set") +assert(f:read"a" == "alo") + +end --} + +print'+' + +print("testing date/time") + +assert(os.date("") == "") +assert(os.date("!") == "") +assert(os.date("\0\0") == "\0\0") +assert(os.date("!\0\0") == "\0\0") +local x = string.rep("a", 10000) +assert(os.date(x) == x) +local t = os.time() +D = os.date("*t", t) +assert(os.date(string.rep("%d", 1000), t) == + string.rep(os.date("%d", t), 1000)) +assert(os.date(string.rep("%", 200)) == string.rep("%", 100)) + +local t = os.time() +D = os.date("*t", t) +load(os.date([[assert(D.year==%Y and D.month==%m and D.day==%d and + D.hour==%H and D.min==%M and D.sec==%S and + D.wday==%w+1 and D.yday==%j and type(D.isdst) == 'boolean')]], t))() + +checkerr("invalid conversion specifier", os.date, "%") +checkerr("invalid conversion specifier", os.date, "%9") +checkerr("invalid conversion specifier", os.date, "%") +checkerr("invalid conversion specifier", os.date, "%O") +checkerr("invalid conversion specifier", os.date, "%E") +checkerr("invalid conversion specifier", os.date, "%Ea") + +checkerr("not an integer", os.time, {year=1000, month=1, day=1, hour='x'}) +checkerr("not an integer", os.time, {year=1000, month=1, day=1, hour=1.5}) + +checkerr("missing", os.time, {hour = 12}) -- missing date + +if not _port then + -- test Posix-specific modifiers + assert(type(os.date("%Ex")) == 'string') + assert(type(os.date("%Oy")) == 'string') + + + -- test out-of-range dates (at least for Unix) + if maxint >= 2^62 then -- cannot do these tests in Small Lua + -- no arith overflows + checkerr("out-of-bound", os.time, {year = -maxint, month = 1, day = 1}) + if string.packsize("i") == 4 then -- 4-byte ints + if testerr("out-of-bound", os.date, "%Y", 2^40) then + -- time_t has 4 bytes and therefore cannot represent year 4000 + print(" 4-byte time_t") + checkerr("cannot be represented", os.time, {year=4000, month=1, day=1}) + else + -- time_t has 8 bytes; an int year cannot represent a huge time + print(" 8-byte time_t") + checkerr("cannot be represented", os.date, "%Y", 2^60) + -- it should have no problems with year 4000 + assert(tonumber(os.time{year=4000, month=1, day=1})) + end + else -- 8-byte ints + -- assume time_t has 8 bytes too + print(" 8-byte time_t") + assert(tonumber(os.date("%Y", 2^60))) + -- but still cannot represent a huge year + checkerr("cannot be represented", os.time, {year=2^60, month=1, day=1}) + end + end +end + + +D = os.date("!*t", t) +load(os.date([[!assert(D.year==%Y and D.month==%m and D.day==%d and + D.hour==%H and D.min==%M and D.sec==%S and + D.wday==%w+1 and D.yday==%j and type(D.isdst) == 'boolean')]], t))() + +do + local D = os.date("*t") + local t = os.time(D) + assert(type(D.isdst) == 'boolean') + D.isdst = nil + local t1 = os.time(D) + assert(t == t1) -- if isdst is absent uses correct default +end + +t = os.time(D) +D.year = D.year-1; +local t1 = os.time(D) +-- allow for leap years +assert(math.abs(os.difftime(t,t1)/(24*3600) - 365) < 2) + +-- should not take more than 1 second to execute these two lines +t = os.time() +t1 = os.time(os.date("*t")) +local diff = os.difftime(t1,t) +assert(0 <= diff and diff <= 1) +diff = os.difftime(t,t1) +assert(-1 <= diff and diff <= 0) + +local t1 = os.time{year=2000, month=10, day=1, hour=23, min=12} +local t2 = os.time{year=2000, month=10, day=1, hour=23, min=10, sec=19} +assert(os.difftime(t1,t2) == 60*2-19) + +-- since 5.3.3, 'os.time' normalizes table fields +t1 = {year = 2005, month = 1, day = 1, hour = 1, min = 0, sec = -3602} +os.time(t1) +assert(t1.day == 31 and t1.month == 12 and t1.year == 2004 and + t1.hour == 23 and t1.min == 59 and t1.sec == 58 and + t1.yday == 366) + +io.output(io.stdout) +local t = os.date('%d %m %Y %H %M %S') +local d, m, a, h, min, s = string.match(t, + "(%d+) (%d+) (%d+) (%d+) (%d+) (%d+)") +d = tonumber(d) +m = tonumber(m) +a = tonumber(a) +h = tonumber(h) +min = tonumber(min) +s = tonumber(s) +io.write(string.format('test done on %2.2d/%2.2d/%d', d, m, a)) +io.write(string.format(', at %2.2d:%2.2d:%2.2d\n', h, min, s)) +io.write(string.format('%s\n', _VERSION)) + + diff --git a/tests/lua-5.3/gc.lua b/tests/lua-5.3/gc.lua new file mode 100644 index 0000000..93fd6d6 --- /dev/null +++ b/tests/lua-5.3/gc.lua @@ -0,0 +1,624 @@ +-- $Id: gc.lua,v 1.72 2016/11/07 13:11:28 roberto Exp $ +-- See Copyright Notice in file all.lua + +print('testing garbage collection') + +local debug = require"debug" + +collectgarbage() + +assert(collectgarbage("isrunning")) + +local function gcinfo () return collectgarbage"count" * 1024 end + + +-- test weird parameters +do + -- save original parameters + local a = collectgarbage("setpause", 200) + local b = collectgarbage("setstepmul", 200) + local t = {0, 2, 10, 90, 500, 5000, 30000, 0x7ffffffe} + for i = 1, #t do + local p = t[i] + for j = 1, #t do + local m = t[j] + collectgarbage("setpause", p) + collectgarbage("setstepmul", m) + collectgarbage("step", 0) + collectgarbage("step", 10000) + end + end + -- restore original parameters + collectgarbage("setpause", a) + collectgarbage("setstepmul", b) + collectgarbage() +end + + +_G["while"] = 234 + +limit = 5000 + + +local function GC1 () + local u + local b -- must be declared after 'u' (to be above it in the stack) + local finish = false + u = setmetatable({}, {__gc = function () finish = true end}) + b = {34} + repeat u = {} until finish + assert(b[1] == 34) -- 'u' was collected, but 'b' was not + + finish = false; local i = 1 + u = setmetatable({}, {__gc = function () finish = true end}) + repeat i = i + 1; u = tostring(i) .. tostring(i) until finish + assert(b[1] == 34) -- 'u' was collected, but 'b' was not + + finish = false + u = setmetatable({}, {__gc = function () finish = true end}) + repeat local i; u = function () return i end until finish + assert(b[1] == 34) -- 'u' was collected, but 'b' was not +end + +local function GC2 () + local u + local finish = false + u = {setmetatable({}, {__gc = function () finish = true end})} + b = {34} + repeat u = {{}} until finish + assert(b[1] == 34) -- 'u' was collected, but 'b' was not + + finish = false; local i = 1 + u = {setmetatable({}, {__gc = function () finish = true end})} + repeat i = i + 1; u = {tostring(i) .. tostring(i)} until finish + assert(b[1] == 34) -- 'u' was collected, but 'b' was not + + finish = false + u = {setmetatable({}, {__gc = function () finish = true end})} + repeat local i; u = {function () return i end} until finish + assert(b[1] == 34) -- 'u' was collected, but 'b' was not +end + +local function GC() GC1(); GC2() end + + +contCreate = 0 + +print('tables') +while contCreate <= limit do + local a = {}; a = nil + contCreate = contCreate+1 +end + +a = "a" + +contCreate = 0 +print('strings') +while contCreate <= limit do + a = contCreate .. "b"; + a = string.gsub(a, '(%d%d*)', string.upper) + a = "a" + contCreate = contCreate+1 +end + + +contCreate = 0 + +a = {} + +print('functions') +function a:test () + while contCreate <= limit do + load(string.format("function temp(a) return 'a%d' end", contCreate), "")() + assert(temp() == string.format('a%d', contCreate)) + contCreate = contCreate+1 + end +end + +a:test() + +-- collection of functions without locals, globals, etc. +do local f = function () end end + + +print("functions with errors") +prog = [[ +do + a = 10; + function foo(x,y) + a = sin(a+0.456-0.23e-12); + return function (z) return sin(%x+z) end + end + local x = function (w) a=a+w; end +end +]] +do + local step = 1 + if _soft then step = 13 end + for i=1, string.len(prog), step do + for j=i, string.len(prog), step do + pcall(load(string.sub(prog, i, j), "")) + end + end +end + +foo = nil +print('long strings') +x = "01234567890123456789012345678901234567890123456789012345678901234567890123456789" +assert(string.len(x)==80) +s = '' +n = 0 +k = math.min(300, (math.maxinteger // 80) // 2) +while n < k do s = s..x; n=n+1; j=tostring(n) end +assert(string.len(s) == k*80) +s = string.sub(s, 1, 10000) +s, i = string.gsub(s, '(%d%d%d%d)', '') +assert(i==10000 // 4) +s = nil +x = nil + +assert(_G["while"] == 234) + + +print("steps") + +print("steps (2)") + +local function dosteps (siz) + assert(not collectgarbage("isrunning")) + collectgarbage() + assert(not collectgarbage("isrunning")) + local a = {} + for i=1,100 do a[i] = {{}}; local b = {} end + local x = gcinfo() + local i = 0 + repeat -- do steps until it completes a collection cycle + i = i+1 + until collectgarbage("step", siz) + assert(gcinfo() < x) + return i +end + +collectgarbage"stop" + +if not _port then + -- test the "size" of basic GC steps (whatever they mean...) + assert(dosteps(0) > 10) + assert(dosteps(10) < dosteps(2)) +end + +-- collector should do a full collection with so many steps +assert(dosteps(20000) == 1) +assert(collectgarbage("step", 20000) == true) +assert(collectgarbage("step", 20000) == true) + +assert(not collectgarbage("isrunning")) +collectgarbage"restart" +assert(collectgarbage("isrunning")) + + +if not _port then + -- test the pace of the collector + collectgarbage(); collectgarbage() + local x = gcinfo() + collectgarbage"stop" + assert(not collectgarbage("isrunning")) + repeat + local a = {} + until gcinfo() > 3 * x + collectgarbage"restart" + assert(collectgarbage("isrunning")) + repeat + local a = {} + until gcinfo() <= x * 2 +end + + +print("clearing tables") +lim = 15 +a = {} +-- fill a with `collectable' indices +for i=1,lim do a[{}] = i end +b = {} +for k,v in pairs(a) do b[k]=v end +-- remove all indices and collect them +for n in pairs(b) do + a[n] = nil + assert(type(n) == 'table' and next(n) == nil) + collectgarbage() +end +b = nil +collectgarbage() +for n in pairs(a) do error'cannot be here' end +for i=1,lim do a[i] = i end +for i=1,lim do assert(a[i] == i) end + + +print('weak tables') +a = {}; setmetatable(a, {__mode = 'k'}); +-- fill a with some `collectable' indices +for i=1,lim do a[{}] = i end +-- and some non-collectable ones +for i=1,lim do a[i] = i end +for i=1,lim do local s=string.rep('@', i); a[s] = s..'#' end +collectgarbage() +local i = 0 +for k,v in pairs(a) do assert(k==v or k..'#'==v); i=i+1 end +assert(i == 2*lim) + +a = {}; setmetatable(a, {__mode = 'v'}); +a[1] = string.rep('b', 21) +collectgarbage() +assert(a[1]) -- strings are *values* +a[1] = nil +-- fill a with some `collectable' values (in both parts of the table) +for i=1,lim do a[i] = {} end +for i=1,lim do a[i..'x'] = {} end +-- and some non-collectable ones +for i=1,lim do local t={}; a[t]=t end +for i=1,lim do a[i+lim]=i..'x' end +collectgarbage() +local i = 0 +for k,v in pairs(a) do assert(k==v or k-lim..'x' == v); i=i+1 end +assert(i == 2*lim) + +a = {}; setmetatable(a, {__mode = 'vk'}); +local x, y, z = {}, {}, {} +-- keep only some items +a[1], a[2], a[3] = x, y, z +a[string.rep('$', 11)] = string.rep('$', 11) +-- fill a with some `collectable' values +for i=4,lim do a[i] = {} end +for i=1,lim do a[{}] = i end +for i=1,lim do local t={}; a[t]=t end +collectgarbage() +assert(next(a) ~= nil) +local i = 0 +for k,v in pairs(a) do + assert((k == 1 and v == x) or + (k == 2 and v == y) or + (k == 3 and v == z) or k==v); + i = i+1 +end +assert(i == 4) +x,y,z=nil +collectgarbage() +assert(next(a) == string.rep('$', 11)) + + +-- 'bug' in 5.1 +a = {} +local t = {x = 10} +local C = setmetatable({key = t}, {__mode = 'v'}) +local C1 = setmetatable({[t] = 1}, {__mode = 'k'}) +a.x = t -- this should not prevent 't' from being removed from + -- weak table 'C' by the time 'a' is finalized + +setmetatable(a, {__gc = function (u) + assert(C.key == nil) + assert(type(next(C1)) == 'table') + end}) + +a, t = nil +collectgarbage() +collectgarbage() +assert(next(C) == nil and next(C1) == nil) +C, C1 = nil + + +-- ephemerons +local mt = {__mode = 'k'} +a = {{10},{20},{30},{40}}; setmetatable(a, mt) +x = nil +for i = 1, 100 do local n = {}; a[n] = {k = {x}}; x = n end +GC() +local n = x +local i = 0 +while n do n = a[n].k[1]; i = i + 1 end +assert(i == 100) +x = nil +GC() +for i = 1, 4 do assert(a[i][1] == i * 10); a[i] = nil end +assert(next(a) == nil) + +local K = {} +a[K] = {} +for i=1,10 do a[K][i] = {}; a[a[K][i]] = setmetatable({}, mt) end +x = nil +local k = 1 +for j = 1,100 do + local n = {}; local nk = k%10 + 1 + a[a[K][nk]][n] = {x, k = k}; x = n; k = nk +end +GC() +local n = x +local i = 0 +while n do local t = a[a[K][k]][n]; n = t[1]; k = t.k; i = i + 1 end +assert(i == 100) +K = nil +GC() +-- assert(next(a) == nil) + + +-- testing errors during GC +do +collectgarbage("stop") -- stop collection +local u = {} +local s = {}; setmetatable(s, {__mode = 'k'}) +setmetatable(u, {__gc = function (o) + local i = s[o] + s[i] = true + assert(not s[i - 1]) -- check proper finalization order + if i == 8 then error("here") end -- error during GC +end}) + +for i = 6, 10 do + local n = setmetatable({}, getmetatable(u)) + s[n] = i +end + +assert(not pcall(collectgarbage)) +for i = 8, 10 do assert(s[i]) end + +for i = 1, 5 do + local n = setmetatable({}, getmetatable(u)) + s[n] = i +end + +collectgarbage() +for i = 1, 10 do assert(s[i]) end + +getmetatable(u).__gc = false + + +-- __gc errors with non-string messages +setmetatable({}, {__gc = function () error{} end}) +local a, b = pcall(collectgarbage) +assert(not a and type(b) == "string" and string.find(b, "error in __gc")) + +end +print '+' + + +-- testing userdata +if T==nil then + (Message or print)('\n >>> testC not active: skipping userdata GC tests <<<\n') + +else + + local function newproxy(u) + return debug.setmetatable(T.newuserdata(0), debug.getmetatable(u)) + end + + collectgarbage("stop") -- stop collection + local u = newproxy(nil) + debug.setmetatable(u, {__gc = true}) + local s = 0 + local a = {[u] = 0}; setmetatable(a, {__mode = 'vk'}) + for i=1,10 do a[newproxy(u)] = i end + for k in pairs(a) do assert(getmetatable(k) == getmetatable(u)) end + local a1 = {}; for k,v in pairs(a) do a1[k] = v end + for k,v in pairs(a1) do a[v] = k end + for i =1,10 do assert(a[i]) end + getmetatable(u).a = a1 + getmetatable(u).u = u + do + local u = u + getmetatable(u).__gc = function (o) + assert(a[o] == 10-s) + assert(a[10-s] == nil) -- udata already removed from weak table + assert(getmetatable(o) == getmetatable(u)) + assert(getmetatable(o).a[o] == 10-s) + s=s+1 + end + end + a1, u = nil + assert(next(a) ~= nil) + collectgarbage() + assert(s==11) + collectgarbage() + assert(next(a) == nil) -- finalized keys are removed in two cycles +end + + +-- __gc x weak tables +local u = setmetatable({}, {__gc = true}) +-- __gc metamethod should be collected before running +setmetatable(getmetatable(u), {__mode = "v"}) +getmetatable(u).__gc = function (o) os.exit(1) end -- cannot happen +u = nil +collectgarbage() + +local u = setmetatable({}, {__gc = true}) +local m = getmetatable(u) +m.x = {[{0}] = 1; [0] = {1}}; setmetatable(m.x, {__mode = "kv"}); +m.__gc = function (o) + assert(next(getmetatable(o).x) == nil) + m = 10 +end +u, m = nil +collectgarbage() +assert(m==10) + + +-- errors during collection +u = setmetatable({}, {__gc = function () error "!!!" end}) +u = nil +assert(not pcall(collectgarbage)) + + +if not _soft then + print("deep structures") + local a = {} + for i = 1,200000 do + a = {next = a} + end + collectgarbage() +end + +-- create many threads with self-references and open upvalues +print("self-referenced threads") +local thread_id = 0 +local threads = {} + +local function fn (thread) + local x = {} + threads[thread_id] = function() + thread = x + end + coroutine.yield() +end + +while thread_id < 1000 do + local thread = coroutine.create(fn) + coroutine.resume(thread, thread) + thread_id = thread_id + 1 +end + + +-- Create a closure (function inside 'f') with an upvalue ('param') that +-- points (through a table) to the closure itself and to the thread +-- ('co' and the initial value of 'param') where closure is running. +-- Then, assert that table (and therefore everything else) will be +-- collected. +do + local collected = false -- to detect collection + collectgarbage(); collectgarbage("stop") + do + local function f (param) + ;(function () + assert(type(f) == 'function' and type(param) == 'thread') + param = {param, f} + setmetatable(param, {__gc = function () collected = true end}) + coroutine.yield(100) + end)() + end + local co = coroutine.create(f) + assert(coroutine.resume(co, co)) + end + -- Now, thread and closure are not reacheable any more; + -- two collections are needed to break cycle + collectgarbage() + assert(not collected) + collectgarbage() + assert(collected) + collectgarbage("restart") +end + + +do + collectgarbage() + collectgarbage"stop" + local x = gcinfo() + repeat + for i=1,1000 do _ENV.a = {} end + collectgarbage("step", 0) -- steps should not unblock the collector + until gcinfo() > 2 * x + collectgarbage"restart" +end + + +if T then -- tests for weird cases collecting upvalues + + local function foo () + local a = {x = 20} + coroutine.yield(function () return a.x end) -- will run collector + assert(a.x == 20) -- 'a' is 'ok' + a = {x = 30} -- create a new object + assert(T.gccolor(a) == "white") -- of course it is new... + coroutine.yield(100) -- 'a' is still local to this thread + end + + local t = setmetatable({}, {__mode = "kv"}) + collectgarbage(); collectgarbage('stop') + -- create coroutine in a weak table, so it will never be marked + t.co = coroutine.wrap(foo) + local f = t.co() -- create function to access local 'a' + T.gcstate("atomic") -- ensure all objects are traversed + assert(T.gcstate() == "atomic") + assert(t.co() == 100) -- resume coroutine, creating new table for 'a' + assert(T.gccolor(t.co) == "white") -- thread was not traversed + T.gcstate("pause") -- collect thread, but should mark 'a' before that + assert(t.co == nil and f() == 30) -- ensure correct access to 'a' + + collectgarbage("restart") + + -- test barrier in sweep phase (advance cleaning of upvalue to white) + local u = T.newuserdata(0) -- create a userdata + collectgarbage() + collectgarbage"stop" + T.gcstate"atomic" + T.gcstate"sweepallgc" + local x = {} + assert(T.gccolor(u) == "black") -- upvalue is "old" (black) + assert(T.gccolor(x) == "white") -- table is "new" (white) + debug.setuservalue(u, x) -- trigger barrier + assert(T.gccolor(u) == "white") -- upvalue changed to white + collectgarbage"restart" + + print"+" +end + + +if T then + local debug = require "debug" + collectgarbage("stop") + local x = T.newuserdata(0) + local y = T.newuserdata(0) + debug.setmetatable(y, {__gc = true}) -- bless the new udata before... + debug.setmetatable(x, {__gc = true}) -- ...the old one + assert(T.gccolor(y) == "white") + T.checkmemory() + collectgarbage("restart") +end + + +if T then + print("emergency collections") + collectgarbage() + collectgarbage() + T.totalmem(T.totalmem() + 200) + for i=1,200 do local a = {} end + T.totalmem(0) + collectgarbage() + local t = T.totalmem("table") + local a = {{}, {}, {}} -- create 4 new tables + assert(T.totalmem("table") == t + 4) + t = T.totalmem("function") + a = function () end -- create 1 new closure + assert(T.totalmem("function") == t + 1) + t = T.totalmem("thread") + a = coroutine.create(function () end) -- create 1 new coroutine + assert(T.totalmem("thread") == t + 1) +end + +-- create an object to be collected when state is closed +do + local setmetatable,assert,type,print,getmetatable = + setmetatable,assert,type,print,getmetatable + local tt = {} + tt.__gc = function (o) + assert(getmetatable(o) == tt) + -- create new objects during GC + local a = 'xuxu'..(10+3)..'joao', {} + ___Glob = o -- ressurect object! + setmetatable({}, tt) -- creates a new one with same metatable + print(">>> closing state " .. "<<<\n") + end + local u = setmetatable({}, tt) + ___Glob = {u} -- avoid object being collected before program end +end + +-- create several objects to raise errors when collected while closing state +do + local mt = {__gc = function (o) return o + 1 end} + for i = 1,10 do + -- create object and preserve it until the end + table.insert(___Glob, setmetatable({}, mt)) + end +end + +-- just to make sure +assert(collectgarbage'isrunning') + +print('OK') diff --git a/tests/lua-5.3/goto.lua b/tests/lua-5.3/goto.lua new file mode 100644 index 0000000..8b9bedb --- /dev/null +++ b/tests/lua-5.3/goto.lua @@ -0,0 +1,232 @@ +-- $Id: goto.lua,v 1.13 2016/11/07 13:11:28 roberto Exp $ +-- See Copyright Notice in file all.lua + +collectgarbage() + +local function errmsg (code, m) + local st, msg = load(code) + assert(not st and string.find(msg, m)) +end + +-- cannot see label inside block +errmsg([[ goto l1; do ::l1:: end ]], "label 'l1'") +errmsg([[ do ::l1:: end goto l1; ]], "label 'l1'") + +-- repeated label +errmsg([[ ::l1:: ::l1:: ]], "label 'l1'") + + +-- undefined label +errmsg([[ goto l1; local aa ::l1:: ::l2:: print(3) ]], "local 'aa'") + +-- jumping over variable definition +errmsg([[ +do local bb, cc; goto l1; end +local aa +::l1:: print(3) +]], "local 'aa'") + +-- jumping into a block +errmsg([[ do ::l1:: end goto l1 ]], "label 'l1'") +errmsg([[ goto l1 do ::l1:: end ]], "label 'l1'") + +-- cannot continue a repeat-until with variables +errmsg([[ + repeat + if x then goto cont end + local xuxu = 10 + ::cont:: + until xuxu < x +]], "local 'xuxu'") + +-- simple gotos +local x +do + local y = 12 + goto l1 + ::l2:: x = x + 1; goto l3 + ::l1:: x = y; goto l2 +end +::l3:: ::l3_1:: assert(x == 13) + + +-- long labels +do + local prog = [[ + do + local a = 1 + goto l%sa; a = a + 1 + ::l%sa:: a = a + 10 + goto l%sb; a = a + 2 + ::l%sb:: a = a + 20 + return a + end + ]] + local label = string.rep("0123456789", 40) + prog = string.format(prog, label, label, label, label) + assert(assert(load(prog))() == 31) +end + +-- goto to correct label when nested +do goto l3; ::l3:: end -- does not loop jumping to previous label 'l3' + +-- ok to jump over local dec. to end of block +do + goto l1 + local a = 23 + x = a + ::l1::; +end + +while true do + goto l4 + goto l1 -- ok to jump over local dec. to end of block + goto l1 -- multiple uses of same label + local x = 45 + ::l1:: ;;; +end +::l4:: assert(x == 13) + +if print then + goto l1 -- ok to jump over local dec. to end of block + error("should not be here") + goto l2 -- ok to jump over local dec. to end of block + local x + ::l1:: ; ::l2:: ;; +else end + +-- to repeat a label in a different function is OK +local function foo () + local a = {} + goto l3 + ::l1:: a[#a + 1] = 1; goto l2; + ::l2:: a[#a + 1] = 2; goto l5; + ::l3:: + ::l3a:: a[#a + 1] = 3; goto l1; + ::l4:: a[#a + 1] = 4; goto l6; + ::l5:: a[#a + 1] = 5; goto l4; + ::l6:: assert(a[1] == 3 and a[2] == 1 and a[3] == 2 and + a[4] == 5 and a[5] == 4) + if not a[6] then a[6] = true; goto l3a end -- do it twice +end + +::l6:: foo() + + +do -- bug in 5.2 -> 5.3.2 + local x + ::L1:: + local y -- cannot join this SETNIL with previous one + assert(y == nil) + y = true + if x == nil then + x = 1 + goto L1 + else + x = x + 1 + end + assert(x == 2 and y == true) +end + +-------------------------------------------------------------------------------- +-- testing closing of upvalues + +-- local debug = require 'debug' + +local function foo () + local t = {} + do + local i = 1 + local a, b, c, d + t[1] = function () return a, b, c, d end + ::l1:: + local b + do + local c + t[#t + 1] = function () return a, b, c, d end -- t[2], t[4], t[6] + if i > 2 then goto l2 end + do + local d + t[#t + 1] = function () return a, b, c, d end -- t[3], t[5] + i = i + 1 + local a + goto l1 + end + end + end + ::l2:: return t +end + +local a = foo() +assert(#a == 6) + +-- -- all functions share same 'a' +-- for i = 2, 6 do +-- assert(debug.upvalueid(a[1], 1) == debug.upvalueid(a[i], 1)) +-- end + +-- -- 'b' and 'c' are shared among some of them +-- for i = 2, 6 do +-- -- only a[1] uses external 'b'/'b' +-- assert(debug.upvalueid(a[1], 2) ~= debug.upvalueid(a[i], 2)) +-- assert(debug.upvalueid(a[1], 3) ~= debug.upvalueid(a[i], 3)) +-- end + +-- for i = 3, 5, 2 do +-- -- inner functions share 'b'/'c' with previous ones +-- assert(debug.upvalueid(a[i], 2) == debug.upvalueid(a[i - 1], 2)) +-- assert(debug.upvalueid(a[i], 3) == debug.upvalueid(a[i - 1], 3)) +-- -- but not with next ones +-- assert(debug.upvalueid(a[i], 2) ~= debug.upvalueid(a[i + 1], 2)) +-- assert(debug.upvalueid(a[i], 3) ~= debug.upvalueid(a[i + 1], 3)) +-- end + +-- -- only external 'd' is shared +-- for i = 2, 6, 2 do +-- assert(debug.upvalueid(a[1], 4) == debug.upvalueid(a[i], 4)) +-- end + +-- -- internal 'd's are all different +-- for i = 3, 5, 2 do +-- for j = 1, 6 do +-- assert((debug.upvalueid(a[i], 4) == debug.upvalueid(a[j], 4)) +-- == (i == j)) +-- end +-- end + +-------------------------------------------------------------------------------- +-- testing if x goto optimizations + +local function testG (a) + if a == 1 then + goto l1 + error("should never be here!") + elseif a == 2 then goto l2 + elseif a == 3 then goto l3 + elseif a == 4 then + goto l1 -- go to inside the block + error("should never be here!") + ::l1:: a = a + 1 -- must go to 'if' end + else + goto l4 + ::l4a:: a = a * 2; goto l4b + error("should never be here!") + ::l4:: goto l4a + error("should never be here!") + ::l4b:: + end + do return a end + ::l2:: do return "2" end + ::l3:: do return "3" end + ::l1:: return "1" +end + +assert(testG(1) == "1") +assert(testG(2) == "2") +assert(testG(3) == "3") +assert(testG(4) == 5) +assert(testG(5) == 10) +-------------------------------------------------------------------------------- + + +print'OK' diff --git a/tests/lua-5.3/heavy.lua b/tests/lua-5.3/heavy.lua new file mode 100644 index 0000000..889d9f4 --- /dev/null +++ b/tests/lua-5.3/heavy.lua @@ -0,0 +1,72 @@ +-- $Id: heavy.lua,v 1.4 2016/11/07 13:11:28 roberto Exp $ +-- See Copyright Notice in file all.lua + +print("creating a string too long") +do + local st, msg = pcall(function () + local a = "x" + while true do + a = a .. a.. a.. a.. a.. a.. a.. a.. a.. a + .. a .. a.. a.. a.. a.. a.. a.. a.. a.. a + .. a .. a.. a.. a.. a.. a.. a.. a.. a.. a + .. a .. a.. a.. a.. a.. a.. a.. a.. a.. a + .. a .. a.. a.. a.. a.. a.. a.. a.. a.. a + .. a .. a.. a.. a.. a.. a.. a.. a.. a.. a + .. a .. a.. a.. a.. a.. a.. a.. a.. a.. a + .. a .. a.. a.. a.. a.. a.. a.. a.. a.. a + .. a .. a.. a.. a.. a.. a.. a.. a.. a.. a + .. a .. a.. a.. a.. a.. a.. a.. a.. a.. a + print(string.format("string with %d bytes", #a)) + end + end) + assert(not st and + (string.find(msg, "string length overflow") or + string.find(msg, "not enough memory"))) +end +print('+') + + +local function loadrep (x, what) + local p = 1<<20 + local s = string.rep(x, p) + local count = 0 + local function f() + count = count + p + if count % (0x80*p) == 0 then + io.stderr:write("(", string.format("0x%x", count), ")") + end + return s + end + local st, msg = load(f, "=big") + print(string.format("\ntotal: 0x%x %s", count, what)) + return st, msg +end + + +print("loading chunk with too many lines") +do + local st, msg = loadrep("\n", "lines") + assert(not st and string.find(msg, "too many lines")) +end +print('+') + + +print("loading chunk with huge identifier") +do + local st, msg = loadrep("a", "chars") + assert(not st and + (string.find(msg, "lexical element too long") or + string.find(msg, "not enough memory"))) +end +print('+') + + +print("loading chunk with too many instructions") +do + local st, msg = loadrep("a = 10; ", "instructions") + print(st, msg) +end +print('+') + + +print "OK" diff --git a/tests/lua-5.3/literals.lua b/tests/lua-5.3/literals.lua new file mode 100644 index 0000000..3922b3f --- /dev/null +++ b/tests/lua-5.3/literals.lua @@ -0,0 +1,302 @@ +-- $Id: literals.lua,v 1.36 2016/11/07 13:11:28 roberto Exp $ +-- See Copyright Notice in file all.lua + +print('testing scanner') + +local debug = require "debug" + + +local function dostring (x) return assert(load(x), "")() end + +dostring("x \v\f = \t\r 'a\0a' \v\f\f") +assert(x == 'a\0a' and string.len(x) == 3) + +-- escape sequences +assert('\n\"\'\\' == [[ + +"'\]]) + +assert(string.find("\a\b\f\n\r\t\v", "^%c%c%c%c%c%c%c$")) + +-- assume ASCII just for tests: +assert("\09912" == 'c12') +assert("\99ab" == 'cab') +assert("\099" == '\99') +assert("\099\n" == 'c\10') +assert('\0\0\0alo' == '\0' .. '\0\0' .. 'alo') + +assert(010 .. 020 .. -030 == "1020-30") + +-- hexadecimal escapes +assert("\x00\x05\x10\x1f\x3C\xfF\xe8" == "\0\5\16\31\60\255\232") + +local function lexstring (x, y, n) + local f = assert(load('return ' .. x .. + ', require"debug".getinfo(1).currentline', '')) + local s, l = f() + assert(s == y and l == n) +end + +lexstring("'abc\\z \n efg'", "abcefg", 2) +lexstring("'abc\\z \n\n\n'", "abc", 4) +lexstring("'\\z \n\t\f\v\n'", "", 3) +lexstring("[[\nalo\nalo\n\n]]", "alo\nalo\n\n", 5) +lexstring("[[\nalo\ralo\n\n]]", "alo\nalo\n\n", 5) +lexstring("[[\nalo\ralo\r\n]]", "alo\nalo\n", 4) +lexstring("[[\ralo\n\ralo\r\n]]", "alo\nalo\n", 4) +lexstring("[[alo]\n]alo]]", "alo]\n]alo", 2) + +assert("abc\z + def\z + ghi\z + " == 'abcdefghi') + + +-- UTF-8 sequences +assert("\u{0}\u{00000000}\x00\0" == string.char(0, 0, 0, 0)) + +-- limits for 1-byte sequences +assert("\u{0}\u{7F}" == "\x00\z\x7F") + +-- limits for 2-byte sequences +assert("\u{80}\u{7FF}" == "\xC2\x80\z\xDF\xBF") + +-- limits for 3-byte sequences +assert("\u{800}\u{FFFF}" == "\xE0\xA0\x80\z\xEF\xBF\xBF") + +-- limits for 4-byte sequences +assert("\u{10000}\u{10FFFF}" == "\xF0\x90\x80\x80\z\xF4\x8F\xBF\xBF") + + +-- Error in escape sequences +local function lexerror (s, err) + local st, msg = load('return ' .. s, '') + if err ~= '' then err = err .. "'" end + assert(not st and string.find(msg, "near .-" .. err)) +end + +lexerror([["abc\x"]], [[\x"]]) +lexerror([["abc\x]], [[\x]]) +lexerror([["\x]], [[\x]]) +lexerror([["\x5"]], [[\x5"]]) +lexerror([["\x5]], [[\x5]]) +lexerror([["\xr"]], [[\xr]]) +lexerror([["\xr]], [[\xr]]) +lexerror([["\x.]], [[\x.]]) +lexerror([["\x8%"]], [[\x8%%]]) +lexerror([["\xAG]], [[\xAG]]) +lexerror([["\g"]], [[\g]]) +lexerror([["\g]], [[\g]]) +lexerror([["\."]], [[\%.]]) + +lexerror([["\999"]], [[\999"]]) +lexerror([["xyz\300"]], [[\300"]]) +lexerror([[" \256"]], [[\256"]]) + +-- errors in UTF-8 sequences +lexerror([["abc\u{110000}"]], [[abc\u{110000]]) -- too large +lexerror([["abc\u11r"]], [[abc\u1]]) -- missing '{' +lexerror([["abc\u"]], [[abc\u"]]) -- missing '{' +lexerror([["abc\u{11r"]], [[abc\u{11r]]) -- missing '}' +lexerror([["abc\u{11"]], [[abc\u{11"]]) -- missing '}' +lexerror([["abc\u{11]], [[abc\u{11]]) -- missing '}' +lexerror([["abc\u{r"]], [[abc\u{r]]) -- no digits + +-- unfinished strings +lexerror("[=[alo]]", "") +lexerror("[=[alo]=", "") +lexerror("[=[alo]", "") +lexerror("'alo", "") +lexerror("'alo \\z \n\n", "") +lexerror("'alo \\z", "") +lexerror([['alo \98]], "") + +-- valid characters in variable names +for i = 0, 255 do + local s = string.char(i) + assert(not string.find(s, "[a-zA-Z_]") == not load(s .. "=1", "")) + assert(not string.find(s, "[a-zA-Z_0-9]") == + not load("a" .. s .. "1 = 1", "")) +end + + +-- long variable names + +var1 = string.rep('a', 15000) .. '1' +var2 = string.rep('a', 15000) .. '2' +prog = string.format([[ + %s = 5 + %s = %s + 1 + return function () return %s - %s end +]], var1, var2, var1, var1, var2) +local f = dostring(prog) +assert(_G[var1] == 5 and _G[var2] == 6 and f() == -1) +var1, var2, f = nil +print('+') + +-- escapes -- +assert("\n\t" == [[ + + ]]) +assert([[ + + $debug]] == "\n $debug") +assert([[ [ ]] ~= [[ ] ]]) +-- long strings -- +b = "001234567890123456789012345678901234567891234567890123456789012345678901234567890012345678901234567890123456789012345678912345678901234567890123456789012345678900123456789012345678901234567890123456789123456789012345678901234567890123456789001234567890123456789012345678901234567891234567890123456789012345678901234567890012345678901234567890123456789012345678912345678901234567890123456789012345678900123456789012345678901234567890123456789123456789012345678901234567890123456789001234567890123456789012345678901234567891234567890123456789012345678901234567890012345678901234567890123456789012345678912345678901234567890123456789012345678900123456789012345678901234567890123456789123456789012345678901234567890123456789001234567890123456789012345678901234567891234567890123456789012345678901234567890012345678901234567890123456789012345678912345678901234567890123456789012345678900123456789012345678901234567890123456789123456789012345678901234567890123456789" +assert(string.len(b) == 960) +prog = [=[ +print('+') + +a1 = [["this is a 'string' with several 'quotes'"]] +a2 = "'quotes'" + +assert(string.find(a1, a2) == 34) +print('+') + +a1 = [==[temp = [[an arbitrary value]]; ]==] +assert(load(a1))() +assert(temp == 'an arbitrary value') +-- long strings -- +b = "001234567890123456789012345678901234567891234567890123456789012345678901234567890012345678901234567890123456789012345678912345678901234567890123456789012345678900123456789012345678901234567890123456789123456789012345678901234567890123456789001234567890123456789012345678901234567891234567890123456789012345678901234567890012345678901234567890123456789012345678912345678901234567890123456789012345678900123456789012345678901234567890123456789123456789012345678901234567890123456789001234567890123456789012345678901234567891234567890123456789012345678901234567890012345678901234567890123456789012345678912345678901234567890123456789012345678900123456789012345678901234567890123456789123456789012345678901234567890123456789001234567890123456789012345678901234567891234567890123456789012345678901234567890012345678901234567890123456789012345678912345678901234567890123456789012345678900123456789012345678901234567890123456789123456789012345678901234567890123456789" +assert(string.len(b) == 960) +print('+') + +a = [[00123456789012345678901234567890123456789123456789012345678901234567890123456789 +00123456789012345678901234567890123456789123456789012345678901234567890123456789 +00123456789012345678901234567890123456789123456789012345678901234567890123456789 +00123456789012345678901234567890123456789123456789012345678901234567890123456789 +00123456789012345678901234567890123456789123456789012345678901234567890123456789 +00123456789012345678901234567890123456789123456789012345678901234567890123456789 +00123456789012345678901234567890123456789123456789012345678901234567890123456789 +00123456789012345678901234567890123456789123456789012345678901234567890123456789 +00123456789012345678901234567890123456789123456789012345678901234567890123456789 +00123456789012345678901234567890123456789123456789012345678901234567890123456789 +00123456789012345678901234567890123456789123456789012345678901234567890123456789 +00123456789012345678901234567890123456789123456789012345678901234567890123456789 +00123456789012345678901234567890123456789123456789012345678901234567890123456789 +00123456789012345678901234567890123456789123456789012345678901234567890123456789 +00123456789012345678901234567890123456789123456789012345678901234567890123456789 +00123456789012345678901234567890123456789123456789012345678901234567890123456789 +00123456789012345678901234567890123456789123456789012345678901234567890123456789 +00123456789012345678901234567890123456789123456789012345678901234567890123456789 +00123456789012345678901234567890123456789123456789012345678901234567890123456789 +00123456789012345678901234567890123456789123456789012345678901234567890123456789 +00123456789012345678901234567890123456789123456789012345678901234567890123456789 +00123456789012345678901234567890123456789123456789012345678901234567890123456789 +00123456789012345678901234567890123456789123456789012345678901234567890123456789 +]] +assert(string.len(a) == 1863) +assert(string.sub(a, 1, 40) == string.sub(b, 1, 40)) +x = 1 +]=] + +print('+') +x = nil +dostring(prog) +assert(x) + +prog = nil +a = nil +b = nil + + +-- testing line ends +prog = [[ +a = 1 -- a comment +b = 2 + + +x = [=[ +hi +]=] +y = "\ +hello\r\n\ +" +return require"debug".getinfo(1).currentline +]] + +for _, n in pairs{"\n", "\r", "\n\r", "\r\n"} do + local prog, nn = string.gsub(prog, "\n", n) + assert(dostring(prog) == nn) + assert(_G.x == "hi\n" and _G.y == "\nhello\r\n\n") +end + + +-- testing comments and strings with long brackets +a = [==[]=]==] +assert(a == "]=") + +a = [==[[===[[=[]]=][====[]]===]===]==] +assert(a == "[===[[=[]]=][====[]]===]===") + +a = [====[[===[[=[]]=][====[]]===]===]====] +assert(a == "[===[[=[]]=][====[]]===]===") + +a = [=[]]]]]]]]]=] +assert(a == "]]]]]]]]") + + +--[===[ +x y z [==[ blu foo +]== +] +]=]==] +error error]=]===] + +-- generate all strings of four of these chars +local x = {"=", "[", "]", "\n"} +local len = 4 +local function gen (c, n) + if n==0 then coroutine.yield(c) + else + for _, a in pairs(x) do + gen(c..a, n-1) + end + end +end + +for s in coroutine.wrap(function () gen("", len) end) do + assert(s == load("return [====[\n"..s.."]====]", "")()) +end + + +-- testing decimal point locale +if os.setlocale("pt_BR") or os.setlocale("ptb") then + assert(tonumber("3,4") == 3.4 and tonumber"3.4" == 3.4) + assert(tonumber(" -.4 ") == -0.4) + assert(tonumber(" +0x.41 ") == 0X0.41) + assert(not load("a = (3,4)")) + assert(assert(load("return 3.4"))() == 3.4) + assert(assert(load("return .4,3"))() == .4) + assert(assert(load("return 4."))() == 4.) + assert(assert(load("return 4.+.5"))() == 4.5) + + assert(" 0x.1 " + " 0x,1" + "-0X.1\t" == 0x0.1) + + assert(tonumber"inf" == nil and tonumber"NAN" == nil) + + assert(assert(load(string.format("return %q", 4.51)))() == 4.51) + + local a,b = load("return 4.5.") + assert(string.find(b, "'4%.5%.'")) + + assert(os.setlocale("C")) +else + (Message or print)( + '\n >>> pt_BR locale not available: skipping decimal point tests <<<\n') +end + + +-- testing %q x line ends +local s = "a string with \r and \n and \r\n and \n\r" +local c = string.format("return %q", s) +assert(assert(load(c))() == s) + +-- testing errors +assert(not load"a = 'non-ending string") +assert(not load"a = 'non-ending string\n'") +assert(not load"a = '\\345'") +assert(not load"a = [=x]") + +print('OK') diff --git a/tests/lua-5.3/locals.lua b/tests/lua-5.3/locals.lua new file mode 100644 index 0000000..f66f6f7 --- /dev/null +++ b/tests/lua-5.3/locals.lua @@ -0,0 +1,162 @@ +-- $Id: locals.lua,v 1.37 2016/11/07 13:11:28 roberto Exp $ +-- See Copyright Notice in file all.lua + +print('testing local variables and environments') + +local debug = require"debug" + + +-- bug in 5.1: + +local function f(x) x = nil; return x end +assert(f(10) == nil) + +local function f() local x; return x end +assert(f(10) == nil) + +local function f(x) x = nil; local y; return x, y end +assert(f(10) == nil and select(2, f(20)) == nil) + +do + local i = 10 + do local i = 100; assert(i==100) end + do local i = 1000; assert(i==1000) end + assert(i == 10) + if i ~= 10 then + local i = 20 + else + local i = 30 + assert(i == 30) + end +end + + + +f = nil + +local f +x = 1 + +a = nil +load('local a = {}')() +assert(a == nil) + +function f (a) + local _1, _2, _3, _4, _5 + local _6, _7, _8, _9, _10 + local x = 3 + local b = a + local c,d = a,b + if (d == b) then + local x = 'q' + x = b + assert(x == 2) + else + assert(nil) + end + assert(x == 3) + local f = 10 +end + +local b=10 +local a; repeat local b; a,b=1,2; assert(a+1==b); until a+b==3 + + +assert(x == 1) + +f(2) +assert(type(f) == 'function') + + +local function getenv (f) + local a,b = debug.getupvalue(f, 1) + assert(a == '_ENV') + return b +end + +-- test for global table of loaded chunks +assert(getenv(load"a=3") == _G) +local c = {}; local f = load("a = 3", nil, nil, c) +assert(getenv(f) == c) +assert(c.a == nil) +f() +assert(c.a == 3) + +-- old test for limits for special instructions (now just a generic test) +do + local i = 2 + local p = 4 -- p == 2^i + repeat + for j=-3,3 do + assert(load(string.format([[local a=%s; + a=a+%s; + assert(a ==2^%s)]], j, p-j, i), '')) () + assert(load(string.format([[local a=%s; + a=a-%s; + assert(a==-2^%s)]], -j, p-j, i), '')) () + assert(load(string.format([[local a,b=0,%s; + a=b-%s; + assert(a==-2^%s)]], -j, p-j, i), '')) () + end + p = 2 * p; i = i + 1 + until p <= 0 +end + +print'+' + + +if rawget(_G, "querytab") then + -- testing clearing of dead elements from tables + collectgarbage("stop") -- stop GC + local a = {[{}] = 4, [3] = 0, alo = 1, + a1234567890123456789012345678901234567890 = 10} + + local t = querytab(a) + + for k,_ in pairs(a) do a[k] = nil end + collectgarbage() -- restore GC and collect dead fiels in `a' + for i=0,t-1 do + local k = querytab(a, i) + assert(k == nil or type(k) == 'number' or k == 'alo') + end +end + + +-- testing lexical environments + +assert(_ENV == _G) + +do +local dummy +local _ENV = (function (...) return ... end)(_G, dummy) -- { + +do local _ENV = {assert=assert}; assert(true) end +mt = {_G = _G} +local foo,x +A = false -- "declare" A +do local _ENV = mt + function foo (x) + A = x + do local _ENV = _G; A = 1000 end + return function (x) return A .. x end + end +end +assert(getenv(foo) == mt) +x = foo('hi'); assert(mt.A == 'hi' and A == 1000) +assert(x('*') == mt.A .. '*') + +do local _ENV = {assert=assert, A=10}; + do local _ENV = {assert=assert, A=20}; + assert(A==20);x=A + end + assert(A==10 and x==20) +end +assert(x==20) + + +print('OK') + +return 5,f + +end -- } + diff --git a/tests/lua-5.3/main.lua b/tests/lua-5.3/main.lua new file mode 100644 index 0000000..9fc20c1 --- /dev/null +++ b/tests/lua-5.3/main.lua @@ -0,0 +1,381 @@ +# testing special comment on first line +-- $Id: main.lua,v 1.65 2016/11/07 13:11:28 roberto Exp $ +-- See Copyright Notice in file all.lua + +-- most (all?) tests here assume a reasonable "Unix-like" shell +if _port then return end + +-- use only "double quotes" inside shell scripts (better change to +-- run on Windows) + + +print ("testing stand-alone interpreter") + +assert(os.execute()) -- machine has a system command + +local arg = arg or _ARG + +local prog = os.tmpname() +local otherprog = os.tmpname() +local out = os.tmpname() + +local progname +do + local i = 0 + while arg[i] do i=i-1 end + progname = arg[i+1] +end +print("progname: "..progname) + +local prepfile = function (s, p) + p = p or prog + io.output(p) + io.write(s) + assert(io.close()) +end + +local function getoutput () + io.input(out) + local t = io.read("a") + io.input():close() + assert(os.remove(out)) + return t +end + +local function checkprogout (s) + local t = getoutput() + for line in string.gmatch(s, ".-\n") do + assert(string.find(t, line, 1, true)) + end +end + +local function checkout (s) + local t = getoutput() + if s ~= t then print(string.format("'%s' - '%s'\n", s, t)) end + assert(s == t) + return t +end + + +local function RUN (p, ...) + p = string.gsub(p, "lua", '"'..progname..'"', 1) + local s = string.format(p, ...) + assert(os.execute(s)) +end + +local function NoRun (msg, p, ...) + p = string.gsub(p, "lua", '"'..progname..'"', 1) + local s = string.format(p, ...) + s = string.format("%s 2> %s", s, out) -- will send error to 'out' + assert(not os.execute(s)) + assert(string.find(getoutput(), msg, 1, true)) -- check error message +end + +RUN('lua -v') + +print(string.format("(temporary program file used in these tests: %s)", prog)) + +-- running stdin as a file +prepfile"" +RUN('lua - < %s > %s', prog, out) +checkout("") + +prepfile[[ + print( +1, a +) +]] +RUN('lua - < %s > %s', prog, out) +checkout("1\tnil\n") + +RUN('echo "print(10)\nprint(2)\n" | lua > %s', out) +checkout("10\n2\n") + + +-- test option '-' +RUN('echo "print(arg[1])" | lua - -h > %s', out) +checkout("-h\n") + +-- test environment variables used by Lua + +prepfile("print(package.path)") + +-- test LUA_PATH +RUN('env LUA_INIT= LUA_PATH=x lua %s > %s', prog, out) +checkout("x\n") + +-- test LUA_PATH_version +RUN('env LUA_INIT= LUA_PATH_5_3=y LUA_PATH=x lua %s > %s', prog, out) +checkout("y\n") + +-- test LUA_CPATH +prepfile("print(package.cpath)") +RUN('env LUA_INIT= LUA_CPATH=xuxu lua %s > %s', prog, out) +checkout("xuxu\n") + +-- test LUA_CPATH_version +RUN('env LUA_INIT= LUA_CPATH_5_3=yacc LUA_CPATH=x lua %s > %s', prog, out) +checkout("yacc\n") + +-- test LUA_INIT (and its access to 'arg' table) +prepfile("print(X)") +RUN('env LUA_INIT="X=tonumber(arg[1])" lua %s 3.2 > %s', prog, out) +checkout("3.2\n") + +-- test LUA_INIT_version +prepfile("print(X)") +RUN('env LUA_INIT_5_3="X=10" LUA_INIT="X=3" lua %s > %s', prog, out) +checkout("10\n") + +-- test LUA_INIT for files +prepfile("x = x or 10; print(x); x = x + 1") +RUN('env LUA_INIT="@%s" lua %s > %s', prog, prog, out) +checkout("10\n11\n") + +-- test errors in LUA_INIT +NoRun('LUA_INIT:1: msg', 'env LUA_INIT="error(\'msg\')" lua') + +-- test option '-E' +local defaultpath, defaultCpath + +do + prepfile("print(package.path, package.cpath)") + RUN('env LUA_INIT="error(10)" LUA_PATH=xxx LUA_CPATH=xxx lua -E %s > %s', + prog, out) + local out = getoutput() + defaultpath = string.match(out, "^(.-)\t") + defaultCpath = string.match(out, "\t(.-)$") +end + +-- paths did not changed +assert(not string.find(defaultpath, "xxx") and + string.find(defaultpath, "lua") and + not string.find(defaultCpath, "xxx") and + string.find(defaultCpath, "lua")) + + +-- test replacement of ';;' to default path +local function convert (p) + prepfile("print(package.path)") + RUN('env LUA_PATH="%s" lua %s > %s', p, prog, out) + local expected = getoutput() + expected = string.sub(expected, 1, -2) -- cut final end of line + assert(string.gsub(p, ";;", ";"..defaultpath..";") == expected) +end + +convert(";") +convert(";;") +convert(";;;") +convert(";;;;") +convert(";;;;;") +convert(";;a;;;bc") + + +-- test -l over multiple libraries +prepfile("print(1); a=2; return {x=15}") +prepfile(("print(a); print(_G['%s'].x)"):format(prog), otherprog) +RUN('env LUA_PATH="?;;" lua -l %s -l%s -lstring -l io %s > %s', prog, otherprog, otherprog, out) +checkout("1\n2\n15\n2\n15\n") + +-- test 'arg' table +local a = [[ + assert(#arg == 3 and arg[1] == 'a' and + arg[2] == 'b' and arg[3] == 'c') + assert(arg[-1] == '--' and arg[-2] == "-e " and arg[-3] == '%s') + assert(arg[4] == nil and arg[-4] == nil) + local a, b, c = ... + assert(... == 'a' and a == 'a' and b == 'b' and c == 'c') +]] +a = string.format(a, progname) +prepfile(a) +RUN('lua "-e " -- %s a b c', prog) -- "-e " runs an empty command + +-- test 'arg' availability in libraries +prepfile"assert(arg)" +prepfile("assert(arg)", otherprog) +RUN('env LUA_PATH="?;;" lua -l%s - < %s', prog, otherprog) + +-- test messing up the 'arg' table +RUN('echo "print(...)" | lua -e "arg[1] = 100" - > %s', out) +checkout("100\n") +NoRun("'arg' is not a table", 'echo "" | lua -e "arg = 1" -') + +-- test error in 'print' +RUN('echo 10 | lua -e "print=nil" -i > /dev/null 2> %s', out) +assert(string.find(getoutput(), "error calling 'print'")) + +-- test 'debug.debug' +RUN('echo "io.stderr:write(1000)\ncont" | lua -e "require\'debug\'.debug()" 2> %s', out) +checkout("lua_debug> 1000lua_debug> ") + +-- test many arguments +prepfile[[print(({...})[30])]] +RUN('lua %s %s > %s', prog, string.rep(" a", 30), out) +checkout("a\n") + +RUN([[lua "-eprint(1)" -ea=3 -e "print(a)" > %s]], out) +checkout("1\n3\n") + +-- test iteractive mode +prepfile[[ +(6*2-6) -- === +a = +10 +print(a) +a]] +RUN([[lua -e"_PROMPT='' _PROMPT2=''" -i < %s > %s]], prog, out) +checkprogout("6\n10\n10\n\n") + +prepfile("a = [[b\nc\nd\ne]]\n=a") +RUN([[lua -e"_PROMPT='' _PROMPT2=''" -i < %s > %s]], prog, out) +checkprogout("b\nc\nd\ne\n\n") + +prompt = "alo" +prepfile[[ -- +a = 2 +]] +RUN([[lua "-e_PROMPT='%s'" -i < %s > %s]], prompt, prog, out) +local t = getoutput() +assert(string.find(t, prompt .. ".*" .. prompt .. ".*" .. prompt)) + +-- test for error objects +prepfile[[ +debug = require "debug" +m = {x=0} +setmetatable(m, {__tostring = function(x) + return tostring(debug.getinfo(4).currentline + x.x) +end}) +error(m) +]] +NoRun(progname .. ": 6\n", [[lua %s]], prog) + +prepfile("error{}") +NoRun("error object is a table value", [[lua %s]], prog) + + +-- chunk broken in many lines +s = [=[ -- +function f ( x ) + local a = [[ +xuxu +]] + local b = "\ +xuxu\n" + if x == 11 then return 1 + 12 , 2 + 20 end --[[ test multiple returns ]] + return x + 1 + --\\ +end +return( f( 100 ) ) +assert( a == b ) +do return f( 11 ) end ]=] +s = string.gsub(s, ' ', '\n\n') -- change all spaces for newlines +prepfile(s) +RUN([[lua -e"_PROMPT='' _PROMPT2=''" -i < %s > %s]], prog, out) +checkprogout("101\n13\t22\n\n") + +prepfile[[#comment in 1st line without \n at the end]] +RUN('lua %s', prog) + +prepfile[[#test line number when file starts with comment line +debug = require"debug" +print(debug.getinfo(1).currentline) +]] +RUN('lua %s > %s', prog, out) +checkprogout('3') + +-- close Lua with an open file +prepfile(string.format([[io.output(%q); io.write('alo')]], out)) +RUN('lua %s', prog) +checkout('alo') + +-- bug in 5.2 beta (extra \0 after version line) +RUN([[lua -v -e"print'hello'" > %s]], out) +t = getoutput() +assert(string.find(t, "PUC%-Rio\nhello")) + + +-- testing os.exit +prepfile("os.exit(nil, true)") +RUN('lua %s', prog) +prepfile("os.exit(0, true)") +RUN('lua %s', prog) +prepfile("os.exit(true, true)") +RUN('lua %s', prog) +prepfile("os.exit(1, true)") +NoRun("", "lua %s", prog) -- no message +prepfile("os.exit(false, true)") +NoRun("", "lua %s", prog) -- no message + +-- remove temporary files +assert(os.remove(prog)) +assert(os.remove(otherprog)) +assert(not os.remove(out)) + +-- invalid options +NoRun("unrecognized option '-h'", "lua -h") +NoRun("unrecognized option '---'", "lua ---") +NoRun("unrecognized option '-Ex'", "lua -Ex") +NoRun("unrecognized option '-vv'", "lua -vv") +NoRun("unrecognized option '-iv'", "lua -iv") +NoRun("'-e' needs argument", "lua -e") +NoRun("syntax error", "lua -e a") +NoRun("'-l' needs argument", "lua -l") + + +if T then -- auxiliary library? + print("testing 'not enough memory' to create a state") + NoRun("not enough memory", "env MEMLIMIT=100 lua") +end +print('+') + +print('testing Ctrl C') +do + -- interrupt a script + local function kill (pid) + return os.execute(string.format('kill -INT %d 2> /dev/null', pid)) + end + + -- function to run a script in background, returning its output file + -- descriptor and its pid + local function runback (luaprg) + -- shell script to run 'luaprg' in background and echo its pid + local shellprg = string.format('%s -e "%s" & echo $!', progname, luaprg) + local f = io.popen(shellprg, "r") -- run shell script + local pid = f:read() -- get pid for Lua script + print("(if test fails now, it may leave a Lua script running in \z + background, pid " .. pid .. ")") + return f, pid + end + + -- Lua script that runs protected infinite loop and then prints '42' + local f, pid = runback[[ + pcall(function () print(12); while true do end end); print(42)]] + -- wait until script is inside 'pcall' + assert(f:read() == "12") + kill(pid) -- send INT signal to Lua script + -- check that 'pcall' captured the exception and script continued running + assert(f:read() == "42") -- expected output + assert(f:close()) + print("done") + + -- Lua script in a long unbreakable search + local f, pid = runback[[ + print(15); string.find(string.rep('a', 100000), '.*b')]] + -- wait (so script can reach the loop) + assert(f:read() == "15") + assert(os.execute("sleep 1")) + -- must send at least two INT signals to stop this Lua script + local n = 100 + for i = 0, 100 do -- keep sending signals + if not kill(pid) then -- until it fails + n = i -- number of non-failed kills + break + end + end + assert(f:close()) + assert(n >= 2) + print(string.format("done (with %d kills)", n)) + +end + +print("OK") diff --git a/tests/lua-5.3/math.lua b/tests/lua-5.3/math.lua new file mode 100644 index 0000000..53ce9b5 --- /dev/null +++ b/tests/lua-5.3/math.lua @@ -0,0 +1,824 @@ +-- $Id: math.lua,v 1.78 2016/11/07 13:11:28 roberto Exp $ +-- See Copyright Notice in file all.lua + +print("testing numbers and math lib") + +local minint = math.mininteger +local maxint = math.maxinteger + +local intbits = math.floor(math.log(maxint, 2) + 0.5) + 1 +assert((1 << intbits) == 0) + +assert(minint == 1 << (intbits - 1)) +assert(maxint == minint - 1) + +-- number of bits in the mantissa of a floating-point number +local floatbits = 24 +do + local p = 2.0^floatbits + while p < p + 1.0 do + p = p * 2.0 + floatbits = floatbits + 1 + end +end + +local function isNaN (x) + return (x ~= x) +end + +assert(isNaN(0/0)) +assert(not isNaN(1/0)) + + +do + local x = 2.0^floatbits + assert(x > x - 1.0 and x == x + 1.0) + + print(string.format("%d-bit integers, %d-bit (mantissa) floats", + intbits, floatbits)) +end + +assert(math.type(0) == "integer" and math.type(0.0) == "float" + and math.type("10") == nil) + + +local function checkerror (msg, f, ...) + local s, err = pcall(f, ...) + assert(not s and string.find(err, msg)) +end + +local msgf2i = "number.* has no integer representation" + +-- float equality +function eq (a,b,limit) + if not limit then + if floatbits >= 50 then limit = 1E-11 + else limit = 1E-5 + end + end + -- a == b needed for +inf/-inf + return a == b or math.abs(a-b) <= limit +end + + +-- equality with types +function eqT (a,b) + return a == b and math.type(a) == math.type(b) +end + + +-- basic float notation +assert(0e12 == 0 and .0 == 0 and 0. == 0 and .2e2 == 20 and 2.E-1 == 0.2) + +do + local a,b,c = "2", " 3e0 ", " 10 " + assert(a+b == 5 and -b == -3 and b+"2" == 5 and "10"-c == 0) + assert(type(a) == 'string' and type(b) == 'string' and type(c) == 'string') + assert(a == "2" and b == " 3e0 " and c == " 10 " and -c == -" 10 ") + assert(c%a == 0 and a^b == 08) + a = 0 + assert(a == -a and 0 == -0) +end + +do + local x = -1 + local mz = 0/x -- minus zero + t = {[0] = 10, 20, 30, 40, 50} + assert(t[mz] == t[0] and t[-0] == t[0]) +end + +do -- tests for 'modf' + local a,b = math.modf(3.5) + assert(a == 3.0 and b == 0.5) + a,b = math.modf(-2.5) + assert(a == -2.0 and b == -0.5) + a,b = math.modf(-3e23) + assert(a == -3e23 and b == 0.0) + a,b = math.modf(3e35) + assert(a == 3e35 and b == 0.0) + a,b = math.modf(-1/0) -- -inf + assert(a == -1/0 and b == 0.0) + a,b = math.modf(1/0) -- inf + assert(a == 1/0 and b == 0.0) + a,b = math.modf(0/0) -- NaN + assert(isNaN(a) and isNaN(b)) + a,b = math.modf(3) -- integer argument + assert(eqT(a, 3) and eqT(b, 0.0)) + a,b = math.modf(minint) + assert(eqT(a, minint) and eqT(b, 0.0)) +end + +assert(math.huge > 10e30) +assert(-math.huge < -10e30) + + +-- integer arithmetic +assert(minint < minint + 1) +assert(maxint - 1 < maxint) +assert(0 - minint == minint) +assert(minint * minint == 0) +assert(maxint * maxint * maxint == maxint) + + +-- testing floor division and conversions + +for _, i in pairs{-16, -15, -3, -2, -1, 0, 1, 2, 3, 15} do + for _, j in pairs{-16, -15, -3, -2, -1, 1, 2, 3, 15} do + for _, ti in pairs{0, 0.0} do -- try 'i' as integer and as float + for _, tj in pairs{0, 0.0} do -- try 'j' as integer and as float + local x = i + ti + local y = j + tj + assert(i//j == math.floor(i/j)) + end + end + end +end + +assert(1//0.0 == 1/0) +assert(-1 // 0.0 == -1/0) +assert(eqT(3.5 // 1.5, 2.0)) +assert(eqT(3.5 // -1.5, -3.0)) + +assert(maxint // maxint == 1) +assert(maxint // 1 == maxint) +assert((maxint - 1) // maxint == 0) +assert(maxint // (maxint - 1) == 1) +assert(minint // minint == 1) +assert(minint // minint == 1) +assert((minint + 1) // minint == 0) +assert(minint // (minint + 1) == 1) +assert(minint // 1 == minint) + +assert(minint // -1 == -minint) +assert(minint // -2 == 2^(intbits - 2)) +assert(maxint // -1 == -maxint) + + +-- negative exponents +do + assert(2^-3 == 1 / 2^3) + assert(eq((-3)^-3, 1 / (-3)^3)) + for i = -3, 3 do -- variables avoid constant folding + for j = -3, 3 do + -- domain errors (0^(-n)) are not portable + if not _port or i ~= 0 or j > 0 then + assert(eq(i^j, 1 / i^(-j))) + end + end + end +end + +-- comparison between floats and integers (border cases) +if floatbits < intbits then + assert(2.0^floatbits == (1 << floatbits)) + assert(2.0^floatbits - 1.0 == (1 << floatbits) - 1.0) + assert(2.0^floatbits - 1.0 ~= (1 << floatbits)) + -- float is rounded, int is not + assert(2.0^floatbits + 1.0 ~= (1 << floatbits) + 1) +else -- floats can express all integers with full accuracy + assert(maxint == maxint + 0.0) + assert(maxint - 1 == maxint - 1.0) + assert(minint + 1 == minint + 1.0) + assert(maxint ~= maxint - 1.0) +end +assert(maxint + 0.0 == 2.0^(intbits - 1) - 1.0) +assert(minint + 0.0 == minint) +assert(minint + 0.0 == -2.0^(intbits - 1)) + + +-- order between floats and integers +assert(1 < 1.1); assert(not (1 < 0.9)) +assert(1 <= 1.1); assert(not (1 <= 0.9)) +assert(-1 < -0.9); assert(not (-1 < -1.1)) +assert(1 <= 1.1); assert(not (-1 <= -1.1)) +assert(-1 < -0.9); assert(not (-1 < -1.1)) +assert(-1 <= -0.9); assert(not (-1 <= -1.1)) +assert(minint <= minint + 0.0) +assert(minint + 0.0 <= minint) +assert(not (minint < minint + 0.0)) +assert(not (minint + 0.0 < minint)) +assert(maxint < minint * -1.0) +assert(maxint <= minint * -1.0) + +do + local fmaxi1 = 2^(intbits - 1) + assert(maxint < fmaxi1) + assert(maxint <= fmaxi1) + assert(not (fmaxi1 <= maxint)) + assert(minint <= -2^(intbits - 1)) + assert(-2^(intbits - 1) <= minint) +end + +if floatbits < intbits then + print("testing order (floats cannot represent all integers)") + local fmax = 2^floatbits + local ifmax = fmax | 0 + assert(fmax < ifmax + 1) + assert(fmax - 1 < ifmax) + assert(-(fmax - 1) > -ifmax) + assert(not (fmax <= ifmax - 1)) + assert(-fmax > -(ifmax + 1)) + assert(not (-fmax >= -(ifmax - 1))) + + assert(fmax/2 - 0.5 < ifmax//2) + assert(-(fmax/2 - 0.5) > -ifmax//2) + + assert(maxint < 2^intbits) + assert(minint > -2^intbits) + assert(maxint <= 2^intbits) + assert(minint >= -2^intbits) +else + print("testing order (floats can represent all integers)") + assert(maxint < maxint + 1.0) + assert(maxint < maxint + 0.5) + assert(maxint - 1.0 < maxint) + assert(maxint - 0.5 < maxint) + assert(not (maxint + 0.0 < maxint)) + assert(maxint + 0.0 <= maxint) + assert(not (maxint < maxint + 0.0)) + assert(maxint + 0.0 <= maxint) + assert(maxint <= maxint + 0.0) + assert(not (maxint + 1.0 <= maxint)) + assert(not (maxint + 0.5 <= maxint)) + assert(not (maxint <= maxint - 1.0)) + assert(not (maxint <= maxint - 0.5)) + + assert(minint < minint + 1.0) + assert(minint < minint + 0.5) + assert(minint <= minint + 0.5) + assert(minint - 1.0 < minint) + assert(minint - 1.0 <= minint) + assert(not (minint + 0.0 < minint)) + assert(not (minint + 0.5 < minint)) + assert(not (minint < minint + 0.0)) + assert(minint + 0.0 <= minint) + assert(minint <= minint + 0.0) + assert(not (minint + 1.0 <= minint)) + assert(not (minint + 0.5 <= minint)) + assert(not (minint <= minint - 1.0)) +end + +do + local NaN = 0/0 + assert(not (NaN < 0)) + assert(not (NaN > minint)) + assert(not (NaN <= -9)) + assert(not (NaN <= maxint)) + assert(not (NaN < maxint)) + assert(not (minint <= NaN)) + assert(not (minint < NaN)) +end + + +-- avoiding errors at compile time +local function checkcompt (msg, code) + checkerror(msg, assert(load(code))) +end +checkcompt("divide by zero", "return 2 // 0") +checkcompt(msgf2i, "return 2.3 >> 0") +checkcompt(msgf2i, ("return 2.0^%d & 1"):format(intbits - 1)) +checkcompt("field 'huge'", "return math.huge << 1") +checkcompt(msgf2i, ("return 1 | 2.0^%d"):format(intbits - 1)) +checkcompt(msgf2i, "return 2.3 ~ '0.0'") + + +-- testing overflow errors when converting from float to integer (runtime) +local function f2i (x) return x | x end +checkerror(msgf2i, f2i, math.huge) -- +inf +checkerror(msgf2i, f2i, -math.huge) -- -inf +checkerror(msgf2i, f2i, 0/0) -- NaN + +if floatbits < intbits then + -- conversion tests when float cannot represent all integers + assert(maxint + 1.0 == maxint + 0.0) + assert(minint - 1.0 == minint + 0.0) + checkerror(msgf2i, f2i, maxint + 0.0) + assert(f2i(2.0^(intbits - 2)) == 1 << (intbits - 2)) + assert(f2i(-2.0^(intbits - 2)) == -(1 << (intbits - 2))) + assert((2.0^(floatbits - 1) + 1.0) // 1 == (1 << (floatbits - 1)) + 1) + -- maximum integer representable as a float + local mf = maxint - (1 << (floatbits - intbits)) + 1 + assert(f2i(mf + 0.0) == mf) -- OK up to here + mf = mf + 1 + assert(f2i(mf + 0.0) ~= mf) -- no more representable +else + -- conversion tests when float can represent all integers + assert(maxint + 1.0 > maxint) + assert(minint - 1.0 < minint) + assert(f2i(maxint + 0.0) == maxint) + checkerror("no integer rep", f2i, maxint + 1.0) + checkerror("no integer rep", f2i, minint - 1.0) +end + +-- 'minint' should be representable as a float no matter the precision +assert(f2i(minint + 0.0) == minint) + + +-- testing numeric strings + +assert("2" + 1 == 3) +assert("2 " + 1 == 3) +assert(" -2 " + 1 == -1) +assert(" -0xa " + 1 == -9) + + +-- Literal integer Overflows (new behavior in 5.3.3) +do + -- no overflows + assert(eqT(tonumber(tostring(maxint)), maxint)) + assert(eqT(tonumber(tostring(minint)), minint)) + + -- add 1 to last digit as a string (it cannot be 9...) + local function incd (n) + local s = string.format("%d", n) + s = string.gsub(s, "%d$", function (d) + assert(d ~= '9') + return string.char(string.byte(d) + 1) + end) + return s + end + + -- 'tonumber' with overflow by 1 + assert(eqT(tonumber(incd(maxint)), maxint + 1.0)) + assert(eqT(tonumber(incd(minint)), minint - 1.0)) + + -- large numbers + assert(eqT(tonumber("1"..string.rep("0", 30)), 1e30)) + assert(eqT(tonumber("-1"..string.rep("0", 30)), -1e30)) + + -- hexa format still wraps around + assert(eqT(tonumber("0x1"..string.rep("0", 30)), 0)) + + -- lexer in the limits + assert(minint == load("return " .. minint)()) + assert(eqT(maxint, load("return " .. maxint)())) + + assert(eqT(10000000000000000000000.0, 10000000000000000000000)) + assert(eqT(-10000000000000000000000.0, -10000000000000000000000)) +end + + +-- testing 'tonumber' + +-- 'tonumber' with numbers +assert(tonumber(3.4) == 3.4) +assert(eqT(tonumber(3), 3)) +assert(eqT(tonumber(maxint), maxint) and eqT(tonumber(minint), minint)) +assert(tonumber(1/0) == 1/0) + +-- 'tonumber' with strings +assert(tonumber("0") == 0) +assert(tonumber("") == nil) +assert(tonumber(" ") == nil) +assert(tonumber("-") == nil) +assert(tonumber(" -0x ") == nil) +assert(tonumber{} == nil) +assert(tonumber'+0.01' == 1/100 and tonumber'+.01' == 0.01 and + tonumber'.01' == 0.01 and tonumber'-1.' == -1 and + tonumber'+1.' == 1) +assert(tonumber'+ 0.01' == nil and tonumber'+.e1' == nil and + tonumber'1e' == nil and tonumber'1.0e+' == nil and + tonumber'.' == nil) +assert(tonumber('-012') == -010-2) +assert(tonumber('-1.2e2') == - - -120) + +assert(tonumber("0xffffffffffff") == (1 << (4*12)) - 1) +assert(tonumber("0x"..string.rep("f", (intbits//4))) == -1) +assert(tonumber("-0x"..string.rep("f", (intbits//4))) == 1) + +-- testing 'tonumber' with base +assert(tonumber(' 001010 ', 2) == 10) +assert(tonumber(' 001010 ', 10) == 001010) +assert(tonumber(' -1010 ', 2) == -10) +assert(tonumber('10', 36) == 36) +assert(tonumber(' -10 ', 36) == -36) +assert(tonumber(' +1Z ', 36) == 36 + 35) +assert(tonumber(' -1z ', 36) == -36 + -35) +assert(tonumber('-fFfa', 16) == -(10+(16*(15+(16*(15+(16*15))))))) +assert(tonumber(string.rep('1', (intbits - 2)), 2) + 1 == 2^(intbits - 2)) +assert(tonumber('ffffFFFF', 16)+1 == (1 << 32)) +assert(tonumber('0ffffFFFF', 16)+1 == (1 << 32)) +assert(tonumber('-0ffffffFFFF', 16) - 1 == -(1 << 40)) +for i = 2,36 do + local i2 = i * i + local i10 = i2 * i2 * i2 * i2 * i2 -- i^10 + assert(tonumber('\t10000000000\t', i) == i10) +end + +if not _soft then + -- tests with very long numerals + assert(tonumber("0x"..string.rep("f", 13)..".0") == 2.0^(4*13) - 1) + assert(tonumber("0x"..string.rep("f", 150)..".0") == 2.0^(4*150) - 1) + assert(tonumber("0x"..string.rep("f", 300)..".0") == 2.0^(4*300) - 1) + assert(tonumber("0x"..string.rep("f", 500)..".0") == 2.0^(4*500) - 1) + assert(tonumber('0x3.' .. string.rep('0', 1000)) == 3) + assert(tonumber('0x' .. string.rep('0', 1000) .. 'a') == 10) + assert(tonumber('0x0.' .. string.rep('0', 13).."1") == 2.0^(-4*14)) + assert(tonumber('0x0.' .. string.rep('0', 150).."1") == 2.0^(-4*151)) + assert(tonumber('0x0.' .. string.rep('0', 300).."1") == 2.0^(-4*301)) + assert(tonumber('0x0.' .. string.rep('0', 500).."1") == 2.0^(-4*501)) + + assert(tonumber('0xe03' .. string.rep('0', 1000) .. 'p-4000') == 3587.0) + assert(tonumber('0x.' .. string.rep('0', 1000) .. '74p4004') == 0x7.4) +end + +-- testing 'tonumber' for invalid formats + +local function f (...) + if select('#', ...) == 1 then + return (...) + else + return "***" + end +end + +assert(f(tonumber('fFfa', 15)) == nil) +assert(f(tonumber('099', 8)) == nil) +assert(f(tonumber('1\0', 2)) == nil) +assert(f(tonumber('', 8)) == nil) +assert(f(tonumber(' ', 9)) == nil) +assert(f(tonumber(' ', 9)) == nil) +assert(f(tonumber('0xf', 10)) == nil) + +assert(f(tonumber('inf')) == nil) +assert(f(tonumber(' INF ')) == nil) +assert(f(tonumber('Nan')) == nil) +assert(f(tonumber('nan')) == nil) + +assert(f(tonumber(' ')) == nil) +assert(f(tonumber('')) == nil) +assert(f(tonumber('1 a')) == nil) +assert(f(tonumber('1 a', 2)) == nil) +assert(f(tonumber('1\0')) == nil) +assert(f(tonumber('1 \0')) == nil) +assert(f(tonumber('1\0 ')) == nil) +assert(f(tonumber('e1')) == nil) +assert(f(tonumber('e 1')) == nil) +assert(f(tonumber(' 3.4.5 ')) == nil) + + +-- testing 'tonumber' for invalid hexadecimal formats + +assert(tonumber('0x') == nil) +assert(tonumber('x') == nil) +assert(tonumber('x3') == nil) +assert(tonumber('0x3.3.3') == nil) -- two decimal points +assert(tonumber('00x2') == nil) +assert(tonumber('0x 2') == nil) +assert(tonumber('0 x2') == nil) +assert(tonumber('23x') == nil) +assert(tonumber('- 0xaa') == nil) +assert(tonumber('-0xaaP ') == nil) -- no exponent +assert(tonumber('0x0.51p') == nil) +assert(tonumber('0x5p+-2') == nil) + + +-- testing hexadecimal numerals + +assert(0x10 == 16 and 0xfff == 2^12 - 1 and 0XFB == 251) +assert(0x0p12 == 0 and 0x.0p-3 == 0) +assert(0xFFFFFFFF == (1 << 32) - 1) +assert(tonumber('+0x2') == 2) +assert(tonumber('-0xaA') == -170) +assert(tonumber('-0xffFFFfff') == -(1 << 32) + 1) + +-- possible confusion with decimal exponent +assert(0E+1 == 0 and 0xE+1 == 15 and 0xe-1 == 13) + + +-- floating hexas + +assert(tonumber(' 0x2.5 ') == 0x25/16) +assert(tonumber(' -0x2.5 ') == -0x25/16) +assert(tonumber(' +0x0.51p+8 ') == 0x51) +assert(0x.FfffFFFF == 1 - '0x.00000001') +assert('0xA.a' + 0 == 10 + 10/16) +assert(0xa.aP4 == 0XAA) +assert(0x4P-2 == 1) +assert(0x1.1 == '0x1.' + '+0x.1') +assert(0Xabcdef.0 == 0x.ABCDEFp+24) + + +assert(1.1 == 1.+.1) +assert(100.0 == 1E2 and .01 == 1e-2) +assert(1111111111 - 1111111110 == 1000.00e-03) +assert(1.1 == '1.'+'.1') +assert(tonumber'1111111111' - tonumber'1111111110' == + tonumber" +0.001e+3 \n\t") + +assert(0.1e-30 > 0.9E-31 and 0.9E30 < 0.1e31) + +assert(0.123456 > 0.123455) + +assert(tonumber('+1.23E18') == 1.23*10.0^18) + +-- testing order operators +assert(not(1<1) and (1<2) and not(2<1)) +assert(not('a'<'a') and ('a'<'b') and not('b'<'a')) +assert((1<=1) and (1<=2) and not(2<=1)) +assert(('a'<='a') and ('a'<='b') and not('b'<='a')) +assert(not(1>1) and not(1>2) and (2>1)) +assert(not('a'>'a') and not('a'>'b') and ('b'>'a')) +assert((1>=1) and not(1>=2) and (2>=1)) +assert(('a'>='a') and not('a'>='b') and ('b'>='a')) +assert(1.3 < 1.4 and 1.3 <= 1.4 and not (1.3 < 1.3) and 1.3 <= 1.3) + +-- testing mod operator +assert(eqT(-4 % 3, 2)) +assert(eqT(4 % -3, -2)) +assert(eqT(-4.0 % 3, 2.0)) +assert(eqT(4 % -3.0, -2.0)) +assert(math.pi - math.pi % 1 == 3) +assert(math.pi - math.pi % 0.001 == 3.141) + +assert(eqT(minint % minint, 0)) +assert(eqT(maxint % maxint, 0)) +assert((minint + 1) % minint == minint + 1) +assert((maxint - 1) % maxint == maxint - 1) +assert(minint % maxint == maxint - 1) + +assert(minint % -1 == 0) +assert(minint % -2 == 0) +assert(maxint % -2 == -1) + +-- non-portable tests because Windows C library cannot compute +-- fmod(1, huge) correctly +if not _port then + local function anan (x) assert(isNaN(x)) end -- assert Not a Number + anan(0.0 % 0) + anan(1.3 % 0) + anan(math.huge % 1) + anan(math.huge % 1e30) + anan(-math.huge % 1e30) + anan(-math.huge % -1e30) + assert(1 % math.huge == 1) + assert(1e30 % math.huge == 1e30) + assert(1e30 % -math.huge == -math.huge) + assert(-1 % math.huge == math.huge) + assert(-1 % -math.huge == -1) +end + + +-- testing unsigned comparisons +assert(math.ult(3, 4)) +assert(not math.ult(4, 4)) +assert(math.ult(-2, -1)) +assert(math.ult(2, -1)) +assert(not math.ult(-2, -2)) +assert(math.ult(maxint, minint)) +assert(not math.ult(minint, maxint)) + + +assert(eq(math.sin(-9.8)^2 + math.cos(-9.8)^2, 1)) +assert(eq(math.tan(math.pi/4), 1)) +assert(eq(math.sin(math.pi/2), 1) and eq(math.cos(math.pi/2), 0)) +assert(eq(math.atan(1), math.pi/4) and eq(math.acos(0), math.pi/2) and + eq(math.asin(1), math.pi/2)) +assert(eq(math.deg(math.pi/2), 90) and eq(math.rad(90), math.pi/2)) +assert(math.abs(-10.43) == 10.43) +assert(eqT(math.abs(minint), minint)) +assert(eqT(math.abs(maxint), maxint)) +assert(eqT(math.abs(-maxint), maxint)) +assert(eq(math.atan(1,0), math.pi/2)) +assert(math.fmod(10,3) == 1) +assert(eq(math.sqrt(10)^2, 10)) +assert(eq(math.log(2, 10), math.log(2)/math.log(10))) +assert(eq(math.log(2, 2), 1)) +assert(eq(math.log(9, 3), 2)) +assert(eq(math.exp(0), 1)) +assert(eq(math.sin(10), math.sin(10%(2*math.pi)))) + + +assert(tonumber(' 1.3e-2 ') == 1.3e-2) +assert(tonumber(' -1.00000000000001 ') == -1.00000000000001) + +-- testing constant limits +-- 2^23 = 8388608 +assert(8388609 + -8388609 == 0) +assert(8388608 + -8388608 == 0) +assert(8388607 + -8388607 == 0) + + + +do -- testing floor & ceil + assert(eqT(math.floor(3.4), 3)) + assert(eqT(math.ceil(3.4), 4)) + assert(eqT(math.floor(-3.4), -4)) + assert(eqT(math.ceil(-3.4), -3)) + assert(eqT(math.floor(maxint), maxint)) + assert(eqT(math.ceil(maxint), maxint)) + assert(eqT(math.floor(minint), minint)) + assert(eqT(math.floor(minint + 0.0), minint)) + assert(eqT(math.ceil(minint), minint)) + assert(eqT(math.ceil(minint + 0.0), minint)) + assert(math.floor(1e50) == 1e50) + assert(math.ceil(1e50) == 1e50) + assert(math.floor(-1e50) == -1e50) + assert(math.ceil(-1e50) == -1e50) + for _, p in pairs{31,32,63,64} do + assert(math.floor(2^p) == 2^p) + assert(math.floor(2^p + 0.5) == 2^p) + assert(math.ceil(2^p) == 2^p) + assert(math.ceil(2^p - 0.5) == 2^p) + end + checkerror("number expected", math.floor, {}) + checkerror("number expected", math.ceil, print) + assert(eqT(math.tointeger(minint), minint)) + assert(eqT(math.tointeger(minint .. ""), minint)) + assert(eqT(math.tointeger(maxint), maxint)) + assert(eqT(math.tointeger(maxint .. ""), maxint)) + assert(eqT(math.tointeger(minint + 0.0), minint)) + assert(math.tointeger(0.0 - minint) == nil) + assert(math.tointeger(math.pi) == nil) + assert(math.tointeger(-math.pi) == nil) + assert(math.floor(math.huge) == math.huge) + assert(math.ceil(math.huge) == math.huge) + assert(math.tointeger(math.huge) == nil) + assert(math.floor(-math.huge) == -math.huge) + assert(math.ceil(-math.huge) == -math.huge) + assert(math.tointeger(-math.huge) == nil) + assert(math.tointeger("34.0") == 34) + assert(math.tointeger("34.3") == nil) + assert(math.tointeger({}) == nil) + assert(math.tointeger(0/0) == nil) -- NaN +end + + +-- testing fmod for integers +for i = -6, 6 do + for j = -6, 6 do + if j ~= 0 then + local mi = math.fmod(i, j) + local mf = math.fmod(i + 0.0, j) + assert(mi == mf) + assert(math.type(mi) == 'integer' and math.type(mf) == 'float') + if (i >= 0 and j >= 0) or (i <= 0 and j <= 0) or mi == 0 then + assert(eqT(mi, i % j)) + end + end + end +end +assert(eqT(math.fmod(minint, minint), 0)) +assert(eqT(math.fmod(maxint, maxint), 0)) +assert(eqT(math.fmod(minint + 1, minint), minint + 1)) +assert(eqT(math.fmod(maxint - 1, maxint), maxint - 1)) + +checkerror("zero", math.fmod, 3, 0) + + +do -- testing max/min + checkerror("value expected", math.max) + checkerror("value expected", math.min) + assert(eqT(math.max(3), 3)) + assert(eqT(math.max(3, 5, 9, 1), 9)) + assert(math.max(maxint, 10e60) == 10e60) + assert(eqT(math.max(minint, minint + 1), minint + 1)) + assert(eqT(math.min(3), 3)) + assert(eqT(math.min(3, 5, 9, 1), 1)) + assert(math.min(3.2, 5.9, -9.2, 1.1) == -9.2) + assert(math.min(1.9, 1.7, 1.72) == 1.7) + assert(math.min(-10e60, minint) == -10e60) + assert(eqT(math.min(maxint, maxint - 1), maxint - 1)) + assert(eqT(math.min(maxint - 2, maxint, maxint - 1), maxint - 2)) +end +-- testing implicit convertions + +local a,b = '10', '20' +assert(a*b == 200 and a+b == 30 and a-b == -10 and a/b == 0.5 and -b == -20) +assert(a == '10' and b == '20') + + +do + print("testing -0 and NaN") + local mz, z = -0.0, 0.0 + assert(mz == z) + assert(1/mz < 0 and 0 < 1/z) + local a = {[mz] = 1} + assert(a[z] == 1 and a[mz] == 1) + a[z] = 2 + assert(a[z] == 2 and a[mz] == 2) + local inf = math.huge * 2 + 1 + mz, z = -1/inf, 1/inf + assert(mz == z) + assert(1/mz < 0 and 0 < 1/z) + local NaN = inf - inf + assert(NaN ~= NaN) + assert(not (NaN < NaN)) + assert(not (NaN <= NaN)) + assert(not (NaN > NaN)) + assert(not (NaN >= NaN)) + assert(not (0 < NaN) and not (NaN < 0)) + local NaN1 = 0/0 + assert(NaN ~= NaN1 and not (NaN <= NaN1) and not (NaN1 <= NaN)) + local a = {} + assert(not pcall(rawset, a, NaN, 1)) + assert(a[NaN] == nil) + a[1] = 1 + assert(not pcall(rawset, a, NaN, 1)) + assert(a[NaN] == nil) + -- strings with same binary representation as 0.0 (might create problems + -- for constant manipulation in the pre-compiler) + local a1, a2, a3, a4, a5 = 0, 0, "\0\0\0\0\0\0\0\0", 0, "\0\0\0\0\0\0\0\0" + assert(a1 == a2 and a2 == a4 and a1 ~= a3) + assert(a3 == a5) +end + + +print("testing 'math.random'") +math.randomseed(0) + +do -- test random for floats + local max = -math.huge + local min = math.huge + for i = 0, 20000 do + local t = math.random() + assert(0 <= t and t < 1) + max = math.max(max, t) + min = math.min(min, t) + if eq(max, 1, 0.001) and eq(min, 0, 0.001) then + goto ok + end + end + -- loop ended without satisfing condition + assert(false) + ::ok:: +end + +do + local function aux (p, lim) -- test random for small intervals + local x1, x2 + if #p == 1 then x1 = 1; x2 = p[1] + else x1 = p[1]; x2 = p[2] + end + local mark = {}; local count = 0 -- to check that all values appeared + for i = 0, lim or 2000 do + local t = math.random(table.unpack(p)) + assert(x1 <= t and t <= x2) + if not mark[t] then -- new value + mark[t] = true + count = count + 1 + end + if count == x2 - x1 + 1 then -- all values appeared; OK + goto ok + end + end + -- loop ended without satisfing condition + assert(false) + ::ok:: + end + + aux({-10,0}) + aux({6}) + aux({-10, 10}) + aux({minint, minint}) + aux({maxint, maxint}) + aux({minint, minint + 9}) + aux({maxint - 3, maxint}) +end + +do + local function aux(p1, p2) -- test random for large intervals + local max = minint + local min = maxint + local n = 200 + local mark = {}; local count = 0 -- to count how many different values + for _ = 1, n do + local t = math.random(p1, p2) + max = math.max(max, t) + min = math.min(min, t) + if not mark[t] then -- new value + mark[t] = true + count = count + 1 + end + end + -- at least 80% of values are different + assert(count >= n * 0.8) + -- min and max not too far from formal min and max + local diff = (p2 - p1) // 8 + assert(min < p1 + diff and max > p2 - diff) + end + aux(0, maxint) + aux(1, maxint) + aux(minint, -1) + aux(minint // 2, maxint // 2) +end + +for i=1,100 do + assert(math.random(maxint) > 0) + assert(math.random(minint, -1) < 0) +end + +assert(not pcall(math.random, 1, 2, 3)) -- too many arguments + +-- empty interval +assert(not pcall(math.random, minint + 1, minint)) +assert(not pcall(math.random, maxint, maxint - 1)) +assert(not pcall(math.random, maxint, minint)) + +-- interval too large +assert(not pcall(math.random, minint, 0)) +assert(not pcall(math.random, -1, maxint)) +assert(not pcall(math.random, minint // 2, maxint // 2 + 1)) + + +print('OK') diff --git a/tests/lua-5.3/nextvar.lua b/tests/lua-5.3/nextvar.lua new file mode 100644 index 0000000..ce7312e --- /dev/null +++ b/tests/lua-5.3/nextvar.lua @@ -0,0 +1,631 @@ +-- $Id: nextvar.lua,v 1.79 2016/11/07 13:11:28 roberto Exp $ +-- See Copyright Notice in file all.lua + +print('testing tables, next, and for') + +local function checkerror (msg, f, ...) + local s, err = pcall(f, ...) + assert(not s and string.find(err, msg)) +end + + +local a = {} + +-- make sure table has lots of space in hash part +for i=1,100 do a[i.."+"] = true end +for i=1,100 do a[i.."+"] = nil end +-- fill hash part with numeric indices testing size operator +for i=1,100 do + a[i] = true + assert(#a == i) +end + +-- testing ipairs +local x = 0 +for k,v in ipairs{10,20,30;x=12} do + x = x + 1 + assert(k == x and v == x * 10) +end + +for _ in ipairs{x=12, y=24} do assert(nil) end + +-- test for 'false' x ipair +x = false +local i = 0 +for k,v in ipairs{true,false,true,false} do + i = i + 1 + x = not x + assert(x == v) +end +assert(i == 4) + +-- iterator function is always the same +assert(type(ipairs{}) == 'function' and ipairs{} == ipairs{}) + + +if not T then + (Message or print) + ('\n >>> testC not active: skipping tests for table sizes <<<\n') +else --[ +-- testing table sizes + +local function log2 (x) return math.log(x, 2) end + +local function mp2 (n) -- minimum power of 2 >= n + local mp = 2^math.ceil(log2(n)) + assert(n == 0 or (mp/2 < n and n <= mp)) + return mp +end + +local function fb (n) + local r, nn = T.int2fb(n) + assert(r < 256) + return nn +end + +-- test fb function +for a = 1, 10000 do -- all numbers up to 10^4 + local n = fb(a) + assert(a <= n and n <= a*1.125) +end +local a = 1024 -- plus a few up to 2 ^30 +local lim = 2^30 +while a < lim do + local n = fb(a) + assert(a <= n and n <= a*1.125) + a = math.ceil(a*1.3) +end + + +local function check (t, na, nh) + local a, h = T.querytab(t) + if a ~= na or h ~= nh then + print(na, nh, a, h) + assert(nil) + end +end + + +-- testing C library sizes +do + local s = 0 + for _ in pairs(math) do s = s + 1 end + check(math, 0, mp2(s)) +end + + +-- testing constructor sizes +local lim = 40 +local s = 'return {' +for i=1,lim do + s = s..i..',' + local s = s + for k=0,lim do + local t = load(s..'}', '')() + assert(#t == i) + check(t, fb(i), mp2(k)) + s = string.format('%sa%d=%d,', s, k, k) + end +end + + +-- tests with unknown number of elements +local a = {} +for i=1,lim do a[i] = i end -- build auxiliary table +for k=0,lim do + local a = {table.unpack(a,1,k)} + assert(#a == k) + check(a, k, 0) + a = {1,2,3,table.unpack(a,1,k)} + check(a, k+3, 0) + assert(#a == k + 3) +end + + +-- testing tables dynamically built +local lim = 130 +local a = {}; a[2] = 1; check(a, 0, 1) +a = {}; a[0] = 1; check(a, 0, 1); a[2] = 1; check(a, 0, 2) +a = {}; a[0] = 1; a[1] = 1; check(a, 1, 1) +a = {} +for i = 1,lim do + a[i] = 1 + assert(#a == i) + check(a, mp2(i), 0) +end + +a = {} +for i = 1,lim do + a['a'..i] = 1 + assert(#a == 0) + check(a, 0, mp2(i)) +end + +a = {} +for i=1,16 do a[i] = i end +check(a, 16, 0) +do + for i=1,11 do a[i] = nil end + for i=30,50 do a[i] = nil end -- force a rehash (?) + check(a, 0, 8) -- only 5 elements in the table + a[10] = 1 + for i=30,50 do a[i] = nil end -- force a rehash (?) + check(a, 0, 8) -- only 6 elements in the table + for i=1,14 do a[i] = nil end + for i=18,50 do a[i] = nil end -- force a rehash (?) + check(a, 0, 4) -- only 2 elements ([15] and [16]) +end + +-- reverse filling +for i=1,lim do + local a = {} + for i=i,1,-1 do a[i] = i end -- fill in reverse + check(a, mp2(i), 0) +end + +-- size tests for vararg +lim = 35 +function foo (n, ...) + local arg = {...} + check(arg, n, 0) + assert(select('#', ...) == n) + arg[n+1] = true + check(arg, mp2(n+1), 0) + arg.x = true + check(arg, mp2(n+1), 1) +end +local a = {} +for i=1,lim do a[i] = true; foo(i, table.unpack(a)) end + +end --] + + +-- test size operation on empty tables +assert(#{} == 0) +assert(#{nil} == 0) +assert(#{nil, nil} == 0) +assert(#{nil, nil, nil} == 0) +assert(#{nil, nil, nil, nil} == 0) +print'+' + + +local nofind = {} + +a,b,c = 1,2,3 +a,b,c = nil + + +-- next uses always the same iteraction function +assert(next{} == next{}) + +local function find (name) + local n,v + while 1 do + n,v = next(_G, n) + if not n then return nofind end + assert(v ~= nil) + if n == name then return v end + end +end + +local function find1 (name) + for n,v in pairs(_G) do + if n==name then return v end + end + return nil -- not found +end + + +assert(print==find("print") and print == find1("print")) +assert(_G["print"]==find("print")) +assert(assert==find1("assert")) +assert(nofind==find("return")) +assert(not find1("return")) +_G["ret" .. "urn"] = nil +assert(nofind==find("return")) +_G["xxx"] = 1 +assert(xxx==find("xxx")) + +-- invalid key to 'next' +checkerror("invalid key", next, {10,20}, 3) + +-- both 'pairs' and 'ipairs' need an argument +checkerror("bad argument", pairs) +checkerror("bad argument", ipairs) + +print('+') + +a = {} +for i=0,10000 do + if math.fmod(i,10) ~= 0 then + a['x'..i] = i + end +end + +n = {n=0} +for i,v in pairs(a) do + n.n = n.n+1 + assert(i and v and a[i] == v) +end +assert(n.n == 9000) +a = nil + +do -- clear global table + local a = {} + for n,v in pairs(_G) do a[n]=v end + for n,v in pairs(a) do + if not package.loaded[n] and type(v) ~= "function" and + not string.find(n, "^[%u_]") then + _G[n] = nil + end + collectgarbage() + end +end + + +-- + +local function checknext (a) + local b = {} + do local k,v = next(a); while k do b[k] = v; k,v = next(a,k) end end + for k,v in pairs(b) do assert(a[k] == v) end + for k,v in pairs(a) do assert(b[k] == v) end +end + +checknext{1,x=1,y=2,z=3} +checknext{1,2,x=1,y=2,z=3} +checknext{1,2,3,x=1,y=2,z=3} +checknext{1,2,3,4,x=1,y=2,z=3} +checknext{1,2,3,4,5,x=1,y=2,z=3} + +assert(#{} == 0) +assert(#{[-1] = 2} == 0) +assert(#{1,2,3,nil,nil} == 3) +for i=0,40 do + local a = {} + for j=1,i do a[j]=j end + assert(#a == i) +end + +-- 'maxn' is now deprecated, but it is easily defined in Lua +function table.maxn (t) + local max = 0 + for k in pairs(t) do + max = (type(k) == 'number') and math.max(max, k) or max + end + return max +end + +assert(table.maxn{} == 0) +assert(table.maxn{["1000"] = true} == 0) +assert(table.maxn{["1000"] = true, [24.5] = 3} == 24.5) +assert(table.maxn{[1000] = true} == 1000) +assert(table.maxn{[10] = true, [100*math.pi] = print} == 100*math.pi) + +table.maxn = nil + +-- int overflow +a = {} +for i=0,50 do a[2^i] = true end +assert(a[#a]) + +print('+') + + +-- erasing values +local t = {[{1}] = 1, [{2}] = 2, [string.rep("x ", 4)] = 3, + [100.3] = 4, [4] = 5} + +local n = 0 +for k, v in pairs( t ) do + n = n+1 + assert(t[k] == v) + t[k] = nil + collectgarbage() + assert(t[k] == nil) +end +assert(n == 5) + + +local function test (a) + assert(not pcall(table.insert, a, 2, 20)); + table.insert(a, 10); table.insert(a, 2, 20); + table.insert(a, 1, -1); table.insert(a, 40); + table.insert(a, #a+1, 50) + table.insert(a, 2, -2) + assert(not pcall(table.insert, a, 0, 20)); + assert(not pcall(table.insert, a, #a + 2, 20)); + assert(table.remove(a,1) == -1) + assert(table.remove(a,1) == -2) + assert(table.remove(a,1) == 10) + assert(table.remove(a,1) == 20) + assert(table.remove(a,1) == 40) + assert(table.remove(a,1) == 50) + assert(table.remove(a,1) == nil) + assert(table.remove(a) == nil) + assert(table.remove(a, #a) == nil) +end + +a = {n=0, [-7] = "ban"} +test(a) +assert(a.n == 0 and a[-7] == "ban") + +a = {[-7] = "ban"}; +test(a) +assert(a.n == nil and #a == 0 and a[-7] == "ban") + +a = {[-1] = "ban"} +test(a) +assert(#a == 0 and table.remove(a) == nil and a[-1] == "ban") + +a = {[0] = "ban"} +assert(#a == 0 and table.remove(a) == "ban" and a[0] == nil) + +table.insert(a, 1, 10); table.insert(a, 1, 20); table.insert(a, 1, -1) +assert(table.remove(a) == 10) +assert(table.remove(a) == 20) +assert(table.remove(a) == -1) +assert(table.remove(a) == nil) + +a = {'c', 'd'} +table.insert(a, 3, 'a') +table.insert(a, 'b') +assert(table.remove(a, 1) == 'c') +assert(table.remove(a, 1) == 'd') +assert(table.remove(a, 1) == 'a') +assert(table.remove(a, 1) == 'b') +assert(table.remove(a, 1) == nil) +assert(#a == 0 and a.n == nil) + +a = {10,20,30,40} +assert(table.remove(a, #a + 1) == nil) +assert(not pcall(table.remove, a, 0)) +assert(a[#a] == 40) +assert(table.remove(a, #a) == 40) +assert(a[#a] == 30) +assert(table.remove(a, 2) == 20) +assert(a[#a] == 30 and #a == 2) + +do -- testing table library with metamethods + local function test (proxy, t) + for i = 1, 10 do + table.insert(proxy, 1, i) + end + assert(#proxy == 10 and #t == 10) + for i = 1, 10 do + assert(t[i] == 11 - i) + end + table.sort(proxy) + for i = 1, 10 do + assert(t[i] == i and proxy[i] == i) + end + assert(table.concat(proxy, ",") == "1,2,3,4,5,6,7,8,9,10") + for i = 1, 8 do + assert(table.remove(proxy, 1) == i) + end + assert(#proxy == 2 and #t == 2) + local a, b, c = table.unpack(proxy) + assert(a == 9 and b == 10 and c == nil) + end + + -- all virtual + local t = {} + local proxy = setmetatable({}, { + __len = function () return #t end, + __index = t, + __newindex = t, + }) + test(proxy, t) + + -- only __newindex + local count = 0 + t = setmetatable({}, { + __newindex = function (t,k,v) count = count + 1; rawset(t,k,v) end}) + test(t, t) + assert(count == 10) -- after first 10, all other sets are not new + + -- no __newindex + t = setmetatable({}, { + __index = function (_,k) return k + 1 end, + __len = function (_) return 5 end}) + assert(table.concat(t, ";") == "2;3;4;5;6") + +end + + +if not T then + (Message or print) + ('\n >>> testC not active: skipping tests for table library on non-tables <<<\n') +else --[ + local debug = require'debug' + local tab = {10, 20, 30} + local mt = {} + local u = T.newuserdata(0) + checkerror("table expected", table.insert, u, 40) + checkerror("table expected", table.remove, u) + debug.setmetatable(u, mt) + checkerror("table expected", table.insert, u, 40) + checkerror("table expected", table.remove, u) + mt.__index = tab + checkerror("table expected", table.insert, u, 40) + checkerror("table expected", table.remove, u) + mt.__newindex = tab + checkerror("table expected", table.insert, u, 40) + checkerror("table expected", table.remove, u) + mt.__len = function () return #tab end + table.insert(u, 40) + assert(#u == 4 and #tab == 4 and u[4] == 40 and tab[4] == 40) + assert(table.remove(u) == 40) + table.insert(u, 1, 50) + assert(#u == 4 and #tab == 4 and u[4] == 30 and tab[1] == 50) + + mt.__newindex = nil + mt.__len = nil + local tab2 = {} + local u2 = T.newuserdata(0) + debug.setmetatable(u2, {__newindex = function (_, k, v) tab2[k] = v end}) + table.move(u, 1, 4, 1, u2) + assert(#tab2 == 4 and tab2[1] == tab[1] and tab2[4] == tab[4]) + +end -- ] + +print('+') + +a = {} +for i=1,1000 do + a[i] = i; a[i-1] = nil +end +assert(next(a,nil) == 1000 and next(a,1000) == nil) + +assert(next({}) == nil) +assert(next({}, nil) == nil) + +for a,b in pairs{} do error"not here" end +for i=1,0 do error'not here' end +for i=0,1,-1 do error'not here' end +a = nil; for i=1,1 do assert(not a); a=1 end; assert(a) +a = nil; for i=1,1,-1 do assert(not a); a=1 end; assert(a) + +do + print("testing floats in numeric for") + local a + -- integer count + a = 0; for i=1, 1, 1 do a=a+1 end; assert(a==1) + a = 0; for i=10000, 1e4, -1 do a=a+1 end; assert(a==1) + a = 0; for i=1, 0.99999, 1 do a=a+1 end; assert(a==0) + a = 0; for i=9999, 1e4, -1 do a=a+1 end; assert(a==0) + a = 0; for i=1, 0.99999, -1 do a=a+1 end; assert(a==1) + + -- float count + a = 0; for i=0, 0.999999999, 0.1 do a=a+1 end; assert(a==10) + a = 0; for i=1.0, 1, 1 do a=a+1 end; assert(a==1) + a = 0; for i=-1.5, -1.5, 1 do a=a+1 end; assert(a==1) + a = 0; for i=1e6, 1e6, -1 do a=a+1 end; assert(a==1) + a = 0; for i=1.0, 0.99999, 1 do a=a+1 end; assert(a==0) + a = 0; for i=99999, 1e5, -1.0 do a=a+1 end; assert(a==0) + a = 0; for i=1.0, 0.99999, -1 do a=a+1 end; assert(a==1) +end + +-- conversion +a = 0; for i="10","1","-2" do a=a+1 end; assert(a==5) + +do -- checking types + local c + local function checkfloat (i) + assert(math.type(i) == "float") + c = c + 1 + end + + c = 0; for i = 1.0, 10 do checkfloat(i) end + assert(c == 10) + + c = 0; for i = -1, -10, -1.0 do checkfloat(i) end + assert(c == 10) + + local function checkint (i) + assert(math.type(i) == "integer") + c = c + 1 + end + + local m = math.maxinteger + c = 0; for i = m, m - 10, -1 do checkint(i) end + assert(c == 11) + + c = 0; for i = 1, 10.9 do checkint(i) end + assert(c == 10) + + c = 0; for i = 10, 0.001, -1 do checkint(i) end + assert(c == 10) + + c = 0; for i = 1, "10.8" do checkint(i) end + assert(c == 10) + + c = 0; for i = 9, "3.4", -1 do checkint(i) end + assert(c == 6) + + c = 0; for i = 0, " -3.4 ", -1 do checkint(i) end + assert(c == 4) + + c = 0; for i = 100, "96.3", -2 do checkint(i) end + assert(c == 2) + + c = 0; for i = 1, math.huge do if i > 10 then break end; checkint(i) end + assert(c == 10) + + c = 0; for i = -1, -math.huge, -1 do + if i < -10 then break end; checkint(i) + end + assert(c == 10) + + + for i = math.mininteger, -10e100 do assert(false) end + for i = math.maxinteger, 10e100, -1 do assert(false) end + +end + +collectgarbage() + + +-- testing generic 'for' + +local function f (n, p) + local t = {}; for i=1,p do t[i] = i*10 end + return function (_,n) + if n > 0 then + n = n-1 + return n, table.unpack(t) + end + end, nil, n +end + +local x = 0 +for n,a,b,c,d in f(5,3) do + x = x+1 + assert(a == 10 and b == 20 and c == 30 and d == nil) +end +assert(x == 5) + + + +-- testing __pairs and __ipairs metamethod +a = {} +do + local x,y,z = pairs(a) + assert(type(x) == 'function' and y == a and z == nil) +end + +local function foo (e,i) + assert(e == a) + if i <= 10 then return i+1, i+2 end +end + +local function foo1 (e,i) + i = i + 1 + assert(e == a) + if i <= e.n then return i,a[i] end +end + +setmetatable(a, {__pairs = function (x) return foo, x, 0 end}) + +local i = 0 +for k,v in pairs(a) do + i = i + 1 + assert(k == i and v == k+1) +end + +a.n = 5 +a[3] = 30 + +-- testing ipairs with metamethods +a = {n=10} +setmetatable(a, { __index = function (t,k) + if k <= t.n then return k * 10 end + end}) +i = 0 +for k,v in ipairs(a) do + i = i + 1 + assert(k == i and v == i * 10) +end +assert(i == a.n) + +print"OK" diff --git a/tests/lua-5.3/pm.lua b/tests/lua-5.3/pm.lua new file mode 100644 index 0000000..fde39ff --- /dev/null +++ b/tests/lua-5.3/pm.lua @@ -0,0 +1,374 @@ +-- $Id: pm.lua,v 1.48 2016/11/07 13:11:28 roberto Exp $ +-- See Copyright Notice in file all.lua + +print('testing pattern matching') + +local function checkerror (msg, f, ...) + local s, err = pcall(f, ...) + assert(not s and string.find(err, msg)) +end + + +function f(s, p) + local i,e = string.find(s, p) + if i then return string.sub(s, i, e) end +end + +a,b = string.find('', '') -- empty patterns are tricky +assert(a == 1 and b == 0); +a,b = string.find('alo', '') +assert(a == 1 and b == 0) +a,b = string.find('a\0o a\0o a\0o', 'a', 1) -- first position +assert(a == 1 and b == 1) +a,b = string.find('a\0o a\0o a\0o', 'a\0o', 2) -- starts in the midle +assert(a == 5 and b == 7) +a,b = string.find('a\0o a\0o a\0o', 'a\0o', 9) -- starts in the midle +assert(a == 9 and b == 11) +a,b = string.find('a\0a\0a\0a\0\0ab', '\0ab', 2); -- finds at the end +assert(a == 9 and b == 11); +a,b = string.find('a\0a\0a\0a\0\0ab', 'b') -- last position +assert(a == 11 and b == 11) +assert(string.find('a\0a\0a\0a\0\0ab', 'b\0') == nil) -- check ending +assert(string.find('', '\0') == nil) +assert(string.find('alo123alo', '12') == 4) +assert(string.find('alo123alo', '^12') == nil) + +assert(string.match("aaab", ".*b") == "aaab") +assert(string.match("aaa", ".*a") == "aaa") +assert(string.match("b", ".*b") == "b") + +assert(string.match("aaab", ".+b") == "aaab") +assert(string.match("aaa", ".+a") == "aaa") +assert(not string.match("b", ".+b")) + +assert(string.match("aaab", ".?b") == "ab") +assert(string.match("aaa", ".?a") == "aa") +assert(string.match("b", ".?b") == "b") + +assert(f('aloALO', '%l*') == 'alo') +assert(f('aLo_ALO', '%a*') == 'aLo') + +assert(f(" \n\r*&\n\r xuxu \n\n", "%g%g%g+") == "xuxu") + +assert(f('aaab', 'a*') == 'aaa'); +assert(f('aaa', '^.*$') == 'aaa'); +assert(f('aaa', 'b*') == ''); +assert(f('aaa', 'ab*a') == 'aa') +assert(f('aba', 'ab*a') == 'aba') +assert(f('aaab', 'a+') == 'aaa') +assert(f('aaa', '^.+$') == 'aaa') +assert(f('aaa', 'b+') == nil) +assert(f('aaa', 'ab+a') == nil) +assert(f('aba', 'ab+a') == 'aba') +assert(f('a$a', '.$') == 'a') +assert(f('a$a', '.%$') == 'a$') +assert(f('a$a', '.$.') == 'a$a') +assert(f('a$a', '$$') == nil) +assert(f('a$b', 'a$') == nil) +assert(f('a$a', '$') == '') +assert(f('', 'b*') == '') +assert(f('aaa', 'bb*') == nil) +assert(f('aaab', 'a-') == '') +assert(f('aaa', '^.-$') == 'aaa') +assert(f('aabaaabaaabaaaba', 'b.*b') == 'baaabaaabaaab') +assert(f('aabaaabaaabaaaba', 'b.-b') == 'baaab') +assert(f('alo xo', '.o$') == 'xo') +assert(f(' \n isto é assim', '%S%S*') == 'isto') +assert(f(' \n isto é assim', '%S*$') == 'assim') +assert(f(' \n isto é assim', '[a-z]*$') == 'assim') +assert(f('um caracter ? extra', '[^%sa-z]') == '?') +assert(f('', 'a?') == '') +assert(f('á', 'á?') == 'á') +assert(f('ábl', 'á?b?l?') == 'ábl') +assert(f(' ábl', 'á?b?l?') == '') +assert(f('aa', '^aa?a?a') == 'aa') +assert(f(']]]áb', '[^]]') == 'á') +assert(f("0alo alo", "%x*") == "0a") +assert(f("alo alo", "%C+") == "alo alo") +print('+') + + +function f1(s, p) + p = string.gsub(p, "%%([0-9])", function (s) + return "%" .. (tonumber(s)+1) + end) + p = string.gsub(p, "^(^?)", "%1()", 1) + p = string.gsub(p, "($?)$", "()%1", 1) + local t = {string.match(s, p)} + return string.sub(s, t[1], t[#t] - 1) +end + +assert(f1('alo alx 123 b\0o b\0o', '(..*) %1') == "b\0o b\0o") +assert(f1('axz123= 4= 4 34', '(.+)=(.*)=%2 %1') == '3= 4= 4 3') +assert(f1('=======', '^(=*)=%1$') == '=======') +assert(string.match('==========', '^([=]*)=%1$') == nil) + +local function range (i, j) + if i <= j then + return i, range(i+1, j) + end +end + +local abc = string.char(range(0, 255)); + +assert(string.len(abc) == 256) + +function strset (p) + local res = {s=''} + string.gsub(abc, p, function (c) res.s = res.s .. c end) + return res.s +end; + +assert(string.len(strset('[\200-\210]')) == 11) + +assert(strset('[a-z]') == "abcdefghijklmnopqrstuvwxyz") +assert(strset('[a-z%d]') == strset('[%da-uu-z]')) +assert(strset('[a-]') == "-a") +assert(strset('[^%W]') == strset('[%w]')) +assert(strset('[]%%]') == '%]') +assert(strset('[a%-z]') == '-az') +assert(strset('[%^%[%-a%]%-b]') == '-[]^ab') +assert(strset('%Z') == strset('[\1-\255]')) +assert(strset('.') == strset('[\1-\255%z]')) +print('+'); + +assert(string.match("alo xyzK", "(%w+)K") == "xyz") +assert(string.match("254 K", "(%d*)K") == "") +assert(string.match("alo ", "(%w*)$") == "") +assert(string.match("alo ", "(%w+)$") == nil) +assert(string.find("(álo)", "%(á") == 1) +local a, b, c, d, e = string.match("âlo alo", "^(((.).).* (%w*))$") +assert(a == 'âlo alo' and b == 'âl' and c == 'â' and d == 'alo' and e == nil) +a, b, c, d = string.match('0123456789', '(.+(.?)())') +assert(a == '0123456789' and b == '' and c == 11 and d == nil) +print('+') + +assert(string.gsub('ülo ülo', 'ü', 'x') == 'xlo xlo') +assert(string.gsub('alo úlo ', ' +$', '') == 'alo úlo') -- trim +assert(string.gsub(' alo alo ', '^%s*(.-)%s*$', '%1') == 'alo alo') -- double trim +assert(string.gsub('alo alo \n 123\n ', '%s+', ' ') == 'alo alo 123 ') +t = "abç d" +a, b = string.gsub(t, '(.)', '%1@') +assert('@'..a == string.gsub(t, '', '@') and b == 5) +a, b = string.gsub('abçd', '(.)', '%0@', 2) +assert(a == 'a@b@çd' and b == 2) +assert(string.gsub('alo alo', '()[al]', '%1') == '12o 56o') +assert(string.gsub("abc=xyz", "(%w*)(%p)(%w+)", "%3%2%1-%0") == + "xyz=abc-abc=xyz") +assert(string.gsub("abc", "%w", "%1%0") == "aabbcc") +assert(string.gsub("abc", "%w+", "%0%1") == "abcabc") +assert(string.gsub('áéí', '$', '\0óú') == 'áéí\0óú') +assert(string.gsub('', '^', 'r') == 'r') +assert(string.gsub('', '$', 'r') == 'r') +print('+') + + +do -- new (5.3.3) semantics for empty matches + assert(string.gsub("a b cd", " *", "-") == "-a-b-c-d-") + + local res = "" + local sub = "a \nbc\t\td" + local i = 1 + for p, e in string.gmatch(sub, "()%s*()") do + res = res .. string.sub(sub, i, p - 1) .. "-" + i = e + end + assert(res == "-a-b-c-d-") +end + + +assert(string.gsub("um (dois) tres (quatro)", "(%(%w+%))", string.upper) == + "um (DOIS) tres (QUATRO)") + +do + local function setglobal (n,v) rawset(_G, n, v) end + string.gsub("a=roberto,roberto=a", "(%w+)=(%w%w*)", setglobal) + assert(_G.a=="roberto" and _G.roberto=="a") +end + +function f(a,b) return string.gsub(a,'.',b) end +assert(string.gsub("trocar tudo em |teste|b| é |beleza|al|", "|([^|]*)|([^|]*)|", f) == + "trocar tudo em bbbbb é alalalalalal") + +local function dostring (s) return load(s, "")() or "" end +assert(string.gsub("alo $a='x'$ novamente $return a$", + "$([^$]*)%$", + dostring) == "alo novamente x") + +x = string.gsub("$x=string.gsub('alo', '.', string.upper)$ assim vai para $return x$", + "$([^$]*)%$", dostring) +assert(x == ' assim vai para ALO') + +t = {} +s = 'a alo jose joao' +r = string.gsub(s, '()(%w+)()', function (a,w,b) + assert(string.len(w) == b-a); + t[a] = b-a; + end) +assert(s == r and t[1] == 1 and t[3] == 3 and t[7] == 4 and t[13] == 4) + + +function isbalanced (s) + return string.find(string.gsub(s, "%b()", ""), "[()]") == nil +end + +assert(isbalanced("(9 ((8))(\0) 7) \0\0 a b ()(c)() a")) +assert(not isbalanced("(9 ((8) 7) a b (\0 c) a")) +assert(string.gsub("alo 'oi' alo", "%b''", '"') == 'alo " alo') + + +local t = {"apple", "orange", "lime"; n=0} +assert(string.gsub("x and x and x", "x", function () t.n=t.n+1; return t[t.n] end) + == "apple and orange and lime") + +t = {n=0} +string.gsub("first second word", "%w%w*", function (w) t.n=t.n+1; t[t.n] = w end) +assert(t[1] == "first" and t[2] == "second" and t[3] == "word" and t.n == 3) + +t = {n=0} +assert(string.gsub("first second word", "%w+", + function (w) t.n=t.n+1; t[t.n] = w end, 2) == "first second word") +assert(t[1] == "first" and t[2] == "second" and t[3] == nil) + +checkerror("invalid replacement value %(a table%)", + string.gsub, "alo", ".", {a = {}}) +checkerror("invalid capture index %%2", string.gsub, "alo", ".", "%2") +checkerror("invalid capture index %%0", string.gsub, "alo", "(%0)", "a") +checkerror("invalid capture index %%1", string.gsub, "alo", "(%1)", "a") +checkerror("invalid use of '%%'", string.gsub, "alo", ".", "%x") + +-- bug since 2.5 (C-stack overflow) +do + local function f (size) + local s = string.rep("a", size) + local p = string.rep(".?", size) + return pcall(string.match, s, p) + end + local r, m = f(80) + assert(r and #m == 80) + r, m = f(200000) + assert(not r and string.find(m, "too complex")) +end + +if not _soft then + print("big strings") + local a = string.rep('a', 300000) + assert(string.find(a, '^a*.?$')) + assert(not string.find(a, '^a*.?b$')) + assert(string.find(a, '^a-.?$')) + + -- bug in 5.1.2 + a = string.rep('a', 10000) .. string.rep('b', 10000) + assert(not pcall(string.gsub, a, 'b')) +end + +-- recursive nest of gsubs +function rev (s) + return string.gsub(s, "(.)(.+)", function (c,s1) return rev(s1)..c end) +end + +local x = "abcdef" +assert(rev(rev(x)) == x) + + +-- gsub with tables +assert(string.gsub("alo alo", ".", {}) == "alo alo") +assert(string.gsub("alo alo", "(.)", {a="AA", l=""}) == "AAo AAo") +assert(string.gsub("alo alo", "(.).", {a="AA", l="K"}) == "AAo AAo") +assert(string.gsub("alo alo", "((.)(.?))", {al="AA", o=false}) == "AAo AAo") + +assert(string.gsub("alo alo", "().", {'x','yy','zzz'}) == "xyyzzz alo") + +t = {}; setmetatable(t, {__index = function (t,s) return string.upper(s) end}) +assert(string.gsub("a alo b hi", "%w%w+", t) == "a ALO b HI") + + +-- tests for gmatch +local a = 0 +for i in string.gmatch('abcde', '()') do assert(i == a+1); a=i end +assert(a==6) + +t = {n=0} +for w in string.gmatch("first second word", "%w+") do + t.n=t.n+1; t[t.n] = w +end +assert(t[1] == "first" and t[2] == "second" and t[3] == "word") + +t = {3, 6, 9} +for i in string.gmatch ("xuxx uu ppar r", "()(.)%2") do + assert(i == table.remove(t, 1)) +end +assert(#t == 0) + +t = {} +for i,j in string.gmatch("13 14 10 = 11, 15= 16, 22=23", "(%d+)%s*=%s*(%d+)") do + t[tonumber(i)] = tonumber(j) +end +a = 0 +for k,v in pairs(t) do assert(k+1 == v+0); a=a+1 end +assert(a == 3) + + +-- tests for `%f' (`frontiers') + +assert(string.gsub("aaa aa a aaa a", "%f[%w]a", "x") == "xaa xa x xaa x") +assert(string.gsub("[[]] [][] [[[[", "%f[[].", "x") == "x[]] x]x] x[[[") +assert(string.gsub("01abc45de3", "%f[%d]", ".") == ".01abc.45de.3") +assert(string.gsub("01abc45 de3x", "%f[%D]%w", ".") == "01.bc45 de3.") +assert(string.gsub("function", "%f[\1-\255]%w", ".") == ".unction") +assert(string.gsub("function", "%f[^\1-\255]", ".") == "function.") + +assert(string.find("a", "%f[a]") == 1) +assert(string.find("a", "%f[^%z]") == 1) +assert(string.find("a", "%f[^%l]") == 2) +assert(string.find("aba", "%f[a%z]") == 3) +assert(string.find("aba", "%f[%z]") == 4) +assert(not string.find("aba", "%f[%l%z]")) +assert(not string.find("aba", "%f[^%l%z]")) + +local i, e = string.find(" alo aalo allo", "%f[%S].-%f[%s].-%f[%S]") +assert(i == 2 and e == 5) +local k = string.match(" alo aalo allo", "%f[%S](.-%f[%s].-%f[%S])") +assert(k == 'alo ') + +local a = {1, 5, 9, 14, 17,} +for k in string.gmatch("alo alo th02 is 1hat", "()%f[%w%d]") do + assert(table.remove(a, 1) == k) +end +assert(#a == 0) + + +-- malformed patterns +local function malform (p, m) + m = m or "malformed" + local r, msg = pcall(string.find, "a", p) + assert(not r and string.find(msg, m)) +end + +malform("(.", "unfinished capture") +malform(".)", "invalid pattern capture") +malform("[a") +malform("[]") +malform("[^]") +malform("[a%]") +malform("[a%") +malform("%b") +malform("%ba") +malform("%") +malform("%f", "missing") + +-- \0 in patterns +assert(string.match("ab\0\1\2c", "[\0-\2]+") == "\0\1\2") +assert(string.match("ab\0\1\2c", "[\0-\0]+") == "\0") +assert(string.find("b$a", "$\0?") == 2) +assert(string.find("abc\0efg", "%\0") == 4) +assert(string.match("abc\0efg\0\1e\1g", "%b\0\1") == "\0efg\0\1e\1") +assert(string.match("abc\0\0\0", "%\0+") == "\0\0\0") +assert(string.match("abc\0\0\0", "%\0%\0?") == "\0\0") + +-- magic char after \0 +assert(string.find("abc\0\0","\0.") == 4) +assert(string.find("abcx\0\0abc\0abc","x\0\0abc\0a.") == 4) + +print('OK') + diff --git a/tests/lua-5.3/sort.lua b/tests/lua-5.3/sort.lua new file mode 100644 index 0000000..d52feee --- /dev/null +++ b/tests/lua-5.3/sort.lua @@ -0,0 +1,310 @@ +-- $Id: sort.lua,v 1.38 2016/11/07 13:11:28 roberto Exp $ +-- See Copyright Notice in file all.lua + +print "testing (parts of) table library" + +print "testing unpack" + +local unpack = table.unpack + +local maxI = math.maxinteger +local minI = math.mininteger + + +local function checkerror (msg, f, ...) + local s, err = pcall(f, ...) + assert(not s and string.find(err, msg)) +end + + +checkerror("wrong number of arguments", table.insert, {}, 2, 3, 4) + +local x,y,z,a,n +a = {}; lim = _soft and 200 or 2000 +for i=1, lim do a[i]=i end +assert(select(lim, unpack(a)) == lim and select('#', unpack(a)) == lim) +x = unpack(a) +assert(x == 1) +x = {unpack(a)} +assert(#x == lim and x[1] == 1 and x[lim] == lim) +x = {unpack(a, lim-2)} +assert(#x == 3 and x[1] == lim-2 and x[3] == lim) +x = {unpack(a, 10, 6)} +assert(next(x) == nil) -- no elements +x = {unpack(a, 11, 10)} +assert(next(x) == nil) -- no elements +x,y = unpack(a, 10, 10) +assert(x == 10 and y == nil) +x,y,z = unpack(a, 10, 11) +assert(x == 10 and y == 11 and z == nil) +a,x = unpack{1} +assert(a==1 and x==nil) +a,x = unpack({1,2}, 1, 1) +assert(a==1 and x==nil) + +do + local maxi = (1 << 31) - 1 -- maximum value for an int (usually) + local mini = -(1 << 31) -- minimum value for an int (usually) + checkerror("too many results", unpack, {}, 0, maxi) + checkerror("too many results", unpack, {}, 1, maxi) + checkerror("too many results", unpack, {}, 0, maxI) + checkerror("too many results", unpack, {}, 1, maxI) + checkerror("too many results", unpack, {}, mini, maxi) + checkerror("too many results", unpack, {}, -maxi, maxi) + checkerror("too many results", unpack, {}, minI, maxI) + unpack({}, maxi, 0) + unpack({}, maxi, 1) + unpack({}, maxI, minI) + pcall(unpack, {}, 1, maxi + 1) + local a, b = unpack({[maxi] = 20}, maxi, maxi) + assert(a == 20 and b == nil) + a, b = unpack({[maxi] = 20}, maxi - 1, maxi) + assert(a == nil and b == 20) + local t = {[maxI - 1] = 12, [maxI] = 23} + a, b = unpack(t, maxI - 1, maxI); assert(a == 12 and b == 23) + a, b = unpack(t, maxI, maxI); assert(a == 23 and b == nil) + a, b = unpack(t, maxI, maxI - 1); assert(a == nil and b == nil) + t = {[minI] = 12.3, [minI + 1] = 23.5} + a, b = unpack(t, minI, minI + 1); assert(a == 12.3 and b == 23.5) + a, b = unpack(t, minI, minI); assert(a == 12.3 and b == nil) + a, b = unpack(t, minI + 1, minI); assert(a == nil and b == nil) +end + +do -- length is not an integer + local t = setmetatable({}, {__len = function () return 'abc' end}) + assert(#t == 'abc') + checkerror("object length is not an integer", table.insert, t, 1) +end + +print "testing pack" + +a = table.pack() +assert(a[1] == nil and a.n == 0) + +a = table.pack(table) +assert(a[1] == table and a.n == 1) + +a = table.pack(nil, nil, nil, nil) +assert(a[1] == nil and a.n == 4) + + +-- testing move +do + + checkerror("table expected", table.move, 1, 2, 3, 4) + + local function eqT (a, b) + for k, v in pairs(a) do assert(b[k] == v) end + for k, v in pairs(b) do assert(a[k] == v) end + end + + local a = table.move({10,20,30}, 1, 3, 2) -- move forward + eqT(a, {10,10,20,30}) + + -- move forward with overlap of 1 + a = table.move({10, 20, 30}, 1, 3, 3) + eqT(a, {10, 20, 10, 20, 30}) + + -- moving to the same table (not being explicit about it) + a = {10, 20, 30, 40} + table.move(a, 1, 4, 2, a) + eqT(a, {10, 10, 20, 30, 40}) + + a = table.move({10,20,30}, 2, 3, 1) -- move backward + eqT(a, {20,30,30}) + + a = {} -- move to new table + assert(table.move({10,20,30}, 1, 3, 1, a) == a) + eqT(a, {10,20,30}) + + a = {} + assert(table.move({10,20,30}, 1, 0, 3, a) == a) -- empty move (no move) + eqT(a, {}) + + a = table.move({10,20,30}, 1, 10, 1) -- move to the same place + eqT(a, {10,20,30}) + + -- moving on the fringes + a = table.move({[maxI - 2] = 1, [maxI - 1] = 2, [maxI] = 3}, + maxI - 2, maxI, -10, {}) + eqT(a, {[-10] = 1, [-9] = 2, [-8] = 3}) + + a = table.move({[minI] = 1, [minI + 1] = 2, [minI + 2] = 3}, + minI, minI + 2, -10, {}) + eqT(a, {[-10] = 1, [-9] = 2, [-8] = 3}) + + a = table.move({45}, 1, 1, maxI) + eqT(a, {45, [maxI] = 45}) + + a = table.move({[maxI] = 100}, maxI, maxI, minI) + eqT(a, {[minI] = 100, [maxI] = 100}) + + a = table.move({[minI] = 100}, minI, minI, maxI) + eqT(a, {[minI] = 100, [maxI] = 100}) + + a = setmetatable({}, { + __index = function (_,k) return k * 10 end, + __newindex = error}) + local b = table.move(a, 1, 10, 3, {}) + eqT(a, {}) + eqT(b, {nil,nil,10,20,30,40,50,60,70,80,90,100}) + + b = setmetatable({""}, { + __index = error, + __newindex = function (t,k,v) + t[1] = string.format("%s(%d,%d)", t[1], k, v) + end}) + table.move(a, 10, 13, 3, b) + assert(b[1] == "(3,100)(4,110)(5,120)(6,130)") + local stat, msg = pcall(table.move, b, 10, 13, 3, b) + assert(not stat and msg == b) +end + +do + -- for very long moves, just check initial accesses and interrupt + -- move with an error + local function checkmove (f, e, t, x, y) + local pos1, pos2 + local a = setmetatable({}, { + __index = function (_,k) pos1 = k end, + __newindex = function (_,k) pos2 = k; error() end, }) + local st, msg = pcall(table.move, a, f, e, t) + assert(not st and not msg and pos1 == x and pos2 == y) + end + checkmove(1, maxI, 0, 1, 0) + checkmove(0, maxI - 1, 1, maxI - 1, maxI) + checkmove(minI, -2, -5, -2, maxI - 6) + checkmove(minI + 1, -1, -2, -1, maxI - 3) + checkmove(minI, -2, 0, minI, 0) -- non overlapping + checkmove(minI + 1, -1, 1, minI + 1, 1) -- non overlapping +end + +checkerror("too many", table.move, {}, 0, maxI, 1) +checkerror("too many", table.move, {}, -1, maxI - 1, 1) +checkerror("too many", table.move, {}, minI, -1, 1) +checkerror("too many", table.move, {}, minI, maxI, 1) +checkerror("wrap around", table.move, {}, 1, maxI, 2) +checkerror("wrap around", table.move, {}, 1, 2, maxI) +checkerror("wrap around", table.move, {}, minI, -2, 2) + + +print"testing sort" + + +-- strange lengths +local a = setmetatable({}, {__len = function () return -1 end}) +assert(#a == -1) +table.sort(a, error) -- should not compare anything +a = setmetatable({}, {__len = function () return maxI end}) +checkerror("too big", table.sort, a) + +-- test checks for invalid order functions +local function check (t) + local function f(a, b) assert(a and b); return true end + checkerror("invalid order function", table.sort, t, f) +end + +check{1,2,3,4} +check{1,2,3,4,5} +check{1,2,3,4,5,6} + + +function check (a, f) + f = f or function (x,y) return x 'alo\0alo\0') +assert('alo' < 'alo\0') +assert('alo\0' > 'alo') +assert('\0' < '\1') +assert('\0\0' < '\0\1') +assert('\1\0a\0a' <= '\1\0a\0a') +assert(not ('\1\0a\0b' <= '\1\0a\0a')) +assert('\0\0\0' < '\0\0\0\0') +assert(not('\0\0\0\0' < '\0\0\0')) +assert('\0\0\0' <= '\0\0\0\0') +assert(not('\0\0\0\0' <= '\0\0\0')) +assert('\0\0\0' <= '\0\0\0') +assert('\0\0\0' >= '\0\0\0') +assert(not ('\0\0b' < '\0\0a\0')) + +-- testing string.sub +assert(string.sub("123456789",2,4) == "234") +assert(string.sub("123456789",7) == "789") +assert(string.sub("123456789",7,6) == "") +assert(string.sub("123456789",7,7) == "7") +assert(string.sub("123456789",0,0) == "") +assert(string.sub("123456789",-10,10) == "123456789") +assert(string.sub("123456789",1,9) == "123456789") +assert(string.sub("123456789",-10,-20) == "") +assert(string.sub("123456789",-1) == "9") +assert(string.sub("123456789",-4) == "6789") +assert(string.sub("123456789",-6, -4) == "456") +assert(string.sub("123456789", mini, -4) == "123456") +assert(string.sub("123456789", mini, maxi) == "123456789") +assert(string.sub("123456789", mini, mini) == "") +assert(string.sub("\000123456789",3,5) == "234") +assert(("\000123456789"):sub(8) == "789") + +-- testing string.find +assert(string.find("123456789", "345") == 3) +a,b = string.find("123456789", "345") +assert(string.sub("123456789", a, b) == "345") +assert(string.find("1234567890123456789", "345", 3) == 3) +assert(string.find("1234567890123456789", "345", 4) == 13) +assert(string.find("1234567890123456789", "346", 4) == nil) +assert(string.find("1234567890123456789", ".45", -9) == 13) +assert(string.find("abcdefg", "\0", 5, 1) == nil) +assert(string.find("", "") == 1) +assert(string.find("", "", 1) == 1) +assert(not string.find("", "", 2)) +assert(string.find('', 'aaa', 1) == nil) +assert(('alo(.)alo'):find('(.)', 1, 1) == 4) + +assert(string.len("") == 0) +assert(string.len("\0\0\0") == 3) +assert(string.len("1234567890") == 10) + +assert(#"" == 0) +assert(#"\0\0\0" == 3) +assert(#"1234567890" == 10) + +-- testing string.byte/string.char +assert(string.byte("a") == 97) +assert(string.byte("\xe4") > 127) +assert(string.byte(string.char(255)) == 255) +assert(string.byte(string.char(0)) == 0) +assert(string.byte("\0") == 0) +assert(string.byte("\0\0alo\0x", -1) == string.byte('x')) +assert(string.byte("ba", 2) == 97) +assert(string.byte("\n\n", 2, -1) == 10) +assert(string.byte("\n\n", 2, 2) == 10) +assert(string.byte("") == nil) +assert(string.byte("hi", -3) == nil) +assert(string.byte("hi", 3) == nil) +assert(string.byte("hi", 9, 10) == nil) +assert(string.byte("hi", 2, 1) == nil) +assert(string.char() == "") +assert(string.char(0, 255, 0) == "\0\255\0") +assert(string.char(0, string.byte("\xe4"), 0) == "\0\xe4\0") +assert(string.char(string.byte("\xe4l\0óu", 1, -1)) == "\xe4l\0óu") +assert(string.char(string.byte("\xe4l\0óu", 1, 0)) == "") +assert(string.char(string.byte("\xe4l\0óu", -10, 100)) == "\xe4l\0óu") + +assert(string.upper("ab\0c") == "AB\0C") +assert(string.lower("\0ABCc%$") == "\0abcc%$") +assert(string.rep('teste', 0) == '') +assert(string.rep('tés\00tê', 2) == 'tés\0têtés\000tê') +assert(string.rep('', 10) == '') + +if string.packsize("i") == 4 then + -- result length would be 2^31 (int overflow) + checkerror("too large", string.rep, 'aa', (1 << 30)) + checkerror("too large", string.rep, 'a', (1 << 30), ',') +end + +-- repetitions with separator +assert(string.rep('teste', 0, 'xuxu') == '') +assert(string.rep('teste', 1, 'xuxu') == 'teste') +assert(string.rep('\1\0\1', 2, '\0\0') == '\1\0\1\0\0\1\0\1') +assert(string.rep('', 10, '.') == string.rep('.', 9)) +assert(not pcall(string.rep, "aa", maxi // 2 + 10)) +assert(not pcall(string.rep, "", maxi // 2 + 10, "aa")) + +assert(string.reverse"" == "") +assert(string.reverse"\0\1\2\3" == "\3\2\1\0") +assert(string.reverse"\0001234" == "4321\0") + +for i=0,30 do assert(string.len(string.rep('a', i)) == i) end + +assert(type(tostring(nil)) == 'string') +assert(type(tostring(12)) == 'string') +assert(string.find(tostring{}, 'table:')) +assert(string.find(tostring(print), 'function:')) +assert(#tostring('\0') == 1) +assert(tostring(true) == "true") +assert(tostring(false) == "false") +assert(tostring(-1203) == "-1203") +assert(tostring(1203.125) == "1203.125") +assert(tostring(-0.5) == "-0.5") +assert(tostring(-32767) == "-32767") +if math.tointeger(2147483647) then -- no overflow? (32 bits) + assert(tostring(-2147483647) == "-2147483647") +end +if math.tointeger(4611686018427387904) then -- no overflow? (64 bits) + assert(tostring(4611686018427387904) == "4611686018427387904") + assert(tostring(-4611686018427387904) == "-4611686018427387904") +end + +if tostring(0.0) == "0.0" then -- "standard" coercion float->string + assert('' .. 12 == '12' and 12.0 .. '' == '12.0') + assert(tostring(-1203 + 0.0) == "-1203.0") +else -- compatible coercion + assert(tostring(0.0) == "0") + assert('' .. 12 == '12' and 12.0 .. '' == '12') + assert(tostring(-1203 + 0.0) == "-1203") +end + + +x = '"ílo"\n\\' +assert(string.format('%q%s', x, x) == '"\\"ílo\\"\\\n\\\\""ílo"\n\\') +assert(string.format('%q', "\0") == [["\0"]]) +assert(load(string.format('return %q', x))() == x) +x = "\0\1\0023\5\0009" +assert(load(string.format('return %q', x))() == x) +assert(string.format("\0%c\0%c%x\0", string.byte("\xe4"), string.byte("b"), 140) == + "\0\xe4\0b8c\0") +assert(string.format('') == "") +assert(string.format("%c",34)..string.format("%c",48)..string.format("%c",90)..string.format("%c",100) == + string.format("%c%c%c%c", 34, 48, 90, 100)) +assert(string.format("%s\0 is not \0%s", 'not be', 'be') == 'not be\0 is not \0be') +assert(string.format("%%%d %010d", 10, 23) == "%10 0000000023") +assert(tonumber(string.format("%f", 10.3)) == 10.3) +x = string.format('"%-50s"', 'a') +assert(#x == 52) +assert(string.sub(x, 1, 4) == '"a ') + +assert(string.format("-%.20s.20s", string.rep("%", 2000)) == + "-"..string.rep("%", 20)..".20s") +assert(string.format('"-%20s.20s"', string.rep("%", 2000)) == + string.format("%q", "-"..string.rep("%", 2000)..".20s")) + +do + local function checkQ (v) + local s = string.format("%q", v) + local nv = load("return " .. s)() + assert(v == nv and math.type(v) == math.type(nv)) + end + checkQ("\0\0\1\255\u{234}") + checkQ(math.maxinteger) + checkQ(math.mininteger) + checkQ(math.pi) + checkQ(0.1) + checkQ(true) + checkQ(nil) + checkQ(false) + checkerror("no literal", string.format, "%q", {}) +end + +assert(string.format("\0%s\0", "\0\0\1") == "\0\0\0\1\0") +checkerror("contains zeros", string.format, "%10s", "\0") + +-- format x tostring +assert(string.format("%s %s", nil, true) == "nil true") +assert(string.format("%s %.4s", false, true) == "false true") +assert(string.format("%.3s %.3s", false, true) == "fal tru") +local m = setmetatable({}, {__tostring = function () return "hello" end, + __name = "hi"}) +assert(string.format("%s %.10s", m, m) == "hello hello") +getmetatable(m).__tostring = nil -- will use '__name' from now on +assert(string.format("%.4s", m) == "hi: ") + +getmetatable(m).__tostring = function () return {} end +checkerror("'__tostring' must return a string", tostring, m) + + +assert(string.format("%x", 0.0) == "0") +assert(string.format("%02x", 0.0) == "00") +assert(string.format("%08X", 0xFFFFFFFF) == "FFFFFFFF") +assert(string.format("%+08d", 31501) == "+0031501") +assert(string.format("%+08d", -30927) == "-0030927") + + +do -- longest number that can be formatted + local i = 1 + local j = 10000 + while i + 1 < j do -- binary search for maximum finite float + local m = (i + j) // 2 + if 10^m < math.huge then i = m else j = m end + end + assert(10^i < math.huge and 10^j == math.huge) + local s = string.format('%.99f', -(10^i)) + assert(string.len(s) >= i + 101) + assert(tonumber(s) == -(10^i)) +end + + +-- testing large numbers for format +do -- assume at least 32 bits + local max, min = 0x7fffffff, -0x80000000 -- "large" for 32 bits + assert(string.sub(string.format("%8x", -1), -8) == "ffffffff") + assert(string.format("%x", max) == "7fffffff") + assert(string.sub(string.format("%x", min), -8) == "80000000") + assert(string.format("%d", max) == "2147483647") + assert(string.format("%d", min) == "-2147483648") + assert(string.format("%u", 0xffffffff) == "4294967295") + assert(string.format("%o", 0xABCD) == "125715") + + max, min = 0x7fffffffffffffff, -0x8000000000000000 + if max > 2.0^53 then -- only for 64 bits + assert(string.format("%x", (2^52 | 0) - 1) == "fffffffffffff") + assert(string.format("0x%8X", 0x8f000003) == "0x8F000003") + assert(string.format("%d", 2^53) == "9007199254740992") + assert(string.format("%i", -2^53) == "-9007199254740992") + assert(string.format("%x", max) == "7fffffffffffffff") + assert(string.format("%x", min) == "8000000000000000") + assert(string.format("%d", max) == "9223372036854775807") + assert(string.format("%d", min) == "-9223372036854775808") + assert(string.format("%u", ~(-1 << 64)) == "18446744073709551615") + assert(tostring(1234567890123) == '1234567890123') + end +end + + +do print("testing 'format %a %A'") + local function matchhexa (n) + local s = string.format("%a", n) + -- result matches ISO C requirements + assert(string.find(s, "^%-?0x[1-9a-f]%.?[0-9a-f]*p[-+]?%d+$")) + assert(tonumber(s) == n) -- and has full precision + s = string.format("%A", n) + assert(string.find(s, "^%-?0X[1-9A-F]%.?[0-9A-F]*P[-+]?%d+$")) + assert(tonumber(s) == n) + end + for _, n in ipairs{0.1, -0.1, 1/3, -1/3, 1e30, -1e30, + -45/247, 1, -1, 2, -2, 3e-20, -3e-20} do + matchhexa(n) + end + + assert(string.find(string.format("%A", 0.0), "^0X0%.?0?P%+?0$")) + assert(string.find(string.format("%a", -0.0), "^%-0x0%.?0?p%+?0$")) + + if not _port then -- test inf, -inf, NaN, and -0.0 + assert(string.find(string.format("%a", 1/0), "^inf")) + assert(string.find(string.format("%A", -1/0), "^%-INF")) + assert(string.find(string.format("%a", 0/0), "^%-?nan")) + assert(string.find(string.format("%a", -0.0), "^%-0x0")) + end + + if not pcall(string.format, "%.3a", 0) then + (Message or print)("\n >>> modifiers for format '%a' not available <<<\n") + else + assert(string.find(string.format("%+.2A", 12), "^%+0X%x%.%x0P%+?%d$")) + assert(string.find(string.format("%.4A", -12), "^%-0X%x%.%x000P%+?%d$")) + end +end + + +-- errors in format + +local function check (fmt, msg) + checkerror(msg, string.format, fmt, 10) +end + +local aux = string.rep('0', 600) +check("%100.3d", "too long") +check("%1"..aux..".3d", "too long") +check("%1.100d", "too long") +check("%10.1"..aux.."004d", "too long") +check("%t", "invalid option") +check("%"..aux.."d", "repeated flags") +check("%d %d", "no value") + + +assert(load("return 1\n--comment without ending EOL")() == 1) + + +checkerror("table expected", table.concat, 3) +assert(table.concat{} == "") +assert(table.concat({}, 'x') == "") +assert(table.concat({'\0', '\0\1', '\0\1\2'}, '.\0.') == "\0.\0.\0\1.\0.\0\1\2") +local a = {}; for i=1,300 do a[i] = "xuxu" end +assert(table.concat(a, "123").."123" == string.rep("xuxu123", 300)) +assert(table.concat(a, "b", 20, 20) == "xuxu") +assert(table.concat(a, "", 20, 21) == "xuxuxuxu") +assert(table.concat(a, "x", 22, 21) == "") +assert(table.concat(a, "3", 299) == "xuxu3xuxu") +assert(table.concat({}, "x", maxi, maxi - 1) == "") +assert(table.concat({}, "x", mini + 1, mini) == "") +assert(table.concat({}, "x", maxi, mini) == "") +assert(table.concat({[maxi] = "alo"}, "x", maxi, maxi) == "alo") +assert(table.concat({[maxi] = "alo", [maxi - 1] = "y"}, "-", maxi - 1, maxi) + == "y-alo") + +assert(not pcall(table.concat, {"a", "b", {}})) + +a = {"a","b","c"} +assert(table.concat(a, ",", 1, 0) == "") +assert(table.concat(a, ",", 1, 1) == "a") +assert(table.concat(a, ",", 1, 2) == "a,b") +assert(table.concat(a, ",", 2) == "b,c") +assert(table.concat(a, ",", 3) == "c") +assert(table.concat(a, ",", 4) == "") + +if not _port then + + local locales = { "ptb", "pt_BR.iso88591", "ISO-8859-1" } + local function trylocale (w) + for i = 1, #locales do + if os.setlocale(locales[i], w) then + print(string.format("'%s' locale set to '%s'", w, locales[i])) + return locales[i] + end + end + print(string.format("'%s' locale not found", w)) + return false + end + + if trylocale("collate") then + assert("alo" < "álo" and "álo" < "amo") + end + + if trylocale("ctype") then + assert(string.gsub("áéíóú", "%a", "x") == "xxxxx") + assert(string.gsub("áÁéÉ", "%l", "x") == "xÁxÉ") + assert(string.gsub("áÁéÉ", "%u", "x") == "áxéx") + assert(string.upper"áÁé{xuxu}ção" == "ÁÁÉ{XUXU}ÇÃO") + end + + os.setlocale("C") + assert(os.setlocale() == 'C') + assert(os.setlocale(nil, "numeric") == 'C') + +end + + +-- bug in Lua 5.3.2 +-- 'gmatch' iterator does not work across coroutines +do + local f = string.gmatch("1 2 3 4 5", "%d+") + assert(f() == "1") + co = coroutine.wrap(f) + assert(co() == "2") +end + +print('OK') + diff --git a/tests/lua-5.3/tpack.lua b/tests/lua-5.3/tpack.lua new file mode 100644 index 0000000..96bb4da --- /dev/null +++ b/tests/lua-5.3/tpack.lua @@ -0,0 +1,322 @@ +-- $Id: tpack.lua,v 1.13 2016/11/07 13:11:28 roberto Exp $ +-- See Copyright Notice in file all.lua + +local pack = string.pack +local packsize = string.packsize +local unpack = string.unpack + +print "testing pack/unpack" + +-- maximum size for integers +local NB = 16 + +local sizeshort = packsize("h") +local sizeint = packsize("i") +local sizelong = packsize("l") +local sizesize_t = packsize("T") +local sizeLI = packsize("j") +local sizefloat = packsize("f") +local sizedouble = packsize("d") +local sizenumber = packsize("n") +local little = (pack("i2", 1) == "\1\0") +local align = packsize("!xXi16") + +assert(1 <= sizeshort and sizeshort <= sizeint and sizeint <= sizelong and + sizefloat <= sizedouble) + +print("platform:") +print(string.format( + "\tshort %d, int %d, long %d, size_t %d, float %d, double %d,\n\z + \tlua Integer %d, lua Number %d", + sizeshort, sizeint, sizelong, sizesize_t, sizefloat, sizedouble, + sizeLI, sizenumber)) +print("\t" .. (little and "little" or "big") .. " endian") +print("\talignment: " .. align) + + +-- check errors in arguments +function checkerror (msg, f, ...) + local status, err = pcall(f, ...) + -- print(status, err, msg) + assert(not status and string.find(err, msg)) +end + +-- minimum behavior for integer formats +assert(unpack("B", pack("B", 0xff)) == 0xff) +assert(unpack("b", pack("b", 0x7f)) == 0x7f) +assert(unpack("b", pack("b", -0x80)) == -0x80) + +assert(unpack("H", pack("H", 0xffff)) == 0xffff) +assert(unpack("h", pack("h", 0x7fff)) == 0x7fff) +assert(unpack("h", pack("h", -0x8000)) == -0x8000) + +assert(unpack("L", pack("L", 0xffffffff)) == 0xffffffff) +assert(unpack("l", pack("l", 0x7fffffff)) == 0x7fffffff) +assert(unpack("l", pack("l", -0x80000000)) == -0x80000000) + + +for i = 1, NB do + -- small numbers with signal extension ("\xFF...") + local s = string.rep("\xff", i) + assert(pack("i" .. i, -1) == s) + assert(packsize("i" .. i) == #s) + assert(unpack("i" .. i, s) == -1) + + -- small unsigned number ("\0...\xAA") + s = "\xAA" .. string.rep("\0", i - 1) + assert(pack("I" .. i, 0xAA) == s:reverse()) + assert(unpack(">I" .. i, s:reverse()) == 0xAA) +end + +do + local lnum = 0x13121110090807060504030201 + local s = pack("i" .. i, ("\xFF"):rep(i - sizeLI) .. s:reverse()) == -lnum) + assert(unpack("i" .. i, "\1" .. ("\x00"):rep(i - 1)) + end +end + +for i = 1, sizeLI do + local lstr = "\1\2\3\4\5\6\7\8\9\10\11\12\13" + local lnum = 0x13121110090807060504030201 + local n = lnum & (~(-1 << (i * 8))) + local s = string.sub(lstr, 1, i) + assert(pack("i" .. i, n) == s:reverse()) + assert(unpack(">i" .. i, s:reverse()) == n) +end + +-- sign extension +do + local u = 0xf0 + for i = 1, sizeLI - 1 do + assert(unpack("I"..i, "\xf0"..("\xff"):rep(i - 1)) == u) + u = u * 256 + 0xff + end +end + +-- mixed endianness +do + assert(pack(">i2 i2", "\10\0\0\20") + assert(a == 10 and b == 20) + assert(pack("=i4", 2001) == pack("i4", 2001)) +end + +print("testing invalid formats") + +checkerror("out of limits", pack, "i0", 0) +checkerror("out of limits", pack, "i" .. NB + 1, 0) +checkerror("out of limits", pack, "!" .. NB + 1, 0) +checkerror("%(17%) out of limits %[1,16%]", pack, "Xi" .. NB + 1) +checkerror("invalid format option 'r'", pack, "i3r", 0) +checkerror("16%-byte integer", unpack, "i16", string.rep('\3', 16)) +checkerror("not power of 2", pack, "!4i3", 0); +checkerror("missing size", pack, "c", "") +checkerror("variable%-length format", packsize, "s") +checkerror("variable%-length format", packsize, "z") + +-- overflow in option size (error will be in digit after limit) +checkerror("invalid format", packsize, "c1" .. string.rep("0", 40)) + +if packsize("i") == 4 then + -- result would be 2^31 (2^3 repetitions of 2^28 strings) + local s = string.rep("c268435456", 2^3) + checkerror("too large", packsize, s) + -- one less is OK + s = string.rep("c268435456", 2^3 - 1) .. "c268435455" + assert(packsize(s) == 0x7fffffff) +end + +-- overflow in packing +for i = 1, sizeLI - 1 do + local umax = (1 << (i * 8)) - 1 + local max = umax >> 1 + local min = ~max + checkerror("overflow", pack, "I" .. i, umax + 1) + + checkerror("overflow", pack, ">i" .. i, umax) + checkerror("overflow", pack, ">i" .. i, max + 1) + checkerror("overflow", pack, "i" .. i, pack(">i" .. i, max)) == max) + assert(unpack("I" .. i, pack(">I" .. i, umax)) == umax) +end + +-- Lua integer size +assert(unpack(">j", pack(">j", math.maxinteger)) == math.maxinteger) +assert(unpack("f", 24)) +end + +print "testing pack/unpack of floating-point numbers" + +for _, n in ipairs{0, -1.1, 1.9, 1/0, -1/0, 1e20, -1e20, 0.1, 2000.7} do + assert(unpack("n", pack("n", n)) == n) + assert(unpack("n", pack(">n", n)) == n) + assert(pack("f", n):reverse()) + assert(pack(">d", n) == pack("f", pack(">f", n)) == n) + assert(unpack("d", pack(">d", n)) == n) +end + +print "testing pack/unpack of strings" +do + local s = string.rep("abc", 1000) + assert(pack("zB", s, 247) == s .. "\0\xF7") + local s1, b = unpack("zB", s .. "\0\xF9") + assert(b == 249 and s1 == s) + s1 = pack("s", s) + assert(unpack("s", s1) == s) + + checkerror("does not fit", pack, "s1", s) + + checkerror("contains zeros", pack, "z", "alo\0"); + + for i = 2, NB do + local s1 = pack("s" .. i, s) + assert(unpack("s" .. i, s1) == s and #s1 == #s + i) + end +end + +do + local x = pack("s", "alo") + checkerror("too short", unpack, "s", x:sub(1, -2)) + checkerror("too short", unpack, "c5", "abcd") + checkerror("out of limits", pack, "s100", "alo") +end + +do + assert(pack("c0", "") == "") + assert(packsize("c0") == 0) + assert(unpack("c0", "") == "") + assert(pack("!4 c6", "abcdef") == "abcdef") + assert(pack("c3", "123") == "123") + assert(pack("c0", "") == "") + assert(pack("c8", "123456") == "123456\0\0") + assert(pack("c88", "") == string.rep("\0", 88)) + assert(pack("c188", "ab") == "ab" .. string.rep("\0", 188 - 2)) + local a, b, c = unpack("!4 z c3", "abcdefghi\0xyz") + assert(a == "abcdefghi" and b == "xyz" and c == 14) + checkerror("longer than", pack, "c3", "1234") +end + + +-- testing multiple types and sequence +do + local x = pack("!8 b Xh i4 i8 c1 Xi8", -12, 100, 200, "\xEC") + assert(#x == packsize(">!8 b Xh i4 i8 c1 Xi8")) + assert(x == "\xf4" .. "\0\0\0" .. + "\0\0\0\100" .. + "\0\0\0\0\0\0\0\xC8" .. + "\xEC" .. "\0\0\0\0\0\0\0") + local a, b, c, d, pos = unpack(">!8 c1 Xh i4 i8 b Xi8 XI XH", x) + assert(a == "\xF4" and b == 100 and c == 200 and d == -20 and (pos - 1) == #x) + + x = pack(">!4 c3 c4 c2 z i4 c5 c2 Xi4", + "abc", "abcd", "xz", "hello", 5, "world", "xy") + assert(x == "abcabcdxzhello\0\0\0\0\0\5worldxy\0") + local a, b, c, d, e, f, g, pos = unpack(">!4 c3 c4 c2 z i4 c5 c2 Xh Xi4", x) + assert(a == "abc" and b == "abcd" and c == "xz" and d == "hello" and + e == 5 and f == "world" and g == "xy" and (pos - 1) % 4 == 0) + + x = pack(" b b Xd b Xb x", 1, 2, 3) + assert(packsize(" b b Xd b Xb x") == 4) + assert(x == "\1\2\3\0") + a, b, c, pos = unpack("bbXdb", x) + assert(a == 1 and b == 2 and c == 3 and pos == #x) + + -- only alignment + assert(packsize("!8 xXi8") == 8) + local pos = unpack("!8 xXi8", "0123456701234567"); assert(pos == 9) + assert(packsize("!8 xXi2") == 2) + local pos = unpack("!8 xXi2", "0123456701234567"); assert(pos == 3) + assert(packsize("!2 xXi2") == 2) + local pos = unpack("!2 xXi2", "0123456701234567"); assert(pos == 3) + assert(packsize("!2 xXi8") == 2) + local pos = unpack("!2 xXi8", "0123456701234567"); assert(pos == 3) + assert(packsize("!16 xXi16") == 16) + local pos = unpack("!16 xXi16", "0123456701234567"); assert(pos == 17) + + checkerror("invalid next option", pack, "X") + checkerror("invalid next option", unpack, "XXi", "") + checkerror("invalid next option", unpack, "X i", "") + checkerror("invalid next option", pack, "Xc1") +end + +do -- testing initial position + local x = pack("i4i4i4i4", 1, 2, 3, 4) + for pos = 1, 16, 4 do + local i, p = unpack("i4", x, pos) + assert(i == pos//4 + 1 and p == pos + 4) + end + + -- with alignment + for pos = 0, 12 do -- will always round position to power of 2 + local i, p = unpack("!4 i4", x, pos + 1) + assert(i == (pos + 3)//4 + 1 and p == i*4 + 1) + end + + -- negative indices + local i, p = unpack("!4 i4", x, -4) + assert(i == 4 and p == 17) + local i, p = unpack("!4 i4", x, -7) + assert(i == 4 and p == 17) + local i, p = unpack("!4 i4", x, -#x) + assert(i == 1 and p == 5) + + -- limits + for i = 1, #x + 1 do + assert(unpack("c0", x, i) == "") + end + checkerror("out of string", unpack, "c0", x, 0) + checkerror("out of string", unpack, "c0", x, #x + 2) + checkerror("out of string", unpack, "c0", x, -(#x + 1)) + +end + +print "OK" + diff --git a/tests/lua-5.3/utf8.lua b/tests/lua-5.3/utf8.lua new file mode 100644 index 0000000..ebc190b --- /dev/null +++ b/tests/lua-5.3/utf8.lua @@ -0,0 +1,210 @@ +-- $Id: utf8.lua,v 1.12 2016/11/07 13:11:28 roberto Exp $ +-- See Copyright Notice in file all.lua + +print "testing UTF-8 library" + +local utf8 = require'utf8' + + +local function checkerror (msg, f, ...) + local s, err = pcall(f, ...) + assert(not s and string.find(err, msg)) +end + + +local function len (s) + return #string.gsub(s, "[\x80-\xBF]", "") +end + + +local justone = "^" .. utf8.charpattern .. "$" + +-- 't' is the list of codepoints of 's' +local function checksyntax (s, t) + local ts = {"return '"} + for i = 1, #t do ts[i + 1] = string.format("\\u{%x}", t[i]) end + ts[#t + 2] = "'" + ts = table.concat(ts) + assert(assert(load(ts))() == s) +end + +assert(utf8.offset("alo", 5) == nil) +assert(utf8.offset("alo", -4) == nil) + +-- 't' is the list of codepoints of 's' +local function check (s, t) + local l = utf8.len(s) + assert(#t == l and len(s) == l) + assert(utf8.char(table.unpack(t)) == s) + + assert(utf8.offset(s, 0) == 1) + + checksyntax(s, t) + + local t1 = {utf8.codepoint(s, 1, -1)} + assert(#t == #t1) + for i = 1, #t do assert(t[i] == t1[i]) end + + for i = 1, l do + local pi = utf8.offset(s, i) -- position of i-th char + local pi1 = utf8.offset(s, 2, pi) -- position of next char + assert(string.find(string.sub(s, pi, pi1 - 1), justone)) + assert(utf8.offset(s, -1, pi1) == pi) + assert(utf8.offset(s, i - l - 1) == pi) + assert(pi1 - pi == #utf8.char(utf8.codepoint(s, pi))) + for j = pi, pi1 - 1 do + assert(utf8.offset(s, 0, j) == pi) + end + for j = pi + 1, pi1 - 1 do + assert(not utf8.len(s, j)) + end + assert(utf8.len(s, pi, pi) == 1) + assert(utf8.len(s, pi, pi1 - 1) == 1) + assert(utf8.len(s, pi) == l - i + 1) + assert(utf8.len(s, pi1) == l - i) + assert(utf8.len(s, 1, pi) == i) + end + + local i = 0 + for p, c in utf8.codes(s) do + i = i + 1 + assert(c == t[i] and p == utf8.offset(s, i)) + assert(utf8.codepoint(s, p) == c) + end + assert(i == #t) + + i = 0 + for p, c in utf8.codes(s) do + i = i + 1 + assert(c == t[i] and p == utf8.offset(s, i)) + end + assert(i == #t) + + i = 0 + for c in string.gmatch(s, utf8.charpattern) do + i = i + 1 + assert(c == utf8.char(t[i])) + end + assert(i == #t) + + for i = 1, l do + assert(utf8.offset(s, i) == utf8.offset(s, i - l - 1, #s + 1)) + end + +end + + +do -- error indication in utf8.len + local function check (s, p) + local a, b = utf8.len(s) + assert(not a and b == p) + end + check("abc\xE3def", 4) + check("汉字\x80", #("汉字") + 1) + check("\xF4\x9F\xBF", 1) + check("\xF4\x9F\xBF\xBF", 1) +end + +-- error in utf8.codes +checkerror("invalid UTF%-8 code", + function () + local s = "ab\xff" + for c in utf8.codes(s) do assert(c) end + end) + + +-- error in initial position for offset +checkerror("position out of range", utf8.offset, "abc", 1, 5) +checkerror("position out of range", utf8.offset, "abc", 1, -4) +checkerror("position out of range", utf8.offset, "", 1, 2) +checkerror("position out of range", utf8.offset, "", 1, -1) +checkerror("continuation byte", utf8.offset, "𦧺", 1, 2) +checkerror("continuation byte", utf8.offset, "𦧺", 1, 2) +checkerror("continuation byte", utf8.offset, "\x80", 1) + + + +local s = "hello World" +local t = {string.byte(s, 1, -1)} +for i = 1, utf8.len(s) do assert(t[i] == string.byte(s, i)) end +check(s, t) + +check("汉字/漢字", {27721, 23383, 47, 28450, 23383,}) + +do + local s = "áéí\128" + local t = {utf8.codepoint(s,1,#s - 1)} + assert(#t == 3 and t[1] == 225 and t[2] == 233 and t[3] == 237) + checkerror("invalid UTF%-8 code", utf8.codepoint, s, 1, #s) + checkerror("out of range", utf8.codepoint, s, #s + 1) + t = {utf8.codepoint(s, 4, 3)} + assert(#t == 0) + checkerror("out of range", utf8.codepoint, s, -(#s + 1), 1) + checkerror("out of range", utf8.codepoint, s, 1, #s + 1) +end + +assert(utf8.char() == "") +assert(utf8.char(97, 98, 99) == "abc") + +assert(utf8.codepoint(utf8.char(0x10FFFF)) == 0x10FFFF) + +checkerror("value out of range", utf8.char, 0x10FFFF + 1) + +local function invalid (s) + checkerror("invalid UTF%-8 code", utf8.codepoint, s) + assert(not utf8.len(s)) +end + +-- UTF-8 representation for 0x11ffff (value out of valid range) +invalid("\xF4\x9F\xBF\xBF") + +-- overlong sequences +invalid("\xC0\x80") -- zero +invalid("\xC1\xBF") -- 0x7F (should be coded in 1 byte) +invalid("\xE0\x9F\xBF") -- 0x7FF (should be coded in 2 bytes) +invalid("\xF0\x8F\xBF\xBF") -- 0xFFFF (should be coded in 3 bytes) + + +-- invalid bytes +invalid("\x80") -- continuation byte +invalid("\xBF") -- continuation byte +invalid("\xFE") -- invalid byte +invalid("\xFF") -- invalid byte + + +-- empty string +check("", {}) + +-- minimum and maximum values for each sequence size +s = "\0 \x7F\z + \xC2\x80 \xDF\xBF\z + \xE0\xA0\x80 \xEF\xBF\xBF\z + \xF0\x90\x80\x80 \xF4\x8F\xBF\xBF" +s = string.gsub(s, " ", "") +check(s, {0,0x7F, 0x80,0x7FF, 0x800,0xFFFF, 0x10000,0x10FFFF}) + +x = "日本語a-4\0éó" +check(x, {26085, 26412, 35486, 97, 45, 52, 0, 233, 243}) + + +-- Supplementary Characters +check("𣲷𠜎𠱓ð¡»ð µ¼ab𠺢", + {0x23CB7, 0x2070E, 0x20C53, 0x2107B, 0x20D7C, 0x61, 0x62, 0x20EA2,}) + +check("𨳊𩶘𦧺𨳒𥄫𤓓\xF4\x8F\xBF\xBF", + {0x28CCA, 0x29D98, 0x269FA, 0x28CD2, 0x2512B, 0x244D3, 0x10ffff}) + + +local i = 0 +for p, c in string.gmatch(x, "()(" .. utf8.charpattern .. ")") do + i = i + 1 + assert(utf8.offset(x, i) == p) + assert(utf8.len(x, p) == utf8.len(x) - i + 1) + assert(utf8.len(c) == 1) + for j = 1, #c - 1 do + assert(utf8.offset(x, 0, p + j - 1) == p) + end +end + +print'ok' + diff --git a/tests/lua-5.3/vararg.lua b/tests/lua-5.3/vararg.lua new file mode 100644 index 0000000..d617a98 --- /dev/null +++ b/tests/lua-5.3/vararg.lua @@ -0,0 +1,142 @@ +-- $Id: vararg.lua,v 1.25 2016/11/07 13:11:28 roberto Exp $ +-- See Copyright Notice in file all.lua + +print('testing vararg') + +function f(a, ...) + local arg = {n = select('#', ...), ...} + for i=1,arg.n do assert(a[i]==arg[i]) end + return arg.n +end + +function c12 (...) + assert(arg == _G.arg) -- no local 'arg' + local x = {...}; x.n = #x + local res = (x.n==2 and x[1] == 1 and x[2] == 2) + if res then res = 55 end + return res, 2 +end + +function vararg (...) return {n = select('#', ...), ...} end + +local call = function (f, args) return f(table.unpack(args, 1, args.n)) end + +assert(f() == 0) +assert(f({1,2,3}, 1, 2, 3) == 3) +assert(f({"alo", nil, 45, f, nil}, "alo", nil, 45, f, nil) == 5) + +assert(c12(1,2)==55) +a,b = assert(call(c12, {1,2})) +assert(a == 55 and b == 2) +a = call(c12, {1,2;n=2}) +assert(a == 55 and b == 2) +a = call(c12, {1,2;n=1}) +assert(not a) +assert(c12(1,2,3) == false) +local a = vararg(call(next, {_G,nil;n=2})) +local b,c = next(_G) +assert(a[1] == b and a[2] == c and a.n == 2) +a = vararg(call(call, {c12, {1,2}})) +assert(a.n == 2 and a[1] == 55 and a[2] == 2) +a = call(print, {'+'}) +assert(a == nil) + +local t = {1, 10} +function t:f (...) local arg = {...}; return self[...]+#arg end +assert(t:f(1,4) == 3 and t:f(2) == 11) +print('+') + +lim = 20 +local i, a = 1, {} +while i <= lim do a[i] = i+0.3; i=i+1 end + +function f(a, b, c, d, ...) + local more = {...} + assert(a == 1.3 and more[1] == 5.3 and + more[lim-4] == lim+0.3 and not more[lim-3]) +end + +function g(a,b,c) + assert(a == 1.3 and b == 2.3 and c == 3.3) +end + +call(f, a) +call(g, a) + +a = {} +i = 1 +while i <= lim do a[i] = i; i=i+1 end +assert(call(math.max, a) == lim) + +print("+") + + +-- new-style varargs + +function oneless (a, ...) return ... end + +function f (n, a, ...) + local b + assert(arg == _G.arg) -- no local 'arg' + if n == 0 then + local b, c, d = ... + return a, b, c, d, oneless(oneless(oneless(...))) + else + n, b, a = n-1, ..., a + assert(b == ...) + return f(n, a, ...) + end +end + +a,b,c,d,e = assert(f(10,5,4,3,2,1)) +assert(a==5 and b==4 and c==3 and d==2 and e==1) + +a,b,c,d,e = f(4) +assert(a==nil and b==nil and c==nil and d==nil and e==nil) + + +-- varargs for main chunks +f = load[[ return {...} ]] +x = f(2,3) +assert(x[1] == 2 and x[2] == 3 and x[3] == nil) + + +f = load[[ + local x = {...} + for i=1,select('#', ...) do assert(x[i] == select(i, ...)) end + assert(x[select('#', ...)+1] == nil) + return true +]] + +assert(f("a", "b", nil, {}, assert)) +assert(f()) + +a = {select(3, table.unpack{10,20,30,40})} +assert(#a == 2 and a[1] == 30 and a[2] == 40) +a = {select(1)} +assert(next(a) == nil) +a = {select(-1, 3, 5, 7)} +assert(a[1] == 7 and a[2] == nil) +a = {select(-2, 3, 5, 7)} +assert(a[1] == 5 and a[2] == 7 and a[3] == nil) +pcall(select, 10000) +pcall(select, -10000) + + +-- bug in 5.2.2 + +function f(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, +p11, p12, p13, p14, p15, p16, p17, p18, p19, p20, +p21, p22, p23, p24, p25, p26, p27, p28, p29, p30, +p31, p32, p33, p34, p35, p36, p37, p38, p39, p40, +p41, p42, p43, p44, p45, p46, p48, p49, p50, ...) + local a1,a2,a3,a4,a5,a6,a7 + local a8,a9,a10,a11,a12,a13,a14 +end + +-- assertion fail here +f() + + +print('OK') + diff --git a/tests/lua-5.3/verybig.lua b/tests/lua-5.3/verybig.lua new file mode 100644 index 0000000..1cfd10b --- /dev/null +++ b/tests/lua-5.3/verybig.lua @@ -0,0 +1,152 @@ +-- $Id: verybig.lua,v 1.25 2016/11/07 13:11:28 roberto Exp $ +-- See Copyright Notice in file all.lua + +print "testing RK" + +-- testing opcodes with RK arguments larger than K limit +local function foo () + local dummy = { + -- fill first 256 entries in table of constants + 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, + 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, + 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, + 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, + 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, + 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, + 97, 98, 99, 100, 101, 102, 103, 104, + 105, 106, 107, 108, 109, 110, 111, 112, + 113, 114, 115, 116, 117, 118, 119, 120, + 121, 122, 123, 124, 125, 126, 127, 128, + 129, 130, 131, 132, 133, 134, 135, 136, + 137, 138, 139, 140, 141, 142, 143, 144, + 145, 146, 147, 148, 149, 150, 151, 152, + 153, 154, 155, 156, 157, 158, 159, 160, + 161, 162, 163, 164, 165, 166, 167, 168, + 169, 170, 171, 172, 173, 174, 175, 176, + 177, 178, 179, 180, 181, 182, 183, 184, + 185, 186, 187, 188, 189, 190, 191, 192, + 193, 194, 195, 196, 197, 198, 199, 200, + 201, 202, 203, 204, 205, 206, 207, 208, + 209, 210, 211, 212, 213, 214, 215, 216, + 217, 218, 219, 220, 221, 222, 223, 224, + 225, 226, 227, 228, 229, 230, 231, 232, + 233, 234, 235, 236, 237, 238, 239, 240, + 241, 242, 243, 244, 245, 246, 247, 248, + 249, 250, 251, 252, 253, 254, 255, 256, + } + assert(24.5 + 0.6 == 25.1) + local t = {foo = function (self, x) return x + self.x end, x = 10} + t.t = t + assert(t:foo(1.5) == 11.5) + assert(t.t:foo(0.5) == 10.5) -- bug in 5.2 alpha + assert(24.3 == 24.3) + assert((function () return t.x end)() == 10) +end + + +foo() +foo = nil + +if _soft then return 10 end + +print "testing large programs (>64k)" + +-- template to create a very big test file +prog = [[$ + +local a,b + +b = {$1$ + b30009 = 65534, + b30010 = 65535, + b30011 = 65536, + b30012 = 65537, + b30013 = 16777214, + b30014 = 16777215, + b30015 = 16777216, + b30016 = 16777217, + b30017 = 0x7fffff, + b30018 = -0x7fffff, + b30019 = 0x1ffffff, + b30020 = -0x1ffffd, + b30021 = -65534, + b30022 = -65535, + b30023 = -65536, + b30024 = -0xffffff, + b30025 = 15012.5, + $2$ +}; + +assert(b.a50008 == 25004 and b["a11"] == -5.5) +assert(b.a33007 == -16503.5 and b.a50009 == -25004.5) +assert(b["b"..30024] == -0xffffff) + +function b:xxx (a,b) return a+b end +assert(b:xxx(10, 12) == 22) -- pushself with non-constant index +b.xxx = nil + +s = 0; n=0 +for a,b in pairs(b) do s=s+b; n=n+1 end +-- with 32-bit floats, exact value of 's' depends on summation order +assert(81800000.0 < s and s < 81860000 and n == 70001) + +a = nil; b = nil +print'+' + +function f(x) b=x end + +a = f{$3$} or 10 + +assert(a==10) +assert(b[1] == "a10" and b[2] == 5 and b[#b-1] == "a50009") + + +function xxxx (x) return b[x] end + +assert(xxxx(3) == "a11") + +a = nil; b=nil +xxxx = nil + +return 10 + +]] + +-- functions to fill in the $n$ + +local function sig (x) + return (x % 2 == 0) and '' or '-' +end + +F = { +function () -- $1$ + for i=10,50009 do + io.write('a', i, ' = ', sig(i), 5+((i-10)/2), ',\n') + end +end, + +function () -- $2$ + for i=30026,50009 do + io.write('b', i, ' = ', sig(i), 15013+((i-30026)/2), ',\n') + end +end, + +function () -- $3$ + for i=10,50009 do + io.write('"a', i, '", ', sig(i), 5+((i-10)/2), ',\n') + end +end, +} + +file = os.tmpname() +io.output(file) +for s in string.gmatch(prog, "$([^$]+)") do + local n = tonumber(s) + if not n then io.write(s) else F[n]() end +end +io.close() +result = dofile(file) +assert(os.remove(file)) +print'OK' +return result + diff --git a/tests/starlight/coercion.lua b/tests/starlight/coercion.lua new file mode 100644 index 0000000..5eb8dac --- /dev/null +++ b/tests/starlight/coercion.lua @@ -0,0 +1,188 @@ + +assertTrue (0, 'Zero should coerce to true.') +assertTrue (1, 'Positive number should coerce to true.') +assertTrue (-1, 'Negative number should coerce to true.') +assertTrue ('Test', 'String should coerce to true.') +assertTrue ('', 'Empty string should coerce to true.') + +assertTrue (0 + '123' == 123, 'Integer strings should coerce to integers') +assertTrue (0 + '123.45' == 123.45, 'Floating point strings should coerce to floats') +assertTrue (0 + '0xa' == 10, 'Hexidecimal syntax strings should coerce to decimal integers') +assertTrue (0 + '0xa.2' == 10.125, 'Floating point hexidecimal syntax strings should coerce to decimal floats') +assertTrue (0 + '0123' == 123, 'JS Octal syntax strings should be coerced as normal decimal strings in Lua') + +assertTrue (0 + '-123' == -123, 'Negative integer strings should coerce to negative integers') +assertTrue (0 + '-0xa.2' == -10.125, 'Negative floating point hexidecimal syntax strings should coerce to negative decimal floats') +assertTrue (0 + 'inf' == math.huge, '"inf" should coerce to inf') +assertTrue (0 + '-inf' == -math.huge, '"-inf" should coerce to negative inf') + +local a = 0 + 'nan' +assertTrue (a ~= a, '"nan" should coerce to nan') + + +assertTrue (not (nil), 'Nil should coerce to false.') +assertTrue (not (false), 'False should be false.') +assertTrue (not (10 == '10'), 'String should coerce to number.') + + + +-- TYPE ERRORS + +function conc (a, b) + return a..b +end + +a = pcall (conc, 'a', 'b') +b = pcall (conc, 'a', 44) +c = pcall (conc, 55, 'b') +d = pcall (conc, 55, 44) +e = pcall (conc, 'a', {}) +f = pcall (conc, {}, 'b') +g = pcall (conc, 'a', os.date) + +assertTrue (a, 'Concatenation should not error with two strings') +assertTrue (b, 'Concatenation should not error with a string and a number') +assertTrue (c, 'Concatenation should not error with a number and a string') +assertTrue (d, 'Concatenation should not error with two numbers') +assertTrue (not (e), 'Concatenation should error with a string and a table') +assertTrue (not (f), 'Concatenation should error with a table and a string') +assertTrue (not (g), 'Concatenation should error with a string and a function') + + +function add (a, b) + return a + b +end + +a = pcall (add, 'a', 'b') +b = pcall (add, 'a', 44) +c = pcall (add, 55, 'b') +d = pcall (add, 55, 44) +e = pcall (add, 'a', {}) +f = pcall (add, {}, 'b') +g = pcall (add, 'a', os.date) + +assertTrue (not (a), 'Addition operator should error with two strings') +assertTrue (not (b), 'Addition operator should error with a string and a number') +assertTrue (not (c), 'Addition operator should error with a number and a string') +assertTrue (d, 'Addition operator should not error with two numbers') +assertTrue (not (e), 'Addition operator should error with a string and a table') +assertTrue (not (f), 'Addition operator should error with a table and a string') +assertTrue (not (g), 'Addition operator should error with a string and a function') + + +function sub (a, b) + return a - b +end + +a = pcall (sub, 'a', 'b') +b = pcall (sub, 'a', 44) +c = pcall (sub, 55, 'b') +d = pcall (sub, 55, 44) +e = pcall (sub, 'a', {}) +f = pcall (sub, {}, 'b') +g = pcall (sub, 'a', os.date) + +assertTrue (not (a), 'Subtraction operator should error with two strings') +assertTrue (not (b), 'Subtraction operator should error with a string and a number') +assertTrue (not (c), 'Subtraction operator should error with a number and a string') +assertTrue (d, 'Subtraction operator should not error with two numbers') +assertTrue (not (e), 'Subtraction operator should error with a string and a table') +assertTrue (not (f), 'Subtraction operator should error with a table and a string') +assertTrue (not (g), 'Subtraction operator should error with a string and a function') + + +function mult (a, b) + return a * b +end + +a = pcall (mult, 'a', 'b') +b = pcall (mult, 'a', 44) +c = pcall (mult, 55, 'b') +d = pcall (mult, 55, 44) +e = pcall (mult, 'a', {}) +f = pcall (mult, {}, 'b') +g = pcall (mult, 'a', os.date) + +assertTrue (not (a), 'Multiplication operator should error with two strings') +assertTrue (not (b), 'Multiplication operator should error with a string and a number') +assertTrue (not (c), 'Multiplication operator should error with a number and a string') +assertTrue (d, 'Multiplication operator should not error with two numbers') +assertTrue (not (e), 'Multiplication operator should error with a string and a table') +assertTrue (not (f), 'Multiplication operator should error with a table and a string') +assertTrue (not (g), 'Multiplication operator should error with a string and a function') + + +function divide (a, b) + return a / b +end + +a = pcall (divide, 'a', 'b') +b = pcall (divide, 'a', 44) +c = pcall (divide, 55, 'b') +d = pcall (divide, 55, 44) +e = pcall (divide, 'a', {}) +f = pcall (divide, {}, 'b') +g = pcall (divide, 'a', os.date) + +assertTrue (not (a), 'Division operator should error with two strings') +assertTrue (not (b), 'Division operator should error with a string and a number') +assertTrue (not (c), 'Division operator should error with a number and a string') +assertTrue (d, 'Division operator should not error with two numbers') +assertTrue (not (e), 'Division operator should error with a string and a table') +assertTrue (not (f), 'Division operator should error with a table and a string') +assertTrue (not (g), 'Division operator should error with a string and a function') + + +function modu (a, b) + return a % b +end + +a = pcall (modu, 'a', 'b') +b = pcall (modu, 'a', 44) +c = pcall (modu, 55, 'b') +d = pcall (modu, 55, 44) +e = pcall (modu, 'a', {}) +f = pcall (modu, {}, 'b') +g = pcall (modu, 'a', os.date) + +assertTrue (not (a), 'Modulo operator should error with two strings') +assertTrue (not (b), 'Modulo operator should error with a string and a number') +assertTrue (not (c), 'Modulo operator should error with a number and a string') +assertTrue (d, 'Modulo operator should not error with two numbers') +assertTrue (not (e), 'Modulo operator should error with a string and a table') +assertTrue (not (f), 'Modulo operator should error with a table and a string') +assertTrue (not (g), 'Modulo operator should error with a string and a function') + + +function power (a, b) + return a ^ b +end + +a = pcall (power, 'a', 'b') +b = pcall (power, 'a', 44) +c = pcall (power, 55, 'b') +d = pcall (power, 55, 44) +e = pcall (power, 'a', {}) +f = pcall (power, {}, 'b') +g = pcall (power, 'a', os.date) + +assertTrue (not (a), 'Exponentiation operator should error with two strings') +assertTrue (not (b), 'Exponentiation operator should error with a string and a number') +assertTrue (not (c), 'Exponentiation operator should error with a number and a string') +assertTrue (d, 'Exponentiation operator should not error with two numbers') +assertTrue (not (e), 'Exponentiation operator should error with a string and a table') +assertTrue (not (f), 'Exponentiation operator should error with a table and a string') +assertTrue (not (g), 'Exponentiation operator should error with a string and a function') + + +function neg (a) + return -a +end + +a = pcall (neg, 'a') +b = pcall (neg, 55) +c = pcall (neg, {}) + +assertTrue (not (a), 'Negation operator should error when passed a string') +assertTrue (b, 'Negation operator should not error when passed a number') +assertTrue (not (c), 'Negation operator should error when passed a table') diff --git a/tests/starlight/control-structures.lua b/tests/starlight/control-structures.lua new file mode 100644 index 0000000..e076d98 --- /dev/null +++ b/tests/starlight/control-structures.lua @@ -0,0 +1,294 @@ + +local a, b, i = 0, 0, 0 + +for i = 1, 5 do + a = a + 1 + b = b + i +end + +assertTrue (a == 5, 'For loop should iterate the correct number of times') +assertTrue (b == 15, 'For loop variable should hold the value of the current iteration') + + +local funcs = {} +local b = '' + +for i = 1, 3 do + table.insert(funcs, function () b = b..i end) +end + +funcs[1]() +funcs[2]() +funcs[3]() +assertTrue (b == '123', 'Each loop of numeric for should maintain its own scope') + + + + +a = { a = 1, b = 2 } +b = 0 + +for _ in pairs(a) do b = b + 1 end + +assertTrue (b == 2, 'For block should iterate over all properties of a table') + + +a.a = nil +b = 0 + +for _ in pairs(a) do b = b + 1 end + +assertTrue (b == 1, 'Setting a table property to nil should remove that property from the table.') + + + +b = {} + +for i = 1, 3 do + local c = i + b[i] = function() return c end +end + +assertTrue (b[1]() == 1, 'Local within a closure should keep its value [1]') +assertTrue (b[2]() == 2, 'Local within a closure should keep its value [2]') +assertTrue (b[3]() == 3, 'Local within a closure should keep its value [3]') + +b = '' +i = 1 +for i = 1, 4 do + b = b..i + break +end +assertTrue (b == '1', 'Break should exit numerical for loop') + + +a = '' +u = {['@!#'] = 'qbert', [{}] = 1729, [6.28] = 'tau', [function () end] = 'test'} + +for key, val in pairs(u) do + a = a..'['..tostring(key)..'=='..tostring(val)..']' +end + + +assertTrue (string.find(a, '[6.28==tau]') ~= nil, 'for/pairs iteration should include items with double as key.') +assertTrue (string.find(a, '[@!#==qbert]') ~= nil, 'for/pairs iteration should include items with string as key.') +assertTrue (string.find(a, '[table: 0x%d+==1729]') ~= nil, 'for/pairs iteration should include items with table as key.') +assertTrue (string.find(a, '[function: 0x%d+==test]') ~= nil, 'for/pairs iteration should include items with function as key.') + +a = '' +t = {1,2,3} +for key, val in pairs(t) do + a = a..'['..tostring(key)..'=='..tostring(val)..']' + break +end +assertTrue (a == '[1==1]', 'Break should exit generic for loop') + + +function iter(t, i) + if i < 5 then + return i + 1, i + else + return nil + end +end +a = '' +for key, val in iter, {}, 2 do + a = a..'['..tostring(key)..'=='..tostring(val)..']' +end +assertTrue (a == '[3==2][4==3][5==4]', 'Generic for loop should accept an expression list') + +function iter(t, i) + i = i + 1 + v = t[i] + if v then + return i, v, v * 2 + end +end +a = '' +for x,y,z in iter, {4,5,6}, 0 do + a = a..'['..tostring(x)..','..tostring(y)..','..tostring(z)..']' +end +assertTrue (a == '[1,4,8][2,5,10][3,6,12]', 'Generic for loop should pass all values returned from iterator to the variables in the loop') + + +local funcs = {} +local a = {1,2,3} +local b = '' + +for _, i in ipairs(a) do + table.insert(funcs, function () b = b..i end) +end + +funcs[1]() +funcs[2]() +funcs[3]() +assertTrue (b == '123', 'Each loop of generic for should maintain its own scope') + + +a = '' +b = 1 +while #a < 15 do + a = a..b + b = b + 1 +end + +assertEqual (a, '123456789101112', 'While loop should iterate until condition is met') + +local fail = false +while b < 0 do + fail = true +end + +assertEqual (fail, false, 'While loop should not iterate if condition is never met') + +b = {} +i = 1 +while i < 4 do + local c = i + b[i] = function() return c end + i = i + 1 +end + +assertTrue (b[1]() == 1, 'Local within a while loop closure should keep its value [1]') +assertTrue (b[2]() == 2, 'Local within a while loop closure should keep its value [2]') +assertTrue (b[3]() == 3, 'Local within a while loop closure should keep its value [3]') + +b = '' +i = 1 +while i < 4 do + b = b..i + i = i + 1 + break +end +assertTrue (b == '1', 'Break should exit while loop') + + +local funcs = {} +local b = '' +i = 1 + +while i < 4 do + table.insert(funcs, function () b = b..i end) + i = i + 1 +end + +funcs[1]() +funcs[2]() +funcs[3]() +assertTrue (b == '444', 'Each loop of while should not maintain its own scope') + + + +a = '' +b = 1 +repeat + a = a..b + b = b + 1 +until #a > 15 + +assertEqual (a, '12345678910111213', 'Repeat loop should iterate until condition is met') + +b = 1 +repeat + b = b + 1 +until b > 0 + +assertEqual (b, 2, 'Repeat loop should iterate once if condition is always met') + +b = {} +i = 1 +repeat + local c = i + b[i] = function() return c end + i = i + 1 +until i == 4 + +assertTrue (b[1]() == 1, 'Local within a while loop closure should keep its value [1]') +assertTrue (b[2]() == 2, 'Local within a while loop closure should keep its value [2]') +assertTrue (b[3]() == 3, 'Local within a while loop closure should keep its value [3]') + + +b = '' +i = 1 +repeat + b = b..i + i = i + 1 + break +until i == 4 +assertTrue (b == '1', 'Break should exit repeat loop') + + +local funcs = {} +local b = '' +i = 1 + +repeat + table.insert(funcs, function () b = b..i end) + i = i + 1 +until i == 4 + +funcs[1]() +funcs[2]() +funcs[3]() +assertTrue (b == '444', 'Each loop of repeat should not maintain its own scope') + + +a = ':' +t = { 123, 456, x = 789, 10 } +for i, v in ipairs(t) do + a = a..i..'='..v..':' +end + +assertTrue (string.find(a, ':1=123:') ~= nil, 'for-in-ipairs loop should iterate over numeric keys [1]') +assertTrue (string.find(a, ':2=456:') ~= nil, 'for-in-ipairs loop should iterate over numeric keys [2]') +assertTrue (string.find(a, ':3=10:') ~= nil, 'for-in-ipairs loop should iterate over numeric keys [3]') +assertTrue (string.find(a, ':x=789:') == nil, 'for-in-ipairs loop should not iterate over non-numeric keys') +assertEqual (a, ':1=123:2=456:3=10:', 'for-in-ipairs loop should iterate over numeric keys in order') + + +b = nil +a = function () + return false, true +end + +if a() then + b = 'THIS SHOULD NOT EXECUTE' +end +assertEqual (b, nil, 'If clause with function call should only use first returned value. [1]') + +b = nil +a = function () + return true, false +end + +if a() then + b = 'THIS SHOULD EXECUTE' +end +assertEqual (b, 'THIS SHOULD EXECUTE', 'If clause with function call should only use first returned value. [2]') + + +-- do block + +local a = 1 +local b = 10 +do + local a = 2 + b = 20 + assertEqual (a, 2, 'Do block should use local variables') + assertEqual (b, 20, 'Do block should set upvalues') +end +assertEqual (a, 1, 'Do block should create its own local variable scope') +assertEqual (b, 20, 'Do block should update upvalues') + +a = '1' +function testReturn() + a = a..'2' + do + a = a..'3' + return + end + a = a..'X' +end + +testReturn() +assertEqual (a, '123', 'Do block containing return should return from parent function') diff --git a/tests/starlight/functions.lua b/tests/starlight/functions.lua new file mode 100644 index 0000000..a933960 --- /dev/null +++ b/tests/starlight/functions.lua @@ -0,0 +1,134 @@ + +local b = 20 + +function addOne () + assertTrue (b == 20, 'Functions should be able to access locals of parent closures [1]') + + function nested () + assertTrue (b == 20, 'Functions should be able to access locals of parent closures [2]') + + local c = 9 + assertTrue (c == 9, 'Functions should be able to access their own locals') + end + + nested () + assertTrue (c == nil, 'Function locals should not be accessible from outside the function') + + b = b + 1 + assertTrue (b == 21, 'Operations performed on upvalues should use external value') +end + +addOne () +assertTrue (b == 21, 'Operations performed on upvalues in functions should affect the external value too') + + +function f (...) + local a, b, c = ... + assertTrue (a == -1, 'Varargs should pass values around correctly [1]') + assertTrue (b == 0, 'Varargs should pass values around correctly [2]') + assertTrue (c == 2, 'Varargs should pass values around correctly [3]') + + local d, e, f, g, h = ... + assertTrue (d == -1, 'Varargs should pass values around correctly [4]') + assertTrue (e == 0, 'Varargs should pass values around correctly [5]') + assertTrue (f == 2, 'Varargs should pass values around correctly [6]') + assertTrue (g == 9, 'Varargs should pass values around correctly [7]') + assertTrue (h == nil, 'Varargs should pass nil for list entries beyond its length') +end + +f(-1,0,2,9) + + +function g (a, ...) + local b, c = ... + assertTrue (a == -1, 'Varargs should pass values around correctly [8]') + assertTrue (b == 0, 'Varargs should pass values around correctly [9]') + assertTrue (c == 2, 'Varargs should pass values around correctly [10]') +end + +g(-1,0,2,9) + + +function h (a, b, ...) + local c = ... + assertTrue (a == -1, 'Varargs should pass values around correctly [11]') + assertTrue (b == 0, 'Varargs should pass values around correctly [12]') + assertTrue (c == 2, 'Varargs should pass values around correctly [13]') +end + +h(-1,0,2,9) + + +function getFunc () + local b = 6 + return function () return b end +end + +x = getFunc () () +assertTrue (x == 6, 'Functions should be able to return functions (and maintain their scope)') + + + +function add (val1) + return function (val2) return val1 + val2 end +end + +local addThree = add (3) +x = addThree (4) + +assertTrue (x == 7, 'Functions should be able to be curried') + + +do + local function x() + return 'inner' + end + + function y() + return x() + end +end + +function x() + return 'outer' +end + +local z = y() +assertTrue (z == 'inner', 'Local functions should be locally scoped') + + +function oneTwo() + return 1, 2 +end + +function testReturnValues() + return oneTwo(), 10 +end + +local a, b, c = testReturnValues() +assertTrue (a == 1, 'return should return the first item returned from a function call') +assertTrue (b == 10, 'return should only return the first item from a function call when not last item in an expression list') +assertTrue (c == nil, 'return should know when to stop') + +function testReturnValues2() + return 10, oneTwo() +end + +local a, b, c = testReturnValues2() +assertTrue (a == 10, 'return should return the first item in an expression list') +assertTrue (b == 1, 'return should return the first item from a function call') +assertTrue (c == 2, 'return should return all items returned from a function call if at end of expression list') + +function testArgs1(a, b, c) + assertTrue (a == 1, 'Function call in argument list should pass return value as argument') + assertTrue (b == 10, 'Function call in middle of argument list should only pass one argument') + assertTrue (c == nil, 'Arguments should stop at the end of argument list') +end +testArgs1(oneTwo(), 10) + +function testArgs2(a, b, c) + assertTrue (a == 10, 'Arguments should be passed in order') + assertTrue (b == 1, 'Function call should pass return values') + assertTrue (c == 2, 'Function call at end of argument list should pass all return values') +end +testArgs2(10, oneTwo()) diff --git a/tests/starlight/lib-coroutine.lua b/tests/starlight/lib-coroutine.lua new file mode 100644 index 0000000..29928d8 --- /dev/null +++ b/tests/starlight/lib-coroutine.lua @@ -0,0 +1,60 @@ + +local innerOrder = {'Y','twelve','ten','six','four'} +local midOrder = {'Z','thirteen','nine','seven','three'} +local outerOrder = {'two','eight','fourteen','A'} +local loopOrder = {'five','eleven','fifteen','B'} +local order = '' +local arguments = '' + + +function innerFunc (...) + order = order..table.remove(innerOrder) + + local a, b, c = ... + arguments = arguments..'Ia'..tostring(a)..tostring(b)..tostring(c) + + a, b, c = coroutine.yield (...) + + order = order..table.remove(innerOrder) + arguments = arguments..'Ib'..tostring(a)..tostring(b)..tostring(c) +end + + +function midFunc () + order = order..table.remove(midOrder) + arguments = arguments..'Ma' + + innerFunc ('IIaa') + + order = order..table.remove(midOrder) + arguments = arguments..'Mb' +end + + +function outerFunc () + order = order..outerOrder[1] + arguments = arguments..'Oa' + + for i = 2,3 do + midFunc () + + arguments = arguments..'Ob' + order = order..outerOrder[i] + end +end + + +order = order..'one' + +co = coroutine.create (outerFunc) +for f = 1, 3 do + local x, y, z = coroutine.resume (co, 123) + order = order..loopOrder[f] + arguments = arguments..'loop'..tostring(x)..tostring(y)..tostring(z) +end + +order = order..'sixteen' + + +assertTrue (order == 'onetwothreefourfivesixseveneightnineteneleventwelvethirteenfourteenfifteensixteen', 'Coroutines should execute in the correct order') +assertTrue (arguments == 'OaMaIaIIaanilnillooptrueIIaanilIb123nilnilMbObMaIaIIaanilnillooptrueIIaanilIb123nilnilMbOblooptruenilnil', 'Coroutines should pass the correct values to and from yields and resumes') diff --git a/tests/starlight/lib-date.lua b/tests/starlight/lib-date.lua new file mode 100644 index 0000000..040263d --- /dev/null +++ b/tests/starlight/lib-date.lua @@ -0,0 +1,1164 @@ + +--[[ +local dates = {{1, 1}, {1, 2}, {28, 2}, {29, 2}, {1, 3}, {31, 12}} +local years = {1999, 2000, 2011} +local symbols = {'%a', '%A', '%b', '%B', '%d', '%H', '%I', '%j', '%m', '%M', '%p', '%S', '%U', '%w', '%W', '%x', '%X', '%y', '%Y', '%Z', '%%', '!%a', '!%A', '!%b', '!%B', '!%d', '!%H', '!%I', '!%j', '!%m', '!%M', '!%p', '!%S', '!%U', '!%w', '!%W', '!%x', '!%X', '!%y', '!%Y', '!%Z'} +local index = 0 + +for _, year in pairs (years) do + for _, date in pairs (dates) do + local time = os.time { + year = year, + month = date[2], + day = date[1], + hour = date[2] + } + + print ('\nlocal time = '..time..'\n') + + for _, symbol in pairs (symbols) do + index = index + 1 + print ("assertTrue (os.date ('"..symbol.."', time) == '"..os.date (symbol, time).."', 'os.date() did not return expected value when passed \""..symbol.."\" ["..index.."]')") + end + + local data = os.date ('*t', time) + for key, value in pairs (data) do + index = index + 1 + + local val = tostring (value) + if type (value) == 'string' then val = "'"..val.."'" end + + print ("assertTrue (os.date ('*t', time)."..key.." == "..val..", 'os.date() did not return expected value when passed \"*t\" ["..index.."]')") + end + + local data = os.date ('!*t', time) + for key, value in pairs (data) do + index = index + 1 + + local val = tostring (value) + if type (value) == 'string' then val = "'"..val.."'" end + + print ("assertTrue (os.date ('!*t', time)."..key.." == "..val..", 'os.date() did not return expected value when passed \"!*t\" ["..index.."]')") + end + + + end +end +--]] + + +local time = 915152400 + +-- assertTrue (os.date ('%a', time) == 'Fri', 'os.date() did not return expected value when passed "%a" [1]') +-- assertTrue (os.date ('%A', time) == 'Friday', 'os.date() did not return expected value when passed "%A" [2]') +-- assertTrue (os.date ('%b', time) == 'Jan', 'os.date() did not return expected value when passed "%b" [3]') +-- assertTrue (os.date ('%B', time) == 'January', 'os.date() did not return expected value when passed "%B" [4]') +-- assertTrue (os.date ('%d', time) == '01', 'os.date() did not return expected value when passed "%d" [5]') +-- assertTrue (os.date ('%H', time) == '01', 'os.date() did not return expected value when passed "%H" [6]') +-- assertTrue (os.date ('%I', time) == '01', 'os.date() did not return expected value when passed "%I" [7]') +-- assertTrue (os.date ('%j', time) == '001', 'os.date() did not return expected value when passed "%j" [8]') +-- assertTrue (os.date ('%m', time) == '01', 'os.date() did not return expected value when passed "%m" [9]') +-- assertTrue (os.date ('%M', time) == '00', 'os.date() did not return expected value when passed "%M" [10]') +-- assertTrue (os.date ('%p', time) == 'AM', 'os.date() did not return expected value when passed "%p" [11]') +-- assertTrue (os.date ('%S', time) == '00', 'os.date() did not return expected value when passed "%S" [12]') +-- assertTrue (os.date ('%U', time) == '00', 'os.date() did not return expected value when passed "%U" [13]') +-- assertTrue (os.date ('%w', time) == '5', 'os.date() did not return expected value when passed "%w" [14]') +-- assertTrue (os.date ('%W', time) == '00', 'os.date() did not return expected value when passed "%W" [15]') +-- assertTrue (os.date ('%x', time) == '01/01/99', 'os.date() did not return expected value when passed "%x" [16]') +-- assertTrue (os.date ('%X', time) == '01:00:00', 'os.date() did not return expected value when passed "%X" [17]') +-- assertTrue (os.date ('%y', time) == '99', 'os.date() did not return expected value when passed "%y" [18]') +-- assertTrue (os.date ('%Y', time) == '1999', 'os.date() did not return expected value when passed "%Y" [19]') +-- assertTrue (os.date ('%Z', time) == 'GMT', 'os.date() did not return expected value when passed "%Z" [20]') +-- assertTrue (os.date ('%%', time) == '%', 'os.date() did not return expected value when passed "%%" [21]') +assertTrue (os.date ('!%a', time) == 'Fri', 'os.date() did not return expected value when passed "!%a" [22]') +assertTrue (os.date ('!%A', time) == 'Friday', 'os.date() did not return expected value when passed "!%A" [23]') +assertTrue (os.date ('!%b', time) == 'Jan', 'os.date() did not return expected value when passed "!%b" [24]') +assertTrue (os.date ('!%B', time) == 'January', 'os.date() did not return expected value when passed "!%B" [25]') +assertTrue (os.date ('!%d', time) == '01', 'os.date() did not return expected value when passed "!%d" [26]') +assertTrue (os.date ('!%H', time) == '01', 'os.date() did not return expected value when passed "!%H" [27]') +assertTrue (os.date ('!%I', time) == '01', 'os.date() did not return expected value when passed "!%I" [28]') +assertTrue (os.date ('!%j', time) == '001', 'os.date() did not return expected value when passed "!%j" [29]') +assertTrue (os.date ('!%m', time) == '01', 'os.date() did not return expected value when passed "!%m" [30]') +assertTrue (os.date ('!%M', time) == '00', 'os.date() did not return expected value when passed "!%M" [31]') +assertTrue (os.date ('!%p', time) == 'AM', 'os.date() did not return expected value when passed "!%p" [32]') +assertTrue (os.date ('!%S', time) == '00', 'os.date() did not return expected value when passed "!%S" [33]') +assertTrue (os.date ('!%U', time) == '00', 'os.date() did not return expected value when passed "!%U" [34]') +assertTrue (os.date ('!%w', time) == '5', 'os.date() did not return expected value when passed "!%w" [35]') +assertTrue (os.date ('!%W', time) == '00', 'os.date() did not return expected value when passed "!%W" [36]') +assertTrue (os.date ('!%x', time) == '01/01/99', 'os.date() did not return expected value when passed "!%x" [37]') +assertTrue (os.date ('!%X', time) == '01:00:00', 'os.date() did not return expected value when passed "!%X" [38]') +assertTrue (os.date ('!%y', time) == '99', 'os.date() did not return expected value when passed "!%y" [39]') +assertTrue (os.date ('!%Y', time) == '1999', 'os.date() did not return expected value when passed "!%Y" [40]') +assertTrue (os.date ('!%Z', time) == 'UTC', 'os.date() did not return expected value when passed "!%Z" [41]') +-- assertTrue (os.date ('*t', time).hour == 1, 'os.date() did not return expected value when passed "*t" [42]') +-- assertTrue (os.date ('*t', time).min == 0, 'os.date() did not return expected value when passed "*t" [43]') +-- assertTrue (os.date ('*t', time).wday == 6, 'os.date() did not return expected value when passed "*t" [44]') +-- assertTrue (os.date ('*t', time).day == 1, 'os.date() did not return expected value when passed "*t" [45]') +-- assertTrue (os.date ('*t', time).month == 1, 'os.date() did not return expected value when passed "*t" [46]') +-- assertTrue (os.date ('*t', time).year == 1999, 'os.date() did not return expected value when passed "*t" [47]') +-- assertTrue (os.date ('*t', time).sec == 0, 'os.date() did not return expected value when passed "*t" [48]') +-- assertTrue (os.date ('*t', time).yday == 1, 'os.date() did not return expected value when passed "*t" [49]') +-- assertTrue (os.date ('*t', time).isdst == false, 'os.date() did not return expected value when passed "*t" [50]') +assertTrue (os.date ('!*t', time).hour == 1, 'os.date() did not return expected value when passed "!*t" [51]') +assertTrue (os.date ('!*t', time).min == 0, 'os.date() did not return expected value when passed "!*t" [52]') +assertTrue (os.date ('!*t', time).wday == 6, 'os.date() did not return expected value when passed "!*t" [53]') +assertTrue (os.date ('!*t', time).day == 1, 'os.date() did not return expected value when passed "!*t" [54]') +assertTrue (os.date ('!*t', time).month == 1, 'os.date() did not return expected value when passed "!*t" [55]') +assertTrue (os.date ('!*t', time).year == 1999, 'os.date() did not return expected value when passed "!*t" [56]') +assertTrue (os.date ('!*t', time).sec == 0, 'os.date() did not return expected value when passed "!*t" [57]') +assertTrue (os.date ('!*t', time).yday == 1, 'os.date() did not return expected value when passed "!*t" [58]') +assertTrue (os.date ('!*t', time).isdst == false, 'os.date() did not return expected value when passed "!*t" [59]') + +local time = 917834400 + +-- assertTrue (os.date ('%a', time) == 'Mon', 'os.date() did not return expected value when passed "%a" [60]') +-- assertTrue (os.date ('%A', time) == 'Monday', 'os.date() did not return expected value when passed "%A" [61]') +-- assertTrue (os.date ('%b', time) == 'Feb', 'os.date() did not return expected value when passed "%b" [62]') +-- assertTrue (os.date ('%B', time) == 'February', 'os.date() did not return expected value when passed "%B" [63]') +-- assertTrue (os.date ('%d', time) == '01', 'os.date() did not return expected value when passed "%d" [64]') +-- assertTrue (os.date ('%H', time) == '02', 'os.date() did not return expected value when passed "%H" [65]') +-- assertTrue (os.date ('%I', time) == '02', 'os.date() did not return expected value when passed "%I" [66]') +-- assertTrue (os.date ('%j', time) == '032', 'os.date() did not return expected value when passed "%j" [67]') +-- assertTrue (os.date ('%m', time) == '02', 'os.date() did not return expected value when passed "%m" [68]') +-- assertTrue (os.date ('%M', time) == '00', 'os.date() did not return expected value when passed "%M" [69]') +-- assertTrue (os.date ('%p', time) == 'AM', 'os.date() did not return expected value when passed "%p" [70]') +-- assertTrue (os.date ('%S', time) == '00', 'os.date() did not return expected value when passed "%S" [71]') +-- assertTrue (os.date ('%U', time) == '05', 'os.date() did not return expected value when passed "%U" [72]') +-- assertTrue (os.date ('%w', time) == '1', 'os.date() did not return expected value when passed "%w" [73]') +-- assertTrue (os.date ('%W', time) == '05', 'os.date() did not return expected value when passed "%W" [74]') +-- assertTrue (os.date ('%x', time) == '02/01/99', 'os.date() did not return expected value when passed "%x" [75]') +-- assertTrue (os.date ('%X', time) == '02:00:00', 'os.date() did not return expected value when passed "%X" [76]') +-- assertTrue (os.date ('%y', time) == '99', 'os.date() did not return expected value when passed "%y" [77]') +-- assertTrue (os.date ('%Y', time) == '1999', 'os.date() did not return expected value when passed "%Y" [78]') +-- assertTrue (os.date ('%Z', time) == 'GMT', 'os.date() did not return expected value when passed "%Z" [79]') +-- assertTrue (os.date ('%%', time) == '%', 'os.date() did not return expected value when passed "%%" [80]') +assertTrue (os.date ('!%a', time) == 'Mon', 'os.date() did not return expected value when passed "!%a" [81]') +assertTrue (os.date ('!%A', time) == 'Monday', 'os.date() did not return expected value when passed "!%A" [82]') +assertTrue (os.date ('!%b', time) == 'Feb', 'os.date() did not return expected value when passed "!%b" [83]') +assertTrue (os.date ('!%B', time) == 'February', 'os.date() did not return expected value when passed "!%B" [84]') +assertTrue (os.date ('!%d', time) == '01', 'os.date() did not return expected value when passed "!%d" [85]') +assertTrue (os.date ('!%H', time) == '02', 'os.date() did not return expected value when passed "!%H" [86]') +assertTrue (os.date ('!%I', time) == '02', 'os.date() did not return expected value when passed "!%I" [87]') +assertTrue (os.date ('!%j', time) == '032', 'os.date() did not return expected value when passed "!%j" [88]') +assertTrue (os.date ('!%m', time) == '02', 'os.date() did not return expected value when passed "!%m" [89]') +assertTrue (os.date ('!%M', time) == '00', 'os.date() did not return expected value when passed "!%M" [90]') +assertTrue (os.date ('!%p', time) == 'AM', 'os.date() did not return expected value when passed "!%p" [91]') +assertTrue (os.date ('!%S', time) == '00', 'os.date() did not return expected value when passed "!%S" [92]') +assertTrue (os.date ('!%U', time) == '05', 'os.date() did not return expected value when passed "!%U" [93]') +assertTrue (os.date ('!%w', time) == '1', 'os.date() did not return expected value when passed "!%w" [94]') +assertTrue (os.date ('!%W', time) == '05', 'os.date() did not return expected value when passed "!%W" [95]') +assertTrue (os.date ('!%x', time) == '02/01/99', 'os.date() did not return expected value when passed "!%x" [96]') +assertTrue (os.date ('!%X', time) == '02:00:00', 'os.date() did not return expected value when passed "!%X" [97]') +assertTrue (os.date ('!%y', time) == '99', 'os.date() did not return expected value when passed "!%y" [98]') +assertTrue (os.date ('!%Y', time) == '1999', 'os.date() did not return expected value when passed "!%Y" [99]') +assertTrue (os.date ('!%Z', time) == 'UTC', 'os.date() did not return expected value when passed "!%Z" [100]') +-- assertTrue (os.date ('*t', time).hour == 2, 'os.date() did not return expected value when passed "*t" [101]') +-- assertTrue (os.date ('*t', time).min == 0, 'os.date() did not return expected value when passed "*t" [102]') +-- assertTrue (os.date ('*t', time).wday == 2, 'os.date() did not return expected value when passed "*t" [103]') +-- assertTrue (os.date ('*t', time).day == 1, 'os.date() did not return expected value when passed "*t" [104]') +-- assertTrue (os.date ('*t', time).month == 2, 'os.date() did not return expected value when passed "*t" [105]') +-- assertTrue (os.date ('*t', time).year == 1999, 'os.date() did not return expected value when passed "*t" [106]') +-- assertTrue (os.date ('*t', time).sec == 0, 'os.date() did not return expected value when passed "*t" [107]') +-- assertTrue (os.date ('*t', time).yday == 32, 'os.date() did not return expected value when passed "*t" [108]') +-- assertTrue (os.date ('*t', time).isdst == false, 'os.date() did not return expected value when passed "*t" [109]') +assertTrue (os.date ('!*t', time).hour == 2, 'os.date() did not return expected value when passed "!*t" [110]') +assertTrue (os.date ('!*t', time).min == 0, 'os.date() did not return expected value when passed "!*t" [111]') +assertTrue (os.date ('!*t', time).wday == 2, 'os.date() did not return expected value when passed "!*t" [112]') +assertTrue (os.date ('!*t', time).day == 1, 'os.date() did not return expected value when passed "!*t" [113]') +assertTrue (os.date ('!*t', time).month == 2, 'os.date() did not return expected value when passed "!*t" [114]') +assertTrue (os.date ('!*t', time).year == 1999, 'os.date() did not return expected value when passed "!*t" [115]') +assertTrue (os.date ('!*t', time).sec == 0, 'os.date() did not return expected value when passed "!*t" [116]') +assertTrue (os.date ('!*t', time).yday == 32, 'os.date() did not return expected value when passed "!*t" [117]') +assertTrue (os.date ('!*t', time).isdst == false, 'os.date() did not return expected value when passed "!*t" [118]') + +local time = 920167200 + +-- assertTrue (os.date ('%a', time) == 'Sun', 'os.date() did not return expected value when passed "%a" [119]') +-- assertTrue (os.date ('%A', time) == 'Sunday', 'os.date() did not return expected value when passed "%A" [120]') +-- assertTrue (os.date ('%b', time) == 'Feb', 'os.date() did not return expected value when passed "%b" [121]') +-- assertTrue (os.date ('%B', time) == 'February', 'os.date() did not return expected value when passed "%B" [122]') +-- assertTrue (os.date ('%d', time) == '28', 'os.date() did not return expected value when passed "%d" [123]') +-- assertTrue (os.date ('%H', time) == '02', 'os.date() did not return expected value when passed "%H" [124]') +-- assertTrue (os.date ('%I', time) == '02', 'os.date() did not return expected value when passed "%I" [125]') +-- assertTrue (os.date ('%j', time) == '059', 'os.date() did not return expected value when passed "%j" [126]') +-- assertTrue (os.date ('%m', time) == '02', 'os.date() did not return expected value when passed "%m" [127]') +-- assertTrue (os.date ('%M', time) == '00', 'os.date() did not return expected value when passed "%M" [128]') +-- assertTrue (os.date ('%p', time) == 'AM', 'os.date() did not return expected value when passed "%p" [129]') +-- assertTrue (os.date ('%S', time) == '00', 'os.date() did not return expected value when passed "%S" [130]') +-- assertTrue (os.date ('%U', time) == '09', 'os.date() did not return expected value when passed "%U" [131]') +-- assertTrue (os.date ('%w', time) == '0', 'os.date() did not return expected value when passed "%w" [132]') +-- assertTrue (os.date ('%W', time) == '08', 'os.date() did not return expected value when passed "%W" [133]') +-- assertTrue (os.date ('%x', time) == '02/28/99', 'os.date() did not return expected value when passed "%x" [134]') +-- assertTrue (os.date ('%X', time) == '02:00:00', 'os.date() did not return expected value when passed "%X" [135]') +-- assertTrue (os.date ('%y', time) == '99', 'os.date() did not return expected value when passed "%y" [136]') +-- assertTrue (os.date ('%Y', time) == '1999', 'os.date() did not return expected value when passed "%Y" [137]') +-- assertTrue (os.date ('%Z', time) == 'GMT', 'os.date() did not return expected value when passed "%Z" [138]') +-- assertTrue (os.date ('%%', time) == '%', 'os.date() did not return expected value when passed "%%" [139]') +assertTrue (os.date ('!%a', time) == 'Sun', 'os.date() did not return expected value when passed "!%a" [140]') +assertTrue (os.date ('!%A', time) == 'Sunday', 'os.date() did not return expected value when passed "!%A" [141]') +assertTrue (os.date ('!%b', time) == 'Feb', 'os.date() did not return expected value when passed "!%b" [142]') +assertTrue (os.date ('!%B', time) == 'February', 'os.date() did not return expected value when passed "!%B" [143]') +assertTrue (os.date ('!%d', time) == '28', 'os.date() did not return expected value when passed "!%d" [144]') +assertTrue (os.date ('!%H', time) == '02', 'os.date() did not return expected value when passed "!%H" [145]') +assertTrue (os.date ('!%I', time) == '02', 'os.date() did not return expected value when passed "!%I" [146]') +assertTrue (os.date ('!%j', time) == '059', 'os.date() did not return expected value when passed "!%j" [147]') +assertTrue (os.date ('!%m', time) == '02', 'os.date() did not return expected value when passed "!%m" [148]') +assertTrue (os.date ('!%M', time) == '00', 'os.date() did not return expected value when passed "!%M" [149]') +assertTrue (os.date ('!%p', time) == 'AM', 'os.date() did not return expected value when passed "!%p" [150]') +assertTrue (os.date ('!%S', time) == '00', 'os.date() did not return expected value when passed "!%S" [151]') +assertTrue (os.date ('!%U', time) == '09', 'os.date() did not return expected value when passed "!%U" [152]') +assertTrue (os.date ('!%w', time) == '0', 'os.date() did not return expected value when passed "!%w" [153]') +assertTrue (os.date ('!%W', time) == '08', 'os.date() did not return expected value when passed "!%W" [154]') +assertTrue (os.date ('!%x', time) == '02/28/99', 'os.date() did not return expected value when passed "!%x" [155]') +assertTrue (os.date ('!%X', time) == '02:00:00', 'os.date() did not return expected value when passed "!%X" [156]') +assertTrue (os.date ('!%y', time) == '99', 'os.date() did not return expected value when passed "!%y" [157]') +assertTrue (os.date ('!%Y', time) == '1999', 'os.date() did not return expected value when passed "!%Y" [158]') +assertTrue (os.date ('!%Z', time) == 'UTC', 'os.date() did not return expected value when passed "!%Z" [159]') +-- assertTrue (os.date ('*t', time).hour == 2, 'os.date() did not return expected value when passed "*t" [160]') +-- assertTrue (os.date ('*t', time).min == 0, 'os.date() did not return expected value when passed "*t" [161]') +-- assertTrue (os.date ('*t', time).wday == 1, 'os.date() did not return expected value when passed "*t" [162]') +-- assertTrue (os.date ('*t', time).day == 28, 'os.date() did not return expected value when passed "*t" [163]') +-- assertTrue (os.date ('*t', time).month == 2, 'os.date() did not return expected value when passed "*t" [164]') +-- assertTrue (os.date ('*t', time).year == 1999, 'os.date() did not return expected value when passed "*t" [165]') +-- assertTrue (os.date ('*t', time).sec == 0, 'os.date() did not return expected value when passed "*t" [166]') +-- assertTrue (os.date ('*t', time).yday == 59, 'os.date() did not return expected value when passed "*t" [167]') +-- assertTrue (os.date ('*t', time).isdst == false, 'os.date() did not return expected value when passed "*t" [168]') +assertTrue (os.date ('!*t', time).hour == 2, 'os.date() did not return expected value when passed "!*t" [169]') +assertTrue (os.date ('!*t', time).min == 0, 'os.date() did not return expected value when passed "!*t" [170]') +assertTrue (os.date ('!*t', time).wday == 1, 'os.date() did not return expected value when passed "!*t" [171]') +assertTrue (os.date ('!*t', time).day == 28, 'os.date() did not return expected value when passed "!*t" [172]') +assertTrue (os.date ('!*t', time).month == 2, 'os.date() did not return expected value when passed "!*t" [173]') +assertTrue (os.date ('!*t', time).year == 1999, 'os.date() did not return expected value when passed "!*t" [174]') +assertTrue (os.date ('!*t', time).sec == 0, 'os.date() did not return expected value when passed "!*t" [175]') +assertTrue (os.date ('!*t', time).yday == 59, 'os.date() did not return expected value when passed "!*t" [176]') +assertTrue (os.date ('!*t', time).isdst == false, 'os.date() did not return expected value when passed "!*t" [177]') + +local time = 920253600 + +-- assertTrue (os.date ('%a', time) == 'Mon', 'os.date() did not return expected value when passed "%a" [178]') +-- assertTrue (os.date ('%A', time) == 'Monday', 'os.date() did not return expected value when passed "%A" [179]') +-- assertTrue (os.date ('%b', time) == 'Mar', 'os.date() did not return expected value when passed "%b" [180]') +-- assertTrue (os.date ('%B', time) == 'March', 'os.date() did not return expected value when passed "%B" [181]') +-- assertTrue (os.date ('%d', time) == '01', 'os.date() did not return expected value when passed "%d" [182]') +-- assertTrue (os.date ('%H', time) == '02', 'os.date() did not return expected value when passed "%H" [183]') +-- assertTrue (os.date ('%I', time) == '02', 'os.date() did not return expected value when passed "%I" [184]') +-- assertTrue (os.date ('%j', time) == '060', 'os.date() did not return expected value when passed "%j" [185]') +-- assertTrue (os.date ('%m', time) == '03', 'os.date() did not return expected value when passed "%m" [186]') +-- assertTrue (os.date ('%M', time) == '00', 'os.date() did not return expected value when passed "%M" [187]') +-- assertTrue (os.date ('%p', time) == 'AM', 'os.date() did not return expected value when passed "%p" [188]') +-- assertTrue (os.date ('%S', time) == '00', 'os.date() did not return expected value when passed "%S" [189]') +-- assertTrue (os.date ('%U', time) == '09', 'os.date() did not return expected value when passed "%U" [190]') +-- assertTrue (os.date ('%w', time) == '1', 'os.date() did not return expected value when passed "%w" [191]') +-- assertTrue (os.date ('%W', time) == '09', 'os.date() did not return expected value when passed "%W" [192]') +-- assertTrue (os.date ('%x', time) == '03/01/99', 'os.date() did not return expected value when passed "%x" [193]') +-- assertTrue (os.date ('%X', time) == '02:00:00', 'os.date() did not return expected value when passed "%X" [194]') +-- assertTrue (os.date ('%y', time) == '99', 'os.date() did not return expected value when passed "%y" [195]') +-- assertTrue (os.date ('%Y', time) == '1999', 'os.date() did not return expected value when passed "%Y" [196]') +-- assertTrue (os.date ('%Z', time) == 'GMT', 'os.date() did not return expected value when passed "%Z" [197]') +-- assertTrue (os.date ('%%', time) == '%', 'os.date() did not return expected value when passed "%%" [198]') +assertTrue (os.date ('!%a', time) == 'Mon', 'os.date() did not return expected value when passed "!%a" [199]') +assertTrue (os.date ('!%A', time) == 'Monday', 'os.date() did not return expected value when passed "!%A" [200]') +assertTrue (os.date ('!%b', time) == 'Mar', 'os.date() did not return expected value when passed "!%b" [201]') +assertTrue (os.date ('!%B', time) == 'March', 'os.date() did not return expected value when passed "!%B" [202]') +assertTrue (os.date ('!%d', time) == '01', 'os.date() did not return expected value when passed "!%d" [203]') +assertTrue (os.date ('!%H', time) == '02', 'os.date() did not return expected value when passed "!%H" [204]') +assertTrue (os.date ('!%I', time) == '02', 'os.date() did not return expected value when passed "!%I" [205]') +assertTrue (os.date ('!%j', time) == '060', 'os.date() did not return expected value when passed "!%j" [206]') +assertTrue (os.date ('!%m', time) == '03', 'os.date() did not return expected value when passed "!%m" [207]') +assertTrue (os.date ('!%M', time) == '00', 'os.date() did not return expected value when passed "!%M" [208]') +assertTrue (os.date ('!%p', time) == 'AM', 'os.date() did not return expected value when passed "!%p" [209]') +assertTrue (os.date ('!%S', time) == '00', 'os.date() did not return expected value when passed "!%S" [210]') +assertTrue (os.date ('!%U', time) == '09', 'os.date() did not return expected value when passed "!%U" [211]') +assertTrue (os.date ('!%w', time) == '1', 'os.date() did not return expected value when passed "!%w" [212]') +assertTrue (os.date ('!%W', time) == '09', 'os.date() did not return expected value when passed "!%W" [213]') +assertTrue (os.date ('!%x', time) == '03/01/99', 'os.date() did not return expected value when passed "!%x" [214]') +assertTrue (os.date ('!%X', time) == '02:00:00', 'os.date() did not return expected value when passed "!%X" [215]') +assertTrue (os.date ('!%y', time) == '99', 'os.date() did not return expected value when passed "!%y" [216]') +assertTrue (os.date ('!%Y', time) == '1999', 'os.date() did not return expected value when passed "!%Y" [217]') +assertTrue (os.date ('!%Z', time) == 'UTC', 'os.date() did not return expected value when passed "!%Z" [218]') +-- assertTrue (os.date ('*t', time).hour == 2, 'os.date() did not return expected value when passed "*t" [219]') +-- assertTrue (os.date ('*t', time).min == 0, 'os.date() did not return expected value when passed "*t" [220]') +-- assertTrue (os.date ('*t', time).wday == 2, 'os.date() did not return expected value when passed "*t" [221]') +-- assertTrue (os.date ('*t', time).day == 1, 'os.date() did not return expected value when passed "*t" [222]') +-- assertTrue (os.date ('*t', time).month == 3, 'os.date() did not return expected value when passed "*t" [223]') +-- assertTrue (os.date ('*t', time).year == 1999, 'os.date() did not return expected value when passed "*t" [224]') +-- assertTrue (os.date ('*t', time).sec == 0, 'os.date() did not return expected value when passed "*t" [225]') +-- assertTrue (os.date ('*t', time).yday == 60, 'os.date() did not return expected value when passed "*t" [226]') +-- assertTrue (os.date ('*t', time).isdst == false, 'os.date() did not return expected value when passed "*t" [227]') +assertTrue (os.date ('!*t', time).hour == 2, 'os.date() did not return expected value when passed "!*t" [228]') +assertTrue (os.date ('!*t', time).min == 0, 'os.date() did not return expected value when passed "!*t" [229]') +assertTrue (os.date ('!*t', time).wday == 2, 'os.date() did not return expected value when passed "!*t" [230]') +assertTrue (os.date ('!*t', time).day == 1, 'os.date() did not return expected value when passed "!*t" [231]') +assertTrue (os.date ('!*t', time).month == 3, 'os.date() did not return expected value when passed "!*t" [232]') +assertTrue (os.date ('!*t', time).year == 1999, 'os.date() did not return expected value when passed "!*t" [233]') +assertTrue (os.date ('!*t', time).sec == 0, 'os.date() did not return expected value when passed "!*t" [234]') +assertTrue (os.date ('!*t', time).yday == 60, 'os.date() did not return expected value when passed "!*t" [235]') +assertTrue (os.date ('!*t', time).isdst == false, 'os.date() did not return expected value when passed "!*t" [236]') + +local time = 920257200 + +-- assertTrue (os.date ('%a', time) == 'Mon', 'os.date() did not return expected value when passed "%a" [237]') +-- assertTrue (os.date ('%A', time) == 'Monday', 'os.date() did not return expected value when passed "%A" [238]') +-- assertTrue (os.date ('%b', time) == 'Mar', 'os.date() did not return expected value when passed "%b" [239]') +-- assertTrue (os.date ('%B', time) == 'March', 'os.date() did not return expected value when passed "%B" [240]') +-- assertTrue (os.date ('%d', time) == '01', 'os.date() did not return expected value when passed "%d" [241]') +-- assertTrue (os.date ('%H', time) == '03', 'os.date() did not return expected value when passed "%H" [242]') +-- assertTrue (os.date ('%I', time) == '03', 'os.date() did not return expected value when passed "%I" [243]') +-- assertTrue (os.date ('%j', time) == '060', 'os.date() did not return expected value when passed "%j" [244]') +-- assertTrue (os.date ('%m', time) == '03', 'os.date() did not return expected value when passed "%m" [245]') +-- assertTrue (os.date ('%M', time) == '00', 'os.date() did not return expected value when passed "%M" [246]') +-- assertTrue (os.date ('%p', time) == 'AM', 'os.date() did not return expected value when passed "%p" [247]') +-- assertTrue (os.date ('%S', time) == '00', 'os.date() did not return expected value when passed "%S" [248]') +-- assertTrue (os.date ('%U', time) == '09', 'os.date() did not return expected value when passed "%U" [249]') +-- assertTrue (os.date ('%w', time) == '1', 'os.date() did not return expected value when passed "%w" [250]') +-- assertTrue (os.date ('%W', time) == '09', 'os.date() did not return expected value when passed "%W" [251]') +-- assertTrue (os.date ('%x', time) == '03/01/99', 'os.date() did not return expected value when passed "%x" [252]') +-- assertTrue (os.date ('%X', time) == '03:00:00', 'os.date() did not return expected value when passed "%X" [253]') +-- assertTrue (os.date ('%y', time) == '99', 'os.date() did not return expected value when passed "%y" [254]') +-- assertTrue (os.date ('%Y', time) == '1999', 'os.date() did not return expected value when passed "%Y" [255]') +-- assertTrue (os.date ('%Z', time) == 'GMT', 'os.date() did not return expected value when passed "%Z" [256]') +-- assertTrue (os.date ('%%', time) == '%', 'os.date() did not return expected value when passed "%%" [257]') +assertTrue (os.date ('!%a', time) == 'Mon', 'os.date() did not return expected value when passed "!%a" [258]') +assertTrue (os.date ('!%A', time) == 'Monday', 'os.date() did not return expected value when passed "!%A" [259]') +assertTrue (os.date ('!%b', time) == 'Mar', 'os.date() did not return expected value when passed "!%b" [260]') +assertTrue (os.date ('!%B', time) == 'March', 'os.date() did not return expected value when passed "!%B" [261]') +assertTrue (os.date ('!%d', time) == '01', 'os.date() did not return expected value when passed "!%d" [262]') +assertTrue (os.date ('!%H', time) == '03', 'os.date() did not return expected value when passed "!%H" [263]') +assertTrue (os.date ('!%I', time) == '03', 'os.date() did not return expected value when passed "!%I" [264]') +assertTrue (os.date ('!%j', time) == '060', 'os.date() did not return expected value when passed "!%j" [265]') +assertTrue (os.date ('!%m', time) == '03', 'os.date() did not return expected value when passed "!%m" [266]') +assertTrue (os.date ('!%M', time) == '00', 'os.date() did not return expected value when passed "!%M" [267]') +assertTrue (os.date ('!%p', time) == 'AM', 'os.date() did not return expected value when passed "!%p" [268]') +assertTrue (os.date ('!%S', time) == '00', 'os.date() did not return expected value when passed "!%S" [269]') +assertTrue (os.date ('!%U', time) == '09', 'os.date() did not return expected value when passed "!%U" [270]') +assertTrue (os.date ('!%w', time) == '1', 'os.date() did not return expected value when passed "!%w" [271]') +assertTrue (os.date ('!%W', time) == '09', 'os.date() did not return expected value when passed "!%W" [272]') +assertTrue (os.date ('!%x', time) == '03/01/99', 'os.date() did not return expected value when passed "!%x" [273]') +assertTrue (os.date ('!%X', time) == '03:00:00', 'os.date() did not return expected value when passed "!%X" [274]') +assertTrue (os.date ('!%y', time) == '99', 'os.date() did not return expected value when passed "!%y" [275]') +assertTrue (os.date ('!%Y', time) == '1999', 'os.date() did not return expected value when passed "!%Y" [276]') +assertTrue (os.date ('!%Z', time) == 'UTC', 'os.date() did not return expected value when passed "!%Z" [277]') +-- assertTrue (os.date ('*t', time).hour == 3, 'os.date() did not return expected value when passed "*t" [278]') +-- assertTrue (os.date ('*t', time).min == 0, 'os.date() did not return expected value when passed "*t" [279]') +-- assertTrue (os.date ('*t', time).wday == 2, 'os.date() did not return expected value when passed "*t" [280]') +-- assertTrue (os.date ('*t', time).day == 1, 'os.date() did not return expected value when passed "*t" [281]') +-- assertTrue (os.date ('*t', time).month == 3, 'os.date() did not return expected value when passed "*t" [282]') +-- assertTrue (os.date ('*t', time).year == 1999, 'os.date() did not return expected value when passed "*t" [283]') +-- assertTrue (os.date ('*t', time).sec == 0, 'os.date() did not return expected value when passed "*t" [284]') +-- assertTrue (os.date ('*t', time).yday == 60, 'os.date() did not return expected value when passed "*t" [285]') +-- assertTrue (os.date ('*t', time).isdst == false, 'os.date() did not return expected value when passed "*t" [286]') +assertTrue (os.date ('!*t', time).hour == 3, 'os.date() did not return expected value when passed "!*t" [287]') +assertTrue (os.date ('!*t', time).min == 0, 'os.date() did not return expected value when passed "!*t" [288]') +assertTrue (os.date ('!*t', time).wday == 2, 'os.date() did not return expected value when passed "!*t" [289]') +assertTrue (os.date ('!*t', time).day == 1, 'os.date() did not return expected value when passed "!*t" [290]') +assertTrue (os.date ('!*t', time).month == 3, 'os.date() did not return expected value when passed "!*t" [291]') +assertTrue (os.date ('!*t', time).year == 1999, 'os.date() did not return expected value when passed "!*t" [292]') +assertTrue (os.date ('!*t', time).sec == 0, 'os.date() did not return expected value when passed "!*t" [293]') +assertTrue (os.date ('!*t', time).yday == 60, 'os.date() did not return expected value when passed "!*t" [294]') +assertTrue (os.date ('!*t', time).isdst == false, 'os.date() did not return expected value when passed "!*t" [295]') + +local time = 946641600 + +-- assertTrue (os.date ('%a', time) == 'Fri', 'os.date() did not return expected value when passed "%a" [296]') +-- assertTrue (os.date ('%A', time) == 'Friday', 'os.date() did not return expected value when passed "%A" [297]') +-- assertTrue (os.date ('%b', time) == 'Dec', 'os.date() did not return expected value when passed "%b" [298]') +-- assertTrue (os.date ('%B', time) == 'December', 'os.date() did not return expected value when passed "%B" [299]') +-- assertTrue (os.date ('%d', time) == '31', 'os.date() did not return expected value when passed "%d" [300]') +-- assertTrue (os.date ('%H', time) == '12', 'os.date() did not return expected value when passed "%H" [301]') +-- assertTrue (os.date ('%I', time) == '12', 'os.date() did not return expected value when passed "%I" [302]') +-- assertTrue (os.date ('%j', time) == '365', 'os.date() did not return expected value when passed "%j" [303]') +-- assertTrue (os.date ('%m', time) == '12', 'os.date() did not return expected value when passed "%m" [304]') +-- assertTrue (os.date ('%M', time) == '00', 'os.date() did not return expected value when passed "%M" [305]') +-- assertTrue (os.date ('%p', time) == 'PM', 'os.date() did not return expected value when passed "%p" [306]') +-- assertTrue (os.date ('%S', time) == '00', 'os.date() did not return expected value when passed "%S" [307]') +-- assertTrue (os.date ('%U', time) == '52', 'os.date() did not return expected value when passed "%U" [308]') +-- assertTrue (os.date ('%w', time) == '5', 'os.date() did not return expected value when passed "%w" [309]') +-- assertTrue (os.date ('%W', time) == '52', 'os.date() did not return expected value when passed "%W" [310]') +-- assertTrue (os.date ('%x', time) == '12/31/99', 'os.date() did not return expected value when passed "%x" [311]') +-- assertTrue (os.date ('%X', time) == '12:00:00', 'os.date() did not return expected value when passed "%X" [312]') +-- assertTrue (os.date ('%y', time) == '99', 'os.date() did not return expected value when passed "%y" [313]') +-- assertTrue (os.date ('%Y', time) == '1999', 'os.date() did not return expected value when passed "%Y" [314]') +-- assertTrue (os.date ('%Z', time) == 'GMT', 'os.date() did not return expected value when passed "%Z" [315]') +-- assertTrue (os.date ('%%', time) == '%', 'os.date() did not return expected value when passed "%%" [316]') +assertTrue (os.date ('!%a', time) == 'Fri', 'os.date() did not return expected value when passed "!%a" [317]') +assertTrue (os.date ('!%A', time) == 'Friday', 'os.date() did not return expected value when passed "!%A" [318]') +assertTrue (os.date ('!%b', time) == 'Dec', 'os.date() did not return expected value when passed "!%b" [319]') +assertTrue (os.date ('!%B', time) == 'December', 'os.date() did not return expected value when passed "!%B" [320]') +assertTrue (os.date ('!%d', time) == '31', 'os.date() did not return expected value when passed "!%d" [321]') +assertTrue (os.date ('!%H', time) == '12', 'os.date() did not return expected value when passed "!%H" [322]') +assertTrue (os.date ('!%I', time) == '12', 'os.date() did not return expected value when passed "!%I" [323]') +assertTrue (os.date ('!%j', time) == '365', 'os.date() did not return expected value when passed "!%j" [324]') +assertTrue (os.date ('!%m', time) == '12', 'os.date() did not return expected value when passed "!%m" [325]') +assertTrue (os.date ('!%M', time) == '00', 'os.date() did not return expected value when passed "!%M" [326]') +assertTrue (os.date ('!%p', time) == 'PM', 'os.date() did not return expected value when passed "!%p" [327]') +assertTrue (os.date ('!%S', time) == '00', 'os.date() did not return expected value when passed "!%S" [328]') +assertTrue (os.date ('!%U', time) == '52', 'os.date() did not return expected value when passed "!%U" [329]') +assertTrue (os.date ('!%w', time) == '5', 'os.date() did not return expected value when passed "!%w" [330]') +assertTrue (os.date ('!%W', time) == '52', 'os.date() did not return expected value when passed "!%W" [331]') +assertTrue (os.date ('!%x', time) == '12/31/99', 'os.date() did not return expected value when passed "!%x" [332]') +assertTrue (os.date ('!%X', time) == '12:00:00', 'os.date() did not return expected value when passed "!%X" [333]') +assertTrue (os.date ('!%y', time) == '99', 'os.date() did not return expected value when passed "!%y" [334]') +assertTrue (os.date ('!%Y', time) == '1999', 'os.date() did not return expected value when passed "!%Y" [335]') +assertTrue (os.date ('!%Z', time) == 'UTC', 'os.date() did not return expected value when passed "!%Z" [336]') +-- assertTrue (os.date ('*t', time).hour == 12, 'os.date() did not return expected value when passed "*t" [337]') +-- assertTrue (os.date ('*t', time).min == 0, 'os.date() did not return expected value when passed "*t" [338]') +-- assertTrue (os.date ('*t', time).wday == 6, 'os.date() did not return expected value when passed "*t" [339]') +-- assertTrue (os.date ('*t', time).day == 31, 'os.date() did not return expected value when passed "*t" [340]') +-- assertTrue (os.date ('*t', time).month == 12, 'os.date() did not return expected value when passed "*t" [341]') +-- assertTrue (os.date ('*t', time).year == 1999, 'os.date() did not return expected value when passed "*t" [342]') +-- assertTrue (os.date ('*t', time).sec == 0, 'os.date() did not return expected value when passed "*t" [343]') +-- assertTrue (os.date ('*t', time).yday == 365, 'os.date() did not return expected value when passed "*t" [344]') +-- assertTrue (os.date ('*t', time).isdst == false, 'os.date() did not return expected value when passed "*t" [345]') +assertTrue (os.date ('!*t', time).hour == 12, 'os.date() did not return expected value when passed "!*t" [346]') +assertTrue (os.date ('!*t', time).min == 0, 'os.date() did not return expected value when passed "!*t" [347]') +assertTrue (os.date ('!*t', time).wday == 6, 'os.date() did not return expected value when passed "!*t" [348]') +assertTrue (os.date ('!*t', time).day == 31, 'os.date() did not return expected value when passed "!*t" [349]') +assertTrue (os.date ('!*t', time).month == 12, 'os.date() did not return expected value when passed "!*t" [350]') +assertTrue (os.date ('!*t', time).year == 1999, 'os.date() did not return expected value when passed "!*t" [351]') +assertTrue (os.date ('!*t', time).sec == 0, 'os.date() did not return expected value when passed "!*t" [352]') +assertTrue (os.date ('!*t', time).yday == 365, 'os.date() did not return expected value when passed "!*t" [353]') +assertTrue (os.date ('!*t', time).isdst == false, 'os.date() did not return expected value when passed "!*t" [354]') + +local time = 946688400 + +-- assertTrue (os.date ('%a', time) == 'Sat', 'os.date() did not return expected value when passed "%a" [355]') +-- assertTrue (os.date ('%A', time) == 'Saturday', 'os.date() did not return expected value when passed "%A" [356]') +-- assertTrue (os.date ('%b', time) == 'Jan', 'os.date() did not return expected value when passed "%b" [357]') +-- assertTrue (os.date ('%B', time) == 'January', 'os.date() did not return expected value when passed "%B" [358]') +-- assertTrue (os.date ('%d', time) == '01', 'os.date() did not return expected value when passed "%d" [359]') +-- assertTrue (os.date ('%H', time) == '01', 'os.date() did not return expected value when passed "%H" [360]') +-- assertTrue (os.date ('%I', time) == '01', 'os.date() did not return expected value when passed "%I" [361]') +-- assertTrue (os.date ('%j', time) == '001', 'os.date() did not return expected value when passed "%j" [362]') +-- assertTrue (os.date ('%m', time) == '01', 'os.date() did not return expected value when passed "%m" [363]') +-- assertTrue (os.date ('%M', time) == '00', 'os.date() did not return expected value when passed "%M" [364]') +-- assertTrue (os.date ('%p', time) == 'AM', 'os.date() did not return expected value when passed "%p" [365]') +-- assertTrue (os.date ('%S', time) == '00', 'os.date() did not return expected value when passed "%S" [366]') +-- assertTrue (os.date ('%U', time) == '00', 'os.date() did not return expected value when passed "%U" [367]') +-- assertTrue (os.date ('%w', time) == '6', 'os.date() did not return expected value when passed "%w" [368]') +-- assertTrue (os.date ('%W', time) == '00', 'os.date() did not return expected value when passed "%W" [369]') +-- assertTrue (os.date ('%x', time) == '01/01/00', 'os.date() did not return expected value when passed "%x" [370]') +-- assertTrue (os.date ('%X', time) == '01:00:00', 'os.date() did not return expected value when passed "%X" [371]') +-- assertTrue (os.date ('%y', time) == '00', 'os.date() did not return expected value when passed "%y" [372]') +-- assertTrue (os.date ('%Y', time) == '2000', 'os.date() did not return expected value when passed "%Y" [373]') +-- assertTrue (os.date ('%Z', time) == 'GMT', 'os.date() did not return expected value when passed "%Z" [374]') +-- assertTrue (os.date ('%%', time) == '%', 'os.date() did not return expected value when passed "%%" [375]') +assertTrue (os.date ('!%a', time) == 'Sat', 'os.date() did not return expected value when passed "!%a" [376]') +assertTrue (os.date ('!%A', time) == 'Saturday', 'os.date() did not return expected value when passed "!%A" [377]') +assertTrue (os.date ('!%b', time) == 'Jan', 'os.date() did not return expected value when passed "!%b" [378]') +assertTrue (os.date ('!%B', time) == 'January', 'os.date() did not return expected value when passed "!%B" [379]') +assertTrue (os.date ('!%d', time) == '01', 'os.date() did not return expected value when passed "!%d" [380]') +assertTrue (os.date ('!%H', time) == '01', 'os.date() did not return expected value when passed "!%H" [381]') +assertTrue (os.date ('!%I', time) == '01', 'os.date() did not return expected value when passed "!%I" [382]') +assertTrue (os.date ('!%j', time) == '001', 'os.date() did not return expected value when passed "!%j" [383]') +assertTrue (os.date ('!%m', time) == '01', 'os.date() did not return expected value when passed "!%m" [384]') +assertTrue (os.date ('!%M', time) == '00', 'os.date() did not return expected value when passed "!%M" [385]') +assertTrue (os.date ('!%p', time) == 'AM', 'os.date() did not return expected value when passed "!%p" [386]') +assertTrue (os.date ('!%S', time) == '00', 'os.date() did not return expected value when passed "!%S" [387]') +assertTrue (os.date ('!%U', time) == '00', 'os.date() did not return expected value when passed "!%U" [388]') +assertTrue (os.date ('!%w', time) == '6', 'os.date() did not return expected value when passed "!%w" [389]') +assertTrue (os.date ('!%W', time) == '00', 'os.date() did not return expected value when passed "!%W" [390]') +assertTrue (os.date ('!%x', time) == '01/01/00', 'os.date() did not return expected value when passed "!%x" [391]') +assertTrue (os.date ('!%X', time) == '01:00:00', 'os.date() did not return expected value when passed "!%X" [392]') +assertTrue (os.date ('!%y', time) == '00', 'os.date() did not return expected value when passed "!%y" [393]') +assertTrue (os.date ('!%Y', time) == '2000', 'os.date() did not return expected value when passed "!%Y" [394]') +assertTrue (os.date ('!%Z', time) == 'UTC', 'os.date() did not return expected value when passed "!%Z" [395]') +-- assertTrue (os.date ('*t', time).hour == 1, 'os.date() did not return expected value when passed "*t" [396]') +-- assertTrue (os.date ('*t', time).min == 0, 'os.date() did not return expected value when passed "*t" [397]') +-- assertTrue (os.date ('*t', time).wday == 7, 'os.date() did not return expected value when passed "*t" [398]') +-- assertTrue (os.date ('*t', time).day == 1, 'os.date() did not return expected value when passed "*t" [399]') +-- assertTrue (os.date ('*t', time).month == 1, 'os.date() did not return expected value when passed "*t" [400]') +-- assertTrue (os.date ('*t', time).year == 2000, 'os.date() did not return expected value when passed "*t" [401]') +-- assertTrue (os.date ('*t', time).sec == 0, 'os.date() did not return expected value when passed "*t" [402]') +-- assertTrue (os.date ('*t', time).yday == 1, 'os.date() did not return expected value when passed "*t" [403]') +-- assertTrue (os.date ('*t', time).isdst == false, 'os.date() did not return expected value when passed "*t" [404]') +assertTrue (os.date ('!*t', time).hour == 1, 'os.date() did not return expected value when passed "!*t" [405]') +assertTrue (os.date ('!*t', time).min == 0, 'os.date() did not return expected value when passed "!*t" [406]') +assertTrue (os.date ('!*t', time).wday == 7, 'os.date() did not return expected value when passed "!*t" [407]') +assertTrue (os.date ('!*t', time).day == 1, 'os.date() did not return expected value when passed "!*t" [408]') +assertTrue (os.date ('!*t', time).month == 1, 'os.date() did not return expected value when passed "!*t" [409]') +assertTrue (os.date ('!*t', time).year == 2000, 'os.date() did not return expected value when passed "!*t" [410]') +assertTrue (os.date ('!*t', time).sec == 0, 'os.date() did not return expected value when passed "!*t" [411]') +assertTrue (os.date ('!*t', time).yday == 1, 'os.date() did not return expected value when passed "!*t" [412]') +assertTrue (os.date ('!*t', time).isdst == false, 'os.date() did not return expected value when passed "!*t" [413]') + +local time = 949370400 + +-- assertTrue (os.date ('%a', time) == 'Tue', 'os.date() did not return expected value when passed "%a" [414]') +-- assertTrue (os.date ('%A', time) == 'Tuesday', 'os.date() did not return expected value when passed "%A" [415]') +-- assertTrue (os.date ('%b', time) == 'Feb', 'os.date() did not return expected value when passed "%b" [416]') +-- assertTrue (os.date ('%B', time) == 'February', 'os.date() did not return expected value when passed "%B" [417]') +-- assertTrue (os.date ('%d', time) == '01', 'os.date() did not return expected value when passed "%d" [418]') +-- assertTrue (os.date ('%H', time) == '02', 'os.date() did not return expected value when passed "%H" [419]') +-- assertTrue (os.date ('%I', time) == '02', 'os.date() did not return expected value when passed "%I" [420]') +-- assertTrue (os.date ('%j', time) == '032', 'os.date() did not return expected value when passed "%j" [421]') +-- assertTrue (os.date ('%m', time) == '02', 'os.date() did not return expected value when passed "%m" [422]') +-- assertTrue (os.date ('%M', time) == '00', 'os.date() did not return expected value when passed "%M" [423]') +-- assertTrue (os.date ('%p', time) == 'AM', 'os.date() did not return expected value when passed "%p" [424]') +-- assertTrue (os.date ('%S', time) == '00', 'os.date() did not return expected value when passed "%S" [425]') +-- assertTrue (os.date ('%U', time) == '05', 'os.date() did not return expected value when passed "%U" [426]') +-- assertTrue (os.date ('%w', time) == '2', 'os.date() did not return expected value when passed "%w" [427]') +-- assertTrue (os.date ('%W', time) == '05', 'os.date() did not return expected value when passed "%W" [428]') +-- assertTrue (os.date ('%x', time) == '02/01/00', 'os.date() did not return expected value when passed "%x" [429]') +-- assertTrue (os.date ('%X', time) == '02:00:00', 'os.date() did not return expected value when passed "%X" [430]') +-- assertTrue (os.date ('%y', time) == '00', 'os.date() did not return expected value when passed "%y" [431]') +-- assertTrue (os.date ('%Y', time) == '2000', 'os.date() did not return expected value when passed "%Y" [432]') +-- assertTrue (os.date ('%Z', time) == 'GMT', 'os.date() did not return expected value when passed "%Z" [433]') +-- assertTrue (os.date ('%%', time) == '%', 'os.date() did not return expected value when passed "%%" [434]') +assertTrue (os.date ('!%a', time) == 'Tue', 'os.date() did not return expected value when passed "!%a" [435]') +assertTrue (os.date ('!%A', time) == 'Tuesday', 'os.date() did not return expected value when passed "!%A" [436]') +assertTrue (os.date ('!%b', time) == 'Feb', 'os.date() did not return expected value when passed "!%b" [437]') +assertTrue (os.date ('!%B', time) == 'February', 'os.date() did not return expected value when passed "!%B" [438]') +assertTrue (os.date ('!%d', time) == '01', 'os.date() did not return expected value when passed "!%d" [439]') +assertTrue (os.date ('!%H', time) == '02', 'os.date() did not return expected value when passed "!%H" [440]') +assertTrue (os.date ('!%I', time) == '02', 'os.date() did not return expected value when passed "!%I" [441]') +assertTrue (os.date ('!%j', time) == '032', 'os.date() did not return expected value when passed "!%j" [442]') +assertTrue (os.date ('!%m', time) == '02', 'os.date() did not return expected value when passed "!%m" [443]') +assertTrue (os.date ('!%M', time) == '00', 'os.date() did not return expected value when passed "!%M" [444]') +assertTrue (os.date ('!%p', time) == 'AM', 'os.date() did not return expected value when passed "!%p" [445]') +assertTrue (os.date ('!%S', time) == '00', 'os.date() did not return expected value when passed "!%S" [446]') +assertTrue (os.date ('!%U', time) == '05', 'os.date() did not return expected value when passed "!%U" [447]') +assertTrue (os.date ('!%w', time) == '2', 'os.date() did not return expected value when passed "!%w" [448]') +assertTrue (os.date ('!%W', time) == '05', 'os.date() did not return expected value when passed "!%W" [449]') +assertTrue (os.date ('!%x', time) == '02/01/00', 'os.date() did not return expected value when passed "!%x" [450]') +assertTrue (os.date ('!%X', time) == '02:00:00', 'os.date() did not return expected value when passed "!%X" [451]') +assertTrue (os.date ('!%y', time) == '00', 'os.date() did not return expected value when passed "!%y" [452]') +assertTrue (os.date ('!%Y', time) == '2000', 'os.date() did not return expected value when passed "!%Y" [453]') +assertTrue (os.date ('!%Z', time) == 'UTC', 'os.date() did not return expected value when passed "!%Z" [454]') +-- assertTrue (os.date ('*t', time).hour == 2, 'os.date() did not return expected value when passed "*t" [455]') +-- assertTrue (os.date ('*t', time).min == 0, 'os.date() did not return expected value when passed "*t" [456]') +-- assertTrue (os.date ('*t', time).wday == 3, 'os.date() did not return expected value when passed "*t" [457]') +-- assertTrue (os.date ('*t', time).day == 1, 'os.date() did not return expected value when passed "*t" [458]') +-- assertTrue (os.date ('*t', time).month == 2, 'os.date() did not return expected value when passed "*t" [459]') +-- assertTrue (os.date ('*t', time).year == 2000, 'os.date() did not return expected value when passed "*t" [460]') +-- assertTrue (os.date ('*t', time).sec == 0, 'os.date() did not return expected value when passed "*t" [461]') +-- assertTrue (os.date ('*t', time).yday == 32, 'os.date() did not return expected value when passed "*t" [462]') +-- assertTrue (os.date ('*t', time).isdst == false, 'os.date() did not return expected value when passed "*t" [463]') +assertTrue (os.date ('!*t', time).hour == 2, 'os.date() did not return expected value when passed "!*t" [464]') +assertTrue (os.date ('!*t', time).min == 0, 'os.date() did not return expected value when passed "!*t" [465]') +assertTrue (os.date ('!*t', time).wday == 3, 'os.date() did not return expected value when passed "!*t" [466]') +assertTrue (os.date ('!*t', time).day == 1, 'os.date() did not return expected value when passed "!*t" [467]') +assertTrue (os.date ('!*t', time).month == 2, 'os.date() did not return expected value when passed "!*t" [468]') +assertTrue (os.date ('!*t', time).year == 2000, 'os.date() did not return expected value when passed "!*t" [469]') +assertTrue (os.date ('!*t', time).sec == 0, 'os.date() did not return expected value when passed "!*t" [470]') +assertTrue (os.date ('!*t', time).yday == 32, 'os.date() did not return expected value when passed "!*t" [471]') +assertTrue (os.date ('!*t', time).isdst == false, 'os.date() did not return expected value when passed "!*t" [472]') + +local time = 951703200 + +-- assertTrue (os.date ('%a', time) == 'Mon', 'os.date() did not return expected value when passed "%a" [473]') +-- assertTrue (os.date ('%A', time) == 'Monday', 'os.date() did not return expected value when passed "%A" [474]') +-- assertTrue (os.date ('%b', time) == 'Feb', 'os.date() did not return expected value when passed "%b" [475]') +-- assertTrue (os.date ('%B', time) == 'February', 'os.date() did not return expected value when passed "%B" [476]') +-- assertTrue (os.date ('%d', time) == '28', 'os.date() did not return expected value when passed "%d" [477]') +-- assertTrue (os.date ('%H', time) == '02', 'os.date() did not return expected value when passed "%H" [478]') +-- assertTrue (os.date ('%I', time) == '02', 'os.date() did not return expected value when passed "%I" [479]') +-- assertTrue (os.date ('%j', time) == '059', 'os.date() did not return expected value when passed "%j" [480]') +-- assertTrue (os.date ('%m', time) == '02', 'os.date() did not return expected value when passed "%m" [481]') +-- assertTrue (os.date ('%M', time) == '00', 'os.date() did not return expected value when passed "%M" [482]') +-- assertTrue (os.date ('%p', time) == 'AM', 'os.date() did not return expected value when passed "%p" [483]') +-- assertTrue (os.date ('%S', time) == '00', 'os.date() did not return expected value when passed "%S" [484]') +-- assertTrue (os.date ('%U', time) == '09', 'os.date() did not return expected value when passed "%U" [485]') +-- assertTrue (os.date ('%w', time) == '1', 'os.date() did not return expected value when passed "%w" [486]') +-- assertTrue (os.date ('%W', time) == '09', 'os.date() did not return expected value when passed "%W" [487]') +-- assertTrue (os.date ('%x', time) == '02/28/00', 'os.date() did not return expected value when passed "%x" [488]') +-- assertTrue (os.date ('%X', time) == '02:00:00', 'os.date() did not return expected value when passed "%X" [489]') +-- assertTrue (os.date ('%y', time) == '00', 'os.date() did not return expected value when passed "%y" [490]') +-- assertTrue (os.date ('%Y', time) == '2000', 'os.date() did not return expected value when passed "%Y" [491]') +-- assertTrue (os.date ('%Z', time) == 'GMT', 'os.date() did not return expected value when passed "%Z" [492]') +-- assertTrue (os.date ('%%', time) == '%', 'os.date() did not return expected value when passed "%%" [493]') +assertTrue (os.date ('!%a', time) == 'Mon', 'os.date() did not return expected value when passed "!%a" [494]') +assertTrue (os.date ('!%A', time) == 'Monday', 'os.date() did not return expected value when passed "!%A" [495]') +assertTrue (os.date ('!%b', time) == 'Feb', 'os.date() did not return expected value when passed "!%b" [496]') +assertTrue (os.date ('!%B', time) == 'February', 'os.date() did not return expected value when passed "!%B" [497]') +assertTrue (os.date ('!%d', time) == '28', 'os.date() did not return expected value when passed "!%d" [498]') +assertTrue (os.date ('!%H', time) == '02', 'os.date() did not return expected value when passed "!%H" [499]') +assertTrue (os.date ('!%I', time) == '02', 'os.date() did not return expected value when passed "!%I" [500]') +assertTrue (os.date ('!%j', time) == '059', 'os.date() did not return expected value when passed "!%j" [501]') +assertTrue (os.date ('!%m', time) == '02', 'os.date() did not return expected value when passed "!%m" [502]') +assertTrue (os.date ('!%M', time) == '00', 'os.date() did not return expected value when passed "!%M" [503]') +assertTrue (os.date ('!%p', time) == 'AM', 'os.date() did not return expected value when passed "!%p" [504]') +assertTrue (os.date ('!%S', time) == '00', 'os.date() did not return expected value when passed "!%S" [505]') +assertTrue (os.date ('!%U', time) == '09', 'os.date() did not return expected value when passed "!%U" [506]') +assertTrue (os.date ('!%w', time) == '1', 'os.date() did not return expected value when passed "!%w" [507]') +assertTrue (os.date ('!%W', time) == '09', 'os.date() did not return expected value when passed "!%W" [508]') +assertTrue (os.date ('!%x', time) == '02/28/00', 'os.date() did not return expected value when passed "!%x" [509]') +assertTrue (os.date ('!%X', time) == '02:00:00', 'os.date() did not return expected value when passed "!%X" [510]') +assertTrue (os.date ('!%y', time) == '00', 'os.date() did not return expected value when passed "!%y" [511]') +assertTrue (os.date ('!%Y', time) == '2000', 'os.date() did not return expected value when passed "!%Y" [512]') +assertTrue (os.date ('!%Z', time) == 'UTC', 'os.date() did not return expected value when passed "!%Z" [513]') +-- assertTrue (os.date ('*t', time).hour == 2, 'os.date() did not return expected value when passed "*t" [514]') +-- assertTrue (os.date ('*t', time).min == 0, 'os.date() did not return expected value when passed "*t" [515]') +-- assertTrue (os.date ('*t', time).wday == 2, 'os.date() did not return expected value when passed "*t" [516]') +-- assertTrue (os.date ('*t', time).day == 28, 'os.date() did not return expected value when passed "*t" [517]') +-- assertTrue (os.date ('*t', time).month == 2, 'os.date() did not return expected value when passed "*t" [518]') +-- assertTrue (os.date ('*t', time).year == 2000, 'os.date() did not return expected value when passed "*t" [519]') +-- assertTrue (os.date ('*t', time).sec == 0, 'os.date() did not return expected value when passed "*t" [520]') +-- assertTrue (os.date ('*t', time).yday == 59, 'os.date() did not return expected value when passed "*t" [521]') +-- assertTrue (os.date ('*t', time).isdst == false, 'os.date() did not return expected value when passed "*t" [522]') +assertTrue (os.date ('!*t', time).hour == 2, 'os.date() did not return expected value when passed "!*t" [523]') +assertTrue (os.date ('!*t', time).min == 0, 'os.date() did not return expected value when passed "!*t" [524]') +assertTrue (os.date ('!*t', time).wday == 2, 'os.date() did not return expected value when passed "!*t" [525]') +assertTrue (os.date ('!*t', time).day == 28, 'os.date() did not return expected value when passed "!*t" [526]') +assertTrue (os.date ('!*t', time).month == 2, 'os.date() did not return expected value when passed "!*t" [527]') +assertTrue (os.date ('!*t', time).year == 2000, 'os.date() did not return expected value when passed "!*t" [528]') +assertTrue (os.date ('!*t', time).sec == 0, 'os.date() did not return expected value when passed "!*t" [529]') +assertTrue (os.date ('!*t', time).yday == 59, 'os.date() did not return expected value when passed "!*t" [530]') +assertTrue (os.date ('!*t', time).isdst == false, 'os.date() did not return expected value when passed "!*t" [531]') + +local time = 951789600 + +-- assertTrue (os.date ('%a', time) == 'Tue', 'os.date() did not return expected value when passed "%a" [532]') +-- assertTrue (os.date ('%A', time) == 'Tuesday', 'os.date() did not return expected value when passed "%A" [533]') +-- assertTrue (os.date ('%b', time) == 'Feb', 'os.date() did not return expected value when passed "%b" [534]') +-- assertTrue (os.date ('%B', time) == 'February', 'os.date() did not return expected value when passed "%B" [535]') +-- assertTrue (os.date ('%d', time) == '29', 'os.date() did not return expected value when passed "%d" [536]') +-- assertTrue (os.date ('%H', time) == '02', 'os.date() did not return expected value when passed "%H" [537]') +-- assertTrue (os.date ('%I', time) == '02', 'os.date() did not return expected value when passed "%I" [538]') +-- assertTrue (os.date ('%j', time) == '060', 'os.date() did not return expected value when passed "%j" [539]') +-- assertTrue (os.date ('%m', time) == '02', 'os.date() did not return expected value when passed "%m" [540]') +-- assertTrue (os.date ('%M', time) == '00', 'os.date() did not return expected value when passed "%M" [541]') +-- assertTrue (os.date ('%p', time) == 'AM', 'os.date() did not return expected value when passed "%p" [542]') +-- assertTrue (os.date ('%S', time) == '00', 'os.date() did not return expected value when passed "%S" [543]') +-- assertTrue (os.date ('%U', time) == '09', 'os.date() did not return expected value when passed "%U" [544]') +-- assertTrue (os.date ('%w', time) == '2', 'os.date() did not return expected value when passed "%w" [545]') +-- assertTrue (os.date ('%W', time) == '09', 'os.date() did not return expected value when passed "%W" [546]') +-- assertTrue (os.date ('%x', time) == '02/29/00', 'os.date() did not return expected value when passed "%x" [547]') +-- assertTrue (os.date ('%X', time) == '02:00:00', 'os.date() did not return expected value when passed "%X" [548]') +-- assertTrue (os.date ('%y', time) == '00', 'os.date() did not return expected value when passed "%y" [549]') +-- assertTrue (os.date ('%Y', time) == '2000', 'os.date() did not return expected value when passed "%Y" [550]') +-- assertTrue (os.date ('%Z', time) == 'GMT', 'os.date() did not return expected value when passed "%Z" [551]') +-- assertTrue (os.date ('%%', time) == '%', 'os.date() did not return expected value when passed "%%" [552]') +assertTrue (os.date ('!%a', time) == 'Tue', 'os.date() did not return expected value when passed "!%a" [553]') +assertTrue (os.date ('!%A', time) == 'Tuesday', 'os.date() did not return expected value when passed "!%A" [554]') +assertTrue (os.date ('!%b', time) == 'Feb', 'os.date() did not return expected value when passed "!%b" [555]') +assertTrue (os.date ('!%B', time) == 'February', 'os.date() did not return expected value when passed "!%B" [556]') +assertTrue (os.date ('!%d', time) == '29', 'os.date() did not return expected value when passed "!%d" [557]') +assertTrue (os.date ('!%H', time) == '02', 'os.date() did not return expected value when passed "!%H" [558]') +assertTrue (os.date ('!%I', time) == '02', 'os.date() did not return expected value when passed "!%I" [559]') +assertTrue (os.date ('!%j', time) == '060', 'os.date() did not return expected value when passed "!%j" [560]') +assertTrue (os.date ('!%m', time) == '02', 'os.date() did not return expected value when passed "!%m" [561]') +assertTrue (os.date ('!%M', time) == '00', 'os.date() did not return expected value when passed "!%M" [562]') +assertTrue (os.date ('!%p', time) == 'AM', 'os.date() did not return expected value when passed "!%p" [563]') +assertTrue (os.date ('!%S', time) == '00', 'os.date() did not return expected value when passed "!%S" [564]') +assertTrue (os.date ('!%U', time) == '09', 'os.date() did not return expected value when passed "!%U" [565]') +assertTrue (os.date ('!%w', time) == '2', 'os.date() did not return expected value when passed "!%w" [566]') +assertTrue (os.date ('!%W', time) == '09', 'os.date() did not return expected value when passed "!%W" [567]') +assertTrue (os.date ('!%x', time) == '02/29/00', 'os.date() did not return expected value when passed "!%x" [568]') +assertTrue (os.date ('!%X', time) == '02:00:00', 'os.date() did not return expected value when passed "!%X" [569]') +assertTrue (os.date ('!%y', time) == '00', 'os.date() did not return expected value when passed "!%y" [570]') +assertTrue (os.date ('!%Y', time) == '2000', 'os.date() did not return expected value when passed "!%Y" [571]') +assertTrue (os.date ('!%Z', time) == 'UTC', 'os.date() did not return expected value when passed "!%Z" [572]') +-- assertTrue (os.date ('*t', time).hour == 2, 'os.date() did not return expected value when passed "*t" [573]') +-- assertTrue (os.date ('*t', time).min == 0, 'os.date() did not return expected value when passed "*t" [574]') +-- assertTrue (os.date ('*t', time).wday == 3, 'os.date() did not return expected value when passed "*t" [575]') +-- assertTrue (os.date ('*t', time).day == 29, 'os.date() did not return expected value when passed "*t" [576]') +-- assertTrue (os.date ('*t', time).month == 2, 'os.date() did not return expected value when passed "*t" [577]') +-- assertTrue (os.date ('*t', time).year == 2000, 'os.date() did not return expected value when passed "*t" [578]') +-- assertTrue (os.date ('*t', time).sec == 0, 'os.date() did not return expected value when passed "*t" [579]') +-- assertTrue (os.date ('*t', time).yday == 60, 'os.date() did not return expected value when passed "*t" [580]') +-- assertTrue (os.date ('*t', time).isdst == false, 'os.date() did not return expected value when passed "*t" [581]') +assertTrue (os.date ('!*t', time).hour == 2, 'os.date() did not return expected value when passed "!*t" [582]') +assertTrue (os.date ('!*t', time).min == 0, 'os.date() did not return expected value when passed "!*t" [583]') +assertTrue (os.date ('!*t', time).wday == 3, 'os.date() did not return expected value when passed "!*t" [584]') +assertTrue (os.date ('!*t', time).day == 29, 'os.date() did not return expected value when passed "!*t" [585]') +assertTrue (os.date ('!*t', time).month == 2, 'os.date() did not return expected value when passed "!*t" [586]') +assertTrue (os.date ('!*t', time).year == 2000, 'os.date() did not return expected value when passed "!*t" [587]') +assertTrue (os.date ('!*t', time).sec == 0, 'os.date() did not return expected value when passed "!*t" [588]') +assertTrue (os.date ('!*t', time).yday == 60, 'os.date() did not return expected value when passed "!*t" [589]') +assertTrue (os.date ('!*t', time).isdst == false, 'os.date() did not return expected value when passed "!*t" [590]') + +local time = 951879600 + +-- assertTrue (os.date ('%a', time) == 'Wed', 'os.date() did not return expected value when passed "%a" [591]') +-- assertTrue (os.date ('%A', time) == 'Wednesday', 'os.date() did not return expected value when passed "%A" [592]') +-- assertTrue (os.date ('%b', time) == 'Mar', 'os.date() did not return expected value when passed "%b" [593]') +-- assertTrue (os.date ('%B', time) == 'March', 'os.date() did not return expected value when passed "%B" [594]') +-- assertTrue (os.date ('%d', time) == '01', 'os.date() did not return expected value when passed "%d" [595]') +-- assertTrue (os.date ('%H', time) == '03', 'os.date() did not return expected value when passed "%H" [596]') +-- assertTrue (os.date ('%I', time) == '03', 'os.date() did not return expected value when passed "%I" [597]') +-- assertTrue (os.date ('%j', time) == '061', 'os.date() did not return expected value when passed "%j" [598]') +-- assertTrue (os.date ('%m', time) == '03', 'os.date() did not return expected value when passed "%m" [599]') +-- assertTrue (os.date ('%M', time) == '00', 'os.date() did not return expected value when passed "%M" [600]') +-- assertTrue (os.date ('%p', time) == 'AM', 'os.date() did not return expected value when passed "%p" [601]') +-- assertTrue (os.date ('%S', time) == '00', 'os.date() did not return expected value when passed "%S" [602]') +-- assertTrue (os.date ('%U', time) == '09', 'os.date() did not return expected value when passed "%U" [603]') +-- assertTrue (os.date ('%w', time) == '3', 'os.date() did not return expected value when passed "%w" [604]') +-- assertTrue (os.date ('%W', time) == '09', 'os.date() did not return expected value when passed "%W" [605]') +-- assertTrue (os.date ('%x', time) == '03/01/00', 'os.date() did not return expected value when passed "%x" [606]') +-- assertTrue (os.date ('%X', time) == '03:00:00', 'os.date() did not return expected value when passed "%X" [607]') +-- assertTrue (os.date ('%y', time) == '00', 'os.date() did not return expected value when passed "%y" [608]') +-- assertTrue (os.date ('%Y', time) == '2000', 'os.date() did not return expected value when passed "%Y" [609]') +-- assertTrue (os.date ('%Z', time) == 'GMT', 'os.date() did not return expected value when passed "%Z" [610]') +-- assertTrue (os.date ('%%', time) == '%', 'os.date() did not return expected value when passed "%%" [611]') +assertTrue (os.date ('!%a', time) == 'Wed', 'os.date() did not return expected value when passed "!%a" [612]') +assertTrue (os.date ('!%A', time) == 'Wednesday', 'os.date() did not return expected value when passed "!%A" [613]') +assertTrue (os.date ('!%b', time) == 'Mar', 'os.date() did not return expected value when passed "!%b" [614]') +assertTrue (os.date ('!%B', time) == 'March', 'os.date() did not return expected value when passed "!%B" [615]') +assertTrue (os.date ('!%d', time) == '01', 'os.date() did not return expected value when passed "!%d" [616]') +assertTrue (os.date ('!%H', time) == '03', 'os.date() did not return expected value when passed "!%H" [617]') +assertTrue (os.date ('!%I', time) == '03', 'os.date() did not return expected value when passed "!%I" [618]') +assertTrue (os.date ('!%j', time) == '061', 'os.date() did not return expected value when passed "!%j" [619]') +assertTrue (os.date ('!%m', time) == '03', 'os.date() did not return expected value when passed "!%m" [620]') +assertTrue (os.date ('!%M', time) == '00', 'os.date() did not return expected value when passed "!%M" [621]') +assertTrue (os.date ('!%p', time) == 'AM', 'os.date() did not return expected value when passed "!%p" [622]') +assertTrue (os.date ('!%S', time) == '00', 'os.date() did not return expected value when passed "!%S" [623]') +assertTrue (os.date ('!%U', time) == '09', 'os.date() did not return expected value when passed "!%U" [624]') +assertTrue (os.date ('!%w', time) == '3', 'os.date() did not return expected value when passed "!%w" [625]') +assertTrue (os.date ('!%W', time) == '09', 'os.date() did not return expected value when passed "!%W" [626]') +assertTrue (os.date ('!%x', time) == '03/01/00', 'os.date() did not return expected value when passed "!%x" [627]') +assertTrue (os.date ('!%X', time) == '03:00:00', 'os.date() did not return expected value when passed "!%X" [628]') +assertTrue (os.date ('!%y', time) == '00', 'os.date() did not return expected value when passed "!%y" [629]') +assertTrue (os.date ('!%Y', time) == '2000', 'os.date() did not return expected value when passed "!%Y" [630]') +assertTrue (os.date ('!%Z', time) == 'UTC', 'os.date() did not return expected value when passed "!%Z" [631]') +-- assertTrue (os.date ('*t', time).hour == 3, 'os.date() did not return expected value when passed "*t" [632]') +-- assertTrue (os.date ('*t', time).min == 0, 'os.date() did not return expected value when passed "*t" [633]') +-- assertTrue (os.date ('*t', time).wday == 4, 'os.date() did not return expected value when passed "*t" [634]') +-- assertTrue (os.date ('*t', time).day == 1, 'os.date() did not return expected value when passed "*t" [635]') +-- assertTrue (os.date ('*t', time).month == 3, 'os.date() did not return expected value when passed "*t" [636]') +-- assertTrue (os.date ('*t', time).year == 2000, 'os.date() did not return expected value when passed "*t" [637]') +-- assertTrue (os.date ('*t', time).sec == 0, 'os.date() did not return expected value when passed "*t" [638]') +-- assertTrue (os.date ('*t', time).yday == 61, 'os.date() did not return expected value when passed "*t" [639]') +-- assertTrue (os.date ('*t', time).isdst == false, 'os.date() did not return expected value when passed "*t" [640]') +assertTrue (os.date ('!*t', time).hour == 3, 'os.date() did not return expected value when passed "!*t" [641]') +assertTrue (os.date ('!*t', time).min == 0, 'os.date() did not return expected value when passed "!*t" [642]') +assertTrue (os.date ('!*t', time).wday == 4, 'os.date() did not return expected value when passed "!*t" [643]') +assertTrue (os.date ('!*t', time).day == 1, 'os.date() did not return expected value when passed "!*t" [644]') +assertTrue (os.date ('!*t', time).month == 3, 'os.date() did not return expected value when passed "!*t" [645]') +assertTrue (os.date ('!*t', time).year == 2000, 'os.date() did not return expected value when passed "!*t" [646]') +assertTrue (os.date ('!*t', time).sec == 0, 'os.date() did not return expected value when passed "!*t" [647]') +assertTrue (os.date ('!*t', time).yday == 61, 'os.date() did not return expected value when passed "!*t" [648]') +assertTrue (os.date ('!*t', time).isdst == false, 'os.date() did not return expected value when passed "!*t" [649]') + +local time = 978264000 + +-- assertTrue (os.date ('%a', time) == 'Sun', 'os.date() did not return expected value when passed "%a" [650]') +-- assertTrue (os.date ('%A', time) == 'Sunday', 'os.date() did not return expected value when passed "%A" [651]') +-- assertTrue (os.date ('%b', time) == 'Dec', 'os.date() did not return expected value when passed "%b" [652]') +-- assertTrue (os.date ('%B', time) == 'December', 'os.date() did not return expected value when passed "%B" [653]') +-- assertTrue (os.date ('%d', time) == '31', 'os.date() did not return expected value when passed "%d" [654]') +-- assertTrue (os.date ('%H', time) == '12', 'os.date() did not return expected value when passed "%H" [655]') +-- assertTrue (os.date ('%I', time) == '12', 'os.date() did not return expected value when passed "%I" [656]') +-- assertTrue (os.date ('%j', time) == '366', 'os.date() did not return expected value when passed "%j" [657]') +-- assertTrue (os.date ('%m', time) == '12', 'os.date() did not return expected value when passed "%m" [658]') +-- assertTrue (os.date ('%M', time) == '00', 'os.date() did not return expected value when passed "%M" [659]') +-- assertTrue (os.date ('%p', time) == 'PM', 'os.date() did not return expected value when passed "%p" [660]') +-- assertTrue (os.date ('%S', time) == '00', 'os.date() did not return expected value when passed "%S" [661]') +-- assertTrue (os.date ('%U', time) == '53', 'os.date() did not return expected value when passed "%U" [662]') +-- assertTrue (os.date ('%w', time) == '0', 'os.date() did not return expected value when passed "%w" [663]') +-- assertTrue (os.date ('%W', time) == '52', 'os.date() did not return expected value when passed "%W" [664]') +-- assertTrue (os.date ('%x', time) == '12/31/00', 'os.date() did not return expected value when passed "%x" [665]') +-- assertTrue (os.date ('%X', time) == '12:00:00', 'os.date() did not return expected value when passed "%X" [666]') +-- assertTrue (os.date ('%y', time) == '00', 'os.date() did not return expected value when passed "%y" [667]') +-- assertTrue (os.date ('%Y', time) == '2000', 'os.date() did not return expected value when passed "%Y" [668]') +-- assertTrue (os.date ('%Z', time) == 'GMT', 'os.date() did not return expected value when passed "%Z" [669]') +-- assertTrue (os.date ('%%', time) == '%', 'os.date() did not return expected value when passed "%%" [670]') +assertTrue (os.date ('!%a', time) == 'Sun', 'os.date() did not return expected value when passed "!%a" [671]') +assertTrue (os.date ('!%A', time) == 'Sunday', 'os.date() did not return expected value when passed "!%A" [672]') +assertTrue (os.date ('!%b', time) == 'Dec', 'os.date() did not return expected value when passed "!%b" [673]') +assertTrue (os.date ('!%B', time) == 'December', 'os.date() did not return expected value when passed "!%B" [674]') +assertTrue (os.date ('!%d', time) == '31', 'os.date() did not return expected value when passed "!%d" [675]') +assertTrue (os.date ('!%H', time) == '12', 'os.date() did not return expected value when passed "!%H" [676]') +assertTrue (os.date ('!%I', time) == '12', 'os.date() did not return expected value when passed "!%I" [677]') +assertTrue (os.date ('!%j', time) == '366', 'os.date() did not return expected value when passed "!%j" [678]') +assertTrue (os.date ('!%m', time) == '12', 'os.date() did not return expected value when passed "!%m" [679]') +assertTrue (os.date ('!%M', time) == '00', 'os.date() did not return expected value when passed "!%M" [680]') +assertTrue (os.date ('!%p', time) == 'PM', 'os.date() did not return expected value when passed "!%p" [681]') +assertTrue (os.date ('!%S', time) == '00', 'os.date() did not return expected value when passed "!%S" [682]') +assertTrue (os.date ('!%U', time) == '53', 'os.date() did not return expected value when passed "!%U" [683]') +assertTrue (os.date ('!%w', time) == '0', 'os.date() did not return expected value when passed "!%w" [684]') +assertTrue (os.date ('!%W', time) == '52', 'os.date() did not return expected value when passed "!%W" [685]') +assertTrue (os.date ('!%x', time) == '12/31/00', 'os.date() did not return expected value when passed "!%x" [686]') +assertTrue (os.date ('!%X', time) == '12:00:00', 'os.date() did not return expected value when passed "!%X" [687]') +assertTrue (os.date ('!%y', time) == '00', 'os.date() did not return expected value when passed "!%y" [688]') +assertTrue (os.date ('!%Y', time) == '2000', 'os.date() did not return expected value when passed "!%Y" [689]') +assertTrue (os.date ('!%Z', time) == 'UTC', 'os.date() did not return expected value when passed "!%Z" [690]') +-- assertTrue (os.date ('*t', time).hour == 12, 'os.date() did not return expected value when passed "*t" [691]') +-- assertTrue (os.date ('*t', time).min == 0, 'os.date() did not return expected value when passed "*t" [692]') +-- assertTrue (os.date ('*t', time).wday == 1, 'os.date() did not return expected value when passed "*t" [693]') +-- assertTrue (os.date ('*t', time).day == 31, 'os.date() did not return expected value when passed "*t" [694]') +-- assertTrue (os.date ('*t', time).month == 12, 'os.date() did not return expected value when passed "*t" [695]') +-- assertTrue (os.date ('*t', time).year == 2000, 'os.date() did not return expected value when passed "*t" [696]') +-- assertTrue (os.date ('*t', time).sec == 0, 'os.date() did not return expected value when passed "*t" [697]') +-- assertTrue (os.date ('*t', time).yday == 366, 'os.date() did not return expected value when passed "*t" [698]') +-- assertTrue (os.date ('*t', time).isdst == false, 'os.date() did not return expected value when passed "*t" [699]') +assertTrue (os.date ('!*t', time).hour == 12, 'os.date() did not return expected value when passed "!*t" [700]') +assertTrue (os.date ('!*t', time).min == 0, 'os.date() did not return expected value when passed "!*t" [701]') +assertTrue (os.date ('!*t', time).wday == 1, 'os.date() did not return expected value when passed "!*t" [702]') +assertTrue (os.date ('!*t', time).day == 31, 'os.date() did not return expected value when passed "!*t" [703]') +assertTrue (os.date ('!*t', time).month == 12, 'os.date() did not return expected value when passed "!*t" [704]') +assertTrue (os.date ('!*t', time).year == 2000, 'os.date() did not return expected value when passed "!*t" [705]') +assertTrue (os.date ('!*t', time).sec == 0, 'os.date() did not return expected value when passed "!*t" [706]') +assertTrue (os.date ('!*t', time).yday == 366, 'os.date() did not return expected value when passed "!*t" [707]') +assertTrue (os.date ('!*t', time).isdst == false, 'os.date() did not return expected value when passed "!*t" [708]') + +local time = 1293843600 + +-- assertTrue (os.date ('%a', time) == 'Sat', 'os.date() did not return expected value when passed "%a" [709]') +-- assertTrue (os.date ('%A', time) == 'Saturday', 'os.date() did not return expected value when passed "%A" [710]') +-- assertTrue (os.date ('%b', time) == 'Jan', 'os.date() did not return expected value when passed "%b" [711]') +-- assertTrue (os.date ('%B', time) == 'January', 'os.date() did not return expected value when passed "%B" [712]') +-- assertTrue (os.date ('%d', time) == '01', 'os.date() did not return expected value when passed "%d" [713]') +-- assertTrue (os.date ('%H', time) == '01', 'os.date() did not return expected value when passed "%H" [714]') +-- assertTrue (os.date ('%I', time) == '01', 'os.date() did not return expected value when passed "%I" [715]') +-- assertTrue (os.date ('%j', time) == '001', 'os.date() did not return expected value when passed "%j" [716]') +-- assertTrue (os.date ('%m', time) == '01', 'os.date() did not return expected value when passed "%m" [717]') +-- assertTrue (os.date ('%M', time) == '00', 'os.date() did not return expected value when passed "%M" [718]') +-- assertTrue (os.date ('%p', time) == 'AM', 'os.date() did not return expected value when passed "%p" [719]') +-- assertTrue (os.date ('%S', time) == '00', 'os.date() did not return expected value when passed "%S" [720]') +-- assertTrue (os.date ('%U', time) == '00', 'os.date() did not return expected value when passed "%U" [721]') +-- assertTrue (os.date ('%w', time) == '6', 'os.date() did not return expected value when passed "%w" [722]') +-- assertTrue (os.date ('%W', time) == '00', 'os.date() did not return expected value when passed "%W" [723]') +-- assertTrue (os.date ('%x', time) == '01/01/11', 'os.date() did not return expected value when passed "%x" [724]') +-- assertTrue (os.date ('%X', time) == '01:00:00', 'os.date() did not return expected value when passed "%X" [725]') +-- assertTrue (os.date ('%y', time) == '11', 'os.date() did not return expected value when passed "%y" [726]') +-- assertTrue (os.date ('%Y', time) == '2011', 'os.date() did not return expected value when passed "%Y" [727]') +-- assertTrue (os.date ('%Z', time) == 'GMT', 'os.date() did not return expected value when passed "%Z" [728]') +-- assertTrue (os.date ('%%', time) == '%', 'os.date() did not return expected value when passed "%%" [729]') +assertTrue (os.date ('!%a', time) == 'Sat', 'os.date() did not return expected value when passed "!%a" [730]') +assertTrue (os.date ('!%A', time) == 'Saturday', 'os.date() did not return expected value when passed "!%A" [731]') +assertTrue (os.date ('!%b', time) == 'Jan', 'os.date() did not return expected value when passed "!%b" [732]') +assertTrue (os.date ('!%B', time) == 'January', 'os.date() did not return expected value when passed "!%B" [733]') +assertTrue (os.date ('!%d', time) == '01', 'os.date() did not return expected value when passed "!%d" [734]') +assertTrue (os.date ('!%H', time) == '01', 'os.date() did not return expected value when passed "!%H" [735]') +assertTrue (os.date ('!%I', time) == '01', 'os.date() did not return expected value when passed "!%I" [736]') +assertTrue (os.date ('!%j', time) == '001', 'os.date() did not return expected value when passed "!%j" [737]') +assertTrue (os.date ('!%m', time) == '01', 'os.date() did not return expected value when passed "!%m" [738]') +assertTrue (os.date ('!%M', time) == '00', 'os.date() did not return expected value when passed "!%M" [739]') +assertTrue (os.date ('!%p', time) == 'AM', 'os.date() did not return expected value when passed "!%p" [740]') +assertTrue (os.date ('!%S', time) == '00', 'os.date() did not return expected value when passed "!%S" [741]') +assertTrue (os.date ('!%U', time) == '00', 'os.date() did not return expected value when passed "!%U" [742]') +assertTrue (os.date ('!%w', time) == '6', 'os.date() did not return expected value when passed "!%w" [743]') +assertTrue (os.date ('!%W', time) == '00', 'os.date() did not return expected value when passed "!%W" [744]') +assertTrue (os.date ('!%x', time) == '01/01/11', 'os.date() did not return expected value when passed "!%x" [745]') +assertTrue (os.date ('!%X', time) == '01:00:00', 'os.date() did not return expected value when passed "!%X" [746]') +assertTrue (os.date ('!%y', time) == '11', 'os.date() did not return expected value when passed "!%y" [747]') +assertTrue (os.date ('!%Y', time) == '2011', 'os.date() did not return expected value when passed "!%Y" [748]') +assertTrue (os.date ('!%Z', time) == 'UTC', 'os.date() did not return expected value when passed "!%Z" [749]') +-- assertTrue (os.date ('*t', time).hour == 1, 'os.date() did not return expected value when passed "*t" [750]') +-- assertTrue (os.date ('*t', time).min == 0, 'os.date() did not return expected value when passed "*t" [751]') +-- assertTrue (os.date ('*t', time).wday == 7, 'os.date() did not return expected value when passed "*t" [752]') +-- assertTrue (os.date ('*t', time).day == 1, 'os.date() did not return expected value when passed "*t" [753]') +-- assertTrue (os.date ('*t', time).month == 1, 'os.date() did not return expected value when passed "*t" [754]') +-- assertTrue (os.date ('*t', time).year == 2011, 'os.date() did not return expected value when passed "*t" [755]') +-- assertTrue (os.date ('*t', time).sec == 0, 'os.date() did not return expected value when passed "*t" [756]') +-- assertTrue (os.date ('*t', time).yday == 1, 'os.date() did not return expected value when passed "*t" [757]') +-- assertTrue (os.date ('*t', time).isdst == false, 'os.date() did not return expected value when passed "*t" [758]') +assertTrue (os.date ('!*t', time).hour == 1, 'os.date() did not return expected value when passed "!*t" [759]') +assertTrue (os.date ('!*t', time).min == 0, 'os.date() did not return expected value when passed "!*t" [760]') +assertTrue (os.date ('!*t', time).wday == 7, 'os.date() did not return expected value when passed "!*t" [761]') +assertTrue (os.date ('!*t', time).day == 1, 'os.date() did not return expected value when passed "!*t" [762]') +assertTrue (os.date ('!*t', time).month == 1, 'os.date() did not return expected value when passed "!*t" [763]') +assertTrue (os.date ('!*t', time).year == 2011, 'os.date() did not return expected value when passed "!*t" [764]') +assertTrue (os.date ('!*t', time).sec == 0, 'os.date() did not return expected value when passed "!*t" [765]') +assertTrue (os.date ('!*t', time).yday == 1, 'os.date() did not return expected value when passed "!*t" [766]') +assertTrue (os.date ('!*t', time).isdst == false, 'os.date() did not return expected value when passed "!*t" [767]') + +local time = 1296525600 + +-- assertTrue (os.date ('%a', time) == 'Tue', 'os.date() did not return expected value when passed "%a" [768]') +-- assertTrue (os.date ('%A', time) == 'Tuesday', 'os.date() did not return expected value when passed "%A" [769]') +-- assertTrue (os.date ('%b', time) == 'Feb', 'os.date() did not return expected value when passed "%b" [770]') +-- assertTrue (os.date ('%B', time) == 'February', 'os.date() did not return expected value when passed "%B" [771]') +-- assertTrue (os.date ('%d', time) == '01', 'os.date() did not return expected value when passed "%d" [772]') +-- assertTrue (os.date ('%H', time) == '02', 'os.date() did not return expected value when passed "%H" [773]') +-- assertTrue (os.date ('%I', time) == '02', 'os.date() did not return expected value when passed "%I" [774]') +-- assertTrue (os.date ('%j', time) == '032', 'os.date() did not return expected value when passed "%j" [775]') +-- assertTrue (os.date ('%m', time) == '02', 'os.date() did not return expected value when passed "%m" [776]') +-- assertTrue (os.date ('%M', time) == '00', 'os.date() did not return expected value when passed "%M" [777]') +-- assertTrue (os.date ('%p', time) == 'AM', 'os.date() did not return expected value when passed "%p" [778]') +-- assertTrue (os.date ('%S', time) == '00', 'os.date() did not return expected value when passed "%S" [779]') +-- assertTrue (os.date ('%U', time) == '05', 'os.date() did not return expected value when passed "%U" [780]') +-- assertTrue (os.date ('%w', time) == '2', 'os.date() did not return expected value when passed "%w" [781]') +-- assertTrue (os.date ('%W', time) == '05', 'os.date() did not return expected value when passed "%W" [782]') +-- assertTrue (os.date ('%x', time) == '02/01/11', 'os.date() did not return expected value when passed "%x" [783]') +-- assertTrue (os.date ('%X', time) == '02:00:00', 'os.date() did not return expected value when passed "%X" [784]') +-- assertTrue (os.date ('%y', time) == '11', 'os.date() did not return expected value when passed "%y" [785]') +-- assertTrue (os.date ('%Y', time) == '2011', 'os.date() did not return expected value when passed "%Y" [786]') +-- assertTrue (os.date ('%Z', time) == 'GMT', 'os.date() did not return expected value when passed "%Z" [787]') +-- assertTrue (os.date ('%%', time) == '%', 'os.date() did not return expected value when passed "%%" [788]') +assertTrue (os.date ('!%a', time) == 'Tue', 'os.date() did not return expected value when passed "!%a" [789]') +assertTrue (os.date ('!%A', time) == 'Tuesday', 'os.date() did not return expected value when passed "!%A" [790]') +assertTrue (os.date ('!%b', time) == 'Feb', 'os.date() did not return expected value when passed "!%b" [791]') +assertTrue (os.date ('!%B', time) == 'February', 'os.date() did not return expected value when passed "!%B" [792]') +assertTrue (os.date ('!%d', time) == '01', 'os.date() did not return expected value when passed "!%d" [793]') +assertTrue (os.date ('!%H', time) == '02', 'os.date() did not return expected value when passed "!%H" [794]') +assertTrue (os.date ('!%I', time) == '02', 'os.date() did not return expected value when passed "!%I" [795]') +assertTrue (os.date ('!%j', time) == '032', 'os.date() did not return expected value when passed "!%j" [796]') +assertTrue (os.date ('!%m', time) == '02', 'os.date() did not return expected value when passed "!%m" [797]') +assertTrue (os.date ('!%M', time) == '00', 'os.date() did not return expected value when passed "!%M" [798]') +assertTrue (os.date ('!%p', time) == 'AM', 'os.date() did not return expected value when passed "!%p" [799]') +assertTrue (os.date ('!%S', time) == '00', 'os.date() did not return expected value when passed "!%S" [800]') +assertTrue (os.date ('!%U', time) == '05', 'os.date() did not return expected value when passed "!%U" [801]') +assertTrue (os.date ('!%w', time) == '2', 'os.date() did not return expected value when passed "!%w" [802]') +assertTrue (os.date ('!%W', time) == '05', 'os.date() did not return expected value when passed "!%W" [803]') +assertTrue (os.date ('!%x', time) == '02/01/11', 'os.date() did not return expected value when passed "!%x" [804]') +assertTrue (os.date ('!%X', time) == '02:00:00', 'os.date() did not return expected value when passed "!%X" [805]') +assertTrue (os.date ('!%y', time) == '11', 'os.date() did not return expected value when passed "!%y" [806]') +assertTrue (os.date ('!%Y', time) == '2011', 'os.date() did not return expected value when passed "!%Y" [807]') +assertTrue (os.date ('!%Z', time) == 'UTC', 'os.date() did not return expected value when passed "!%Z" [808]') +-- assertTrue (os.date ('*t', time).hour == 2, 'os.date() did not return expected value when passed "*t" [809]') +-- assertTrue (os.date ('*t', time).min == 0, 'os.date() did not return expected value when passed "*t" [810]') +-- assertTrue (os.date ('*t', time).wday == 3, 'os.date() did not return expected value when passed "*t" [811]') +-- assertTrue (os.date ('*t', time).day == 1, 'os.date() did not return expected value when passed "*t" [812]') +-- assertTrue (os.date ('*t', time).month == 2, 'os.date() did not return expected value when passed "*t" [813]') +-- assertTrue (os.date ('*t', time).year == 2011, 'os.date() did not return expected value when passed "*t" [814]') +-- assertTrue (os.date ('*t', time).sec == 0, 'os.date() did not return expected value when passed "*t" [815]') +-- assertTrue (os.date ('*t', time).yday == 32, 'os.date() did not return expected value when passed "*t" [816]') +-- assertTrue (os.date ('*t', time).isdst == false, 'os.date() did not return expected value when passed "*t" [817]') +assertTrue (os.date ('!*t', time).hour == 2, 'os.date() did not return expected value when passed "!*t" [818]') +assertTrue (os.date ('!*t', time).min == 0, 'os.date() did not return expected value when passed "!*t" [819]') +assertTrue (os.date ('!*t', time).wday == 3, 'os.date() did not return expected value when passed "!*t" [820]') +assertTrue (os.date ('!*t', time).day == 1, 'os.date() did not return expected value when passed "!*t" [821]') +assertTrue (os.date ('!*t', time).month == 2, 'os.date() did not return expected value when passed "!*t" [822]') +assertTrue (os.date ('!*t', time).year == 2011, 'os.date() did not return expected value when passed "!*t" [823]') +assertTrue (os.date ('!*t', time).sec == 0, 'os.date() did not return expected value when passed "!*t" [824]') +assertTrue (os.date ('!*t', time).yday == 32, 'os.date() did not return expected value when passed "!*t" [825]') +assertTrue (os.date ('!*t', time).isdst == false, 'os.date() did not return expected value when passed "!*t" [826]') + +local time = 1298858400 + +-- assertTrue (os.date ('%a', time) == 'Mon', 'os.date() did not return expected value when passed "%a" [827]') +-- assertTrue (os.date ('%A', time) == 'Monday', 'os.date() did not return expected value when passed "%A" [828]') +-- assertTrue (os.date ('%b', time) == 'Feb', 'os.date() did not return expected value when passed "%b" [829]') +-- assertTrue (os.date ('%B', time) == 'February', 'os.date() did not return expected value when passed "%B" [830]') +-- assertTrue (os.date ('%d', time) == '28', 'os.date() did not return expected value when passed "%d" [831]') +-- assertTrue (os.date ('%H', time) == '02', 'os.date() did not return expected value when passed "%H" [832]') +-- assertTrue (os.date ('%I', time) == '02', 'os.date() did not return expected value when passed "%I" [833]') +-- assertTrue (os.date ('%j', time) == '059', 'os.date() did not return expected value when passed "%j" [834]') +-- assertTrue (os.date ('%m', time) == '02', 'os.date() did not return expected value when passed "%m" [835]') +-- assertTrue (os.date ('%M', time) == '00', 'os.date() did not return expected value when passed "%M" [836]') +-- assertTrue (os.date ('%p', time) == 'AM', 'os.date() did not return expected value when passed "%p" [837]') +-- assertTrue (os.date ('%S', time) == '00', 'os.date() did not return expected value when passed "%S" [838]') +-- assertTrue (os.date ('%U', time) == '09', 'os.date() did not return expected value when passed "%U" [839]') +-- assertTrue (os.date ('%w', time) == '1', 'os.date() did not return expected value when passed "%w" [840]') +-- assertTrue (os.date ('%W', time) == '09', 'os.date() did not return expected value when passed "%W" [841]') +-- assertTrue (os.date ('%x', time) == '02/28/11', 'os.date() did not return expected value when passed "%x" [842]') +-- assertTrue (os.date ('%X', time) == '02:00:00', 'os.date() did not return expected value when passed "%X" [843]') +-- assertTrue (os.date ('%y', time) == '11', 'os.date() did not return expected value when passed "%y" [844]') +-- assertTrue (os.date ('%Y', time) == '2011', 'os.date() did not return expected value when passed "%Y" [845]') +-- assertTrue (os.date ('%Z', time) == 'GMT', 'os.date() did not return expected value when passed "%Z" [846]') +-- assertTrue (os.date ('%%', time) == '%', 'os.date() did not return expected value when passed "%%" [847]') +assertTrue (os.date ('!%a', time) == 'Mon', 'os.date() did not return expected value when passed "!%a" [848]') +assertTrue (os.date ('!%A', time) == 'Monday', 'os.date() did not return expected value when passed "!%A" [849]') +assertTrue (os.date ('!%b', time) == 'Feb', 'os.date() did not return expected value when passed "!%b" [850]') +assertTrue (os.date ('!%B', time) == 'February', 'os.date() did not return expected value when passed "!%B" [851]') +assertTrue (os.date ('!%d', time) == '28', 'os.date() did not return expected value when passed "!%d" [852]') +assertTrue (os.date ('!%H', time) == '02', 'os.date() did not return expected value when passed "!%H" [853]') +assertTrue (os.date ('!%I', time) == '02', 'os.date() did not return expected value when passed "!%I" [854]') +assertTrue (os.date ('!%j', time) == '059', 'os.date() did not return expected value when passed "!%j" [855]') +assertTrue (os.date ('!%m', time) == '02', 'os.date() did not return expected value when passed "!%m" [856]') +assertTrue (os.date ('!%M', time) == '00', 'os.date() did not return expected value when passed "!%M" [857]') +assertTrue (os.date ('!%p', time) == 'AM', 'os.date() did not return expected value when passed "!%p" [858]') +assertTrue (os.date ('!%S', time) == '00', 'os.date() did not return expected value when passed "!%S" [859]') +assertTrue (os.date ('!%U', time) == '09', 'os.date() did not return expected value when passed "!%U" [860]') +assertTrue (os.date ('!%w', time) == '1', 'os.date() did not return expected value when passed "!%w" [861]') +assertTrue (os.date ('!%W', time) == '09', 'os.date() did not return expected value when passed "!%W" [862]') +assertTrue (os.date ('!%x', time) == '02/28/11', 'os.date() did not return expected value when passed "!%x" [863]') +assertTrue (os.date ('!%X', time) == '02:00:00', 'os.date() did not return expected value when passed "!%X" [864]') +assertTrue (os.date ('!%y', time) == '11', 'os.date() did not return expected value when passed "!%y" [865]') +assertTrue (os.date ('!%Y', time) == '2011', 'os.date() did not return expected value when passed "!%Y" [866]') +assertTrue (os.date ('!%Z', time) == 'UTC', 'os.date() did not return expected value when passed "!%Z" [867]') +-- assertTrue (os.date ('*t', time).hour == 2, 'os.date() did not return expected value when passed "*t" [868]') +-- assertTrue (os.date ('*t', time).min == 0, 'os.date() did not return expected value when passed "*t" [869]') +-- assertTrue (os.date ('*t', time).wday == 2, 'os.date() did not return expected value when passed "*t" [870]') +-- assertTrue (os.date ('*t', time).day == 28, 'os.date() did not return expected value when passed "*t" [871]') +-- assertTrue (os.date ('*t', time).month == 2, 'os.date() did not return expected value when passed "*t" [872]') +-- assertTrue (os.date ('*t', time).year == 2011, 'os.date() did not return expected value when passed "*t" [873]') +-- assertTrue (os.date ('*t', time).sec == 0, 'os.date() did not return expected value when passed "*t" [874]') +-- assertTrue (os.date ('*t', time).yday == 59, 'os.date() did not return expected value when passed "*t" [875]') +-- assertTrue (os.date ('*t', time).isdst == false, 'os.date() did not return expected value when passed "*t" [876]') +assertTrue (os.date ('!*t', time).hour == 2, 'os.date() did not return expected value when passed "!*t" [877]') +assertTrue (os.date ('!*t', time).min == 0, 'os.date() did not return expected value when passed "!*t" [878]') +assertTrue (os.date ('!*t', time).wday == 2, 'os.date() did not return expected value when passed "!*t" [879]') +assertTrue (os.date ('!*t', time).day == 28, 'os.date() did not return expected value when passed "!*t" [880]') +assertTrue (os.date ('!*t', time).month == 2, 'os.date() did not return expected value when passed "!*t" [881]') +assertTrue (os.date ('!*t', time).year == 2011, 'os.date() did not return expected value when passed "!*t" [882]') +assertTrue (os.date ('!*t', time).sec == 0, 'os.date() did not return expected value when passed "!*t" [883]') +assertTrue (os.date ('!*t', time).yday == 59, 'os.date() did not return expected value when passed "!*t" [884]') +assertTrue (os.date ('!*t', time).isdst == false, 'os.date() did not return expected value when passed "!*t" [885]') + +local time = 1298944800 + +-- assertTrue (os.date ('%a', time) == 'Tue', 'os.date() did not return expected value when passed "%a" [886]') +-- assertTrue (os.date ('%A', time) == 'Tuesday', 'os.date() did not return expected value when passed "%A" [887]') +-- assertTrue (os.date ('%b', time) == 'Mar', 'os.date() did not return expected value when passed "%b" [888]') +-- assertTrue (os.date ('%B', time) == 'March', 'os.date() did not return expected value when passed "%B" [889]') +-- assertTrue (os.date ('%d', time) == '01', 'os.date() did not return expected value when passed "%d" [890]') +-- assertTrue (os.date ('%H', time) == '02', 'os.date() did not return expected value when passed "%H" [891]') +-- assertTrue (os.date ('%I', time) == '02', 'os.date() did not return expected value when passed "%I" [892]') +-- assertTrue (os.date ('%j', time) == '060', 'os.date() did not return expected value when passed "%j" [893]') +-- assertTrue (os.date ('%m', time) == '03', 'os.date() did not return expected value when passed "%m" [894]') +-- assertTrue (os.date ('%M', time) == '00', 'os.date() did not return expected value when passed "%M" [895]') +-- assertTrue (os.date ('%p', time) == 'AM', 'os.date() did not return expected value when passed "%p" [896]') +-- assertTrue (os.date ('%S', time) == '00', 'os.date() did not return expected value when passed "%S" [897]') +-- assertTrue (os.date ('%U', time) == '09', 'os.date() did not return expected value when passed "%U" [898]') +-- assertTrue (os.date ('%w', time) == '2', 'os.date() did not return expected value when passed "%w" [899]') +-- assertTrue (os.date ('%W', time) == '09', 'os.date() did not return expected value when passed "%W" [900]') +-- assertTrue (os.date ('%x', time) == '03/01/11', 'os.date() did not return expected value when passed "%x" [901]') +-- assertTrue (os.date ('%X', time) == '02:00:00', 'os.date() did not return expected value when passed "%X" [902]') +-- assertTrue (os.date ('%y', time) == '11', 'os.date() did not return expected value when passed "%y" [903]') +-- assertTrue (os.date ('%Y', time) == '2011', 'os.date() did not return expected value when passed "%Y" [904]') +-- assertTrue (os.date ('%Z', time) == 'GMT', 'os.date() did not return expected value when passed "%Z" [905]') +-- assertTrue (os.date ('%%', time) == '%', 'os.date() did not return expected value when passed "%%" [906]') +assertTrue (os.date ('!%a', time) == 'Tue', 'os.date() did not return expected value when passed "!%a" [907]') +assertTrue (os.date ('!%A', time) == 'Tuesday', 'os.date() did not return expected value when passed "!%A" [908]') +assertTrue (os.date ('!%b', time) == 'Mar', 'os.date() did not return expected value when passed "!%b" [909]') +assertTrue (os.date ('!%B', time) == 'March', 'os.date() did not return expected value when passed "!%B" [910]') +assertTrue (os.date ('!%d', time) == '01', 'os.date() did not return expected value when passed "!%d" [911]') +assertTrue (os.date ('!%H', time) == '02', 'os.date() did not return expected value when passed "!%H" [912]') +assertTrue (os.date ('!%I', time) == '02', 'os.date() did not return expected value when passed "!%I" [913]') +assertTrue (os.date ('!%j', time) == '060', 'os.date() did not return expected value when passed "!%j" [914]') +assertTrue (os.date ('!%m', time) == '03', 'os.date() did not return expected value when passed "!%m" [915]') +assertTrue (os.date ('!%M', time) == '00', 'os.date() did not return expected value when passed "!%M" [916]') +assertTrue (os.date ('!%p', time) == 'AM', 'os.date() did not return expected value when passed "!%p" [917]') +assertTrue (os.date ('!%S', time) == '00', 'os.date() did not return expected value when passed "!%S" [918]') +assertTrue (os.date ('!%U', time) == '09', 'os.date() did not return expected value when passed "!%U" [919]') +assertTrue (os.date ('!%w', time) == '2', 'os.date() did not return expected value when passed "!%w" [920]') +assertTrue (os.date ('!%W', time) == '09', 'os.date() did not return expected value when passed "!%W" [921]') +assertTrue (os.date ('!%x', time) == '03/01/11', 'os.date() did not return expected value when passed "!%x" [922]') +assertTrue (os.date ('!%X', time) == '02:00:00', 'os.date() did not return expected value when passed "!%X" [923]') +assertTrue (os.date ('!%y', time) == '11', 'os.date() did not return expected value when passed "!%y" [924]') +assertTrue (os.date ('!%Y', time) == '2011', 'os.date() did not return expected value when passed "!%Y" [925]') +assertTrue (os.date ('!%Z', time) == 'UTC', 'os.date() did not return expected value when passed "!%Z" [926]') +-- assertTrue (os.date ('*t', time).hour == 2, 'os.date() did not return expected value when passed "*t" [927]') +-- assertTrue (os.date ('*t', time).min == 0, 'os.date() did not return expected value when passed "*t" [928]') +-- assertTrue (os.date ('*t', time).wday == 3, 'os.date() did not return expected value when passed "*t" [929]') +-- assertTrue (os.date ('*t', time).day == 1, 'os.date() did not return expected value when passed "*t" [930]') +-- assertTrue (os.date ('*t', time).month == 3, 'os.date() did not return expected value when passed "*t" [931]') +-- assertTrue (os.date ('*t', time).year == 2011, 'os.date() did not return expected value when passed "*t" [932]') +-- assertTrue (os.date ('*t', time).sec == 0, 'os.date() did not return expected value when passed "*t" [933]') +-- assertTrue (os.date ('*t', time).yday == 60, 'os.date() did not return expected value when passed "*t" [934]') +-- assertTrue (os.date ('*t', time).isdst == false, 'os.date() did not return expected value when passed "*t" [935]') +assertTrue (os.date ('!*t', time).hour == 2, 'os.date() did not return expected value when passed "!*t" [936]') +assertTrue (os.date ('!*t', time).min == 0, 'os.date() did not return expected value when passed "!*t" [937]') +assertTrue (os.date ('!*t', time).wday == 3, 'os.date() did not return expected value when passed "!*t" [938]') +assertTrue (os.date ('!*t', time).day == 1, 'os.date() did not return expected value when passed "!*t" [939]') +assertTrue (os.date ('!*t', time).month == 3, 'os.date() did not return expected value when passed "!*t" [940]') +assertTrue (os.date ('!*t', time).year == 2011, 'os.date() did not return expected value when passed "!*t" [941]') +assertTrue (os.date ('!*t', time).sec == 0, 'os.date() did not return expected value when passed "!*t" [942]') +assertTrue (os.date ('!*t', time).yday == 60, 'os.date() did not return expected value when passed "!*t" [943]') +assertTrue (os.date ('!*t', time).isdst == false, 'os.date() did not return expected value when passed "!*t" [944]') + +local time = 1298948400 + +-- assertTrue (os.date ('%a', time) == 'Tue', 'os.date() did not return expected value when passed "%a" [945]') +-- assertTrue (os.date ('%A', time) == 'Tuesday', 'os.date() did not return expected value when passed "%A" [946]') +-- assertTrue (os.date ('%b', time) == 'Mar', 'os.date() did not return expected value when passed "%b" [947]') +-- assertTrue (os.date ('%B', time) == 'March', 'os.date() did not return expected value when passed "%B" [948]') +-- assertTrue (os.date ('%d', time) == '01', 'os.date() did not return expected value when passed "%d" [949]') +-- assertTrue (os.date ('%H', time) == '03', 'os.date() did not return expected value when passed "%H" [950]') +-- assertTrue (os.date ('%I', time) == '03', 'os.date() did not return expected value when passed "%I" [951]') +-- assertTrue (os.date ('%j', time) == '060', 'os.date() did not return expected value when passed "%j" [952]') +-- assertTrue (os.date ('%m', time) == '03', 'os.date() did not return expected value when passed "%m" [953]') +-- assertTrue (os.date ('%M', time) == '00', 'os.date() did not return expected value when passed "%M" [954]') +-- assertTrue (os.date ('%p', time) == 'AM', 'os.date() did not return expected value when passed "%p" [955]') +-- assertTrue (os.date ('%S', time) == '00', 'os.date() did not return expected value when passed "%S" [956]') +-- assertTrue (os.date ('%U', time) == '09', 'os.date() did not return expected value when passed "%U" [957]') +-- assertTrue (os.date ('%w', time) == '2', 'os.date() did not return expected value when passed "%w" [958]') +-- assertTrue (os.date ('%W', time) == '09', 'os.date() did not return expected value when passed "%W" [959]') +-- assertTrue (os.date ('%x', time) == '03/01/11', 'os.date() did not return expected value when passed "%x" [960]') +-- assertTrue (os.date ('%X', time) == '03:00:00', 'os.date() did not return expected value when passed "%X" [961]') +-- assertTrue (os.date ('%y', time) == '11', 'os.date() did not return expected value when passed "%y" [962]') +-- assertTrue (os.date ('%Y', time) == '2011', 'os.date() did not return expected value when passed "%Y" [963]') +-- assertTrue (os.date ('%Z', time) == 'GMT', 'os.date() did not return expected value when passed "%Z" [964]') +-- assertTrue (os.date ('%%', time) == '%', 'os.date() did not return expected value when passed "%%" [965]') +assertTrue (os.date ('!%a', time) == 'Tue', 'os.date() did not return expected value when passed "!%a" [966]') +assertTrue (os.date ('!%A', time) == 'Tuesday', 'os.date() did not return expected value when passed "!%A" [967]') +assertTrue (os.date ('!%b', time) == 'Mar', 'os.date() did not return expected value when passed "!%b" [968]') +assertTrue (os.date ('!%B', time) == 'March', 'os.date() did not return expected value when passed "!%B" [969]') +assertTrue (os.date ('!%d', time) == '01', 'os.date() did not return expected value when passed "!%d" [970]') +assertTrue (os.date ('!%H', time) == '03', 'os.date() did not return expected value when passed "!%H" [971]') +assertTrue (os.date ('!%I', time) == '03', 'os.date() did not return expected value when passed "!%I" [972]') +assertTrue (os.date ('!%j', time) == '060', 'os.date() did not return expected value when passed "!%j" [973]') +assertTrue (os.date ('!%m', time) == '03', 'os.date() did not return expected value when passed "!%m" [974]') +assertTrue (os.date ('!%M', time) == '00', 'os.date() did not return expected value when passed "!%M" [975]') +assertTrue (os.date ('!%p', time) == 'AM', 'os.date() did not return expected value when passed "!%p" [976]') +assertTrue (os.date ('!%S', time) == '00', 'os.date() did not return expected value when passed "!%S" [977]') +assertTrue (os.date ('!%U', time) == '09', 'os.date() did not return expected value when passed "!%U" [978]') +assertTrue (os.date ('!%w', time) == '2', 'os.date() did not return expected value when passed "!%w" [979]') +assertTrue (os.date ('!%W', time) == '09', 'os.date() did not return expected value when passed "!%W" [980]') +assertTrue (os.date ('!%x', time) == '03/01/11', 'os.date() did not return expected value when passed "!%x" [981]') +assertTrue (os.date ('!%X', time) == '03:00:00', 'os.date() did not return expected value when passed "!%X" [982]') +assertTrue (os.date ('!%y', time) == '11', 'os.date() did not return expected value when passed "!%y" [983]') +assertTrue (os.date ('!%Y', time) == '2011', 'os.date() did not return expected value when passed "!%Y" [984]') +assertTrue (os.date ('!%Z', time) == 'UTC', 'os.date() did not return expected value when passed "!%Z" [985]') +-- assertTrue (os.date ('*t', time).hour == 3, 'os.date() did not return expected value when passed "*t" [986]') +-- assertTrue (os.date ('*t', time).min == 0, 'os.date() did not return expected value when passed "*t" [987]') +-- assertTrue (os.date ('*t', time).wday == 3, 'os.date() did not return expected value when passed "*t" [988]') +-- assertTrue (os.date ('*t', time).day == 1, 'os.date() did not return expected value when passed "*t" [989]') +-- assertTrue (os.date ('*t', time).month == 3, 'os.date() did not return expected value when passed "*t" [990]') +-- assertTrue (os.date ('*t', time).year == 2011, 'os.date() did not return expected value when passed "*t" [991]') +-- assertTrue (os.date ('*t', time).sec == 0, 'os.date() did not return expected value when passed "*t" [992]') +-- assertTrue (os.date ('*t', time).yday == 60, 'os.date() did not return expected value when passed "*t" [993]') +-- assertTrue (os.date ('*t', time).isdst == false, 'os.date() did not return expected value when passed "*t" [994]') +assertTrue (os.date ('!*t', time).hour == 3, 'os.date() did not return expected value when passed "!*t" [995]') +assertTrue (os.date ('!*t', time).min == 0, 'os.date() did not return expected value when passed "!*t" [996]') +assertTrue (os.date ('!*t', time).wday == 3, 'os.date() did not return expected value when passed "!*t" [997]') +assertTrue (os.date ('!*t', time).day == 1, 'os.date() did not return expected value when passed "!*t" [998]') +assertTrue (os.date ('!*t', time).month == 3, 'os.date() did not return expected value when passed "!*t" [999]') +assertTrue (os.date ('!*t', time).year == 2011, 'os.date() did not return expected value when passed "!*t" [1000]') +assertTrue (os.date ('!*t', time).sec == 0, 'os.date() did not return expected value when passed "!*t" [1001]') +assertTrue (os.date ('!*t', time).yday == 60, 'os.date() did not return expected value when passed "!*t" [1002]') +assertTrue (os.date ('!*t', time).isdst == false, 'os.date() did not return expected value when passed "!*t" [1003]') + +local time = 1325332800 + +-- assertTrue (os.date ('%a', time) == 'Sat', 'os.date() did not return expected value when passed "%a" [1004]') +-- assertTrue (os.date ('%A', time) == 'Saturday', 'os.date() did not return expected value when passed "%A" [1005]') +-- assertTrue (os.date ('%b', time) == 'Dec', 'os.date() did not return expected value when passed "%b" [1006]') +-- assertTrue (os.date ('%B', time) == 'December', 'os.date() did not return expected value when passed "%B" [1007]') +-- assertTrue (os.date ('%d', time) == '31', 'os.date() did not return expected value when passed "%d" [1008]') +-- assertTrue (os.date ('%H', time) == '12', 'os.date() did not return expected value when passed "%H" [1009]') +-- assertTrue (os.date ('%I', time) == '12', 'os.date() did not return expected value when passed "%I" [1010]') +-- assertTrue (os.date ('%j', time) == '365', 'os.date() did not return expected value when passed "%j" [1011]') +-- assertTrue (os.date ('%m', time) == '12', 'os.date() did not return expected value when passed "%m" [1012]') +-- assertTrue (os.date ('%M', time) == '00', 'os.date() did not return expected value when passed "%M" [1013]') +-- assertTrue (os.date ('%p', time) == 'PM', 'os.date() did not return expected value when passed "%p" [1014]') +-- assertTrue (os.date ('%S', time) == '00', 'os.date() did not return expected value when passed "%S" [1015]') +-- assertTrue (os.date ('%U', time) == '52', 'os.date() did not return expected value when passed "%U" [1016]') +-- assertTrue (os.date ('%w', time) == '6', 'os.date() did not return expected value when passed "%w" [1017]') +-- assertTrue (os.date ('%W', time) == '52', 'os.date() did not return expected value when passed "%W" [1018]') +-- assertTrue (os.date ('%x', time) == '12/31/11', 'os.date() did not return expected value when passed "%x" [1019]') +-- assertTrue (os.date ('%X', time) == '12:00:00', 'os.date() did not return expected value when passed "%X" [1020]') +-- assertTrue (os.date ('%y', time) == '11', 'os.date() did not return expected value when passed "%y" [1021]') +-- assertTrue (os.date ('%Y', time) == '2011', 'os.date() did not return expected value when passed "%Y" [1022]') +-- assertTrue (os.date ('%Z', time) == 'GMT', 'os.date() did not return expected value when passed "%Z" [1023]') +-- assertTrue (os.date ('%%', time) == '%', 'os.date() did not return expected value when passed "%%" [1024]') +assertTrue (os.date ('!%a', time) == 'Sat', 'os.date() did not return expected value when passed "!%a" [1025]') +assertTrue (os.date ('!%A', time) == 'Saturday', 'os.date() did not return expected value when passed "!%A" [1026]') +assertTrue (os.date ('!%b', time) == 'Dec', 'os.date() did not return expected value when passed "!%b" [1027]') +assertTrue (os.date ('!%B', time) == 'December', 'os.date() did not return expected value when passed "!%B" [1028]') +assertTrue (os.date ('!%d', time) == '31', 'os.date() did not return expected value when passed "!%d" [1029]') +assertTrue (os.date ('!%H', time) == '12', 'os.date() did not return expected value when passed "!%H" [1030]') +assertTrue (os.date ('!%I', time) == '12', 'os.date() did not return expected value when passed "!%I" [1031]') +assertTrue (os.date ('!%j', time) == '365', 'os.date() did not return expected value when passed "!%j" [1032]') +assertTrue (os.date ('!%m', time) == '12', 'os.date() did not return expected value when passed "!%m" [1033]') +assertTrue (os.date ('!%M', time) == '00', 'os.date() did not return expected value when passed "!%M" [1034]') +assertTrue (os.date ('!%p', time) == 'PM', 'os.date() did not return expected value when passed "!%p" [1035]') +assertTrue (os.date ('!%S', time) == '00', 'os.date() did not return expected value when passed "!%S" [1036]') +assertTrue (os.date ('!%U', time) == '52', 'os.date() did not return expected value when passed "!%U" [1037]') +assertTrue (os.date ('!%w', time) == '6', 'os.date() did not return expected value when passed "!%w" [1038]') +assertTrue (os.date ('!%W', time) == '52', 'os.date() did not return expected value when passed "!%W" [1039]') +assertTrue (os.date ('!%x', time) == '12/31/11', 'os.date() did not return expected value when passed "!%x" [1040]') +assertTrue (os.date ('!%X', time) == '12:00:00', 'os.date() did not return expected value when passed "!%X" [1041]') +assertTrue (os.date ('!%y', time) == '11', 'os.date() did not return expected value when passed "!%y" [1042]') +assertTrue (os.date ('!%Y', time) == '2011', 'os.date() did not return expected value when passed "!%Y" [1043]') +assertTrue (os.date ('!%Z', time) == 'UTC', 'os.date() did not return expected value when passed "!%Z" [1044]') +-- assertTrue (os.date ('*t', time).hour == 12, 'os.date() did not return expected value when passed "*t" [1045]') +-- assertTrue (os.date ('*t', time).min == 0, 'os.date() did not return expected value when passed "*t" [1046]') +-- assertTrue (os.date ('*t', time).wday == 7, 'os.date() did not return expected value when passed "*t" [1047]') +-- assertTrue (os.date ('*t', time).day == 31, 'os.date() did not return expected value when passed "*t" [1048]') +-- assertTrue (os.date ('*t', time).month == 12, 'os.date() did not return expected value when passed "*t" [1049]') +-- assertTrue (os.date ('*t', time).year == 2011, 'os.date() did not return expected value when passed "*t" [1050]') +-- assertTrue (os.date ('*t', time).sec == 0, 'os.date() did not return expected value when passed "*t" [1051]') +-- assertTrue (os.date ('*t', time).yday == 365, 'os.date() did not return expected value when passed "*t" [1052]') +-- assertTrue (os.date ('*t', time).isdst == false, 'os.date() did not return expected value when passed "*t" [1053]') +assertTrue (os.date ('!*t', time).hour == 12, 'os.date() did not return expected value when passed "!*t" [1054]') +assertTrue (os.date ('!*t', time).min == 0, 'os.date() did not return expected value when passed "!*t" [1055]') +assertTrue (os.date ('!*t', time).wday == 7, 'os.date() did not return expected value when passed "!*t" [1056]') +assertTrue (os.date ('!*t', time).day == 31, 'os.date() did not return expected value when passed "!*t" [1057]') +assertTrue (os.date ('!*t', time).month == 12, 'os.date() did not return expected value when passed "!*t" [1058]') +assertTrue (os.date ('!*t', time).year == 2011, 'os.date() did not return expected value when passed "!*t" [1059]') +assertTrue (os.date ('!*t', time).sec == 0, 'os.date() did not return expected value when passed "!*t" [1060]') +assertTrue (os.date ('!*t', time).yday == 365, 'os.date() did not return expected value when passed "!*t" [1061]') +assertTrue (os.date ('!*t', time).isdst == false, 'os.date() did not return expected value when passed "!*t" [1062]') diff --git a/tests/starlight/lib-loadfile.lua b/tests/starlight/lib-loadfile.lua new file mode 100644 index 0000000..a3f8382 --- /dev/null +++ b/tests/starlight/lib-loadfile.lua @@ -0,0 +1,18 @@ + +-- Implicit in the fact that it's already using assertTrue() +assertTrue (mainGlobal2 == 'mainGlbl', 'Files loaded by loadfile() should have access to the same global namespace') +assertTrue (mainLocal == nil, 'Files loaded by loadfile() should not have access to the local scope of the caller') + +local testModName = ... +assertTrue (testModName == nil, 'Files loaded by loadfile() should not be passed any values in varargs.') + + +mainGlobal1 = 'innerGlbl' +local innerLocal = 'innerLoc' + + +return { + getValue = function () + return 'moo' + end +} diff --git a/tests/starlight/lib-math.lua b/tests/starlight/lib-math.lua new file mode 100644 index 0000000..7dd8969 --- /dev/null +++ b/tests/starlight/lib-math.lua @@ -0,0 +1,168 @@ + +-- abs + +local a = math.abs (10) +local b = math.abs (-20) +local c = math.abs (2.56) +local d = math.abs (-34.67) +local e = math.abs (-0) + +assertTrue (a == 10, 'math.abs() should return the passed argument if it is positive') +assertTrue (b == 20, 'math.abs() should return the positive form of the passed argument if it is negative') +assertTrue (c == 2.56, 'math.abs() should return the passed argument if it is a positive floating point number') +assertTrue (d == 34.67, 'math.abs() should return the positive form of the passed argument if it is a positive floating point number') +assertTrue (e == 0, 'math.abs() should return zero if passed zero') + + + + +-- math.acos +-- math.cos + + +local a = math.acos (1) +--local b = math.acos (math.cos (0.3)) +local c = math.cos (0) +--local d = math.cos (math.acos (0.3)) + +assertTrue (a == 0, 'math.acos() should return 0 when passed 1') +--assertTrue (b == 0.3, 'math.acos() should return x when passed math.cos(x)') +assertTrue (c == 1, 'math.cos() should return 1 when passed 0') +--assertTrue (d == 0.3, 'math.cos() should return x when passed math.acos(x)') + + + + +-- math.asin +-- math.sin + + +local a = math.asin (0) +--local b = math.asin (math.sin (90)) +local c = math.sin (0) +local d = math.sin (math.asin (0.2)) + +assertTrue (a == 0, 'math.asin() should return 0 when passed 0') +--assertTrue (b == 90, 'math.asin() should return x when passed math.sin(x)') +assertTrue (c == 0, 'math.sin() should return 0 when passed 0') +assertTrue (d == 0.2, 'math.sin() should return x when passed math.asin(x)') + + + + +-- math.atan +-- math.tan + + +local a = math.atan (0) +--local b = math.atan (math.tan (0.3)) +local c = math.tan (0) +local d = math.tan (math.atan (0.3)) + +assertTrue (a == 0, 'math.atan() should return 0 when passed 0') +--assertTrue (b == 0.3, 'math.atan() should return x when passed math.tan(x)') +assertTrue (c == 0, 'math.tan() should return 0 when passed 0') +assertTrue (d == 0.3, 'math.tan() should return x when passed math.atan(x)') + + + + +-- math.ceil + +local a = math.ceil (14) +local b = math.ceil (14.45) +local c = math.ceil (14.5) +local d = math.ceil (0.1) +local e = math.ceil (0.6) +local f = math.ceil (-0.6) +local g = math.ceil (-122.4) + +assertTrue (a == 14, 'math.ceil() should round up to the next integer [1]') +assertTrue (b == 15, 'math.ceil() should round up to the next integer [2]') +assertTrue (c == 15, 'math.ceil() should round up to the next integer [3]') +assertTrue (d == 1, 'math.ceil() should round up to the next integer [4]') +assertTrue (e == 1, 'math.ceil() should round up to the next integer [5]') +assertTrue (f == 0, 'math.ceil() should round up to the next integer [6]') +assertTrue (g == -122, 'math.ceil() should round up to the next integer [7]') + + + + +-- math.deg + +a = math.deg (0) +b = math.deg (math.pi) +c = math.deg (math.pi * 2) +d = math.deg (math.pi / 2) + +assertTrue (a == 0, 'math.deg() should return 0 when passed zero') +assertTrue (b == 180, 'math.deg() should return 180 when passed Pi') +assertTrue (c == 360, 'math.deg() should return 360 when passed 2Pi') +assertTrue (d == 90, 'math.deg() should return 90 when passed Pi/2') + + + +--math.frexp + +a, b = math.frexp(63) +assertTrue (a == 0.984375, 'math.frexp should return the correct mantissa when passed a positive number.') +assertTrue (b == 6, 'math.frexp should return the correct exponent when passed a positive number.') + +a, b = math.frexp(-63) +assertTrue (a == -0.984375, 'math.frexp should return the correct mantissa when passed a negative number.') +assertTrue (b == 6, 'math.frexp should return the correct exponent when passed a negative number.') + +a, b = math.frexp(0) +assertTrue (a == 0, 'math.frexp should return a zero mantissa when passed zero.') +assertTrue (b == 0, 'math.frexp should return a zero exponent when passed zero.') + + + + +--math.huge + +a = math.huge + 1 +b = -math.huge - 1 + +assertTrue (a == math.huge, 'math.huge should not change value with addition.') +assertTrue (b == -math.huge, 'Negative math.huge should not change value with subtraction.') + + + + +-- math.rad + +a = math.rad (0) +b = math.rad (180) +c = math.rad (270) +d = math.rad (360) +e = math.rad (450) +f = math.rad (-180) + +assertTrue (a == 0, 'math.rad() should return 0 when passed zero') +assertTrue (b == math.pi, 'math.rad() should return Pi when passed 180') +assertTrue (c == 1.5 * math.pi, 'math.rad() should return 1.5*Pi when passed 270') +assertTrue (d == 2 * math.pi, 'math.rad() should return 2*Pi when passed 360') +assertTrue (e == 2.5 * math.pi, 'math.rad() should return 2.5*Pi when passed 450') +assertTrue (f == -math.pi, 'math.rad() should return -Pi when passed -180') + + +-- math.random + +a = math.random() +b = math.random() + +assertTrue (a == 16807 / 2147483647, 'math.random() should initialise with a value of 1') +assertTrue (b == ((16807 * a * 2147483647) % 2147483647) / 2147483647, 'math.random() should follow the right sequence [1]') + + + +-- math.randomseed + +math.randomseed(123) + +c = math.random() +d = math.random() + +assertTrue (c == ((16807 * 123) % 2147483647) / 2147483647, 'math.random() should follow the right sequence [2]') +assertTrue (d == ((16807 * c * 2147483647) % 2147483647) / 2147483647, 'math.random() should follow the right sequence [3]') diff --git a/tests/starlight/lib-require.lua b/tests/starlight/lib-require.lua new file mode 100644 index 0000000..caf7aae --- /dev/null +++ b/tests/starlight/lib-require.lua @@ -0,0 +1,26 @@ + +-- Implicit in the fact that it's already using assertTrue() +assertTrue (mainGlobal2 == 'mainGlbl', 'Modules should have access to the same global namespace') +assertTrue (mainLocal == nil, 'Modules should not have access to the local scope of the caller') + +local testModName = ... +assertTrue (testModName == 'lib-require', 'A module\'s name should be passed into the module using varargs.') + + +local sub = require 'lib-require.sub-module' -- test dot syntax +assertTrue(type(sub) == 'table', 'Module should be able to load more modules using dot syntax.') + +local sub2 = require 'lib-require/sub-module' -- test slash syntax +assertTrue(type(sub2) == 'table', 'Module should be able to load more modules using slash syntax.') + +mainGlobal1 = 'innerGlbl' +local innerLocal = 'innerLoc' + +moduleInitCount = moduleInitCount + 1 + + +return { + getValue = function () + return 'modVal' + end +} diff --git a/tests/starlight/lib-require/sub-module.lua b/tests/starlight/lib-require/sub-module.lua new file mode 100644 index 0000000..93dd16b --- /dev/null +++ b/tests/starlight/lib-require/sub-module.lua @@ -0,0 +1,4 @@ + +return { + moo = 1 +} diff --git a/tests/starlight/lib-string.lua b/tests/starlight/lib-string.lua new file mode 100644 index 0000000..59f9749 --- /dev/null +++ b/tests/starlight/lib-string.lua @@ -0,0 +1,616 @@ + +-- byte + +local a, b = string.byte ('Mo0') + +assertTrue (a == 77, 'string.byte() should return the numerical code for the first character in the first returned item') +assertTrue (b == nil, 'string.byte() should return only one item when no length is given [1]') + + +local a, b = string.byte ('Mo0', 2) + +assertTrue (a == 111, 'string.byte() should return the numerical code for the nth character in the first returned item, when n is specified in the second argument [1]') +assertTrue (b == nil, 'string.byte() should return only one item when no length is given [2]') + + +local a, b, c = string.byte ('Mo0', 2, 3) + +assertTrue (a == 111, 'string.byte() should return the numerical code for the nth character in the first returned item, when n is specified in the second argument [2]') +assertTrue (b == 48, 'string.byte() should return the numerical code for the nth character in the first returned item, when n is specified in the second argument [3]') +assertTrue (c == nil, 'string.byte() should return only the number of items specified in the length argument or the up to the end of the string, whichever is encountered first [1]') + + +local a, b, c = string.byte ('Mo0', 3, 20) + +assertTrue (a == 48, 'string.byte() should return the numerical code for the nth character in the first returned item, when n is specified in the second argument [4]') +assertTrue (b == nil, 'string.byte() should return only the number of items specified in the length argument or the up to the end of the string, whichever is encountered first [2]') + + + + +-- char + +local a = string.char () +local b = string.char (116, 101, 115, 116, 105, 99, 108, 101, 115) + +assertTrue (a == '', 'string.byte() should return an empty string when called with no arguments') +assertTrue (b == 'testicles', 'string.byte() should return a string comprising of characters representing by the value each of the arguments passed') + + + + +-- -- dump + +-- local f = function () end +-- local a = string.dump(f) +-- assertTrue (type(a) == 'string', 'string.dump() should return a string when called with a function') + +-- local s = string.dump(function () return 'bar' end) +-- f = load(s) +-- assertTrue (type(f) == 'function', 'load() should create a function from the output of string.dump() [1]') + +-- result = f() +-- assertTrue (result == 'bar', 'The result of load(string.dump(f)) should behave the same as f() [1]') + +-- function namedFuncWithParams (a, b) +-- return a..b +-- end + +-- s = string.dump(namedFuncWithParams) +-- f = load(s) +-- assertTrue (type(f) == 'function', 'load() should create a function from the output of string.dump() [2]') + +-- result = f('hel','lo') +-- assertTrue (result == 'hello', 'The result of load(string.dump(f)) should behave the same as f() [2]') + + + + + +-- find + +local a = 'The quick brown fox' + +local b = string.find (a, 'quick'); +local c = string.find (a, 'fox'); +local d = string.find (a, 'kipper'); +local e = string.find (a, ''); + +local f = string.find (a, 'quick', 8); +local g = string.find (a, 'fox', 8); + +assertTrue (b == 5, 'string.find() should return the location of the first occurrence of the second argument within the first, if it is present [1]') +assertTrue (c == 17, 'string.find() should return the location of the first occurrence of the second argument within the first, if it is present [2]') +assertTrue (d == nil, 'string.find() should return nil if the second argument is not contained within the first [1]') +assertTrue (e == 1, 'string.find() should return return 1 if the second argument is an empty string') +assertTrue (f == nil, 'string.find() should return nil if the second argument is not contained within the first after the index specified by the third argument') +assertTrue (g == 17, 'string.find() should return the location of the second argument if it is contained within the first after the index specified by the third argument') + +local b, c, d, e = string.find (a, 'q(.)(.)'); +assertEqual (b, 5, 'string.find() should return the location of the first occurrence of the second argument within the first, if it is present [3]') +assertEqual (c, 7, 'string.find() should return the location of the last character of the first occurrence of the second argument within the first, if it is present') +assertEqual (d, 'u', 'string.find() should return the groups that are specified in the regex. [1]') +assertEqual (e, 'i', 'string.find() should return the groups that are specified in the regex. [2]') + +b = string.find('[', '[_%w]') +assertTrue (b == nil, 'string.find() should not return the location of special syntax [ and ].') + +local a = [[The quick +brown fox]] +b = string.find(a, 'The .* fox') +assertTrue (b == 1, 'The dot pattern should match across lines in string.find()') + + + +-- format + +do + local a = string.format("%s %q", "Hello", "Lua user!") + local b = string.format("%c%c%c", 76,117,97) -- char + local c = string.format("%e, %E", math.pi,math.pi) -- exponent + local d1 = string.format("%f", math.pi) -- float + local d2 = string.format("%g", math.pi) -- compact float + +-- issues: + local e = string.format("%d, %i, %u", -100,-100,-100) -- signed, signed, unsigned integer + local f = string.format("%o, %x, %X", -100,-100,-100) -- octal, hex, hex + + local g = string.format("%%s", 100) + + assertTrue (a == 'Hello "Lua user!"', 'string.format() should format %s and %q correctly') + assertTrue (b == 'Lua', 'string.format() should format %c correctly') + assertTrue (d1 == '3.141593', 'string.format() should format %f correctly') + assertTrue (e == '-100, -100, 4294967196', 'string.format() should format %d, %i and %u correctly') + assertTrue (f == '37777777634, ffffff9c, FFFFFF9C', 'string.format() should format %o, %x and %X correctly') + -- 64bit required + -- assertTrue (e == '-100, -100, 18446744073709551516', 'string.format() should format %d, %i and %u correctly') + -- assertTrue (f == '1777777777777777777634, ffffffffffffff9c, FFFFFFFFFFFFFF9C', 'string.format() should format %o, %x and %X correctly') + assertTrue (g == '%s', 'string.format() should format %% correctly') + + assertTrue (c == '3.141593e+00, 3.141593E+00', 'string.format() should format %e and %E correctly') + assertTrue (d2 == '3.14159', 'string.format() should format %g correctly') + + + a = function () string.format("%*", 100) end + b = function () string.format("%l", 100) end + c = function () string.format("%L", 100) end + d = function () string.format("%n", 100) end + e = function () string.format("%p", 100) end + f = function () string.format("%h", 100) end + + assertTrue (not pcall(a), 'string.format() should error when passed %*') + assertTrue (not pcall(b), 'string.format() should error when passed %l') + assertTrue (not pcall(c), 'string.format() should error when passed %L') + assertTrue (not pcall(d), 'string.format() should error when passed %n') + assertTrue (not pcall(e), 'string.format() should error when passed %p') + assertTrue (not pcall(f), 'string.format() should error when passed %h') + + + a = string.format("%.3f", 5.3) + b = "Lua version " .. string.format("%.1f", 5.3) + c = string.format("pi = %.4f", math.pi) + f = string.format("%.3f", 5) + + local d, m, y = 5, 11, 1990 + e = string.format("%02d/%02d/%04d", d, m, y) + + + assertTrue (a == '5.300', 'string.format() should format floating point numbers correctly[1]') + assertTrue (b == 'Lua version 5.3', 'string.format() should format floating point numbers correctly[2]') + assertTrue (c == 'pi = 3.1416', 'string.format() should format floating point numbers correctly[3]') + assertTrue (e == '05/11/1990', 'string.format() should format decimals correctly [0]') + assertTrue (f == '5.000', 'string.format() should format floating point numbers correctly[4]') + + + a = function () string.format('%#####s', 'x') end + b = function () string.format('%######s', 'x') end + + assertTrue (pcall(a), 'string.format() should handle five flags') + assertTrue (not pcall(b), 'string.format() should not handle six flags') + + + local tag, title = "h1", "a title" + a = string.format("<%s>%s", tag, title, tag) + b = string.format("%8s", "Lua") + c = string.format("%.8s", "Lua") + d = string.format("%.2s", "Lua") + e = string.format("%8.2s", "Lua") + f = string.format("%+8.2s", "Lua") + g = string.format("%-8.2s", "Lua") + local h = string.format("%08.2s", "Lua") + local i = string.format("%#8.2s", "Lua") + local j = string.format("% 8.2s", "Lua") + local k = string.format("%+-0# 8.2s", "Lua") + local l = string.format("%0.2s", "Lua") + + assertTrue (a == '

a title

', 'string.format() should format strings correctly[1]') + assertTrue (b == ' Lua', 'string.format() should format strings correctly[2]') + assertTrue (c == 'Lua', 'string.format() should format strings correctly[3]') + assertTrue (d == 'Lu', 'string.format() should format strings correctly[4]') + assertTrue (e == ' Lu', 'string.format() should format strings correctly[5]') + assertTrue (f == ' Lu', 'string.format() should format strings correctly[6]') + assertTrue (g == 'Lu ', 'string.format() should format strings correctly[7]') + assertTrue (h == '000000Lu', 'string.format() should format strings correctly[8]') + assertTrue (i == ' Lu', 'string.format() should format strings correctly[9]') + assertTrue (j == ' Lu', 'string.format() should format strings correctly[10]') + assertTrue (k == 'Lu ', 'string.format() should format strings correctly[11]') + assertTrue (l == 'Lu', 'string.format() should format strings correctly[12]') + + + a = string.format("%8d", 123.45) + b = string.format("%.8d", 123.45) + c = string.format("%.2d", 123.45) + d = string.format("%8.2d", 123.45) + e = string.format("%+8.2d", 123.45) + f = string.format("%-8.2d", 123.45) + g = string.format("%08.2d", 123.45) + h = string.format("%#8.2d", 123.45) + i = string.format("% 8.2d", 123.45) + j = string.format("%+-0# 8.2d", 123.45) + k = string.format("%0.2d", 123.45) + l = string.format("%+.8d", 123.45) + local m = string.format("%-.8d", 123.45) + local n = string.format("%#.8d", 123.45) + local o = string.format("%0.8d", 123.45) + local p = string.format("% .8d", 123.45) + local q = string.format("%+-#0 .8d", 123.45) + local r = string.format("%8.5d", 123.45) + local s = string.format("%+8.5d", 123.45) + local t = string.format("%-8.5d", 123.45) + local u = string.format("%-+8.5d", 123.45) + local v = string.format("%5d", 12.3e8) + local w = string.format("%.d", 123.45) + + assertTrue (a == ' 123', 'string.format() should format decimals correctly[1]') + assertTrue (b == '00000123', 'string.format() should format decimals correctly[2]') + assertTrue (c == '123', 'string.format() should format decimals correctly[3]') + assertTrue (d == ' 123', 'string.format() should format decimals correctly[4]') + assertTrue (e == ' +123', 'string.format() should format decimals correctly[5]') + assertTrue (f == '123 ', 'string.format() should format decimals correctly[6]') + assertTrue (g == ' 123', 'string.format() should format decimals correctly[7]') + assertTrue (h == ' 123', 'string.format() should format decimals correctly[8]') + assertTrue (i == ' 123', 'string.format() should format decimals correctly[9]') + assertTrue (j == '+123 ', 'string.format() should format decimals correctly[10]') + assertTrue (k == '123', 'string.format() should format decimals correctly[11]') + assertTrue (l == '+00000123', 'string.format() should format decimals correctly[12]') + assertTrue (m == '00000123', 'string.format() should format decimals correctly[13]') + assertTrue (n == '00000123', 'string.format() should format decimals correctly[14]') + assertTrue (o == '00000123', 'string.format() should format decimals correctly[15]') + assertTrue (p == ' 00000123', 'string.format() should format decimals correctly[16]') + assertTrue (q == '+00000123', 'string.format() should format decimals correctly[17]') + assertTrue (r == ' 00123', 'string.format() should format decimals correctly[18]') + assertTrue (s == ' +00123', 'string.format() should format decimals correctly[19]') + assertTrue (t == '00123 ', 'string.format() should format decimals correctly[20]') + assertTrue (u == '+00123 ', 'string.format() should format decimals correctly[21]') + assertTrue (v == '1230000000', 'string.format() should format decimals correctly[22]') + assertTrue (w == '123', 'string.format() should format decimals correctly[23]') + + a = string.format("%8d", -123.45) + b = string.format("%.8d", -123.45) + c = string.format("%.2d", -123.45) + d = string.format("%8.2d", -123.45) + e = string.format("%+8.2d", -123.45) + f = string.format("%-8.2d", -123.45) + g = string.format("%08.2d", -123.45) + h = string.format("%#8.2d", -123.45) + i = string.format("% 8.2d", -123.45) + j = string.format("%+-0# 8.2d", -123.45) + k = string.format("%0.2d", -123.45) + l = string.format("%+.8d", -123.45) + m = string.format("%-.8d", -123.45) + n = string.format("%#.8d", -123.45) + o = string.format("%0.8d", -123.45) + p = string.format("% .8d", -123.45) + q = string.format("%+-#0 .8d", -123.45) + r = string.format("%8.5d", -123.45) + s = string.format("%+8.5d", -123.45) + t = string.format("%-8.5d", -123.45) + u = string.format("%-+8.5d", -123.45) + v = string.format("%5d", -12.3e8) + w = string.format("%.d", -123.45) + + + assertTrue (a == ' -123', 'string.format() should format decimals correctly[31]') + assertTrue (b == '-00000123', 'string.format() should format decimals correctly[32]') + assertTrue (c == '-123', 'string.format() should format decimals correctly[33]') + assertTrue (d == ' -123', 'string.format() should format decimals correctly[34]') + assertTrue (e == ' -123', 'string.format() should format decimals correctly[35]') + assertTrue (f == '-123 ', 'string.format() should format decimals correctly[36]') + assertTrue (g == ' -123', 'string.format() should format decimals correctly[37]') + assertTrue (h == ' -123', 'string.format() should format decimals correctly[38]') + assertTrue (i == ' -123', 'string.format() should format decimals correctly[39]') + assertTrue (j == '-123 ', 'string.format() should format decimals correctly[40]') + assertTrue (k == '-123', 'string.format() should format decimals correctly[41]') + assertTrue (l == '-00000123', 'string.format() should format decimals correctly[42]') + assertTrue (m == '-00000123', 'string.format() should format decimals correctly[43]') + assertTrue (n == '-00000123', 'string.format() should format decimals correctly[44]') + assertTrue (o == '-00000123', 'string.format() should format decimals correctly[45]') + assertTrue (p == '-00000123', 'string.format() should format decimals correctly[46]') + assertTrue (q == '-00000123', 'string.format() should format decimals correctly[47]') + assertTrue (r == ' -00123', 'string.format() should format decimals correctly[48]') + assertTrue (s == ' -00123', 'string.format() should format decimals correctly[49]') + assertTrue (t == '-00123 ', 'string.format() should format decimals correctly[50]') + assertTrue (u == '-00123 ', 'string.format() should format decimals correctly[51]') + assertTrue (v == '-1230000000', 'string.format() should format decimals correctly[52]') + assertTrue (w == '-123', 'string.format() should format decimals correctly[53]') + + + a = string.format("%+05.d", 123.45) + b = string.format("%05d", 123.45) + c = string.format("%05d", -123.45) + d = string.format("%+05d", 123.45) + + assertTrue (a == ' +123', 'string.format() should format decimals correctly[60]') + assertTrue (b == '00123', 'string.format() should format decimals correctly[61]') + assertTrue (c == '-0123', 'string.format() should format decimals correctly[62]') + assertTrue (d == '+0123', 'string.format() should format decimals correctly[63]') + + + + a = string.format("%8f", 123.45) + b = string.format("%.8f", 123.45) + c = string.format("%.1f", 123.45) + d = string.format("%8.2f", 123.45) + e = string.format("%+8.2f", 123.45) + f = string.format("%-8.3f", 123.45) + g = string.format("%08.3f", 123.45) + h = string.format("%#8.3f", 123.45) + i = string.format("% 8.3f", 123.45) + j = string.format("%+-0# 8.2f", 123.45) + k = string.format("%0.2f", 123.45) + l = string.format("%+.8f", 123.45) + m = string.format("%-.8f", 123.45) + n = string.format("%#.8f", 123.45) + o = string.format("%9.3f", 123.45) + p = string.format("%+9.3f", 123.45) + q = string.format("%-9.3f", 123.45) + r = string.format("%-+9.3f", 123.45) + s = string.format("%.0f", 123.45) + t = string.format("%.4f", 123.05) + + assertTrue (a == '123.450000', 'string.format() should format floats correctly[1]') + assertTrue (b == '123.45000000', 'string.format() should format floats correctly[2]') + assertTrue (c == '123.5', 'string.format() should format floats correctly[3]') + assertTrue (d == ' 123.45', 'string.format() should format floats correctly[4]') + assertTrue (e == ' +123.45', 'string.format() should format floats correctly[5]') + assertTrue (f == '123.450 ', 'string.format() should format floats correctly[6]') + assertTrue (g == '0123.450', 'string.format() should format floats correctly[7]') + assertTrue (h == ' 123.450', 'string.format() should format floats correctly[8]') + assertTrue (i == ' 123.450', 'string.format() should format floats correctly[9]') + assertTrue (j == '+123.45 ', 'string.format() should format floats correctly[10]') + assertTrue (k == '123.45', 'string.format() should format floats correctly[11]') + assertTrue (l == '+123.45000000', 'string.format() should format floats correctly[12]') + assertTrue (m == '123.45000000', 'string.format() should format floats correctly[13]') + assertTrue (n == '123.45000000', 'string.format() should format floats correctly[14]') + assertTrue (o == ' 123.450', 'string.format() should format floats correctly[15]') + assertTrue (p == ' +123.450', 'string.format() should format floats correctly[16]') + assertTrue (q == '123.450 ', 'string.format() should format floats correctly[17]') + assertTrue (r == '+123.450 ', 'string.format() should format floats correctly[18]') + assertTrue (s == '123', 'string.format() should format floats correctly[19]') + assertTrue (t == '123.0500', 'string.format() should format floats correctly[20]') + + + a = string.format("%x", 123) + b = string.format("%x", 123.45) + c = string.format("%x", -123) + d = string.format("%4x", 123) + e = string.format("%.4x", 123) + f = string.format("%8.4x", 123) + g = string.format("%+8.4x", 123) + h = string.format("%-8.4x", 123) + i = string.format("%#8.4x", 123) + j = string.format("%08.4x", 123) + k = string.format("% 8.4x", 123) + l = string.format("%+-#0 8.4x", 123) + m = string.format("%08x", 123) + n = string.format("% x", 123) + + assertTrue (a == '7b', 'string.format() should format hex correctly[1]') + assertTrue (b == '7b', 'string.format() should format hex correctly[2]') + assertTrue (c == 'ffffff85', 'string.format() should format hex correctly[3]') + assertTrue (d == ' 7b', 'string.format() should format hex correctly[4]') + assertTrue (e == '007b', 'string.format() should format hex correctly[5]') + assertTrue (f == ' 007b', 'string.format() should format hex correctly[6]') + assertTrue (g == ' 007b', 'string.format() should format hex correctly[7]') + assertTrue (h == '007b ', 'string.format() should format hex correctly[8]') + assertTrue (i == ' 0x007b', 'string.format() should format hex correctly[9]') + assertTrue (k == ' 007b', 'string.format() should format hex correctly[11]') + assertTrue (l == '0x007b ', 'string.format() should format hex correctly[12]') + assertTrue (n == '7b', 'string.format() should format hex correctly[14]') + + + a = string.format("%8.2f\n", 1.234) + b = string.format("\n%8.2f", 1.234) + c = string.format("\n%8.2f\n", 1.234) + + assertTrue (a == ' 1.23\n', 'string.format() should correctly format patterns that contain new lines.[1]') + assertTrue (b == '\n 1.23', 'string.format() should correctly format patterns that contain new lines.[2]') + assertTrue (c == '\n 1.23\n', 'string.format() should correctly format patterns that contain new lines.[3]') + + + assertTrue (j == ' 007b', 'string.format() should format hex correctly[10]') + assertTrue (m == '0000007b', 'string.format() should format hex correctly[13]') + +end + + + + +-- gmatch + +local s = "from=world, to=Lua" +local x = string.gmatch(s, "(%w+)=(%w+)") + +assertTrue (type(x) == 'function', 'string.gmatch() should return an iterator function') + +local a, b, c = x() +assertTrue (a == 'from', 'string.gmatch() iterator should return the first group matched in the string [1]') +assertTrue (b == 'world', 'string.gmatch() iterator should return the second group matched in the string [1]') +assertTrue (c == nil, 'string.gmatch() iterator should return nil after all groups are matched [1]') + +local a, b, c = x() +assertTrue (a == 'to', 'string.gmatch() iterator should return the first group matched in the string [2]') +assertTrue (b == 'Lua', 'string.gmatch() iterator should return the second group matched in the string [2]') +assertTrue (c == nil, 'string.gmatch() iterator should return nil after all groups are matched [2]') + +local a = x() +assertTrue (a == nil, 'string.gmatch() iterator should return nil after all matches have ben returned') + + +local x = string.gmatch(s, "%w+=%w+") +local a, b = x() +assertTrue (a == 'from=world', 'string.gmatch() iterator should return the first match when no groups are specified') +assertTrue (b == nil, 'string.gmatch() iterator should return nil as second return value when no groups are specified [1]') + +local a, b = x() +assertTrue (a == 'to=Lua', 'string.gmatch() iterator should return the second match when no groups are specified') +assertTrue (b == nil, 'string.gmatch() iterator should return nil as second return value when no groups are specified [2]') + +do + local x = string.gmatch(';a;', 'a*') + local a, b, c, d, e, f = x(), x(), x(), x(), x(), x(); + + assertEqual (a, '', 'string.gmatch() iterator should return correct values [1]') + assertEqual (b, 'a', 'string.gmatch() iterator should return correct values [2]') + assertEqual (c, '', 'string.gmatch() iterator should return correct values [3]') + assertEqual (d, '', 'string.gmatch() iterator should return correct values [4]') + assertEqual (e, nil, 'string.gmatch() iterator should return correct values [5]') + assertEqual (e, nil, 'string.gmatch() iterator should return correct values [6]') +end + + + +-- gsub + +a = '<%?xml version="1.0" encoding="UTF%-8"%?>' +b = '' + +c = string.gsub (b, a, 'moo') + +assertTrue (c == 'moo', 'string.gsub() should replace the matched part of the string[1]') +-- Not even scraping the surface + +a = '%%1' +b = 'Hello %1' + +c = string.gsub (b, a, 'world') +assertTrue (c == 'Hello world', 'string.gsub() should replace the matched part of the string[2]') + + +a = '%d' +b = 'ab5kfd8scf4lll' +c = function (x) return '('..x..')' end + +d = string.gsub (b, a, c, 2) +assertTrue (d == 'ab(5)kfd(8)scf4lll', 'string.gsub() should replace the matched part of the string with the value returned from the given map function') + + +a = "[^:]+" +b = ":aa:bbb:cccc:ddddd:eee:" +c = function (subStr) end + +d = string.gsub (b, a, c) +assertTrue (d == ':aa:bbb:cccc:ddddd:eee:', 'string.gsub() should not replace the matched part of the string if the value returned from the map function is nil') + +c = function (subStr) return 'X' end + +d = string.gsub (b, a, c) +assertTrue (d == ':X:X:X:X:X:', 'string.gsub() should replace the matched part of the string if the value returned from the map function is not nil') + + +c = string.gsub (';a;', 'a*', 'ITEM') +assertTrue (c == 'ITEM;ITEMITEM;ITEM', 'string.gsub() should replace the matched part of the string[2]') + +a = 'abc\\def' +b = string.gsub(a, '\\', '\\\\') +assertEqual (b, 'abc\\\\def', 'string.gsub() should allow backslashes') + +a = "a = 'a', b = 'b', c = 'c'," +b = string.gsub(a, ",$", "") +assertEqual (b, "a = 'a', b = 'b', c = 'c'", 'string.gsub() should match $ with end of string') + + + +-- len + +local a = 'McLaren Mercedes' + +local b = string.len (''); +local c = string.len (a); + +assertTrue (b == 0, 'string.len() should return 0 if passed an empty string') +assertTrue (c == 16, 'string.len() should return the length of the string in the first argument') + + + + + +-- lower + +local a = 'McLaren Mercedes' + +local b = string.lower (''); +local c = string.lower (a); + +assertTrue (b == '', 'string.lower() should return an empty string if passed an empty string') +assertTrue (c == 'mclaren mercedes', 'string.lower() should return the string in the first argument with all character in lower case') + + + + + +-- match + +local a = string.match('20/11/1988', "^%d+%p%d+%p%d%d%d%d$") +assertEqual (a, '20/11/1988', 'string.match() should handle punctuation.') + +local a = ('foo@bar.com'):match("^[%w+%.%-_]+@[%w+%.%-_]+%.%a%a+$") + +local a = ('test-123_test.2@a-b_c.movie'):match("^[%w+%.%-_]+@[%w+%.%-_]+%.%a%a+$") +assertEqual (a, 'test-123_test.2@a-b_c.movie', 'string.match() should flatten nested groups.') + +local a = ('-=[]\';'):match("%W") +assertEqual (a, '-', 'string.match() match non-word chars.') + + + + + +-- rep + +local a = 'Ho' + +local b = string.rep (a, 0); +local c = string.rep (a, 1); +local d = string.rep (a, 3); + +assertTrue (b == '', 'string.rep() should return an empty string if the second argument is 0') +assertTrue (c == 'Ho', 'string.rep() should return the first argument if the second argument is 1') +assertTrue (d == 'HoHoHo', 'string.rep() should return a string containing the first argument repeated the second argument number of times') + + + + +-- reverse + +local a = string.reverse (''); +local b = string.reverse ('x'); +local c = string.reverse ('tpircSavaJ'); + +assertTrue (a == '', 'string.reverse() should return an empty string if passed an empty string') +assertTrue (b == 'x', 'string.reverse() should return the first argument if its length is 1') +assertTrue (c == 'JavaScript', 'string.reverse() should return a string containing the first argument reversed') + + + + +-- sub + +local a = 'Pub Standards' + +local b = string.sub (a, 1) +local c = string.sub (a, 5) +local d = string.sub (a, -4) + +local e = string.sub (a, 1, 3) +local f = string.sub (a, 7, 9) +local g = string.sub (a, -4, -2) + +local h = string.sub (a, 5, -2) +local i = string.sub (a, 0) + +assertTrue (b == 'Pub Standards', 'string.sub() should return the first argument if the second argument is 1') +assertTrue (c == 'Standards', 'string.sub() should return a subset of the first argument from the nth character onwards, when n is the second argument and positive') +assertTrue (d == 'ards', 'string.sub() should return the last n characters of the first argument, where n is the absolute value of the second argument and the second argument is negative') +assertTrue (e == 'Pub', 'string.sub() should return the first n characters of the first argument when the second argument is one and n is the third argument') +assertTrue (f == 'and', 'string.sub() should return a subset of the first argument from the nth character to the mth character, when n is the second argument and positive and m is the third argument and negative') + + +assertTrue (h == 'Standard', 'string.sub() should return a subset of the first argument from the nth character to the last but mth character, when n is the second argument and positive and m is the third argument and negative') +assertTrue (i == 'Pub Standards', 'string.sub() should return a subset of the first argument from the last but nth character to the last but mth character, when n is the second argument and negative and m is the third argument and negative') + + + + +-- upper + +local a = string.upper (''); +local b = string.upper ('JavaScript'); + +assertTrue (a == '', 'string.upper() should return an empty string if passed an empty string') +assertTrue (b == 'JAVASCRIPT', 'string.upper() should return the first argument in uppercase') + + + + +-- `string` lib as metatable of strings. +local strMeta = getmetatable('') +assertEqual (strMeta.__index, string, 'String lib should be metamethod of string instances.') + +a = ('Hey'):lower() +assertEqual (a, 'hey', 'String lib should be metamethod of string instances.') + + +local foo = "bar" +getmetatable(foo).__index = function () return "Random String" end +assertEqual (foo.random_index, "Random String", 'Metamethod of string instances should be updateable') diff --git a/tests/starlight/lib-table.lua b/tests/starlight/lib-table.lua new file mode 100644 index 0000000..a9ba2dd --- /dev/null +++ b/tests/starlight/lib-table.lua @@ -0,0 +1,302 @@ + +-- concat + +local a = {2, 4, "moo", 102} + +local b = table.concat ({}) +local c = table.concat ({}, ':') +local d = table.concat ({}, ', ', 3) +local e = table.concat ({}, ', ', 3, 4) + +local f = table.concat (a) +local g = table.concat (a, '-') +local h = table.concat (a, '..', 2) +local i = table.concat (a, '+', 2, 3) + +assertTrue (b == '', 'table.concat() should return an empty string if passed an empty table [1]') +assertTrue (c == '', 'table.concat() should return an empty string if passed an empty table [2]') +assertTrue (d == '', 'table.concat() should return an empty string if passed an empty table [3]') +assertTrue (e == '', 'table.concat() should return an empty string if passed an empty table [4]') + +assertTrue (f == '24moo102', 'table.concat() should return all items in the table in argument 1 in a string with no spaces, when arguments 2 and 3 are absent') +assertTrue (g == '2-4-moo-102', 'table.concat() should return return all items in the table in argument 1 in a string delimited by argument 2, when argument 3 is absent') +assertTrue (h == '4..moo..102', 'table.concat() should return the items in the table in argument 1 from the nth index in a string delimited by argument 2, when n is the third argument') +assertTrue (i == '4+moo', 'table.concat() should return the items in the table in argument 1 from the nth index to the mth index in a string delimited by argument 2, when n is the third argument and m is the forth argument') + + + + +-- getn +do + local a = {'a', 'b', 'c'} + local b = {'a', 'b', 'c', nil} + local c = {'a', nil, 'b', 'c'} + local d = {'a', nil, 'b', 'c', nil} + local e = {'a', 'b', 'c', moo = 123 } + local f = { moo = 123 } + local g = {} + + assertTrue (table.getn (a) == 3, 'table.getn() should return the size of the array part of a table') + assertTrue (table.getn (b) == 3, 'table.getn() should ignore nils at the end of the array part of a table') + assertTrue (table.getn (c) == 4, 'table.getn() should include nils in the middle of the array part of a table') + assertTrue (table.getn (d) == 1, 'table.getn() should return the same random value as C implementation when the last item is nil') + assertTrue (table.getn (e) == 3, 'table.getn() should ignore the hash part of a table') + assertTrue (table.getn (f) == 0, 'table.getn() should return zero when the array part of a table is empty') + assertTrue (table.getn (g) == 0, 'table.getn() should return zero when the table is empty') +end + + + + +-- insert + +local b = {} +local w = table.insert (b, 'Lewis') + +local c = {} +local x = table.insert (c, 3, 'Jenson') + +local d = {'We', 'exist', 'to'} +local y = table.insert (d, 'win') + +local e = {1, 1998, 1, 1999} +local z = table.insert (e, 3, 'Mika') + +local f = {'Kimi'} +local z2 = table.insert (f, 4, 2) + +assertTrue (b[1] == 'Lewis', 'table.insert() should add argument 2 to the end of the table in argument 1, when the third argument is absent [1]') +assertTrue (b[2] == nil, 'table.insert() should only add argument 2 to the end of the table in argument 1, when the third argument is absent [2]') + +assertTrue (c[1] == nil, 'table.insert() should pad the table with nils when the desired index is greater than the length of the table [1]') +assertTrue (c[2] == nil, 'table.insert() should pad the table with nils when the desired index is greater than the length of the table [2]') +assertTrue (c[3] == 'Jenson', 'table.insert() should add argument 2 to the end of the table in argument 1, when the third argument is greater than the length of the table [1]') +assertTrue (c[4] == nil, 'table.insert() should only add argument 2 to the end of the table in argument 1, when the third argument is greater than the length of the table [2]') + +assertTrue (d[1] == 'We', 'table.insert() should not affect existing items in the table when the third argument is missing [1]') +assertTrue (d[2] == 'exist', 'table.insert() should not affect existing items in the table when the third argument is missing [2]') +assertTrue (d[3] == 'to', 'table.insert() should not affect existing items in the table when the third argument is missing [3]') +assertTrue (d[4] == 'win', 'table.insert() should add argument 2 to the end of the table in argument 1, when the third argument is missing [1]') +assertTrue (d[5] == nil, 'table.insert() should only add argument 2 to the end of the table in argument 1, when the third argument is missing [2]') + +assertTrue (e[1] == 1, 'table.insert() should not affect existing items in the table at indices less than that specified in the third argument [1]') +assertTrue (e[2] == 1998, 'table.insert() should not affect existing items in the table at indices less than that specified in the third argument [2]') +assertTrue (e[3] == 'Mika', 'table.insert() should add argument 3 into the table in argument 1 at the index specified in argument 2') +assertTrue (e[4] == 1, 'table.insert() should shift items in the table in argument 1 down by one after and including the index at argument 2 [1]') +assertTrue (e[5] == 1999, 'table.insert() should shift items in the table in argument 1 down by one after and including the index at argument 2 [2]') +assertTrue (e[6] == nil, 'table.insert() should only add one index to the table in argument 1 [1]') + +assertTrue (f[1] == 'Kimi', 'table.insert() should not affect existing items in the table at indices less than that specified in the third argument [3]') +assertTrue (f[2] == nil, 'table.insert() should pad the table with nils when the desired index is greater than the length of the table [3]') +assertTrue (f[3] == nil, 'table.insert() should pad the table with nils when the desired index is greater than the length of the table [4]') +assertTrue (f[4] == 2, 'table.insert() should not affect existing items in the table at indices less than that specified in the third argument [2]') +assertTrue (f[5] == nil, 'table.insert() should only add one index to the table in argument 1 [2]') + + +assertTrue (w == nil, 'table.insert() should update list in place and return nil') +assertTrue (x == nil, 'table.insert() should update list in place and return nil') +assertTrue (y == nil, 'table.insert() should update list in place and return nil') +assertTrue (z == nil, 'table.insert() should update list in place and return nil') +assertTrue (z2 == nil, 'table.insert() should update list in place and return nil') + + +local function insertStringKey () + table.insert({}, 'string key', 1) +end +a, b = pcall(insertStringKey) +assertTrue (a == false, 'table.insert() should error when passed a string key') + + +local function insertStringKey () + table.insert({}, '23', 1) +end +a, b = pcall(insertStringKey) +assertTrue (a, 'table.insert() should not error when passed a string key that can be coerced to a number [1]') + + +local function insertStringKey () + table.insert({}, '1.23e33', 1) +end +a, b = pcall(insertStringKey) +assertTrue (a, 'table.insert() should not error when passed a string key that can be coerced to a number [2]') + + +local function insertStringKey () + table.insert({}, '-23', 1) +end +a, b = pcall(insertStringKey) +assertTrue (a, 'table.insert() should not error when passed a string key that can be coerced to a negative number') + + + + +-- maxn + +local a = table.maxn ({}) +local b = table.maxn ({1, 2, 4, 8}) +local c = table.maxn ({nil, nil, 123}) + + +local d = {} +table.insert (d, 3, 'Moo') +local e = table.maxn (d) + +assertTrue (a == 0, 'table.maxn() should return zero when passed an empty table') +assertTrue (b == 4, 'table.maxn() should return the highest index in the passed table [1]') +assertTrue (c == 3, 'table.maxn() should return the highest index in the passed table [2]') +assertTrue (e == 3, 'table.maxn() should return the highest index in the passed table [3]') + +assertTrue (#d == 0, 'Length operator should return the first empty index minus one [1]') + + + + +-- remove + +local a = {14, 2, "Hello", 298} +local b = table.remove (a) + +local c = {14, 2, "Hello", 298} +local d = table.remove (c, 3) + +local e = {14, 2} +local f = table.remove (e, 6) + +local g = table.remove ({}, 1) + +assertTrue (a[1] == 14, 'table.remove() should not affect items before the removed index [1]') +assertTrue (a[2] == 2, 'table.remove() should not affect items before the removed index [2]') +assertTrue (a[3] == "Hello", 'table.remove() should not affect items before the removed index [3]') +assertTrue (a[4] == nil, 'table.remove() should remove the last item in the table when second argument is absent') + +assertTrue (b == 298, 'table.remove() should return the removed item [1]') + +assertTrue (c[1] == 14, 'table.remove() should not affect items before the removed index [3]') +assertTrue (c[2] == 2, 'table.remove() should not affect items before the removed index [4]') +assertTrue (c[3] == 298, 'table.remove() should remove the item at the index specified by the second argument and shift subsequent item down') +assertTrue (c[4] == nil, 'table.remove() should decrease the length of the table by one') + +assertTrue (d == 'Hello', 'table.remove() should return the removed item [2]') + +assertTrue (e[1] == 14, 'table.remove() should not affect items before the removed index [5]') +assertTrue (e[2] == 2, 'table.remove() should not affect items before the removed index [6]') +assertTrue (e[3] == nil, 'table.remove() should not affect the table if the given index is past the length of the table') + +assertTrue (f == nil, 'table.remove() should return nil if the given index is past the length of the table [1]') +assertTrue (g == nil, 'table.remove() should return nil if the given index is past the length of the table [2]') + + +c = {nil, nil, 123} +assertTrue (#c == 3, 'Length operator should return the first empty index minus one [2]') + +table.remove (c, 1) +assertTrue (#c == 0, 'Length operator should return the first empty index minus one [3]') +assertTrue (c[1] == nil, 'table.remove() should shift values down if index <= initial length [1]') +assertTrue (c[2] == 123, 'table.remove() should shift values down if index <= initial length [2]') +assertTrue (c[3] == nil, 'table.remove() should shift values down if index <= initial length [3]') + +table.remove (c, 1) +assertTrue (#c == 0, 'Length operator should return the first empty index minus one [4]') +assertTrue (c[1] == nil, 'table.remove() should not affect the array if index > initial length [1]') +assertTrue (c[2] == 123, 'table.remove() should not affect the array if index > initial length [2]') +assertTrue (c[3] == nil, 'table.remove() should not affect the array if index > initial length [3]') + +table.remove (c, 2) +assertTrue (#c == 0, 'Length operator should return the first empty index minus one [5]') +assertTrue (c[1] == nil, 'table.remove() should not affect the array if index > initial length [4]') +assertTrue (c[2] == 123, 'table.remove() should not affect the array if index > initial length [5]') +assertTrue (c[3] == nil, 'table.remove() should not affect the array if index > initial length [6]') + + + + +-- sort + +local a = { 1, 2, 3, 6, 5, 4, 20 } +table.sort (a) + +assertTrue (a[1] == 1, 'table.sort() should sort elements into alphnumeric order, when not passed a sort function [1]') +assertTrue (a[2] == 2, 'table.sort() should sort elements into alphnumeric order, when not passed a sort function [2]') +assertTrue (a[3] == 3, 'table.sort() should sort elements into alphnumeric order, when not passed a sort function [3]') +assertTrue (a[4] == 4, 'table.sort() should sort elements into alphnumeric order, when not passed a sort function [4]') +assertTrue (a[5] == 5, 'table.sort() should sort elements into alphnumeric order, when not passed a sort function [5]') +assertTrue (a[6] == 6, 'table.sort() should sort elements into alphnumeric order, when not passed a sort function [6]') +assertTrue (a[7] == 20, 'table.sort() should sort elements into alphnumeric order, when not passed a sort function [7]') +assertTrue (a[8] == nil, 'table.sort() should not affect the table if the given index is past the length of the table') + + +local a = { 1, 2, 3, 6, 5, 4, 20 } +table.sort (a, function (a, b) return b < a end) + +assertTrue (a[1] == 20, 'table.sort() should sort elements into order defined by sort function [1]') +assertTrue (a[2] == 6, 'table.sort() should sort elements into order defined by sort function [2]') +assertTrue (a[3] == 5, 'table.sort() should sort elements into order defined by sort function [3]') +assertTrue (a[4] == 4, 'table.sort() should sort elements into order defined by sort function [4]') +assertTrue (a[5] == 3, 'table.sort() should sort elements into order defined by sort function [5]') +assertTrue (a[6] == 2, 'table.sort() should sort elements into order defined by sort function [6]') +assertTrue (a[7] == 1, 'table.sort() should sort elements into order defined by sort function [7]') +assertTrue (a[8] == nil, 'table.sort() should not affect the table if the given index is past the length of the table') + + + + +-- unpack + +local a = {0, 1, 2, 4, 20, 50, 122} + +local b, c, d, e, f, g = table.unpack (a, 3); +local h, i = table.unpack (a, 3, 2); +local j, k, l, m = table.unpack (a, 3, 5); + +assertTrue (b == 2, 'table.unpack() should return the correct items of the given list [1]') +assertTrue (c == 4, 'table.unpack() should return the correct items of the given list [2]') +assertTrue (d == 20, 'table.unpack() should return the correct items of the given list [3]') +assertTrue (e == 50, 'table.unpack() should return the correct items of the given list [4]') +assertTrue (f == 122, 'table.unpack() should return the correct items of the given list [5]') +assertTrue (g == nil, 'table.unpack() should return the correct items of the given list [6]') +assertTrue (h == nil, 'table.unpack() should return the correct items of the given list [7]') +assertTrue (i == nil, 'table.unpack() should return the correct items of the given list [8]') +assertTrue (j == 2, 'table.unpack() should return the correct items of the given list [9]') +assertTrue (k == 4, 'table.unpack() should return the correct items of the given list [10]') +assertTrue (l == 20, 'table.unpack() should return the correct items of the given list [11]') +assertTrue (m == nil, 'table.unpack() should return the correct items of the given list [12]') + + +local a = {nil, nil, 180} +local b, c, d, e = table.unpack (a); +assertTrue (b == nil, 'table.unpack() should return the correct items of the given list [13]') +assertTrue (c == nil, 'table.unpack() should return the correct items of the given list [14]') +assertTrue (d == 180, 'table.unpack() should return the correct items of the given list [15]') +assertTrue (e == nil, 'table.unpack() should return the correct items of the given list [16]') + + +--Make sure binary searching is implemented the same way as C… +local table1 = {true, nil, true, false, nil, true, nil} +local table2 = {true, false, nil, false, nil, true, nil} +local table3 = {true, false, false, false, true, true, nil} + +local a1, b1, c1, d1, e1, f1 = table.unpack (table1); +local a2, b2, c2, d2, e2, f2 = table.unpack (table2); +local a3, b3, c3, d3, e3, f3, g3 = table.unpack (table3); + + +assertTrue (a1, 'table.unpack() should return the same items as the C implementation [1]') +assertTrue (b1 == nil, 'table.unpack() should return the same items as the C implementation [2]') +assertTrue (c1, 'table.unpack() should return the same items as the C implementation [3]') +assertTrue (not d1, 'table.unpack() should return the same items as the C implementation [4]') +assertTrue (e1 == nil, 'table.unpack() should return the same items as the C implementation [5]') +assertTrue (f1 == nil, 'table.unpack() should return the same items as the C implementation [6]') +assertTrue (a2, 'table.unpack() should return the same items as the C implementation [7]') +assertTrue (not b2, 'table.unpack() should return the same items as the C implementation [8]') +assertTrue (c2 == nil, 'table.unpack() should return the same items as the C implementation [9]') +assertTrue (d2 == nil, 'table.unpack() should return the same items as the C implementation [10]') +assertTrue (e2 == nil, 'table.unpack() should return the same items as the C implementation [11]') +assertTrue (f2 == nil, 'table.unpack() should return the same items as the C implementation [12]') + +assertTrue (a3, 'table.unpack() should return the same items as the C implementation [13]') +assertTrue (not b3, 'table.unpack() should return the same items as the C implementation [14]') +assertTrue (not c3, 'table.unpack() should return the same items as the C implementation [15]') +assertTrue (not d3, 'table.unpack() should return the same items as the C implementation [16]') +assertTrue (e3, 'table.unpack() should return the same items as the C implementation [17]') +assertTrue (f3, 'table.unpack() should return the same items as the C implementation [18]') +assertTrue (g3 == nil, 'table.unpack() should return the same items as the C implementation [19]') diff --git a/tests/starlight/lib.lua b/tests/starlight/lib.lua new file mode 100644 index 0000000..c0b7e1a --- /dev/null +++ b/tests/starlight/lib.lua @@ -0,0 +1,561 @@ + +-- assert +local ass = function (test) + return assert (test, 'error message') +end + +a, b, c = pcall (ass, true) +assertTrue (a, 'Assert should not throw an error when passed true') +assertTrue (b, 'Assert should return the value passed in the first return value') +assertTrue (c == 'error message', 'Assert should return the message passed in the second return value') + +a, b, c = pcall (ass, 0) +assertTrue (a, 'Assert should not throw an error when passed 0') + +a, b, c = pcall (ass, 1) +assertTrue (a, 'Assert should not throw an error when passed 1') + +a, b, c = pcall (ass, '') +assertTrue (a, 'Assert should not throw an error when passed an empty string') + +a, b, c = pcall (ass, nil) +assertTrue (not a, 'Assert should throw an error when passed nil') +--assertTrue (b == 'error message', 'Assert should throw an error with the given message') + +a, b, c = pcall (ass, false) +assertTrue (not a, 'Assert should throw an error when passed false') + + + +-- getmetatable + +local mt = {} +local t = {} +setmetatable(t, mt) + +a = getmetatable(t) +b = getmetatable('moo') +c = getmetatable(123) +d = getmetatable({}) +e = getmetatable(true) +f = getmetatable(function () end) +g = getmetatable('baa') + +assertTrue (a == mt, 'getmetatable() should return a table\'s metatable if set') +assertTrue (type(b) == 'table', 'getmetatable() should return a metatable when passed a string') +assertTrue (b.__index == string, 'getmetatable() should return the string module as a prototype of string') +assertTrue (c == nil, 'getmetatable() should return nil when passed a number') +assertTrue (d == nil, 'getmetatable() should return nil when passed a table without a metatable') +assertTrue (e == nil, 'getmetatable() should return nil when passed a boolean') +assertTrue (f == nil, 'getmetatable() should return nil when passed a function') +assertTrue (g == b, 'The metatable of all strings should be the same table') + + + + + + +-- ipairs + +local a = {2,4,8} +local b = '' + +for i, v in ipairs(a) do + b = b..'['..i..'='..v..']' +end + +assertTrue (b == '[1=2][2=4][3=8]', 'ipairs() should iterate over table items [1]') + + +local t = {nil, 1, 2} +local s = '' + +for i, v in ipairs(t) do + s = s..tostring(i)..'='..tostring(v)..';' +end + +assertTrue (s == '', 'ipairs() should not iterate over nil values in a table.') + + +t = {3, 4, nil, 1, 2} +s = '' + +for i, v in ipairs(t) do + s = s..tostring(i)..'='..tostring(v)..';' +end + +assertTrue (s == '1=3;2=4;', 'ipairs() should iterate over values up to but not including nil values in a table.') + + +t = { + [0] = "zero", + [1] = "one", + [2] = "two", + [-1] = "negative", + foo = "string", + [0.5] = "half" +} + +local r = {} + +for i, v in ipairs(t) do + r[v] = true +end + +assertTrue (not r.zero, 'ipairs() should not iterate over zero key') +assertTrue (r.one, 'ipairs() should iterate over positive integer keys [1]') +assertTrue (r.two, 'ipairs() should iterate over positive integer keys [2]') +assertTrue (not r.negative, 'ipairs() should not iterate over negative keys') +assertTrue (not r.string, 'ipairs() should not iterate over string keys') +assertTrue (not r.half, 'ipairs() should not iterate over non-integer numeric keys') + + + + +-- load + +src = 'return "hello"' + +local index = 0 +local function getChar () + index = index + 1 + return string.sub(src, index, index) +end + +local f = load(getChar) +assertTrue (type(f) == 'function', 'load() should return a function when passed a valid source string') + +local result = f(); +assertTrue (result == 'hello', 'The function returned from load() should return the value from the script') + + + + +-- loadfile + +local f = loadfile('scripts/not-a-file.luac') +assertTrue (f == nil, 'loadfile() should return nil when passed an invalid filename') + + +mainGlobal1 = 'mainGlbl' +mainGlobal2 = 'mainGlbl' + +local mainLocal = 'mainLoc' + +f = loadfile('lib-loadfile.lua') +assertTrue (type(f) == 'function', 'loadfile() should return a function when passed a valid filename') + +local result = f(); + +assertTrue (type(result) == 'table', 'The function returned from loadfile() should return the value from the script') +assertTrue (type(result.getValue) == 'function', 'The function returned from loadfile() should return the value that is returned from the script[1]') +assertTrue (result.getValue() == 'moo', 'The function returned from loadfile() should return the value that is returned from the script[2]') + +assertTrue (mainGlobal1 == 'innerGlbl', 'The function returned from loadfile() should share the same global namespace as the outer script[1]') +assertTrue (mainGlobal2 == 'mainGlbl', 'The function returned from loadfile() should share the same global namespace as the outer script[2]') +assertTrue (innerLocal == nil, 'Function locals should not leak into outer environment in a loadfile() function call') + + + +-- pairs + +local a, b = "", {foo=1} +b["bar"] = "Hello", +table.insert(b, 123) + +for i, v in pairs(b) do + a = a..i..':'..v..';' +end + +assertTrue (#a == #'1:123;bar:Hello;foo:1;', 'pairs() should iterate over table items [2]') -- Have to compare lengths because order is arbitrary + + +local t = { + [0] = "zero", + [1] = "one", + [-1] = "negative", + foo = "string", + [0.5] = "half" +} +local r = {} + +for i, v in pairs(t) do + r[v] = true +end + +assertTrue (r.zero, 'pairs() should iterate over zero key') +assertTrue (r.one, 'pairs() should iterate over positive integer keys') +assertTrue (r.negative, 'pairs() should iterate over negative keys') +assertTrue (r.string, 'pairs() should iterate over string keys') +assertTrue (r.half, 'pairs() should iterate over non-integer numberic keys') + + +t = { nil, nil, 123 } +a = '' + +for i, v in pairs(t) do + a = a..i..':'..v..';' +end + +assertTrue (a == '3:123;', 'pairs() should iterate over numeric table items') + + +t = {} +t[10] = {} +t[15] = {} +s = '' + +for i in pairs(t) do + s = s..i..';' +end + +assertTrue (s == '10;15;', 'pairs() should return correct numeric keys') + + + + +-- pcall + +function goodfunc (x) + return x + 1, x + 2 +end + +function badfunc () + error ('I\'m bad.') +end + +a, b, c = pcall (goodfunc, 6) + +assertTrue (a == true, 'pcall() should return true in the first item when a function executes successfully') +assertTrue (b == 7, 'pcall() should return the result of the function in the items following the first item returned, when a function executes successfully [1]') +assertTrue (c == 8, 'pcall() should return the result of the function in the items following the first item returned, when a function executes successfully [2]') + + +a, b, c = pcall (badfunc, 6) + +assertTrue (a == false, 'pcall() should return false in the first item when the function errors during execution') +assertTrue (not (b == nil), 'pcall() should return an error message in the second item when the function error during execution') +assertTrue (c == nil, 'pcall() should only return 2 items when the function error during execution') + + + + + +-- rawequal +-- rawget +-- rawset + +-- TODO + + + + +-- require + +mainGlobal1 = 'mainGlbl' +mainGlobal2 = 'mainGlbl' +moduleInitCount = 0 + +local mainLocal = 'mainLoc' + +local result = require 'lib-require' + +assertTrue (type(result) == 'table', 'require() should return a table') +assertTrue (type(result.getValue) == 'function', 'require() should return the value that is returned from the module[1]') +assertTrue (result.getValue() == 'modVal', 'require() should return the value that is returned from the module[2]') + +assertTrue (package.loaded['lib-require'] == result, 'Module loaded by require() should also be available in package.loaded[modname]') + +assertTrue (moduleInitCount == 1, 'require() should initialise module') +assertTrue (mainGlobal1 == 'innerGlbl', 'require() should pass the same global namespace into the module[1]') +assertTrue (mainGlobal2 == 'mainGlbl', 'require() should pass the same global namespace into the module[2]') +assertTrue (innerLocal == nil, 'Module locals should not leak into outer environment in a require() call') + +local result2 = require 'lib-require' +assertTrue (moduleInitCount == 1, 'require() should only initialise a module once') +assertTrue (result == result2, 'require() should return the same value across multiple calls') + + + + +-- select + +local a, b, c, d = select (3, 2, 4, 6, 8, 10) + +assertTrue (a == 6, 'select() should return its own arguments from the (n + 1)th index, where n is the value of the first argument [1]') +assertTrue (b == 8, 'select() should return its own arguments from the (n + 1)th index, where n is the value of the first argument [2]') +assertTrue (c == 10, 'select() should return its own arguments from the (n + 1)th index, where n is the value of the first argument [3]') +assertTrue (d == nil, 'select() should return its own arguments from the (n + 1)th index, where n is the value of the first argument [4]') + +local a, b, c, d = select (-2, 2, 4, 6, 8, 10) + +assertTrue (a == 8, 'select() should return its own arguments from the (n + 1)th index, where n is the value of the first argument [5]') +assertTrue (b == 10, 'select() should return its own arguments from the (n + 1)th index, where n is the value of the first argument [6]') +assertTrue (c == nil, 'select() should return its own arguments from the (n + 1)th index, where n is the value of the first argument [7]') +assertTrue (d == nil, 'select() should return its own arguments from the (n + 1)th index, where n is the value of the first argument [8]') + +local a, b = select ('#', 2, 4, 6, 8, 10) + +assertTrue (a == 5, 'select() should return the total number of arguments - 1, when the first argument is "#" [1]') +assertTrue (b == nil, 'select() should return the total number of arguments - 1, when the first argument is "#" [2]') + + +local f = function () + local x, y = select ('moo', 2, 4, 6, 8, 10) +end + +local a, b = pcall (f) + +assertTrue (a == false, 'select() should error if the first argument is not a number or a string with the value of "#"') + + + + +-- setmetatable +-- TODO + + + + +-- tonumber + +local a = tonumber ('1234') +local b = tonumber ('1234 ') +local c = tonumber (' 1234 ') +local d = tonumber ('1234abc') +local e = tonumber ('1234 12') +local f = tonumber ('1.234') +local g = tonumber ('1.234e+5') +local h = tonumber ('1.234e-5') + +assertTrue (a == 1234, 'tonumber() should convert basic numeric strings to decimal and default to base 10') +assertTrue (b == 1234, 'tonumber() should convert numeric strings suffixed with spaces [1]') +assertTrue (c == 1234, 'tonumber() should convert numeric strings prefixed with spaces [1]') +assertTrue (d == nil, 'tonumber() should not convert strings containing letters [1]') +assertTrue (e == nil, 'tonumber() should not convert numeric strings containing spaces in the middle [1]') +assertTrue (f == 1.234, 'tonumber() should convert numeric strings of floating point numbers at base 10 [1]') +assertTrue (g == 123400, 'tonumber() should convert numeric strings of exponential (+ve) numbers at base 10 [1]') +assertTrue (h == 0.00001234, 'tonumber() should convert numeric strings of exponential (-ve) numbers at base 10 [1]') + + +local a = tonumber ('1234', 10) +local b = tonumber ('1234 ', 10) +local c = tonumber (' 1234 ', 10) +local d = tonumber ('1234abc', 10) +local e = tonumber ('1234 12', 10) +local f = tonumber ('1.234', 10) +local g = tonumber ('1.234e+5', 10) +local h = tonumber ('1.234e-5', 10) + +assertTrue (a == 1234, 'tonumber() should convert basic numeric strings to decimal with base 10') +assertTrue (b == 1234, 'tonumber() should convert numeric strings suffixed with spaces [2]') +assertTrue (c == 1234, 'tonumber() should convert numeric strings prefixed with spaces [2]') +assertTrue (d == nil, 'tonumber() should not convert strings containing letters [2]') +assertTrue (e == nil, 'tonumber() should not convert numeric strings containing spaces in the middle [2]') +assertTrue (f == 1.234, 'tonumber() should convert numeric strings of floating point numbers at base 10 [2]') +assertTrue (g == 123400, 'tonumber() should convert numeric strings of exponential (+ve) numbers at base 10 [2]') +assertTrue (h == 0.00001234, 'tonumber() should convert numeric strings of exponential (-ve) numbers at base 10 [2]') + + +local a = tonumber ('101', 2) +local b = tonumber ('101 ', 2) +local c = tonumber (' 101 ', 2) +local d = tonumber ('101abc', 2) +local e = tonumber ('101 10', 2) +local f = tonumber ('101.10', 2) +local g = tonumber ('1.01e+10', 2) + +assertTrue (a == 5, 'tonumber() should convert basic numeric strings to decimal with base 2') +assertTrue (b == 5, 'tonumber() should convert numeric strings suffixed with spaces with base 2') +assertTrue (c == 5, 'tonumber() should convert numeric strings prefixed with spaces with base 2') +assertTrue (d == nil, 'tonumber() should not convert strings containing letters with base 2') +assertTrue (e == nil, 'tonumber() should not convert numeric strings containing spaces in the middle with base 2') +assertTrue (f == nil, 'tonumber() should not convert numeric strings of floating point numbers at base 2') +assertTrue (g == nil, 'tonumber() should not convert numeric strings of exponential numbers at base 2') + + +local a = tonumber ('123', 16) +local b = tonumber ('1AF', 16) +local c = tonumber ('1AF ', 16) +local d = tonumber (' 1AF ', 16) +local e = tonumber ('123Axyz', 16) +local f = tonumber ('123 45', 16) +local g = tonumber ('123.4', 16) +local h = tonumber ('1.23e+10', 16) + +assertTrue (a == 291, 'tonumber() should convert basic numeric strings to decimal with base 16') +assertTrue (b == 431, 'tonumber() should convert hexadecimal strings to decimal with base 16') +assertTrue (c == 431, 'tonumber() should convert hexadecimal strings suffixed with spaces with base 16') +assertTrue (d == 431, 'tonumber() should convert hexadecimal strings prefixed with spaces with base 16') +assertTrue (e == nil, 'tonumber() should not convert strings containing letters out of the range of hexadecimal, with base 16') +assertTrue (f == nil, 'tonumber() should not convert hexadecimal strings containing spaces in the middle with base 16') +assertTrue (g == nil, 'tonumber() should not convert hexadecimal strings of floating point numbers at base 16') +assertTrue (h == nil, 'tonumber() should not convert hexadecimal strings of exponential numbers at base 16') + + +local a = tonumber ('') +local b = tonumber ('', 2) +local c = tonumber ('', 10) +local d = tonumber ('', 16) +assertTrue (a == nil, 'tonumber() should return nil with passed an empty string') +assertTrue (b == nil, 'tonumber() should return nil with passed an empty string with base 2') +assertTrue (c == nil, 'tonumber() should return nil with passed an empty string with base 10') +assertTrue (d == nil, 'tonumber() should return nil with passed an empty string with base 16') + +local a = tonumber (nil) +local b = tonumber (0/0) +local c = tonumber (math.huge) +local d = tonumber (-math.huge) +assertTrue (a == nil, 'tonumber() should return nil when passed nil') +assertTrue (b ~= b, 'tonumber() should return nan when passed nan') +assertTrue (c == math.huge, 'tonumber() should return a number when passed inf') +assertTrue (d == -math.huge, 'tonumber() should return a number when passed -inf') + +local a = tonumber (123) +local b = tonumber (-123) +local c = tonumber (0) +local d = tonumber { value = 123 } +local e = tonumber (function () return 123 end) + +assertTrue (a == 123, 'tonumber() should return a number when passed a number') +assertTrue (b == -123, 'tonumber() should return a negative number when passed a negative number') +assertTrue (c == 0, 'tonumber() should return a zero when passed a zero') +assertTrue (d == nil, 'tonumber() should return nil when passed a table') +assertTrue (e == nil, 'tonumber() should return nil when passed a function') + +local a = tonumber ('0xa.2') +local b = tonumber ('0xa.2', 10) +local c = tonumber ('0xa.2', 16) +local d = tonumber ('0xa', 10) +local e = tonumber ('0xa', 16) +local f = tonumber ('0xa', 12) + +assertTrue (a == 10.125, 'tonumber() should coerce string when using base 10 [1]') +assertTrue (b == 10.125, 'tonumber() should coerce string when using base 10 [2]') +assertTrue (c == nil, 'tonumber() should return nil when string is invalid [1]') +assertTrue (d == 10, 'tonumber() should coerce string when using base 10 [3]') +assertTrue (e == 10, 'tonumber() should ignore leading "0x" when converting to base 16.') +assertTrue (f == nil, 'tonumber() should return nil when string is invalid [2]') + +local a = tonumber (10, 16) +local b = tonumber (0xa, 16) +local c = tonumber ('0xa', 34) +local d = tonumber ('inf') +local e = tonumber ('inf', 16) +local f = tonumber (math.huge, 16) + +assertTrue (a == 16, 'tonumber() should coerce first argument to a string [1]') +assertTrue (b == 16, 'tonumber() should coerce first argument to a string [2]') +assertTrue (c == 1132, 'tonumber() should convert "x" correctly for bases greater than 33') +assertTrue (d == math.huge, 'tonumber() should coerce "inf" to inf with base 10') +assertTrue (e == nil, 'tonumber() should coerce "inf" to nil with bases other than 10') +assertTrue (f == nil, 'tonumber() should return nil when passed inf with bases other than 10') + +local a = tonumber (0/0, 16) + +assertTrue (a == nil, 'tonumber() should return nil when passed inf for bases other than 10') + + + +-- tostring +-- TODO Check for use of __tostring metamethod + +a = tostring (123) +b = tostring ({}) +c = tostring ({1, 2, 3}) +d = tostring (function () return true end) +e = tostring(math.huge) +f = tostring(-math.huge) +g = tostring(0/0) +h = tostring(true) + +assertTrue (a == '123', 'tostring() should convert a number to a string') +assertTrue (string.sub(b, 1, 9) == 'table: 0x', 'tostring() should convert an empty table to a string') +assertTrue (string.sub(c, 1, 9) == 'table: 0x', 'tostring() should convert a table to a string') +assertTrue (string.sub(d, 1, 12) == 'function: 0x', 'tostring() should convert a function to a string') +assertTrue (e == 'inf', 'tostring() should convert infinity to "inf"') +assertTrue (f == '-inf', 'tostring() should convert negative infinity to "-inf"') +assertTrue (g == 'nan', 'tostring() should convert not-a-number to "nan"') +assertTrue (h == 'true', 'tostring() should convert a boolean to a string') + +a = tostring ('') +b = tostring ('moo') +c = tostring (0) +d = tostring (false) + +assertTrue (a == '', 'tostring() should convert a zero-length string to a string') +assertTrue (b == 'moo', 'tostring() should convert a non-zero-length string to a string') +assertTrue (c == '0', 'tostring() should convert zero to a string') +assertTrue (d == 'false', 'tostring() should convert false to a string') + + +a = {} +setmetatable(a, { __tostring = function () return 'Les Revenants' end }) +b = tostring (a) + +assertTrue (b == 'Les Revenants', 'tostring() should use __tostring function, if available on metatable') + + + + +-- type + +local a = type (nil) +local b = type (123) +local c = type ('abc') +local d = type (true) +local e = type ({}) +local f = type (function () return true end) + +assertTrue (a == 'nil', 'type() should return "nil" for a variable with value of nil') +assertTrue (b == 'number', 'type() should return "number" for a variable with value of number') +assertTrue (c == 'string', 'type() should return "string" for a variable with value of type string') +assertTrue (d == 'boolean', 'type() should return "boolean" for a variable with value of type boolean') +assertTrue (e == 'table', 'type() should return "table" for a variable with value of type table') +assertTrue (f == 'function', 'type() should return "function" for a variable with value of type function') + + + + +-- _VERSION + +assertTrue (_VERSION == 'Lua 5.3', '_VERSION should be "Lua 5.3"') + + + + +-- xpcall + +function goodfunc () + return 10, "win" +end + +function badfunc () + error ('I\'m bad.') +end + +function errfunc () + return 999, "fail" +end + +a, b, c, d = xpcall (goodfunc, errfunc) + +assertTrue (a == true, 'xpcall() should return true in the first item when a function executes successfully') +assertTrue (b == 10, 'xpcall() should return the result of the function in the items following the first item returned, when a function executes successfully [1]') +assertTrue (c == 'win', 'xpcall() should return the result of the function in the items following the first item returned, when a function executes successfully [2]') +assertTrue (d == nil, 'xpcall() should return the result of the function in the items following the first item returned, when a function executes successfully [3]') + +a, b, c = xpcall (badfunc, errfunc) + +assertTrue (a == false, 'xpcall() should return false in the first item when the function errors during execution') +assertTrue (b == 999, 'xpcall() should return the first item of the result of the error function in the second item returned, when the function errors during execution') +assertTrue (c == nil, 'xpcall() should only return the first item of the result of the error function in the items following the first item returned, when the function errors during execution') + + +-- Libs should be preloaded +assertTrue (package.loaded.table == table, 'table library should exist in package.loaded') +assertTrue (package.loaded.string == string, 'string library should exist in package.loaded') +assertTrue (package.loaded.math == math, 'math library should exist in package.loaded') +assertTrue (package.loaded.os == os, 'os library should exist in package.loaded') +assertTrue (package.loaded.package == package, 'package library should exist in package.loaded') +assertTrue (package.loaded._G == _G, '_G should exist in package.loaded') diff --git a/tests/starlight/metamethods.lua b/tests/starlight/metamethods.lua new file mode 100644 index 0000000..aa99f62 --- /dev/null +++ b/tests/starlight/metamethods.lua @@ -0,0 +1,395 @@ + +-- __index + +local o = {} +local index = 'mogwai' +local returnVal = {} +local test +local x = {} + + +--nil +setmetatable(o, {}) +assertTrue (o[index] == nil, 'Getting an index of an empty table with empty metamethod should return nil.') + + +--function +setmetatable(o, { __index = function (t, i) + assertTrue (t == o, '__index function in metatable should be passed the table as first argument.') + assertTrue (i == index, '__index function in metatable should be passed the index as second argument.') + + test = true + return returnVal +end }) + +local result = o[index] +assertTrue (test, '__index function in metatable should be executed when table has no property by that index.') +assertTrue (result == returnVal, 'Value returned from __index function in metatable should be passed as the value') + + +--table +setmetatable(x, { __index = o }); +test = false +result = x[index] + +assertTrue (test, '__index function in metatable should be executed when table has no property by that index, even when nested.') +assertTrue (result == returnVal, 'Value returned from __index function in metatable should be passed as the value when nested') + + +--don't call if assigned +x[index] = 456 + +test = false +result = x[index] + +assertTrue (not test, '__index function in metatable should not be executed when table has a property by that index.') +assertTrue (result == 456, '__index should be ignored when index is set.') + + +--test diffferent types of keys +setmetatable(o, { __index = function (t, i) + test = true + return returnVal +end }) + +test = false +result = o[123] + +assertTrue (test, '__index function in metatable should be executed when table has no property by numerical index') +assertTrue (result == returnVal, 'Value returned from __index function in metatable should be passed as the value when index is numerical') + +test = false +result = o[function () end] + +assertTrue (test, '__index function in metatable should be executed when table has no property with a function key') +assertTrue (result == returnVal, 'Value returned from __index function in metatable should be passed as the value with a function key') + +test = false +result = o[{}] + +assertTrue (test, '__index function in metatable should be executed when table has no property with a table key') +assertTrue (result == returnVal, 'Value returned from __index function in metatable should be passed as the value with a table key') + + +-- nil (assigned) +getmetatable(o).__index = nil +assertTrue (o[index] == nil, 'When __index property of metatable is nil, value returned should be nil') + + + + +-- __newindex + + +--nil +o = {} +setmetatable(o, {}) + +o[index] = 123 + +assertTrue (o[index] == 123, 'Setting an index of an empty table with empty metamethod should set that value.') + + +--function +local value = {} +test = false +o = {} + +setmetatable(o, { __newindex = function (t, i, v) + assertTrue (t == o, '__newindex function in metatable should be passed the table as first argument.') + assertTrue (i == index, '__newindex function in metatable should be passed the index as second argument.') + assertTrue (v == value, '__newindex function in metatable should be passed the value as third argument.') + + test = true + return returnVal +end }) + +o[index] = value + +assertTrue (test, '__newindex function in metatable should be executed when table has no property by that index.') +assertTrue (o[index] == nil, '__newindex function should not set the value unless done so explicitly,') + + +--table does not have same effect as __index +x = {} +setmetatable(x, { __index = o }); + +test = false +x[index] = value + +assertTrue (not test, '__newindex function in metatable should not be executed when nested.') +assertTrue (x[index] == value, '__newindex function in metatable should be be ignored when nested.') + + +--don't call if assigned +test = false +rawset(o, index, 111) +o[index] = value + +assertTrue (not test, '__newindex function in metatable should not be executed when table has a property by that index.') +assertTrue (o[index] == value, '__newindex should be ignored when index is set.') + + +--test different types of keys +setmetatable(o, { __newindex = function (t, i, v) + test = true + return returnVal +end }) + +test = false +index = 123 +o[index] = value +assertTrue (test, '__newindex function in metatable should be executed when table has not property for numerical key.') +assertTrue (o[index] == nil, '__newindex should return the correct value when passed a numerical key.') + +test = false +index = function () end +o[index] = value +assertTrue (test, '__newindex function in metatable should be executed when table has not property for function key.') +assertTrue (o[index] == nil, '__newindex should return the correct value when passed a function key.') + +test = false +index = {} +o[index] = value +assertTrue (test, '__newindex function in metatable should be executed when table has not property for table key.') +assertTrue (o[index] == nil, '__newindex should return the correct value when passed a table key.') + + +-- nil (assigned) +rawset(o, index, nil) +getmetatable(o).__index = nil +assertTrue (o[index] == nil, 'When __index property of metatable is nil, value returned should be nil') + + + + +-- metatable + +local mt = { moo = '123' } +local fake = {} +local fake2 = {} +o = {} + +setmetatable(o, mt) + +result = getmetatable(o) +assertTrue (result == mt, 'getmetatable() should return metatable when __metatable is not set') + +mt.__metatable = fake +result = getmetatable(o) +assertTrue (result ~= mt, 'getmetatable() should not return metatable when __metatable is set') +assertTrue (result == fake, 'getmetatable() should return the value of __metatable, if set') + +local setmet = function () + setmetatable(o, mt) +end + +local s, _ = pcall(setmet) +assertTrue (not s, 'setmetatable() should error when metatable has __metatable set') + + +mt.__metatable = function () return fake2 end +result = getmetatable(o) +assertTrue (result ~= fake2, 'getmetatable() should not return the value returned by __metatable, if it is set to a function') +assertTrue (type(result) == 'function', 'getmetatable() should return the value of __metatable, even if it is set to a function') + + + + + + +-- Arithmetic metamethods + +local mt = {} +local Obj = {} + +function Obj.new (v) + local self = { ['value'] = v } + setmetatable (self, mt); + return self +end + +local o = Obj.new (3); +local p = Obj.new (5); +local x = { value = 'moo' } + + +-- __add + +mt.__add = function (a, b) + return a.value..'(__add)'..b.value +end + +assertTrue (o + p == '3(__add)5', 'Add operator should use __add metamethod, if provided [1]') +assertTrue (o + x == '3(__add)moo', 'Add operator should use __add metamethod, if provided [2]') +assertTrue (x + p == 'moo(__add)5', 'Add operator should use __add metamethod, if provided [3]') + + + + +-- __concat + +mt.__concat = function (a, b) + return a.value..'(__concat)'..b.value +end +assertTrue (o..p == '3(__concat)5', 'Concatenation operator should use __concat metamethod, if provided [1]') +assertTrue (o..x == '3(__concat)moo', 'Concatenation operator should use __concat metamethod, if provided [2]') +assertTrue (x..p == 'moo(__concat)5', 'Concatenation operator should use __concat metamethod, if provided [3]') + + + + +-- __div + +mt.__div = function (a, b) + return a.value..'(__div)'..b.value +end + +assertTrue (o / p == '3(__div)5', 'Divide operator should use __div metamethod, if provided [1]') +assertTrue (o / x == '3(__div)moo', 'Divide operator should use __div metamethod, if provided [2]') +assertTrue (x / p == 'moo(__div)5', 'Divide operator should use __div metamethod, if provided [3]') + + + + +-- __mod + +mt.__mod = function (a, b) + return a.value..'(__mod)'..b.value +end + +assertTrue (o % p == '3(__mod)5', 'Modulo operator should use __mod metamethod, if provided [1]') +assertTrue (o % x == '3(__mod)moo', 'Modulo operator should use __mod metamethod, if provided [2]') +assertTrue (x % p == 'moo(__mod)5', 'Modulo operator should use __mod metamethod, if provided [3]') + + + + +-- __mul + +mt.__mul = function (a, b) + return a.value..'(__mul)'..b.value +end + +assertTrue (o * p == '3(__mul)5', 'Muliplication operator should use __mul metamethod, if provided [1]') +assertTrue (o * x == '3(__mul)moo', 'Muliplication operator should use __mul metamethod, if provided [2]') +assertTrue (x * p == 'moo(__mul)5', 'Muliplication operator should use __mul metamethod, if provided [3]') + + + + +-- __pow + +mt.__pow = function (a, b) + return a.value..'(__pow)'..b.value +end + +assertTrue (o ^ p == '3(__pow)5', 'Exponentiation operator should use __pow metamethod, if provided [1]') +assertTrue (o ^ x == '3(__pow)moo', 'Exponentiation operator should use __pow metamethod, if provided [2]') +assertTrue (x ^ p == 'moo(__pow)5', 'Exponentiation operator should use __pow metamethod, if provided [3]') + + + + +-- __sub + +mt.__sub = function (a, b) + return a.value..'(__sub)'..b.value +end + +assertTrue (o - p == '3(__sub)5', 'Subtraction operator should use __sub metamethod, if provided [1]') +assertTrue (o - x == '3(__sub)moo', 'Subtraction operator should use __sub metamethod, if provided [2]') +assertTrue (x - p == 'moo(__sub)5', 'Subtraction operator should use __sub metamethod, if provided [3]') + + + + +-- __unm + +mt.__unm = function (a) + return '(__unm)'..a.value +end + +assertTrue (-o == '(__unm)3', 'Negation operator should use __unm metamethod, if provided') + + + + + + + + +-- Relational metamethods + + +-- __eq +local x = 0 + +mt.__eq = function (a, b) + x = x + 1 + return true +end + +assertTrue (o == p, 'Equality operator should use __eq metamethod, if provided [1]') +assertTrue (x == 1, 'Equality operator should use __eq metamethod, if provided [2]') + +assertTrue (not (o == 123), 'Equality operator should not use __eq metamethod if objects are of different type [1]') +assertTrue (x == 1, 'Equality operator should not use __eq metamethod if operands are of different type [2]') + +assertTrue (o == o, 'Equality operator should not use __eq metamethod if the operands are the same object [1]') +assertTrue (x == 1, 'Equality operator should not use __eq metamethod if the operands are the same object [2]') + + + + +-- __le + +x = 0 + +mt.__le = function (a, b) + x = x + 1 + return a.value == 3 +end + +assertTrue (o <= p, 'Less than or equal to operator should use __le metamethod, if provided [1]') +assertTrue (x == 1, 'Less than or equal to operator should use __le metamethod, if provided [2]') +assertTrue (not (p <= o), 'Less than or equal to operator should use __le metamethod, if provided [3]') +assertTrue (x == 2, 'Less than or equal to operator should use __le metamethod, if provided [4]') + + + + +-- __lt + +x = 0 + +mt.__lt = function (a, b) + x = x + 1 + return a.value == 3 +end + +assertTrue (o < p, 'Less than operator should use __le metamethod, if provided [1]') +assertTrue (x == 1, 'Less than operator should use __le metamethod, if provided [2]') +assertTrue (not (p < o), 'Less than operator should use __le metamethod, if provided [3]') +assertTrue (x == 2, 'Less than operator should use __le metamethod, if provided [4]') + + + +-- __call + +x = '' +mt.__concat = nil + +mt.__call = function (p1, p2) + if p1 == o then + x = 'Ron ' + end + + x = x .. p2 + return 'CEO' +end + +y = o('Dennis') + +assertTrue (x == 'Ron Dennis', 'When executing a table, __call metamethod should be used, if provided') +assertTrue (y == 'CEO', 'When executing a table with a __call metamethod, the return value(s) of __call function should be returned') diff --git a/tests/starlight/operators.lua b/tests/starlight/operators.lua new file mode 100644 index 0000000..3193f77 --- /dev/null +++ b/tests/starlight/operators.lua @@ -0,0 +1,278 @@ + +local a = 1 +assertTrue (a == 1, 'Local should retain value') + +local a, b = 12, 34 +a, b = b, a +assertTrue (a == 34, 'Assignment should be able to reverse values [1]') +assertTrue (b == 12, 'Assignment should be able to reverse values [2]') + +local a, b, c, d = 5, 20, 0, nil +assertTrue (a == 5, 'Local should change value') +assertTrue (b == 20, 'Local should accept multiple assignments') + +local i = 3 +local t = {} +i, t[i] = i+1, 20 +assertTrue (t[3] == 20, 'All expressions should evaluate first [0]') + +local x = 1 +local y = 2 +x, y = y, x +assertTrue (x == 2, 'All expressions should evaluate first [1]') +assertTrue (y == 1, 'All expressions should evaluate first [2]') + +local x = 1 +local y = 2 +local z = 3 +x, y, z = y, z, x +assertTrue (x == 2, 'All expressions should evaluate first [3]') +assertTrue (y == 3, 'All expressions should evaluate first [4]') +assertTrue (z == 1, 'All expressions should evaluate first [5]') + +local result = a + b +assertTrue (result == 25, 'Plus operator should result in addition of operands') + +result = a - b +assertTrue (result == -15, 'Minus operator should result in subtraction of operands') + +result = a * b +assertTrue (result == 100, 'Asterisk operator should result in multiplication of operands') + + +result = b / a +assertTrue (result == 4, 'Slash operator should result in division of operands') + +result = a / b +assertTrue (result == .25, 'Division should handle floating point results') + +result = a / c +assertTrue (result == math.huge, 'Division by zero should return infinity') + +result = a / -c +assertTrue (result == -math.huge, 'Division by negative zero should return negative infinity') + +xpcall(function () result = a / d end, function () result = 'failed' end) +assertTrue (result == 'failed', 'Division by nil should error') + +xpcall(function () result = a / 'x' end, function () result = 'failed2' end) +assertTrue (result == 'failed2', 'Division by string value should error') + +xpcall(function () result = 'x' / a end, function () result = 'failed3' end) +assertTrue (result == 'failed3', 'Division of string value should error') + + +result = 5 % 3 +assertTrue (result == 2, 'Modulo operator should return the remainder of the division of the two operands') + +result = #'moo\0moo' +assertTrue (result == 7, 'Length operator should return the correct length of string with null character inside') + +result = #'moo\0' +assertTrue (result == 4, 'Length operator should return the correct length of string with null character appended') + +function testUnpack() + return 1, 2, 3 +end + +local a, b, c = testUnpack(), 8 +assertTrue (a == 1, 'Local assignment should extract the first return value of a function call [1]') +assertTrue (b == 8, 'Local assignment should only extract the first return value when function call not at end of expression list') +assertTrue (c == nil, 'Local assignment should know when to stop') + +local a, b, c = 8, testUnpack() +assertTrue (a == 8, 'Local assignment should set the first value from expression list') +assertTrue (b == 1, 'Local assignment should extract the first return value of a function call [2]') +assertTrue (c == 2, 'Local assignment should extract all return values when function call at end of expression list') + +local a, b, c +do + a, b, c = testUnpack(), 8 + assertTrue (a == 1, 'Assignment should extract the first return value of a function call [1]') + assertTrue (b == 8, 'Assignment should only extract the first return value when function call not at end of expression list') + assertTrue (c == nil, 'Assignment should know when to stop') + + a, b, c = 8, testUnpack() + assertTrue (a == 8, 'Assignment should set the first value from expression list') + assertTrue (b == 1, 'Assignment should extract the first return value of a function call [2]') + assertTrue (c == 2, 'Assignment should extract all return values when function call at end of expression list') +end + + + +a = 5 +b = 20 +do + local a = 5 + local b = 3 + local c = 5.5 + local d = 23 + local e = 7 + local f = 0 + local g = 0 / 0 -- nan + local h = math.huge + local i = -math.huge + + + assertEqual (a % b, 2, 'Modulo operator should return the remainder of the division of the two operands') + assertEqual (c % b, 2.5, 'Modulo operator should return the fraction part of the remainder of the division of the two operands') + assertEqual (-d % e, 5, 'Modulo operator should always return a positive number if the divisor is positive and wrap around if passed a negative dividend') + assertEqual (d % -e, -5, 'Modulo operator should always return a negative number if the divisor is negative') + assertEqual (-d % -e, -2, 'Modulo operator should always wrap around when passed a negative dividend') + + assertEqual (d % f, g, 'Modulo operator should always return "nan" when passed zero as a divisor') + assertEqual (f % d, 0, 'Modulo operator should return zero when passed zero as a dividend (unless divisor == 0)') + assertEqual (f % f, g, 'Modulo operator should return "nan" when passed zero as a dividend and divisor') + assertEqual (d % g, g, 'Modulo operator should return "nan" when passed "nan" as a divisor') + assertEqual (g % d, g, 'Modulo operator should return "nan" when passed "nan" as a dividend') + assertEqual (d % h, g, 'Modulo operator should return "nan" when passed "inf" as a divisor') + assertEqual (h % d, g, 'Modulo operator should return "nan" when passed "inf" as a dividend') + assertEqual (d % i, g, 'Modulo operator should return "nan" when passed "-inf" as a divisor') + assertEqual (i % d, g, 'Modulo operator should return "nan" when passed "-inf" as a dividend') + +end + +assertTrue (a == a, 'Equality operator should return true if first operand is equal to second') +assertTrue (not (a == b), 'Equality operator should return false if first operand is not equal to second') + +assertTrue (a < b, 'Less than should return true if first operand is less than second') +assertTrue (not (a < a), 'Less than should return false if first operand is equal to second') +assertTrue (not (b < a), 'Less than should return false if first operand is greater than second') + +assertTrue (b > a, 'Greater than should return true if first operand is Greater than second') +assertTrue (not (a > a), 'Greater than should return false if first operand is equal to second') +assertTrue (not (a > b), 'Greater than should return false if first operand is less than second') + +assertTrue (a <= b, 'Less than or equal to should return true if first operand is less than second') +assertTrue (a <= a, 'Less than or equal to should return true if first operand is equal to second') +assertTrue (not (b <= a), 'Less than or equal to should return false if first operand is greater than second') + +assertTrue (b >= a, 'Greater than or equal to should return true if first operand is Greater than second') +assertTrue (a >= a, 'Greater than or equal to should return true if first operand is equal to second') +assertTrue (not (a >= b), 'Greater than or equal to should return false if first operand is less than second') + +local t = true +local f = false +local n + +assertTrue (t, 'True should be true') +assertTrue (0, '0 should coerce to true') +assertTrue (1, '1 should coerce to true') +assertTrue ('moo', 'A string should coerce to true') +assertTrue ('', 'An empty string should coerce to true') +assertTrue ({}, 'An empty table should coerce to true') + +assertTrue (not f, 'False should coerce to false') +assertTrue (not n, 'nil should coerce to false') + + +assertTrue (t and t, 'And operator should return true if both operands are true') +assertTrue (not (f and t), 'And operator should return false if first operand is false') +assertTrue (not (t and f), 'And operator should return false if second operand is false') +assertTrue (not (f and f), 'And operator should return false if both operands are false') + +assertTrue (t or t, 'Or operator should return true if both operands are true') +assertTrue (f or t, 'Or operator should return true even if first operand is false') +assertTrue (t or f, 'Or operator should return true even if second operand is false') +assertTrue (not (f or f), 'Or operator should return false if both operands are false') + +assertEqual(t and 0 or 1, 0, 'Ternary logic should return the correct result[1]') +assertEqual(f and 0 or 1, 1, 'Ternary logic should return the correct result[2]') + +function f(x) + return x +end + +assertEqual (f('moo') or false, 'moo', 'Or operator should work with function calls as left operand (+ve)') +assertEqual (f(false) or false, false, 'Or operator should work with function calls as left operand (-ve)') +assertEqual (false or f('moo'), 'moo', 'Or operator should work with function calls as right operand (+ve)') +assertEqual (false or f(false), false, 'Or operator should work with function calls as right operand (-ve)') +assertEqual (f(false) or f('moo'), 'moo', 'Or operator should work with function calls as both operands') + +assertEqual (f('moo') and 'baa', 'baa', 'And operator should work with function calls as left operand (+ve)') +assertEqual (f(false) and true, false, 'And operator should work with function calls as left operand (-ve)') +assertEqual (true and f('moo'), 'moo', 'And operator should work with function calls as right operand (+ve)') +assertEqual (true and f(false), false, 'And operator should work with function calls as right operand (-ve)') +assertEqual (f('moo') and f('moo'), 'moo', 'And operator should work with function calls as both operands') + + +local function test() + return true +end + +assertTrue(test() and true, 'Should allow function calls as first operand in boolean operations') +assertTrue(true and test(), 'Should allow function calls as second operand in boolean operations') + + +local tests = { + addition = function (a, b) return a + b end, + subtraction = function (a, b) return a - b end, + muliplication = function (a, b) return a * b end, + division = function (a, b) return a / b end, + modulus = function (a, b) return a % b end, + pow = function (a, b) return a ^ b end, + ['unary-minus'] = function (a, b) return -a, -b end +} + +for name, test in pairs(tests) do + + local success, result = pcall (test, 5, 2) + assertTrue (success, 'Simple use of '..name..' operator should not fail') + + success, result = pcall (test, '3', 6) + assertTrue (success, 'Applying '..name..' operator to a string containing a number should not error [1]') + + success, result = pcall (test, '3.', 9) + assertTrue (success, 'Applying '..name..' operator to a string containing a number should not error [2]') + + success, result = pcall (test, '3.2', 9) + assertTrue (success, 'Applying '..name..' operator to a string containing a number should not error [3]') + + success, result = pcall (test, '3.2e4', 9) + assertTrue (success, 'Applying '..name..' operator to a string containing an exponenial number should not error [4]') + + success, result = pcall (test, 8, '2') + assertTrue (success, 'Passing a string containing a number to the '..name..' operator should not error [1]') + + success, result = pcall (test, 1, '2.') + assertTrue (success, 'Passing a string containing a number to the '..name..' operator should not error [2]') + + success, result = pcall (test, 1, '2.5') + assertTrue (success, 'Passing a string containing a number to the '..name..' operator should not error [3]') + + success, result = pcall (test, 1, '2.5e3') + assertTrue (success, 'Passing a string containing an exponential number to the '..name..' operator should not error [4]') + + success, result = pcall (test, '9', '2') + assertTrue (success, 'Applying '..name..' operator to two strings containing a numbers should not error') + + success, result = pcall (test, 'a', 2) + assertTrue (not success, 'Applying '..name..' operator to an alpha string should error [1]') + + success, result = pcall (test, '8a', 2) + assertTrue (not success, 'Applying '..name..' operator to an alpha string should error [2]') + + success, result = pcall (test, 'a8', 2) + assertTrue (not success, 'Applying '..name..' operator to an alpha string should error [3]') + + success, result = pcall (test, 8, '2a') + assertTrue (not success, 'Passing an alpha string to the '..name..' operator should error') + +end + +assertTrue('abc' < 'def', 'Strings should be comparable') + +local a = '\t' +local b = [[\n\t]] +local c = [[\]] +local d = '\32' +local e = [[\32]] +local f = '\0321' + +assertTrue(a == ' ', 'A quoted string literal should escape chars after backslash') +assertTrue(b == '\\n\\t', 'A long bracketed string literal should not escape chars after backslash [1]') +assertTrue(c == '\\', 'A long bracketed string literal should not escape chars after backslash [2]') + +assertTrue(d == ' ', 'An escaped number should be converted to a char in quoted string literals') +assertTrue(e == '\\32', 'An escaped number should not be converted to a char in long bracketed string literals') +assertTrue(f == ' 1', 'An escaped number should only consume 3 digits in quoted string literals') diff --git a/tests/starlight/tables.lua b/tests/starlight/tables.lua new file mode 100644 index 0000000..03fde7b --- /dev/null +++ b/tests/starlight/tables.lua @@ -0,0 +1,138 @@ + +a = {1,2,3,4} +b = a + +assertTrue (a == b, 'Tables should be able to be compared by identity') +assertTrue (not (a == {1,2,3,4}), 'Tables should not be able to be compared to literals') +assertTrue (#a == 4, 'Length operator should return the number of items in a table') + + +assertTrue (a[1] == 1, 'Square brackets operation on table should return correct value for index [1]') +assertTrue (a[2] == 2, 'Square brackets operation on table should return correct value for index [2]') +assertTrue (a[3] == 3, 'Square brackets operation on table should return correct value for index [3]') +assertTrue (a[4] == 4, 'Square brackets operation on table should return correct value for index [4]') +assertTrue (a[5] == nil, 'Square brackets operation on table should return nil for an index greater than the length') +assertTrue (a[0] == nil, 'Square brackets operation on table should return nil for an index of 0') +assertTrue (a[-1] == nil, 'Square brackets operation on table should return nil for an index less than 0') + + +a = {[1] = 20, [3] = 40} +assertTrue (a[1] == 20, 'Square brackets operation on table should return correct value for index when keys are used in literal assignment [1]') +assertTrue (a[2] == nil, 'Square brackets operation on table should return correct value for index when keys are used in literal assignment [2]') +assertTrue (a[3] == 40, 'Square brackets operation on table should return correct value for index when keys are used in literal assignment [3]') +assertTrue (a[4] == nil, 'Square brackets operation on table should return correct value for index when keys are used in literal assignment [4]') + +b = 'hello' +a = {[b] = 'value'} +assertEqual (a.hello, 'value', 'Identifier should be able to be used as a key') + +b = 2 +a = {[b] = 'value2'} +assertEqual (a[2], 'value2', 'Numeric identifier should be able to be used as a key') + + + + +-- TABLES + + +Account = { balance = 0 } + +function Account:new (o) + o = o or {} + setmetatable (o,self) + self.__index = self + return o +end + +function Account:deposit (v) + self.balance = self.balance + v +end + +function Account:withdraw (v) + if v > self.balance then error "insufficient funds" end + self.balance = self.balance - v +end + + +acc = Account:new () + + +assertTrue (acc.balance == 0, 'Class properties should be initiated when instantiated [1]') + +acc:deposit (20) +assertTrue (acc.balance == 20, 'Class instance properties should be updatable though instance method calls [1]') + +acc:withdraw (5) +assertTrue (acc.balance == 15, 'Class instance properties should maintain their value in the instance') + + +acc2 = Account:new () + +assertTrue (acc2.balance == 0, 'Class properties should be initiated when instantiated [2]') + +acc2:deposit (50) +assertTrue (acc2.balance == 50, 'Class instance properties should be updatable though instance method calls [2]') +assertTrue (acc.balance == 15, 'Class instance properties should maintain their value separate to other instances') + + + +SpecialAccount = Account:new () + +function SpecialAccount:withdraw (v) + if v - self.balance >= self:getLimit () then + error "insufficient funds" + end + + self.balance = self.balance - v +end + +function SpecialAccount:getLimit () + return self.limit or 0 +end + + +s = SpecialAccount:new {limit=1000.00} + +assertTrue (s.balance == 0, 'Class properties should be initiated when instantiated, even if class is inherited') +assertTrue (s:getLimit () == 1000, 'Inherited class should have its own properties') +assertTrue (acc.getLimit == nil, 'Base class properties should not change when inherited class manipulated') + +s:deposit (500) +assertTrue (s.balance == 500, 'Class instance properties should be updatable though instance method calls [3]') + + +function f () + return 1, 3, 9 +end + +local t = {f()} + +assertTrue (t[1] == 1, 'Table should be able to be instantiated by the result of a function [1]') +assertTrue (t[2] == 3, 'Table should be able to be instantiated by the result of a function [2]') +assertTrue (t[3] == 9, 'Table should be able to be instantiated by the result of a function [3]') + + + +t = {} +t[1] = 'number' +t['1'] = 'string' + +assertTrue (t[1] == 'number', 'A numerical table index should return a different value than when using the same index as a sting. [1]') +assertTrue (t['1'] == 'string', 'A numerical table index should return a different value than when using the same index as a sting. [2]') + + + +function testUnpack() + return 1, 2, 3 +end + +t = { testUnpack(), 10 } +assertTrue (t[1] == 1, 'Function call in table literal should pass return value as argument') +assertTrue (t[2] == 10, 'Function call in middle of table literal should only pass one argument') +assertTrue (t[3] == nil, 'Table properties should stop at the end of table literal list') + +t = { 10, testUnpack() } +assertTrue (t[1] == 10, 'Table literal should set properties in order') +assertTrue (t[2] == 1, 'Function call in table literal should set properties') +assertTrue (t[3] == 2, 'Function call at end of table literal should set properties for all return values') diff --git a/tests/starlight/test-runner.lua b/tests/starlight/test-runner.lua new file mode 100644 index 0000000..ac9f7d5 --- /dev/null +++ b/tests/starlight/test-runner.lua @@ -0,0 +1,84 @@ + +local passed, failed = 0, 0 +local startTime +local currentFile + + +if getTimestamp then + startTime = getTimestamp() +end + + +function assertTrue (condition, message) + if not condition then + failed = failed + 1 + reportError(message) + else + passed = passed + 1 + end +end + + +function assertEqual (actual, expected, message) + if actual ~= expected and (actual == actual or expected == expected) then + failed = failed + 1 + reportError(message..'; expected "'..tostring(expected)..'", got "'..tostring(actual)..'".') + else + passed = passed + 1 + end +end + + +function run (modName) + currentFile = modName + dofile(modName..'.lua') +end + + +function reportError (message) + if currentFile ~= lastErrorFile then + print('\n-['..currentFile..']-----------------------------------------') + end + + lastErrorFile = currentFile + print('- '..message) +end + + +function showResults () + local durationStr = '' + + if getTimestamp then + local endTime = getTimestamp() + durationStr = '\nCompleted in '..(endTime - startTime)..'ms.' + end + + print "\n------------------------" + if failed == 0 then + print " Passed." + else + print "FAILED!" + end + + print "------------------------\n" + print ("Total asserts: "..(passed + failed).."; Passed: "..passed.."; Failed: "..failed..durationStr) + + os.exit(failed) +end + + +run 'operators' +run 'functions' +run 'tables' +run 'control-structures' +run 'coercion' +run 'metamethods' +run 'lib' +run 'lib-string' +run 'lib-table' +run 'lib-math' +-- run 'lib-coroutine' +run 'lib-date' + + +showResults() diff --git a/tests/test.js b/tests/test.js new file mode 100644 index 0000000..d81e1b8 --- /dev/null +++ b/tests/test.js @@ -0,0 +1,29 @@ +const fs = require('fs') +const path = require('path') +const luainjs = require('..') + +let exitCode = 0 + +{ + const rootPath = './tests/starlight/' + const luaEnv = luainjs.createEnv({ + fileExists: p => fs.existsSync(path.join(rootPath, p)), + loadFile: p => fs.readFileSync(path.join(rootPath, p), { encoding: 'utf8' }), + osExit: code => (exitCode += code) + }) + luaEnv.runfile('test-runner.lua') +} + +// TODO: make more official lua 5.3 tests pass (most of them don't pass because they `require "debug"`) +{ + const rootPath = './tests/lua-5.3/' + const luaEnv = luainjs.createEnv({ + fileExists: p => fs.existsSync(path.join(rootPath, p)), + loadFile: p => fs.readFileSync(path.join(rootPath, p), { encoding: 'utf8' }), + osExit: code => process.exit(code) + }) + luaEnv.runfile('goto.lua') + luaEnv.runfile('bwcoercion.lua') +} + +process.exit(exitCode) diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..6150815 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,32 @@ +{ + "include": ["src/**/*"], + "exclude": ["node_modules/*"], + "compilerOptions": { + "rootDir": "src", + "outDir": "dist", + "declarationDir": "dist/types", + + "target": "es6", + "module": "es2015", + "moduleResolution": "node", + "lib": ["es6", "dom"], + + "pretty": true, + + "sourceMap": true, + "alwaysStrict": true, + "removeComments": true, + + "noImplicitAny": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + + "preserveConstEnums": true, + + "declaration": true, + "declarationMap": true, + "esModuleInterop": true, + "resolveJsonModule": true, + "allowSyntheticDefaultImports": true + } +} diff --git a/webpack.config.js b/webpack.config.js deleted file mode 100644 index 588adff..0000000 --- a/webpack.config.js +++ /dev/null @@ -1,41 +0,0 @@ -'use strict' -const path = require('path') -const CleanWebpackPlugin = require('clean-webpack-plugin') - -module.exports = { - mode: 'production', - target: 'node', - entry: './src/index', - output: { - path: path.resolve(__dirname, './dist'), - filename: 'lua-in-js.js', - library: 'lua-in-js', - libraryTarget:'umd' - }, - module: { - rules: [ - { - test: /\.js$/, - exclude: /node_modules/, - use: [ - { - loader: 'babel-loader', - options: { - cacheDirectory: true, - presets: [ - ["@babel/preset-env", { - targets: { - node: "current" - } - }] - ] - } - } - ] - } - ] - }, - plugins: [ - new CleanWebpackPlugin(['dist']) - ] -} diff --git a/yarn.lock b/yarn.lock new file mode 100644 index 0000000..05bc879 --- /dev/null +++ b/yarn.lock @@ -0,0 +1,1472 @@ +# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. +# yarn lockfile v1 + + +"@babel/code-frame@^7.0.0": + version "7.5.5" + resolved "https://registry.yarnpkg.com/@babel/code-frame/-/code-frame-7.5.5.tgz#bc0782f6d69f7b7d49531219699b988f669a8f9d" + integrity sha512-27d4lZoomVyo51VegxI20xZPuSHusqbQag/ztrBC7wegWoQ1nLREPVSKSW8byhTlzTKyNE4ifaTA6lCp7JjpFw== + dependencies: + "@babel/highlight" "^7.0.0" + +"@babel/highlight@^7.0.0": + version "7.5.0" + resolved "https://registry.yarnpkg.com/@babel/highlight/-/highlight-7.5.0.tgz#56d11312bd9248fa619591d02472be6e8cb32540" + integrity sha512-7dV4eu9gBxoM0dAnj/BCFDW9LFU0zvTrkq0ugM7pnHEgguOEeOz1so2ZghEdzviYzQEED0r4EAgpsBChKy1TRQ== + dependencies: + chalk "^2.0.0" + esutils "^2.0.2" + js-tokens "^4.0.0" + +"@types/eslint-visitor-keys@^1.0.0": + version "1.0.0" + resolved "https://registry.yarnpkg.com/@types/eslint-visitor-keys/-/eslint-visitor-keys-1.0.0.tgz#1ee30d79544ca84d68d4b3cdb0af4f205663dd2d" + integrity sha512-OCutwjDZ4aFS6PB1UZ988C4YgwlBHJd6wCeQqaLdmadZ/7e+w79+hbMUFC1QXDNCmdyoRfAFdm0RypzwR+Qpag== + +"@types/estree@0.0.39": + version "0.0.39" + resolved "https://registry.yarnpkg.com/@types/estree/-/estree-0.0.39.tgz#e177e699ee1b8c22d23174caaa7422644389509f" + integrity sha512-EYNwp3bU+98cpU4lAWYYL7Zz+2gryWH1qbdDTidVd6hkiR6weksdbMadyXKXNPEkQFhXM+hVO9ZygomHXp+AIw== + +"@types/json-schema@^7.0.3": + version "7.0.3" + resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.3.tgz#bdfd69d61e464dcc81b25159c270d75a73c1a636" + integrity sha512-Il2DtDVRGDcqjDtE+rF8iqg1CArehSK84HZJCT7AMITlyXRBpuPhqGLDQMowraqqu1coEaimg4ZOqggt6L6L+A== + +"@types/luaparse@^0.2.6": + version "0.2.6" + resolved "https://registry.yarnpkg.com/@types/luaparse/-/luaparse-0.2.6.tgz#d0f25c8fac176204e75421ff7081ce482b3d7933" + integrity sha512-C/TORXCQgPwunpAk9ELsbOsR8fX8Vw1Y2yVdlBnC+RPA85iOT00gEZ0AxoXQRVepLwoIfWqA8t2NvnlVs0aPgw== + +"@types/node@*", "@types/node@^12.7.2", "@types/node@^12.7.4": + version "12.7.4" + resolved "https://registry.yarnpkg.com/@types/node/-/node-12.7.4.tgz#64db61e0359eb5a8d99b55e05c729f130a678b04" + integrity sha512-W0+n1Y+gK/8G2P/piTkBBN38Qc5Q1ZSO6B5H3QmPCUewaiXOo2GCAWZ4ElZCcNhjJuBSUSLGFUJnmlCn5+nxOQ== + +"@types/resolve@0.0.8": + version "0.0.8" + resolved "https://registry.yarnpkg.com/@types/resolve/-/resolve-0.0.8.tgz#f26074d238e02659e323ce1a13d041eee280e194" + integrity sha512-auApPaJf3NPfe18hSoJkp8EbZzer2ISk7o8mCC3M9he/a04+gbMF97NkpD2S8riMGvm4BMRI59/SZQSaLTKpsQ== + dependencies: + "@types/node" "*" + +"@typescript-eslint/eslint-plugin@^2.1.0": + version "2.1.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-2.1.0.tgz#4bcd978d88419ea971613675f2620dde39920d69" + integrity sha512-3i/dLPwxaVfCsaLu3HkB8CAA1Uw3McAegrTs+VBJ0BrGRKW7nUwSqRfHfCS7sw7zSbf62q3v0v6pOS8MyaYItg== + dependencies: + "@typescript-eslint/experimental-utils" "2.1.0" + eslint-utils "^1.4.0" + functional-red-black-tree "^1.0.1" + regexpp "^2.0.1" + tsutils "^3.14.0" + +"@typescript-eslint/experimental-utils@2.1.0": + version "2.1.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/experimental-utils/-/experimental-utils-2.1.0.tgz#0837229f0e75a32db0db9bf662ad0eface914453" + integrity sha512-ZJGLYXa4nxjNzomaEk1qts38B/vludg2LOM7dRc7SppEKsMPTS1swaTKS/pom+x4d/luJGoG00BDIss7PR1NQA== + dependencies: + "@types/json-schema" "^7.0.3" + "@typescript-eslint/typescript-estree" "2.1.0" + eslint-scope "^4.0.0" + +"@typescript-eslint/parser@^2.1.0": + version "2.1.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-2.1.0.tgz#ca62b26fa6a5a34ecdec4a000f22baf103791830" + integrity sha512-0+hzirRJoqE1T4lSSvCfKD+kWjIpDWfbGBiisK5CENcr+22pPkHB2sfV1giON+UxHV4A08SSrQonZk7X2zIQdw== + dependencies: + "@types/eslint-visitor-keys" "^1.0.0" + "@typescript-eslint/experimental-utils" "2.1.0" + "@typescript-eslint/typescript-estree" "2.1.0" + eslint-visitor-keys "^1.0.0" + +"@typescript-eslint/typescript-estree@2.1.0": + version "2.1.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-2.1.0.tgz#88e676cc9760516711f6fe43958adc31b93de8e5" + integrity sha512-482ErJJ7QYghBh+KA9G+Fwcuk/PLTy+9NBMz8S+6UFrUUnVvHRNAL7I70kdws2te0FBYEZW7pkDaXoT+y8UARw== + dependencies: + glob "^7.1.4" + is-glob "^4.0.1" + lodash.unescape "4.0.1" + semver "^6.2.0" + +acorn-jsx@^5.0.2: + version "5.0.2" + resolved "https://registry.yarnpkg.com/acorn-jsx/-/acorn-jsx-5.0.2.tgz#84b68ea44b373c4f8686023a551f61a21b7c4a4f" + integrity sha512-tiNTrP1MP0QrChmD2DdupCr6HWSFeKVw5d/dHTu4Y7rkAkRhU/Dt7dphAfIUyxtHpl/eBVip5uTNSpQJHylpAw== + +acorn@^7.0.0: + version "7.0.0" + resolved "https://registry.yarnpkg.com/acorn/-/acorn-7.0.0.tgz#26b8d1cd9a9b700350b71c0905546f64d1284e7a" + integrity sha512-PaF/MduxijYYt7unVGRuds1vBC9bFxbNf+VWqhOClfdgy7RlVkQqt610ig1/yxTgsDIfW1cWDel5EBbOy3jdtQ== + +ajv@^6.10.0, ajv@^6.10.2: + version "6.10.2" + resolved "https://registry.yarnpkg.com/ajv/-/ajv-6.10.2.tgz#d3cea04d6b017b2894ad69040fec8b623eb4bd52" + integrity sha512-TXtUUEYHuaTEbLZWIKUr5pmBuhDLy+8KYtPYdcV8qC+pOZL+NKqYwvWSRrVXHn+ZmRRAu8vJTAznH7Oag6RVRw== + dependencies: + fast-deep-equal "^2.0.1" + fast-json-stable-stringify "^2.0.0" + json-schema-traverse "^0.4.1" + uri-js "^4.2.2" + +ansi-escapes@^3.2.0: + version "3.2.0" + resolved "https://registry.yarnpkg.com/ansi-escapes/-/ansi-escapes-3.2.0.tgz#8780b98ff9dbf5638152d1f1fe5c1d7b4442976b" + integrity sha512-cBhpre4ma+U0T1oM5fXg7Dy1Jw7zzwv7lt/GoCpr+hDQJoYnKVPLL4dCvSEFMmQurOQvSrwT7SL/DAlhBI97RQ== + +ansi-regex@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-3.0.0.tgz#ed0317c322064f79466c02966bddb605ab37d998" + integrity sha1-7QMXwyIGT3lGbAKWa922Bas32Zg= + +ansi-regex@^4.1.0: + version "4.1.0" + resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-4.1.0.tgz#8b9f8f08cf1acb843756a839ca8c7e3168c51997" + integrity sha512-1apePfXM1UOSqw0o9IiFAovVz9M5S1Dg+4TrDwfMewQ6p/rmMueb7tWZjQ1rx4Loy1ArBggoqGpfqqdI4rondg== + +ansi-styles@^3.2.0, ansi-styles@^3.2.1: + version "3.2.1" + resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-3.2.1.tgz#41fbb20243e50b12be0f04b8dedbf07520ce841d" + integrity sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA== + dependencies: + color-convert "^1.9.0" + +argparse@^1.0.7: + version "1.0.10" + resolved "https://registry.yarnpkg.com/argparse/-/argparse-1.0.10.tgz#bcd6791ea5ae09725e17e5ad988134cd40b3d911" + integrity sha512-o5Roy6tNG4SL/FOkCAN6RzjiakZS25RLYFrcMttJqbdd8BWrnA+fGz57iN5Pb06pvBGvl5gQ0B48dJlslXvoTg== + dependencies: + sprintf-js "~1.0.2" + +array-includes@^3.0.3: + version "3.0.3" + resolved "https://registry.yarnpkg.com/array-includes/-/array-includes-3.0.3.tgz#184b48f62d92d7452bb31b323165c7f8bd02266d" + integrity sha1-GEtI9i2S10UrsxsyMWXH+L0CJm0= + dependencies: + define-properties "^1.1.2" + es-abstract "^1.7.0" + +astral-regex@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/astral-regex/-/astral-regex-1.0.0.tgz#6c8c3fb827dd43ee3918f27b82782ab7658a6fd9" + integrity sha512-+Ryf6g3BKoRc7jfp7ad8tM4TtMiaWvbF/1/sQcZPkkS7ag3D5nMBCe2UfOTONtAkaG0tO0ij3C5Lwmf1EiyjHg== + +balanced-match@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.0.tgz#89b4d199ab2bee49de164ea02b89ce462d71b767" + integrity sha1-ibTRmasr7kneFk6gK4nORi1xt2c= + +brace-expansion@^1.1.7: + version "1.1.11" + resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-1.1.11.tgz#3c7fcbf529d87226f3d2f52b966ff5271eb441dd" + integrity sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA== + dependencies: + balanced-match "^1.0.0" + concat-map "0.0.1" + +builtin-modules@^3.1.0: + version "3.1.0" + resolved "https://registry.yarnpkg.com/builtin-modules/-/builtin-modules-3.1.0.tgz#aad97c15131eb76b65b50ef208e7584cd76a7484" + integrity sha512-k0KL0aWZuBt2lrxrcASWDfwOLMnodeQjodT/1SxEQAXsHANgo6ZC/VEaSEHCXt7aSTZ4/4H5LKa+tBXmW7Vtvw== + +callsites@^3.0.0: + version "3.1.0" + resolved "https://registry.yarnpkg.com/callsites/-/callsites-3.1.0.tgz#b3630abd8943432f54b3f0519238e33cd7df2f73" + integrity sha512-P8BjAsXvZS+VIDUI11hHCQEv74YT67YUi5JJFNWIqL235sBmjX4+qx9Muvls5ivyNENctx46xQLQ3aTuE7ssaQ== + +chalk@^2.0.0, chalk@^2.1.0, chalk@^2.4.2: + version "2.4.2" + resolved "https://registry.yarnpkg.com/chalk/-/chalk-2.4.2.tgz#cd42541677a54333cf541a49108c1432b44c9424" + integrity sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ== + dependencies: + ansi-styles "^3.2.1" + escape-string-regexp "^1.0.5" + supports-color "^5.3.0" + +chardet@^0.7.0: + version "0.7.0" + resolved "https://registry.yarnpkg.com/chardet/-/chardet-0.7.0.tgz#90094849f0937f2eedc2425d0d28a9e5f0cbad9e" + integrity sha512-mT8iDcrh03qDGRRmoA2hmBJnxpllMR+0/0qlzjqZES6NdiWDcZkCNAk4rPFZ9Q85r27unkiNNg8ZOiwZXBHwcA== + +cli-cursor@^2.1.0: + version "2.1.0" + resolved "https://registry.yarnpkg.com/cli-cursor/-/cli-cursor-2.1.0.tgz#b35dac376479facc3e94747d41d0d0f5238ffcb5" + integrity sha1-s12sN2R5+sw+lHR9QdDQ9SOP/LU= + dependencies: + restore-cursor "^2.0.0" + +cli-width@^2.0.0: + version "2.2.0" + resolved "https://registry.yarnpkg.com/cli-width/-/cli-width-2.2.0.tgz#ff19ede8a9a5e579324147b0c11f0fbcbabed639" + integrity sha1-/xnt6Kml5XkyQUewwR8PvLq+1jk= + +color-convert@^1.9.0: + version "1.9.3" + resolved "https://registry.yarnpkg.com/color-convert/-/color-convert-1.9.3.tgz#bb71850690e1f136567de629d2d5471deda4c1e8" + integrity sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg== + dependencies: + color-name "1.1.3" + +color-name@1.1.3: + version "1.1.3" + resolved "https://registry.yarnpkg.com/color-name/-/color-name-1.1.3.tgz#a7d0558bd89c42f795dd42328f740831ca53bc25" + integrity sha1-p9BVi9icQveV3UIyj3QIMcpTvCU= + +commondir@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/commondir/-/commondir-1.0.1.tgz#ddd800da0c66127393cca5950ea968a3aaf1253b" + integrity sha1-3dgA2gxmEnOTzKWVDqloo6rxJTs= + +concat-map@0.0.1: + version "0.0.1" + resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b" + integrity sha1-2Klr13/Wjfd5OnMDajug1UBdR3s= + +contains-path@^0.1.0: + version "0.1.0" + resolved "https://registry.yarnpkg.com/contains-path/-/contains-path-0.1.0.tgz#fe8cf184ff6670b6baef01a9d4861a5cbec4120a" + integrity sha1-/ozxhP9mcLa67wGp1IYaXL7EEgo= + +cross-spawn@^6.0.5: + version "6.0.5" + resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-6.0.5.tgz#4a5ec7c64dfae22c3a14124dbacdee846d80cbc4" + integrity sha512-eTVLrBSt7fjbDygz805pMnstIs2VTBNkRm0qxZd+M7A5XDdxVRWO5MxGBXZhjY4cqLYLdtrGqRf8mBPmzwSpWQ== + dependencies: + nice-try "^1.0.4" + path-key "^2.0.1" + semver "^5.5.0" + shebang-command "^1.2.0" + which "^1.2.9" + +debug@^2.6.8, debug@^2.6.9: + version "2.6.9" + resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.9.tgz#5d128515df134ff327e90a4c93f4e077a536341f" + integrity sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA== + dependencies: + ms "2.0.0" + +debug@^4.0.1: + version "4.1.1" + resolved "https://registry.yarnpkg.com/debug/-/debug-4.1.1.tgz#3b72260255109c6b589cee050f1d516139664791" + integrity sha512-pYAIzeRo8J6KPEaJ0VWOh5Pzkbw/RetuzehGM7QRRX5he4fPHx2rdKMB256ehJCkX+XRQm16eZLqLNS8RSZXZw== + dependencies: + ms "^2.1.1" + +deep-is@~0.1.3: + version "0.1.3" + resolved "https://registry.yarnpkg.com/deep-is/-/deep-is-0.1.3.tgz#b369d6fb5dbc13eecf524f91b070feedc357cf34" + integrity sha1-s2nW+128E+7PUk+RsHD+7cNXzzQ= + +define-properties@^1.1.2, define-properties@^1.1.3: + version "1.1.3" + resolved "https://registry.yarnpkg.com/define-properties/-/define-properties-1.1.3.tgz#cf88da6cbee26fe6db7094f61d870cbd84cee9f1" + integrity sha512-3MqfYKj2lLzdMSf8ZIZE/V+Zuy+BgD6f164e8K2w7dgnpKArBDerGYpM46IYYcjnkdPNMjPk9A6VFB8+3SKlXQ== + dependencies: + object-keys "^1.0.12" + +doctrine@1.5.0: + version "1.5.0" + resolved "https://registry.yarnpkg.com/doctrine/-/doctrine-1.5.0.tgz#379dce730f6166f76cefa4e6707a159b02c5a6fa" + integrity sha1-N53Ocw9hZvds76TmcHoVmwLFpvo= + dependencies: + esutils "^2.0.2" + isarray "^1.0.0" + +doctrine@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/doctrine/-/doctrine-3.0.0.tgz#addebead72a6574db783639dc87a121773973961" + integrity sha512-yS+Q5i3hBf7GBkd4KG8a7eBNNWNGLTaEwwYWUijIYM7zrlYDM0BFXHjjPWlWZ1Rg7UaddZeIDmi9jF3HmqiQ2w== + dependencies: + esutils "^2.0.2" + +emoji-regex@^7.0.1: + version "7.0.3" + resolved "https://registry.yarnpkg.com/emoji-regex/-/emoji-regex-7.0.3.tgz#933a04052860c85e83c122479c4748a8e4c72156" + integrity sha512-CwBLREIQ7LvYFB0WyRvwhq5N5qPhc6PMjD6bYggFlI5YyDgl+0vxq5VHbMOFqLg7hfWzmu8T5Z1QofhmTIhItA== + +error-ex@^1.2.0: + version "1.3.2" + resolved "https://registry.yarnpkg.com/error-ex/-/error-ex-1.3.2.tgz#b4ac40648107fdcdcfae242f428bea8a14d4f1bf" + integrity sha512-7dFHNmqeFSEt2ZBsCriorKnn3Z2pj+fd9kmI6QoWw4//DL+icEBfc0U7qJCisqrTsKTjw4fNFy2pW9OqStD84g== + dependencies: + is-arrayish "^0.2.1" + +es-abstract@^1.12.0, es-abstract@^1.7.0: + version "1.14.1" + resolved "https://registry.yarnpkg.com/es-abstract/-/es-abstract-1.14.1.tgz#6e8d84b445ec9c610781e74a6d52cc31aac5b4ca" + integrity sha512-cp/Tb1oA/rh2X7vqeSOvM+TSo3UkJLX70eNihgVEvnzwAgikjkTFr/QVgRCaxjm0knCNQzNoxxxcw2zO2LJdZA== + dependencies: + es-to-primitive "^1.2.0" + function-bind "^1.1.1" + has "^1.0.3" + has-symbols "^1.0.0" + is-callable "^1.1.4" + is-regex "^1.0.4" + object-inspect "^1.6.0" + object-keys "^1.1.1" + string.prototype.trimleft "^2.0.0" + string.prototype.trimright "^2.0.0" + +es-to-primitive@^1.2.0: + version "1.2.0" + resolved "https://registry.yarnpkg.com/es-to-primitive/-/es-to-primitive-1.2.0.tgz#edf72478033456e8dda8ef09e00ad9650707f377" + integrity sha512-qZryBOJjV//LaxLTV6UC//WewneB3LcXOL9NP++ozKVXsIIIpm/2c13UDiD9Jp2eThsecw9m3jPqDwTyobcdbg== + dependencies: + is-callable "^1.1.4" + is-date-object "^1.0.1" + is-symbol "^1.0.2" + +escape-string-regexp@^1.0.5: + version "1.0.5" + resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4" + integrity sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ= + +eslint-config-prettier@^6.2.0: + version "6.2.0" + resolved "https://registry.yarnpkg.com/eslint-config-prettier/-/eslint-config-prettier-6.2.0.tgz#80e0b8714e3f6868c4ac2a25fbf39c02e73527a7" + integrity sha512-VLsgK/D+S/FEsda7Um1+N8FThec6LqE3vhcMyp8mlmto97y3fGf3DX7byJexGuOb1QY0Z/zz222U5t+xSfcZDQ== + dependencies: + get-stdin "^6.0.0" + +eslint-import-resolver-node@^0.3.2: + version "0.3.2" + resolved "https://registry.yarnpkg.com/eslint-import-resolver-node/-/eslint-import-resolver-node-0.3.2.tgz#58f15fb839b8d0576ca980413476aab2472db66a" + integrity sha512-sfmTqJfPSizWu4aymbPr4Iidp5yKm8yDkHp+Ir3YiTHiiDfxh69mOUsmiqW6RZ9zRXFaF64GtYmN7e+8GHBv6Q== + dependencies: + debug "^2.6.9" + resolve "^1.5.0" + +eslint-module-utils@^2.4.0: + version "2.4.1" + resolved "https://registry.yarnpkg.com/eslint-module-utils/-/eslint-module-utils-2.4.1.tgz#7b4675875bf96b0dbf1b21977456e5bb1f5e018c" + integrity sha512-H6DOj+ejw7Tesdgbfs4jeS4YMFrT8uI8xwd1gtQqXssaR0EQ26L+2O/w6wkYFy2MymON0fTwHmXBvvfLNZVZEw== + dependencies: + debug "^2.6.8" + pkg-dir "^2.0.0" + +eslint-plugin-import@^2.18.2: + version "2.18.2" + resolved "https://registry.yarnpkg.com/eslint-plugin-import/-/eslint-plugin-import-2.18.2.tgz#02f1180b90b077b33d447a17a2326ceb400aceb6" + integrity sha512-5ohpsHAiUBRNaBWAF08izwUGlbrJoJJ+W9/TBwsGoR1MnlgfwMIKrFeSjWbt6moabiXW9xNvtFz+97KHRfI4HQ== + dependencies: + array-includes "^3.0.3" + contains-path "^0.1.0" + debug "^2.6.9" + doctrine "1.5.0" + eslint-import-resolver-node "^0.3.2" + eslint-module-utils "^2.4.0" + has "^1.0.3" + minimatch "^3.0.4" + object.values "^1.1.0" + read-pkg-up "^2.0.0" + resolve "^1.11.0" + +eslint-plugin-prettier@^3.1.0: + version "3.1.0" + resolved "https://registry.yarnpkg.com/eslint-plugin-prettier/-/eslint-plugin-prettier-3.1.0.tgz#8695188f95daa93b0dc54b249347ca3b79c4686d" + integrity sha512-XWX2yVuwVNLOUhQijAkXz+rMPPoCr7WFiAl8ig6I7Xn+pPVhDhzg4DxHpmbeb0iqjO9UronEA3Tb09ChnFVHHA== + dependencies: + prettier-linter-helpers "^1.0.0" + +eslint-scope@^4.0.0: + version "4.0.3" + resolved "https://registry.yarnpkg.com/eslint-scope/-/eslint-scope-4.0.3.tgz#ca03833310f6889a3264781aa82e63eb9cfe7848" + integrity sha512-p7VutNr1O/QrxysMo3E45FjYDTeXBy0iTltPFNSqKAIfjDSXC+4dj+qfyuD8bfAXrW/y6lW3O76VaYNPKfpKrg== + dependencies: + esrecurse "^4.1.0" + estraverse "^4.1.1" + +eslint-scope@^5.0.0: + version "5.0.0" + resolved "https://registry.yarnpkg.com/eslint-scope/-/eslint-scope-5.0.0.tgz#e87c8887c73e8d1ec84f1ca591645c358bfc8fb9" + integrity sha512-oYrhJW7S0bxAFDvWqzvMPRm6pcgcnWc4QnofCAqRTRfQC0JcwenzGglTtsLyIuuWFfkqDG9vz67cnttSd53djw== + dependencies: + esrecurse "^4.1.0" + estraverse "^4.1.1" + +eslint-utils@^1.4.0, eslint-utils@^1.4.2: + version "1.4.2" + resolved "https://registry.yarnpkg.com/eslint-utils/-/eslint-utils-1.4.2.tgz#166a5180ef6ab7eb462f162fd0e6f2463d7309ab" + integrity sha512-eAZS2sEUMlIeCjBeubdj45dmBHQwPHWyBcT1VSYB7o9x9WRRqKxyUoiXlRjyAwzN7YEzHJlYg0NmzDRWx6GP4Q== + dependencies: + eslint-visitor-keys "^1.0.0" + +eslint-visitor-keys@^1.0.0, eslint-visitor-keys@^1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-1.1.0.tgz#e2a82cea84ff246ad6fb57f9bde5b46621459ec2" + integrity sha512-8y9YjtM1JBJU/A9Kc+SbaOV4y29sSWckBwMHa+FGtVj5gN/sbnKDf6xJUl+8g7FAij9LVaP8C24DUiH/f/2Z9A== + +eslint@^6.3.0: + version "6.3.0" + resolved "https://registry.yarnpkg.com/eslint/-/eslint-6.3.0.tgz#1f1a902f67bfd4c354e7288b81e40654d927eb6a" + integrity sha512-ZvZTKaqDue+N8Y9g0kp6UPZtS4FSY3qARxBs7p4f0H0iof381XHduqVerFWtK8DPtKmemqbqCFENWSQgPR/Gow== + dependencies: + "@babel/code-frame" "^7.0.0" + ajv "^6.10.0" + chalk "^2.1.0" + cross-spawn "^6.0.5" + debug "^4.0.1" + doctrine "^3.0.0" + eslint-scope "^5.0.0" + eslint-utils "^1.4.2" + eslint-visitor-keys "^1.1.0" + espree "^6.1.1" + esquery "^1.0.1" + esutils "^2.0.2" + file-entry-cache "^5.0.1" + functional-red-black-tree "^1.0.1" + glob-parent "^5.0.0" + globals "^11.7.0" + ignore "^4.0.6" + import-fresh "^3.0.0" + imurmurhash "^0.1.4" + inquirer "^6.4.1" + is-glob "^4.0.0" + js-yaml "^3.13.1" + json-stable-stringify-without-jsonify "^1.0.1" + levn "^0.3.0" + lodash "^4.17.14" + minimatch "^3.0.4" + mkdirp "^0.5.1" + natural-compare "^1.4.0" + optionator "^0.8.2" + progress "^2.0.0" + regexpp "^2.0.1" + semver "^6.1.2" + strip-ansi "^5.2.0" + strip-json-comments "^3.0.1" + table "^5.2.3" + text-table "^0.2.0" + v8-compile-cache "^2.0.3" + +espree@^6.1.1: + version "6.1.1" + resolved "https://registry.yarnpkg.com/espree/-/espree-6.1.1.tgz#7f80e5f7257fc47db450022d723e356daeb1e5de" + integrity sha512-EYbr8XZUhWbYCqQRW0duU5LxzL5bETN6AjKBGy1302qqzPaCH10QbRg3Wvco79Z8x9WbiE8HYB4e75xl6qUYvQ== + dependencies: + acorn "^7.0.0" + acorn-jsx "^5.0.2" + eslint-visitor-keys "^1.1.0" + +esprima@^4.0.0: + version "4.0.1" + resolved "https://registry.yarnpkg.com/esprima/-/esprima-4.0.1.tgz#13b04cdb3e6c5d19df91ab6987a8695619b0aa71" + integrity sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A== + +esquery@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/esquery/-/esquery-1.0.1.tgz#406c51658b1f5991a5f9b62b1dc25b00e3e5c708" + integrity sha512-SmiyZ5zIWH9VM+SRUReLS5Q8a7GxtRdxEBVZpm98rJM7Sb+A9DVCndXfkeFUd3byderg+EbDkfnevfCwynWaNA== + dependencies: + estraverse "^4.0.0" + +esrecurse@^4.1.0: + version "4.2.1" + resolved "https://registry.yarnpkg.com/esrecurse/-/esrecurse-4.2.1.tgz#007a3b9fdbc2b3bb87e4879ea19c92fdbd3942cf" + integrity sha512-64RBB++fIOAXPw3P9cy89qfMlvZEXZkqqJkjqqXIvzP5ezRZjW+lPWjw35UX/3EhUPFYbg5ER4JYgDw4007/DQ== + dependencies: + estraverse "^4.1.0" + +estraverse@^4.0.0, estraverse@^4.1.0, estraverse@^4.1.1: + version "4.3.0" + resolved "https://registry.yarnpkg.com/estraverse/-/estraverse-4.3.0.tgz#398ad3f3c5a24948be7725e83d11a7de28cdbd1d" + integrity sha512-39nnKffWz8xN1BU/2c79n9nB9HDzo0niYUqx6xyqUnyoAnQyyWpOTdZEeiCch8BBu515t4wp9ZmgVfVhn9EBpw== + +estree-walker@^0.6.1: + version "0.6.1" + resolved "https://registry.yarnpkg.com/estree-walker/-/estree-walker-0.6.1.tgz#53049143f40c6eb918b23671d1fe3219f3a1b362" + integrity sha512-SqmZANLWS0mnatqbSfRP5g8OXZC12Fgg1IwNtLsyHDzJizORW4khDfjPqJZsemPWBB2uqykUah5YpQ6epsqC/w== + +esutils@^2.0.2: + version "2.0.3" + resolved "https://registry.yarnpkg.com/esutils/-/esutils-2.0.3.tgz#74d2eb4de0b8da1293711910d50775b9b710ef64" + integrity sha512-kVscqXk4OCp68SZ0dkgEKVi6/8ij300KBWTJq32P/dYeWTSwK41WyTxalN1eRmA5Z9UU/LX9D7FWSmV9SAYx6g== + +external-editor@^3.0.3: + version "3.1.0" + resolved "https://registry.yarnpkg.com/external-editor/-/external-editor-3.1.0.tgz#cb03f740befae03ea4d283caed2741a83f335495" + integrity sha512-hMQ4CX1p1izmuLYyZqLMO/qGNw10wSv9QDCPfzXfyFrOaCSSoRfqE1Kf1s5an66J5JZC62NewG+mK49jOCtQew== + dependencies: + chardet "^0.7.0" + iconv-lite "^0.4.24" + tmp "^0.0.33" + +fast-deep-equal@^2.0.1: + version "2.0.1" + resolved "https://registry.yarnpkg.com/fast-deep-equal/-/fast-deep-equal-2.0.1.tgz#7b05218ddf9667bf7f370bf7fdb2cb15fdd0aa49" + integrity sha1-ewUhjd+WZ79/Nwv3/bLLFf3Qqkk= + +fast-diff@^1.1.2: + version "1.2.0" + resolved "https://registry.yarnpkg.com/fast-diff/-/fast-diff-1.2.0.tgz#73ee11982d86caaf7959828d519cfe927fac5f03" + integrity sha512-xJuoT5+L99XlZ8twedaRf6Ax2TgQVxvgZOYoPKqZufmJib0tL2tegPBOZb1pVNgIhlqDlA0eO0c3wBvQcmzx4w== + +fast-json-stable-stringify@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/fast-json-stable-stringify/-/fast-json-stable-stringify-2.0.0.tgz#d5142c0caee6b1189f87d3a76111064f86c8bbf2" + integrity sha1-1RQsDK7msRifh9OnYREGT4bIu/I= + +fast-levenshtein@~2.0.4: + version "2.0.6" + resolved "https://registry.yarnpkg.com/fast-levenshtein/-/fast-levenshtein-2.0.6.tgz#3d8a5c66883a16a30ca8643e851f19baa7797917" + integrity sha1-PYpcZog6FqMMqGQ+hR8Zuqd5eRc= + +figures@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/figures/-/figures-2.0.0.tgz#3ab1a2d2a62c8bfb431a0c94cb797a2fce27c962" + integrity sha1-OrGi0qYsi/tDGgyUy3l6L84nyWI= + dependencies: + escape-string-regexp "^1.0.5" + +file-entry-cache@^5.0.1: + version "5.0.1" + resolved "https://registry.yarnpkg.com/file-entry-cache/-/file-entry-cache-5.0.1.tgz#ca0f6efa6dd3d561333fb14515065c2fafdf439c" + integrity sha512-bCg29ictuBaKUwwArK4ouCaqDgLZcysCFLmM/Yn/FDoqndh/9vNuQfXRDvTuXKLxfD/JtZQGKFT8MGcJBK644g== + dependencies: + flat-cache "^2.0.1" + +find-cache-dir@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/find-cache-dir/-/find-cache-dir-3.0.0.tgz#cd4b7dd97b7185b7e17dbfe2d6e4115ee3eeb8fc" + integrity sha512-t7ulV1fmbxh5G9l/492O1p5+EBbr3uwpt6odhFTMc+nWyhmbloe+ja9BZ8pIBtqFWhOmCWVjx+pTW4zDkFoclw== + dependencies: + commondir "^1.0.1" + make-dir "^3.0.0" + pkg-dir "^4.1.0" + +find-up@^2.0.0, find-up@^2.1.0: + version "2.1.0" + resolved "https://registry.yarnpkg.com/find-up/-/find-up-2.1.0.tgz#45d1b7e506c717ddd482775a2b77920a3c0c57a7" + integrity sha1-RdG35QbHF93UgndaK3eSCjwMV6c= + dependencies: + locate-path "^2.0.0" + +find-up@^4.0.0: + version "4.1.0" + resolved "https://registry.yarnpkg.com/find-up/-/find-up-4.1.0.tgz#97afe7d6cdc0bc5928584b7c8d7b16e8a9aa5d19" + integrity sha512-PpOwAdQ/YlXQ2vj8a3h8IipDuYRi3wceVQQGYWxNINccq40Anw7BlsEXCMbt1Zt+OLA6Fq9suIpIWD0OsnISlw== + dependencies: + locate-path "^5.0.0" + path-exists "^4.0.0" + +flat-cache@^2.0.1: + version "2.0.1" + resolved "https://registry.yarnpkg.com/flat-cache/-/flat-cache-2.0.1.tgz#5d296d6f04bda44a4630a301413bdbc2ec085ec0" + integrity sha512-LoQe6yDuUMDzQAEH8sgmh4Md6oZnc/7PjtwjNFSzveXqSHt6ka9fPBuso7IGf9Rz4uqnSnWiFH2B/zj24a5ReA== + dependencies: + flatted "^2.0.0" + rimraf "2.6.3" + write "1.0.3" + +flatted@^2.0.0: + version "2.0.1" + resolved "https://registry.yarnpkg.com/flatted/-/flatted-2.0.1.tgz#69e57caa8f0eacbc281d2e2cb458d46fdb449e08" + integrity sha512-a1hQMktqW9Nmqr5aktAux3JMNqaucxGcjtjWnZLHX7yyPCmlSV3M54nGYbqT8K+0GhF3NBgmJCc3ma+WOgX8Jg== + +fs-extra@8.1.0: + version "8.1.0" + resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-8.1.0.tgz#49d43c45a88cd9677668cb7be1b46efdb8d2e1c0" + integrity sha512-yhlQgA6mnOJUKOsRUFsgJdQCvkKhcz8tlZG5HBQfReYZy46OwLcY+Zia0mtdHsOo9y/hP+CxMN0TU9QxoOtG4g== + dependencies: + graceful-fs "^4.2.0" + jsonfile "^4.0.0" + universalify "^0.1.0" + +fs.realpath@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f" + integrity sha1-FQStJSMVjKpA20onh8sBQRmU6k8= + +function-bind@^1.0.2, function-bind@^1.1.1: + version "1.1.1" + resolved "https://registry.yarnpkg.com/function-bind/-/function-bind-1.1.1.tgz#a56899d3ea3c9bab874bb9773b7c5ede92f4895d" + integrity sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A== + +functional-red-black-tree@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/functional-red-black-tree/-/functional-red-black-tree-1.0.1.tgz#1b0ab3bd553b2a0d6399d29c0e3ea0b252078327" + integrity sha1-GwqzvVU7Kg1jmdKcDj6gslIHgyc= + +get-stdin@^6.0.0: + version "6.0.0" + resolved "https://registry.yarnpkg.com/get-stdin/-/get-stdin-6.0.0.tgz#9e09bf712b360ab9225e812048f71fde9c89657b" + integrity sha512-jp4tHawyV7+fkkSKyvjuLZswblUtz+SQKzSWnBbii16BuZksJlU1wuBYXY75r+duh/llF1ur6oNwi+2ZzjKZ7g== + +glob-parent@^5.0.0: + version "5.0.0" + resolved "https://registry.yarnpkg.com/glob-parent/-/glob-parent-5.0.0.tgz#1dc99f0f39b006d3e92c2c284068382f0c20e954" + integrity sha512-Z2RwiujPRGluePM6j699ktJYxmPpJKCfpGA13jz2hmFZC7gKetzrWvg5KN3+OsIFmydGyZ1AVwERCq1w/ZZwRg== + dependencies: + is-glob "^4.0.1" + +glob@^7.1.3, glob@^7.1.4: + version "7.1.4" + resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.4.tgz#aa608a2f6c577ad357e1ae5a5c26d9a8d1969255" + integrity sha512-hkLPepehmnKk41pUGm3sYxoFs/umurYfYJCerbXEyFIWcAzvpipAgVkBqqT9RBKMGjnq6kMuyYwha6csxbiM1A== + dependencies: + fs.realpath "^1.0.0" + inflight "^1.0.4" + inherits "2" + minimatch "^3.0.4" + once "^1.3.0" + path-is-absolute "^1.0.0" + +globals@^11.7.0: + version "11.12.0" + resolved "https://registry.yarnpkg.com/globals/-/globals-11.12.0.tgz#ab8795338868a0babd8525758018c2a7eb95c42e" + integrity sha512-WOBp/EEGUiIsJSp7wcv/y6MO+lV9UoncWqxuFfm8eBwzWNgyfBd6Gz+IeKQ9jCmyhoH99g15M3T+QaVHFjizVA== + +graceful-fs@^4.1.2, graceful-fs@^4.1.6, graceful-fs@^4.2.0: + version "4.2.2" + resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.2.tgz#6f0952605d0140c1cfdb138ed005775b92d67b02" + integrity sha512-IItsdsea19BoLC7ELy13q1iJFNmd7ofZH5+X/pJr90/nRoPEX0DJo1dHDbgtYWOhJhcCgMDTOw84RZ72q6lB+Q== + +has-flag@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/has-flag/-/has-flag-3.0.0.tgz#b5d454dc2199ae225699f3467e5a07f3b955bafd" + integrity sha1-tdRU3CGZriJWmfNGfloH87lVuv0= + +has-symbols@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/has-symbols/-/has-symbols-1.0.0.tgz#ba1a8f1af2a0fc39650f5c850367704122063b44" + integrity sha1-uhqPGvKg/DllD1yFA2dwQSIGO0Q= + +has@^1.0.1, has@^1.0.3: + version "1.0.3" + resolved "https://registry.yarnpkg.com/has/-/has-1.0.3.tgz#722d7cbfc1f6aa8241f16dd814e011e1f41e8796" + integrity sha512-f2dvO0VU6Oej7RkWJGrehjbzMAjFp5/VKPp5tTpWIV4JHHZK1/BxbFRtf/siA2SWTe09caDmVtYYzWEIbBS4zw== + dependencies: + function-bind "^1.1.1" + +hosted-git-info@^2.1.4: + version "2.8.4" + resolved "https://registry.yarnpkg.com/hosted-git-info/-/hosted-git-info-2.8.4.tgz#44119abaf4bc64692a16ace34700fed9c03e2546" + integrity sha512-pzXIvANXEFrc5oFFXRMkbLPQ2rXRoDERwDLyrcUxGhaZhgP54BBSl9Oheh7Vv0T090cszWBxPjkQQ5Sq1PbBRQ== + +iconv-lite@^0.4.24: + version "0.4.24" + resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.4.24.tgz#2022b4b25fbddc21d2f524974a474aafe733908b" + integrity sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA== + dependencies: + safer-buffer ">= 2.1.2 < 3" + +ignore@^4.0.6: + version "4.0.6" + resolved "https://registry.yarnpkg.com/ignore/-/ignore-4.0.6.tgz#750e3db5862087b4737ebac8207ffd1ef27b25fc" + integrity sha512-cyFDKrqc/YdcWFniJhzI42+AzS+gNwmUzOSFcRCQYwySuBBBy/KjuxWLZ/FHEH6Moq1NizMOBWyTcv8O4OZIMg== + +import-fresh@^3.0.0: + version "3.1.0" + resolved "https://registry.yarnpkg.com/import-fresh/-/import-fresh-3.1.0.tgz#6d33fa1dcef6df930fae003446f33415af905118" + integrity sha512-PpuksHKGt8rXfWEr9m9EHIpgyyaltBy8+eF6GJM0QCAxMgxCfucMF3mjecK2QsJr0amJW7gTqh5/wht0z2UhEQ== + dependencies: + parent-module "^1.0.0" + resolve-from "^4.0.0" + +imurmurhash@^0.1.4: + version "0.1.4" + resolved "https://registry.yarnpkg.com/imurmurhash/-/imurmurhash-0.1.4.tgz#9218b9b2b928a238b13dc4fb6b6d576f231453ea" + integrity sha1-khi5srkoojixPcT7a21XbyMUU+o= + +inflight@^1.0.4: + version "1.0.6" + resolved "https://registry.yarnpkg.com/inflight/-/inflight-1.0.6.tgz#49bd6331d7d02d0c09bc910a1075ba8165b56df9" + integrity sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk= + dependencies: + once "^1.3.0" + wrappy "1" + +inherits@2: + version "2.0.4" + resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.4.tgz#0fa2c64f932917c3433a0ded55363aae37416b7c" + integrity sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ== + +inquirer@^6.4.1: + version "6.5.2" + resolved "https://registry.yarnpkg.com/inquirer/-/inquirer-6.5.2.tgz#ad50942375d036d327ff528c08bd5fab089928ca" + integrity sha512-cntlB5ghuB0iuO65Ovoi8ogLHiWGs/5yNrtUcKjFhSSiVeAIVpD7koaSU9RM8mpXw5YDi9RdYXGQMaOURB7ycQ== + dependencies: + ansi-escapes "^3.2.0" + chalk "^2.4.2" + cli-cursor "^2.1.0" + cli-width "^2.0.0" + external-editor "^3.0.3" + figures "^2.0.0" + lodash "^4.17.12" + mute-stream "0.0.7" + run-async "^2.2.0" + rxjs "^6.4.0" + string-width "^2.1.0" + strip-ansi "^5.1.0" + through "^2.3.6" + +is-arrayish@^0.2.1: + version "0.2.1" + resolved "https://registry.yarnpkg.com/is-arrayish/-/is-arrayish-0.2.1.tgz#77c99840527aa8ecb1a8ba697b80645a7a926a9d" + integrity sha1-d8mYQFJ6qOyxqLppe4BkWnqSap0= + +is-callable@^1.1.4: + version "1.1.4" + resolved "https://registry.yarnpkg.com/is-callable/-/is-callable-1.1.4.tgz#1e1adf219e1eeb684d691f9d6a05ff0d30a24d75" + integrity sha512-r5p9sxJjYnArLjObpjA4xu5EKI3CuKHkJXMhT7kwbpUyIFD1n5PMAsoPvWnvtZiNz7LjkYDRZhd7FlI0eMijEA== + +is-date-object@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/is-date-object/-/is-date-object-1.0.1.tgz#9aa20eb6aeebbff77fbd33e74ca01b33581d3a16" + integrity sha1-mqIOtq7rv/d/vTPnTKAbM1gdOhY= + +is-extglob@^2.1.1: + version "2.1.1" + resolved "https://registry.yarnpkg.com/is-extglob/-/is-extglob-2.1.1.tgz#a88c02535791f02ed37c76a1b9ea9773c833f8c2" + integrity sha1-qIwCU1eR8C7TfHahueqXc8gz+MI= + +is-fullwidth-code-point@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz#a3b30a5c4f199183167aaab93beefae3ddfb654f" + integrity sha1-o7MKXE8ZkYMWeqq5O+764937ZU8= + +is-glob@^4.0.0, is-glob@^4.0.1: + version "4.0.1" + resolved "https://registry.yarnpkg.com/is-glob/-/is-glob-4.0.1.tgz#7567dbe9f2f5e2467bc77ab83c4a29482407a5dc" + integrity sha512-5G0tKtBTFImOqDnLB2hG6Bp2qcKEFduo4tZu9MT/H6NQv/ghhy30o55ufafxJ/LdH79LLs2Kfrn85TLKyA7BUg== + dependencies: + is-extglob "^2.1.1" + +is-module@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/is-module/-/is-module-1.0.0.tgz#3258fb69f78c14d5b815d664336b4cffb6441591" + integrity sha1-Mlj7afeMFNW4FdZkM2tM/7ZEFZE= + +is-promise@^2.1.0: + version "2.1.0" + resolved "https://registry.yarnpkg.com/is-promise/-/is-promise-2.1.0.tgz#79a2a9ece7f096e80f36d2b2f3bc16c1ff4bf3fa" + integrity sha1-eaKp7OfwlugPNtKy87wWwf9L8/o= + +is-reference@^1.1.2: + version "1.1.3" + resolved "https://registry.yarnpkg.com/is-reference/-/is-reference-1.1.3.tgz#e99059204b66fdbe09305cfca715a29caa5c8a51" + integrity sha512-W1iHHv/oyBb2pPxkBxtaewxa1BC58Pn5J0hogyCdefwUIvb6R+TGbAcIa4qPNYLqLhb3EnOgUf2MQkkF76BcKw== + dependencies: + "@types/estree" "0.0.39" + +is-regex@^1.0.4: + version "1.0.4" + resolved "https://registry.yarnpkg.com/is-regex/-/is-regex-1.0.4.tgz#5517489b547091b0930e095654ced25ee97e9491" + integrity sha1-VRdIm1RwkbCTDglWVM7SXul+lJE= + dependencies: + has "^1.0.1" + +is-symbol@^1.0.2: + version "1.0.2" + resolved "https://registry.yarnpkg.com/is-symbol/-/is-symbol-1.0.2.tgz#a055f6ae57192caee329e7a860118b497a950f38" + integrity sha512-HS8bZ9ox60yCJLH9snBpIwv9pYUAkcuLhSA1oero1UB5y9aiQpRA8y2ex945AOtCZL1lJDeIk3G5LthswI46Lw== + dependencies: + has-symbols "^1.0.0" + +isarray@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/isarray/-/isarray-1.0.0.tgz#bb935d48582cba168c06834957a54a3e07124f11" + integrity sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE= + +isexe@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/isexe/-/isexe-2.0.0.tgz#e8fbf374dc556ff8947a10dcb0572d633f2cfa10" + integrity sha1-6PvzdNxVb/iUehDcsFctYz8s+hA= + +js-tokens@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-4.0.0.tgz#19203fb59991df98e3a287050d4647cdeaf32499" + integrity sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ== + +js-yaml@^3.13.1: + version "3.13.1" + resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-3.13.1.tgz#aff151b30bfdfa8e49e05da22e7415e9dfa37847" + integrity sha512-YfbcO7jXDdyj0DGxYVSlSeQNHbD7XPWvrVWeVUujrQEoZzWJIRrCPoyk6kL6IAjAG2IolMK4T0hNUe0HOUs5Jw== + dependencies: + argparse "^1.0.7" + esprima "^4.0.0" + +json-schema-traverse@^0.4.1: + version "0.4.1" + resolved "https://registry.yarnpkg.com/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz#69f6a87d9513ab8bb8fe63bdb0979c448e684660" + integrity sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg== + +json-stable-stringify-without-jsonify@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/json-stable-stringify-without-jsonify/-/json-stable-stringify-without-jsonify-1.0.1.tgz#9db7b59496ad3f3cfef30a75142d2d930ad72651" + integrity sha1-nbe1lJatPzz+8wp1FC0tkwrXJlE= + +jsonfile@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/jsonfile/-/jsonfile-4.0.0.tgz#8771aae0799b64076b76640fca058f9c10e33ecb" + integrity sha1-h3Gq4HmbZAdrdmQPygWPnBDjPss= + optionalDependencies: + graceful-fs "^4.1.6" + +levn@^0.3.0, levn@~0.3.0: + version "0.3.0" + resolved "https://registry.yarnpkg.com/levn/-/levn-0.3.0.tgz#3b09924edf9f083c0490fdd4c0bc4421e04764ee" + integrity sha1-OwmSTt+fCDwEkP3UwLxEIeBHZO4= + dependencies: + prelude-ls "~1.1.2" + type-check "~0.3.2" + +load-json-file@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/load-json-file/-/load-json-file-2.0.0.tgz#7947e42149af80d696cbf797bcaabcfe1fe29ca8" + integrity sha1-eUfkIUmvgNaWy/eXvKq8/h/inKg= + dependencies: + graceful-fs "^4.1.2" + parse-json "^2.2.0" + pify "^2.0.0" + strip-bom "^3.0.0" + +locate-path@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/locate-path/-/locate-path-2.0.0.tgz#2b568b265eec944c6d9c0de9c3dbbbca0354cd8e" + integrity sha1-K1aLJl7slExtnA3pw9u7ygNUzY4= + dependencies: + p-locate "^2.0.0" + path-exists "^3.0.0" + +locate-path@^5.0.0: + version "5.0.0" + resolved "https://registry.yarnpkg.com/locate-path/-/locate-path-5.0.0.tgz#1afba396afd676a6d42504d0a67a3a7eb9f62aa0" + integrity sha512-t7hw9pI+WvuwNJXwk5zVHpyhIqzg2qTlklJOf0mVxGSbe3Fp2VieZcduNYjaLDoy6p9uGpQEGWG87WpMKlNq8g== + dependencies: + p-locate "^4.1.0" + +lodash.unescape@4.0.1: + version "4.0.1" + resolved "https://registry.yarnpkg.com/lodash.unescape/-/lodash.unescape-4.0.1.tgz#bf2249886ce514cda112fae9218cdc065211fc9c" + integrity sha1-vyJJiGzlFM2hEvrpIYzcBlIR/Jw= + +lodash@^4.17.12, lodash@^4.17.14: + version "4.17.15" + resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.15.tgz#b447f6670a0455bbfeedd11392eff330ea097548" + integrity sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A== + +luaparse@^0.2.1: + version "0.2.1" + resolved "https://registry.yarnpkg.com/luaparse/-/luaparse-0.2.1.tgz#aa8f56132b0de97d37f3c991a9df42e0e17f656c" + integrity sha1-qo9WEysN6X0388mRqd9C4OF/ZWw= + +magic-string@^0.25.2: + version "0.25.3" + resolved "https://registry.yarnpkg.com/magic-string/-/magic-string-0.25.3.tgz#34b8d2a2c7fec9d9bdf9929a3fd81d271ef35be9" + integrity sha512-6QK0OpF/phMz0Q2AxILkX2mFhi7m+WMwTRg0LQKq/WBB0cDP4rYH3Wp4/d3OTXlrPLVJT/RFqj8tFeAR4nk8AA== + dependencies: + sourcemap-codec "^1.4.4" + +make-dir@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/make-dir/-/make-dir-3.0.0.tgz#1b5f39f6b9270ed33f9f054c5c0f84304989f801" + integrity sha512-grNJDhb8b1Jm1qeqW5R/O63wUo4UXo2v2HMic6YT9i/HBlF93S8jkMgH7yugvY9ABDShH4VZMn8I+U8+fCNegw== + dependencies: + semver "^6.0.0" + +mimic-fn@^1.0.0: + version "1.2.0" + resolved "https://registry.yarnpkg.com/mimic-fn/-/mimic-fn-1.2.0.tgz#820c86a39334640e99516928bd03fca88057d022" + integrity sha512-jf84uxzwiuiIVKiOLpfYk7N46TSy8ubTonmneY9vrpHNAnp0QBt2BxWV9dO3/j+BoVAb+a5G6YDPW3M5HOdMWQ== + +minimatch@^3.0.4: + version "3.0.4" + resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.0.4.tgz#5166e286457f03306064be5497e8dbb0c3d32083" + integrity sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA== + dependencies: + brace-expansion "^1.1.7" + +minimist@0.0.8: + version "0.0.8" + resolved "https://registry.yarnpkg.com/minimist/-/minimist-0.0.8.tgz#857fcabfc3397d2625b8228262e86aa7a011b05d" + integrity sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0= + +mkdirp@^0.5.1: + version "0.5.1" + resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-0.5.1.tgz#30057438eac6cf7f8c4767f38648d6697d75c903" + integrity sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM= + dependencies: + minimist "0.0.8" + +ms@2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/ms/-/ms-2.0.0.tgz#5608aeadfc00be6c2901df5f9861788de0d597c8" + integrity sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g= + +ms@^2.1.1: + version "2.1.2" + resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.2.tgz#d09d1f357b443f493382a8eb3ccd183872ae6009" + integrity sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w== + +mute-stream@0.0.7: + version "0.0.7" + resolved "https://registry.yarnpkg.com/mute-stream/-/mute-stream-0.0.7.tgz#3075ce93bc21b8fab43e1bc4da7e8115ed1e7bab" + integrity sha1-MHXOk7whuPq0PhvE2n6BFe0ee6s= + +natural-compare@^1.4.0: + version "1.4.0" + resolved "https://registry.yarnpkg.com/natural-compare/-/natural-compare-1.4.0.tgz#4abebfeed7541f2c27acfb29bdbbd15c8d5ba4f7" + integrity sha1-Sr6/7tdUHywnrPspvbvRXI1bpPc= + +nice-try@^1.0.4: + version "1.0.5" + resolved "https://registry.yarnpkg.com/nice-try/-/nice-try-1.0.5.tgz#a3378a7696ce7d223e88fc9b764bd7ef1089e366" + integrity sha512-1nh45deeb5olNY7eX82BkPO7SSxR5SSYJiPTrTdFUVYwAl8CKMA5N9PjTYkHiRjisVcxcQ1HXdLhx2qxxJzLNQ== + +normalize-package-data@^2.3.2: + version "2.5.0" + resolved "https://registry.yarnpkg.com/normalize-package-data/-/normalize-package-data-2.5.0.tgz#e66db1838b200c1dfc233225d12cb36520e234a8" + integrity sha512-/5CMN3T0R4XTj4DcGaexo+roZSdSFW/0AOOTROrjxzCG1wrWXEsGbRKevjlIL+ZDE4sZlJr5ED4YW0yqmkK+eA== + dependencies: + hosted-git-info "^2.1.4" + resolve "^1.10.0" + semver "2 || 3 || 4 || 5" + validate-npm-package-license "^3.0.1" + +object-inspect@^1.6.0: + version "1.6.0" + resolved "https://registry.yarnpkg.com/object-inspect/-/object-inspect-1.6.0.tgz#c70b6cbf72f274aab4c34c0c82f5167bf82cf15b" + integrity sha512-GJzfBZ6DgDAmnuaM3104jR4s1Myxr3Y3zfIyN4z3UdqN69oSRacNK8UhnobDdC+7J2AHCjGwxQubNJfE70SXXQ== + +object-keys@^1.0.12, object-keys@^1.1.1: + version "1.1.1" + resolved "https://registry.yarnpkg.com/object-keys/-/object-keys-1.1.1.tgz#1c47f272df277f3b1daf061677d9c82e2322c60e" + integrity sha512-NuAESUOUMrlIXOfHKzD6bpPu3tYt3xvjNdRIQ+FeT0lNb4K8WR70CaDxhuNguS2XG+GjkyMwOzsN5ZktImfhLA== + +object.values@^1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/object.values/-/object.values-1.1.0.tgz#bf6810ef5da3e5325790eaaa2be213ea84624da9" + integrity sha512-8mf0nKLAoFX6VlNVdhGj31SVYpaNFtUnuoOXWyFEstsWRgU837AK+JYM0iAxwkSzGRbwn8cbFmgbyxj1j4VbXg== + dependencies: + define-properties "^1.1.3" + es-abstract "^1.12.0" + function-bind "^1.1.1" + has "^1.0.3" + +once@^1.3.0: + version "1.4.0" + resolved "https://registry.yarnpkg.com/once/-/once-1.4.0.tgz#583b1aa775961d4b113ac17d9c50baef9dd76bd1" + integrity sha1-WDsap3WWHUsROsF9nFC6753Xa9E= + dependencies: + wrappy "1" + +onetime@^2.0.0: + version "2.0.1" + resolved "https://registry.yarnpkg.com/onetime/-/onetime-2.0.1.tgz#067428230fd67443b2794b22bba528b6867962d4" + integrity sha1-BnQoIw/WdEOyeUsiu6UotoZ5YtQ= + dependencies: + mimic-fn "^1.0.0" + +optionator@^0.8.2: + version "0.8.2" + resolved "https://registry.yarnpkg.com/optionator/-/optionator-0.8.2.tgz#364c5e409d3f4d6301d6c0b4c05bba50180aeb64" + integrity sha1-NkxeQJ0/TWMB1sC0wFu6UBgK62Q= + dependencies: + deep-is "~0.1.3" + fast-levenshtein "~2.0.4" + levn "~0.3.0" + prelude-ls "~1.1.2" + type-check "~0.3.2" + wordwrap "~1.0.0" + +os-tmpdir@~1.0.2: + version "1.0.2" + resolved "https://registry.yarnpkg.com/os-tmpdir/-/os-tmpdir-1.0.2.tgz#bbe67406c79aa85c5cfec766fe5734555dfa1274" + integrity sha1-u+Z0BseaqFxc/sdm/lc0VV36EnQ= + +p-limit@^1.1.0: + version "1.3.0" + resolved "https://registry.yarnpkg.com/p-limit/-/p-limit-1.3.0.tgz#b86bd5f0c25690911c7590fcbfc2010d54b3ccb8" + integrity sha512-vvcXsLAJ9Dr5rQOPk7toZQZJApBl2K4J6dANSsEuh6QI41JYcsS/qhTGa9ErIUUgK3WNQoJYvylxvjqmiqEA9Q== + dependencies: + p-try "^1.0.0" + +p-limit@^2.2.0: + version "2.2.1" + resolved "https://registry.yarnpkg.com/p-limit/-/p-limit-2.2.1.tgz#aa07a788cc3151c939b5131f63570f0dd2009537" + integrity sha512-85Tk+90UCVWvbDavCLKPOLC9vvY8OwEX/RtKF+/1OADJMVlFfEHOiMTPVyxg7mk/dKa+ipdHm0OUkTvCpMTuwg== + dependencies: + p-try "^2.0.0" + +p-locate@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/p-locate/-/p-locate-2.0.0.tgz#20a0103b222a70c8fd39cc2e580680f3dde5ec43" + integrity sha1-IKAQOyIqcMj9OcwuWAaA893l7EM= + dependencies: + p-limit "^1.1.0" + +p-locate@^4.1.0: + version "4.1.0" + resolved "https://registry.yarnpkg.com/p-locate/-/p-locate-4.1.0.tgz#a3428bb7088b3a60292f66919278b7c297ad4f07" + integrity sha512-R79ZZ/0wAxKGu3oYMlz8jy/kbhsNrS7SKZ7PxEHBgJ5+F2mtFW2fK2cOtBh1cHYkQsbzFV7I+EoRKe6Yt0oK7A== + dependencies: + p-limit "^2.2.0" + +p-try@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/p-try/-/p-try-1.0.0.tgz#cbc79cdbaf8fd4228e13f621f2b1a237c1b207b3" + integrity sha1-y8ec26+P1CKOE/Yh8rGiN8GyB7M= + +p-try@^2.0.0: + version "2.2.0" + resolved "https://registry.yarnpkg.com/p-try/-/p-try-2.2.0.tgz#cb2868540e313d61de58fafbe35ce9004d5540e6" + integrity sha512-R4nPAVTAU0B9D35/Gk3uJf/7XYbQcyohSKdvAxIRSNghFl4e71hVoGnBNQz9cWaXxO2I10KTC+3jMdvvoKw6dQ== + +parent-module@^1.0.0: + version "1.0.1" + resolved "https://registry.yarnpkg.com/parent-module/-/parent-module-1.0.1.tgz#691d2709e78c79fae3a156622452d00762caaaa2" + integrity sha512-GQ2EWRpQV8/o+Aw8YqtfZZPfNRWZYkbidE9k5rpl/hC3vtHHBfGm2Ifi6qWV+coDGkrUKZAxE3Lot5kcsRlh+g== + dependencies: + callsites "^3.0.0" + +parse-json@^2.2.0: + version "2.2.0" + resolved "https://registry.yarnpkg.com/parse-json/-/parse-json-2.2.0.tgz#f480f40434ef80741f8469099f8dea18f55a4dc9" + integrity sha1-9ID0BDTvgHQfhGkJn43qGPVaTck= + dependencies: + error-ex "^1.2.0" + +path-exists@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/path-exists/-/path-exists-3.0.0.tgz#ce0ebeaa5f78cb18925ea7d810d7b59b010fd515" + integrity sha1-zg6+ql94yxiSXqfYENe1mwEP1RU= + +path-exists@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/path-exists/-/path-exists-4.0.0.tgz#513bdbe2d3b95d7762e8c1137efa195c6c61b5b3" + integrity sha512-ak9Qy5Q7jYb2Wwcey5Fpvg2KoAc/ZIhLSLOSBmRmygPsGwkVVt0fZa0qrtMz+m6tJTAHfZQ8FnmB4MG4LWy7/w== + +path-is-absolute@^1.0.0: + version "1.0.1" + resolved "https://registry.yarnpkg.com/path-is-absolute/-/path-is-absolute-1.0.1.tgz#174b9268735534ffbc7ace6bf53a5a9e1b5c5f5f" + integrity sha1-F0uSaHNVNP+8es5r9TpanhtcX18= + +path-key@^2.0.1: + version "2.0.1" + resolved "https://registry.yarnpkg.com/path-key/-/path-key-2.0.1.tgz#411cadb574c5a140d3a4b1910d40d80cc9f40b40" + integrity sha1-QRyttXTFoUDTpLGRDUDYDMn0C0A= + +path-parse@^1.0.6: + version "1.0.6" + resolved "https://registry.yarnpkg.com/path-parse/-/path-parse-1.0.6.tgz#d62dbb5679405d72c4737ec58600e9ddcf06d24c" + integrity sha512-GSmOT2EbHrINBf9SR7CDELwlJ8AENk3Qn7OikK4nFYAu3Ote2+JYNVvkpAEQm3/TLNEJFD/xZJjzyxg3KBWOzw== + +path-type@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/path-type/-/path-type-2.0.0.tgz#f012ccb8415b7096fc2daa1054c3d72389594c73" + integrity sha1-8BLMuEFbcJb8LaoQVMPXI4lZTHM= + dependencies: + pify "^2.0.0" + +pify@^2.0.0: + version "2.3.0" + resolved "https://registry.yarnpkg.com/pify/-/pify-2.3.0.tgz#ed141a6ac043a849ea588498e7dca8b15330e90c" + integrity sha1-7RQaasBDqEnqWISY59yosVMw6Qw= + +pkg-dir@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/pkg-dir/-/pkg-dir-2.0.0.tgz#f6d5d1109e19d63edf428e0bd57e12777615334b" + integrity sha1-9tXREJ4Z1j7fQo4L1X4Sd3YVM0s= + dependencies: + find-up "^2.1.0" + +pkg-dir@^4.1.0: + version "4.2.0" + resolved "https://registry.yarnpkg.com/pkg-dir/-/pkg-dir-4.2.0.tgz#f099133df7ede422e81d1d8448270eeb3e4261f3" + integrity sha512-HRDzbaKjC+AOWVXxAU/x54COGeIv9eb+6CkDSQoNTt4XyWoIJvuPsXizxu/Fr23EiekbtZwmh1IcIG/l/a10GQ== + dependencies: + find-up "^4.0.0" + +prelude-ls@~1.1.2: + version "1.1.2" + resolved "https://registry.yarnpkg.com/prelude-ls/-/prelude-ls-1.1.2.tgz#21932a549f5e52ffd9a827f570e04be62a97da54" + integrity sha1-IZMqVJ9eUv/ZqCf1cOBL5iqX2lQ= + +prettier-linter-helpers@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/prettier-linter-helpers/-/prettier-linter-helpers-1.0.0.tgz#d23d41fe1375646de2d0104d3454a3008802cf7b" + integrity sha512-GbK2cP9nraSSUF9N2XwUwqfzlAFlMNYYl+ShE/V+H8a9uNl/oUqB1w2EL54Jh0OlyRSd8RfWYJ3coVS4TROP2w== + dependencies: + fast-diff "^1.1.2" + +prettier@1.18.2: + version "1.18.2" + resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.18.2.tgz#6823e7c5900017b4bd3acf46fe9ac4b4d7bda9ea" + integrity sha512-OeHeMc0JhFE9idD4ZdtNibzY0+TPHSpSSb9h8FqtP+YnoZZ1sl8Vc9b1sasjfymH3SonAF4QcA2+mzHPhMvIiw== + +printj@^1.2.2: + version "1.2.2" + resolved "https://registry.yarnpkg.com/printj/-/printj-1.2.2.tgz#620eb0f07509394545fe82f97fe73baa8ad86992" + integrity sha512-dx9nIry0Z12s5oebhenDCFQjj/IMVotLMbvFP6OJ+C3v+EV30mtYoj6QtaulFo+DbWCbpEeaqcLYMh6CRuVjsA== + +progress@^2.0.0: + version "2.0.3" + resolved "https://registry.yarnpkg.com/progress/-/progress-2.0.3.tgz#7e8cf8d8f5b8f239c1bc68beb4eb78567d572ef8" + integrity sha512-7PiHtLll5LdnKIMw100I+8xJXR5gW2QwWYkT6iJva0bXitZKa/XMrSbdmg3r2Xnaidz9Qumd0VPaMrZlF9V9sA== + +punycode@^2.1.0: + version "2.1.1" + resolved "https://registry.yarnpkg.com/punycode/-/punycode-2.1.1.tgz#b58b010ac40c22c5657616c8d2c2c02c7bf479ec" + integrity sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A== + +read-pkg-up@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/read-pkg-up/-/read-pkg-up-2.0.0.tgz#6b72a8048984e0c41e79510fd5e9fa99b3b549be" + integrity sha1-a3KoBImE4MQeeVEP1en6mbO1Sb4= + dependencies: + find-up "^2.0.0" + read-pkg "^2.0.0" + +read-pkg@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/read-pkg/-/read-pkg-2.0.0.tgz#8ef1c0623c6a6db0dc6713c4bfac46332b2368f8" + integrity sha1-jvHAYjxqbbDcZxPEv6xGMysjaPg= + dependencies: + load-json-file "^2.0.0" + normalize-package-data "^2.3.2" + path-type "^2.0.0" + +regexpp@^2.0.1: + version "2.0.1" + resolved "https://registry.yarnpkg.com/regexpp/-/regexpp-2.0.1.tgz#8d19d31cf632482b589049f8281f93dbcba4d07f" + integrity sha512-lv0M6+TkDVniA3aD1Eg0DVpfU/booSu7Eev3TDO/mZKHBfVjgCGTV4t4buppESEYDtkArYFOxTJWv6S5C+iaNw== + +resolve-from@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/resolve-from/-/resolve-from-4.0.0.tgz#4abcd852ad32dd7baabfe9b40e00a36db5f392e6" + integrity sha512-pb/MYmXstAkysRFx8piNI1tGFNQIFA3vkE3Gq4EuA1dF6gHp/+vgZqsCGJapvy8N3Q+4o7FwvquPJcnZ7RYy4g== + +resolve@1.12.0, resolve@^1.10.0, resolve@^1.11.0, resolve@^1.11.1, resolve@^1.5.0: + version "1.12.0" + resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.12.0.tgz#3fc644a35c84a48554609ff26ec52b66fa577df6" + integrity sha512-B/dOmuoAik5bKcD6s6nXDCjzUKnaDvdkRyAk6rsmsKLipWj4797iothd7jmmUhWTfinVMU+wc56rYKsit2Qy4w== + dependencies: + path-parse "^1.0.6" + +restore-cursor@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/restore-cursor/-/restore-cursor-2.0.0.tgz#9f7ee287f82fd326d4fd162923d62129eee0dfaf" + integrity sha1-n37ih/gv0ybU/RYpI9YhKe7g368= + dependencies: + onetime "^2.0.0" + signal-exit "^3.0.2" + +rimraf@2.6.3: + version "2.6.3" + resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-2.6.3.tgz#b2d104fe0d8fb27cf9e0a1cda8262dd3833c6cab" + integrity sha512-mwqeW5XsA2qAejG46gYdENaxXjx9onRNCfn7L0duuP4hCuTIi/QO7PDK07KJfp1d+izWPrzEJDcSqBa0OZQriA== + dependencies: + glob "^7.1.3" + +rimraf@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-3.0.0.tgz#614176d4b3010b75e5c390eb0ee96f6dc0cebb9b" + integrity sha512-NDGVxTsjqfunkds7CqsOiEnxln4Bo7Nddl3XhS4pXg5OzwkLqJ971ZVAAnB+DDLnF76N+VnDEiBHaVV8I06SUg== + dependencies: + glob "^7.1.3" + +rollup-plugin-commonjs@^10.1.0: + version "10.1.0" + resolved "https://registry.yarnpkg.com/rollup-plugin-commonjs/-/rollup-plugin-commonjs-10.1.0.tgz#417af3b54503878e084d127adf4d1caf8beb86fb" + integrity sha512-jlXbjZSQg8EIeAAvepNwhJj++qJWNJw1Cl0YnOqKtP5Djx+fFGkp3WRh+W0ASCaFG5w1jhmzDxgu3SJuVxPF4Q== + dependencies: + estree-walker "^0.6.1" + is-reference "^1.1.2" + magic-string "^0.25.2" + resolve "^1.11.0" + rollup-pluginutils "^2.8.1" + +rollup-plugin-node-resolve@^5.2.0: + version "5.2.0" + resolved "https://registry.yarnpkg.com/rollup-plugin-node-resolve/-/rollup-plugin-node-resolve-5.2.0.tgz#730f93d10ed202473b1fb54a5997a7db8c6d8523" + integrity sha512-jUlyaDXts7TW2CqQ4GaO5VJ4PwwaV8VUGA7+km3n6k6xtOEacf61u0VXwN80phY/evMcaS+9eIeJ9MOyDxt5Zw== + dependencies: + "@types/resolve" "0.0.8" + builtin-modules "^3.1.0" + is-module "^1.0.0" + resolve "^1.11.1" + rollup-pluginutils "^2.8.1" + +rollup-plugin-typescript2@^0.24.0: + version "0.24.0" + resolved "https://registry.yarnpkg.com/rollup-plugin-typescript2/-/rollup-plugin-typescript2-0.24.0.tgz#27ce5459d03e095236bdbcda3ca68fe289718d07" + integrity sha512-yp7z9hZ5kXjOGXKXkfTRJuIPyLvKtUWfAGmreilnYn+qIVhE5CgE7SFvzLKHggsAXPaCAflHRiEj0l71WXWJkA== + dependencies: + find-cache-dir "^3.0.0" + fs-extra "8.1.0" + resolve "1.12.0" + rollup-pluginutils "2.8.1" + tslib "1.10.0" + +rollup-pluginutils@2.8.1, rollup-pluginutils@^2.8.1: + version "2.8.1" + resolved "https://registry.yarnpkg.com/rollup-pluginutils/-/rollup-pluginutils-2.8.1.tgz#8fa6dd0697344938ef26c2c09d2488ce9e33ce97" + integrity sha512-J5oAoysWar6GuZo0s+3bZ6sVZAC0pfqKz68De7ZgDi5z63jOVZn1uJL/+z1jeKHNbGII8kAyHF5q8LnxSX5lQg== + dependencies: + estree-walker "^0.6.1" + +rollup@^1.20.3: + version "1.20.3" + resolved "https://registry.yarnpkg.com/rollup/-/rollup-1.20.3.tgz#6243f6c118ca05f56b2d9433112400cd834a1eb8" + integrity sha512-/OMCkY0c6E8tleeVm4vQVDz24CkVgvueK3r8zTYu2AQNpjrcaPwO9hE+pWj5LTFrvvkaxt4MYIp2zha4y0lRvg== + dependencies: + "@types/estree" "0.0.39" + "@types/node" "^12.7.2" + acorn "^7.0.0" + +run-async@^2.2.0: + version "2.3.0" + resolved "https://registry.yarnpkg.com/run-async/-/run-async-2.3.0.tgz#0371ab4ae0bdd720d4166d7dfda64ff7a445a6c0" + integrity sha1-A3GrSuC91yDUFm19/aZP96RFpsA= + dependencies: + is-promise "^2.1.0" + +rxjs@^6.4.0: + version "6.5.3" + resolved "https://registry.yarnpkg.com/rxjs/-/rxjs-6.5.3.tgz#510e26317f4db91a7eb1de77d9dd9ba0a4899a3a" + integrity sha512-wuYsAYYFdWTAnAaPoKGNhfpWwKZbJW+HgAJ+mImp+Epl7BG8oNWBCTyRM8gba9k4lk8BgWdoYm21Mo/RYhhbgA== + dependencies: + tslib "^1.9.0" + +"safer-buffer@>= 2.1.2 < 3": + version "2.1.2" + resolved "https://registry.yarnpkg.com/safer-buffer/-/safer-buffer-2.1.2.tgz#44fa161b0187b9549dd84bb91802f9bd8385cd6a" + integrity sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg== + +"semver@2 || 3 || 4 || 5", semver@^5.5.0: + version "5.7.1" + resolved "https://registry.yarnpkg.com/semver/-/semver-5.7.1.tgz#a954f931aeba508d307bbf069eff0c01c96116f7" + integrity sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ== + +semver@^6.0.0, semver@^6.1.2, semver@^6.2.0: + version "6.3.0" + resolved "https://registry.yarnpkg.com/semver/-/semver-6.3.0.tgz#ee0a64c8af5e8ceea67687b133761e1becbd1d3d" + integrity sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw== + +shebang-command@^1.2.0: + version "1.2.0" + resolved "https://registry.yarnpkg.com/shebang-command/-/shebang-command-1.2.0.tgz#44aac65b695b03398968c39f363fee5deafdf1ea" + integrity sha1-RKrGW2lbAzmJaMOfNj/uXer98eo= + dependencies: + shebang-regex "^1.0.0" + +shebang-regex@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/shebang-regex/-/shebang-regex-1.0.0.tgz#da42f49740c0b42db2ca9728571cb190c98efea3" + integrity sha1-2kL0l0DAtC2yypcoVxyxkMmO/qM= + +signal-exit@^3.0.2: + version "3.0.2" + resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.2.tgz#b5fdc08f1287ea1178628e415e25132b73646c6d" + integrity sha1-tf3AjxKH6hF4Yo5BXiUTK3NkbG0= + +slice-ansi@^2.1.0: + version "2.1.0" + resolved "https://registry.yarnpkg.com/slice-ansi/-/slice-ansi-2.1.0.tgz#cacd7693461a637a5788d92a7dd4fba068e81636" + integrity sha512-Qu+VC3EwYLldKa1fCxuuvULvSJOKEgk9pi8dZeCVK7TqBfUNTH4sFkk4joj8afVSfAYgJoSOetjx9QWOJ5mYoQ== + dependencies: + ansi-styles "^3.2.0" + astral-regex "^1.0.0" + is-fullwidth-code-point "^2.0.0" + +sourcemap-codec@^1.4.4: + version "1.4.6" + resolved "https://registry.yarnpkg.com/sourcemap-codec/-/sourcemap-codec-1.4.6.tgz#e30a74f0402bad09807640d39e971090a08ce1e9" + integrity sha512-1ZooVLYFxC448piVLBbtOxFcXwnymH9oUF8nRd3CuYDVvkRBxRl6pB4Mtas5a4drtL+E8LDgFkQNcgIw6tc8Hg== + +spdx-correct@^3.0.0: + version "3.1.0" + resolved "https://registry.yarnpkg.com/spdx-correct/-/spdx-correct-3.1.0.tgz#fb83e504445268f154b074e218c87c003cd31df4" + integrity sha512-lr2EZCctC2BNR7j7WzJ2FpDznxky1sjfxvvYEyzxNyb6lZXHODmEoJeFu4JupYlkfha1KZpJyoqiJ7pgA1qq8Q== + dependencies: + spdx-expression-parse "^3.0.0" + spdx-license-ids "^3.0.0" + +spdx-exceptions@^2.1.0: + version "2.2.0" + resolved "https://registry.yarnpkg.com/spdx-exceptions/-/spdx-exceptions-2.2.0.tgz#2ea450aee74f2a89bfb94519c07fcd6f41322977" + integrity sha512-2XQACfElKi9SlVb1CYadKDXvoajPgBVPn/gOQLrTvHdElaVhr7ZEbqJaRnJLVNeaI4cMEAgVCeBMKF6MWRDCRA== + +spdx-expression-parse@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/spdx-expression-parse/-/spdx-expression-parse-3.0.0.tgz#99e119b7a5da00e05491c9fa338b7904823b41d0" + integrity sha512-Yg6D3XpRD4kkOmTpdgbUiEJFKghJH03fiC1OPll5h/0sO6neh2jqRDVHOQ4o/LMea0tgCkbMgea5ip/e+MkWyg== + dependencies: + spdx-exceptions "^2.1.0" + spdx-license-ids "^3.0.0" + +spdx-license-ids@^3.0.0: + version "3.0.5" + resolved "https://registry.yarnpkg.com/spdx-license-ids/-/spdx-license-ids-3.0.5.tgz#3694b5804567a458d3c8045842a6358632f62654" + integrity sha512-J+FWzZoynJEXGphVIS+XEh3kFSjZX/1i9gFBaWQcB+/tmpe2qUsSBABpcxqxnAxFdiUFEgAX1bjYGQvIZmoz9Q== + +sprintf-js@~1.0.2: + version "1.0.3" + resolved "https://registry.yarnpkg.com/sprintf-js/-/sprintf-js-1.0.3.tgz#04e6926f662895354f3dd015203633b857297e2c" + integrity sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw= + +string-width@^2.1.0: + version "2.1.1" + resolved "https://registry.yarnpkg.com/string-width/-/string-width-2.1.1.tgz#ab93f27a8dc13d28cac815c462143a6d9012ae9e" + integrity sha512-nOqH59deCq9SRHlxq1Aw85Jnt4w6KvLKqWVik6oA9ZklXLNIOlqg4F2yrT1MVaTjAqvVwdfeZ7w7aCvJD7ugkw== + dependencies: + is-fullwidth-code-point "^2.0.0" + strip-ansi "^4.0.0" + +string-width@^3.0.0: + version "3.1.0" + resolved "https://registry.yarnpkg.com/string-width/-/string-width-3.1.0.tgz#22767be21b62af1081574306f69ac51b62203961" + integrity sha512-vafcv6KjVZKSgz06oM/H6GDBrAtz8vdhQakGjFIvNrHA6y3HCF1CInLy+QLq8dTJPQ1b+KDUqDFctkdRW44e1w== + dependencies: + emoji-regex "^7.0.1" + is-fullwidth-code-point "^2.0.0" + strip-ansi "^5.1.0" + +string.prototype.trimleft@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/string.prototype.trimleft/-/string.prototype.trimleft-2.0.0.tgz#68b6aa8e162c6a80e76e3a8a0c2e747186e271ff" + integrity sha1-aLaqjhYsaoDnbjqKDC50cYbicf8= + dependencies: + define-properties "^1.1.2" + function-bind "^1.0.2" + +string.prototype.trimright@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/string.prototype.trimright/-/string.prototype.trimright-2.0.0.tgz#ab4a56d802a01fbe7293e11e84f24dc8164661dd" + integrity sha1-q0pW2AKgH75yk+EehPJNyBZGYd0= + dependencies: + define-properties "^1.1.2" + function-bind "^1.0.2" + +strip-ansi@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-4.0.0.tgz#a8479022eb1ac368a871389b635262c505ee368f" + integrity sha1-qEeQIusaw2iocTibY1JixQXuNo8= + dependencies: + ansi-regex "^3.0.0" + +strip-ansi@^5.1.0, strip-ansi@^5.2.0: + version "5.2.0" + resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-5.2.0.tgz#8c9a536feb6afc962bdfa5b104a5091c1ad9c0ae" + integrity sha512-DuRs1gKbBqsMKIZlrffwlug8MHkcnpjs5VPmL1PAh+mA30U0DTotfDZ0d2UUsXpPmPmMMJ6W773MaA3J+lbiWA== + dependencies: + ansi-regex "^4.1.0" + +strip-bom@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/strip-bom/-/strip-bom-3.0.0.tgz#2334c18e9c759f7bdd56fdef7e9ae3d588e68ed3" + integrity sha1-IzTBjpx1n3vdVv3vfprj1YjmjtM= + +strip-json-comments@^3.0.1: + version "3.0.1" + resolved "https://registry.yarnpkg.com/strip-json-comments/-/strip-json-comments-3.0.1.tgz#85713975a91fb87bf1b305cca77395e40d2a64a7" + integrity sha512-VTyMAUfdm047mwKl+u79WIdrZxtFtn+nBxHeb844XBQ9uMNTuTHdx2hc5RiAJYqwTj3wc/xe5HLSdJSkJ+WfZw== + +supports-color@^5.3.0: + version "5.5.0" + resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-5.5.0.tgz#e2e69a44ac8772f78a1ec0b35b689df6530efc8f" + integrity sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow== + dependencies: + has-flag "^3.0.0" + +table@^5.2.3: + version "5.4.6" + resolved "https://registry.yarnpkg.com/table/-/table-5.4.6.tgz#1292d19500ce3f86053b05f0e8e7e4a3bb21079e" + integrity sha512-wmEc8m4fjnob4gt5riFRtTu/6+4rSe12TpAELNSqHMfF3IqnA+CH37USM6/YR3qRZv7e56kAEAtd6nKZaxe0Ug== + dependencies: + ajv "^6.10.2" + lodash "^4.17.14" + slice-ansi "^2.1.0" + string-width "^3.0.0" + +text-table@^0.2.0: + version "0.2.0" + resolved "https://registry.yarnpkg.com/text-table/-/text-table-0.2.0.tgz#7f5ee823ae805207c00af2df4a84ec3fcfa570b4" + integrity sha1-f17oI66AUgfACvLfSoTsP8+lcLQ= + +through@^2.3.6: + version "2.3.8" + resolved "https://registry.yarnpkg.com/through/-/through-2.3.8.tgz#0dd4c9ffaabc357960b1b724115d7e0e86a2e1f5" + integrity sha1-DdTJ/6q8NXlgsbckEV1+Doai4fU= + +tmp@^0.0.33: + version "0.0.33" + resolved "https://registry.yarnpkg.com/tmp/-/tmp-0.0.33.tgz#6d34335889768d21b2bcda0aa277ced3b1bfadf9" + integrity sha512-jRCJlojKnZ3addtTOjdIqoRuPEKBvNXcGYqzO6zWZX8KfKEpnGY5jfggJQ3EjKuu8D4bJRr0y+cYJFmYbImXGw== + dependencies: + os-tmpdir "~1.0.2" + +tslib@1.10.0, tslib@^1.8.1, tslib@^1.9.0: + version "1.10.0" + resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.10.0.tgz#c3c19f95973fb0a62973fb09d90d961ee43e5c8a" + integrity sha512-qOebF53frne81cf0S9B41ByenJ3/IuH8yJKngAX35CmiZySA0khhkovshKK+jGCaMnVomla7gVlIcc3EvKPbTQ== + +tsutils@^3.14.0: + version "3.17.1" + resolved "https://registry.yarnpkg.com/tsutils/-/tsutils-3.17.1.tgz#ed719917f11ca0dee586272b2ac49e015a2dd759" + integrity sha512-kzeQ5B8H3w60nFY2g8cJIuH7JDpsALXySGtwGJ0p2LSjLgay3NdIpqq5SoOBe46bKDW2iq25irHCr8wjomUS2g== + dependencies: + tslib "^1.8.1" + +type-check@~0.3.2: + version "0.3.2" + resolved "https://registry.yarnpkg.com/type-check/-/type-check-0.3.2.tgz#5884cab512cf1d355e3fb784f30804b2b520db72" + integrity sha1-WITKtRLPHTVeP7eE8wgEsrUg23I= + dependencies: + prelude-ls "~1.1.2" + +typescript@^3.6.2: + version "3.6.2" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.6.2.tgz#105b0f1934119dde543ac8eb71af3a91009efe54" + integrity sha512-lmQ4L+J6mnu3xweP8+rOrUwzmN+MRAj7TgtJtDaXE5PMyX2kCrklhg3rvOsOIfNeAWMQWO2F1GPc1kMD2vLAfw== + +universalify@^0.1.0: + version "0.1.2" + resolved "https://registry.yarnpkg.com/universalify/-/universalify-0.1.2.tgz#b646f69be3942dabcecc9d6639c80dc105efaa66" + integrity sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg== + +uri-js@^4.2.2: + version "4.2.2" + resolved "https://registry.yarnpkg.com/uri-js/-/uri-js-4.2.2.tgz#94c540e1ff772956e2299507c010aea6c8838eb0" + integrity sha512-KY9Frmirql91X2Qgjry0Wd4Y+YTdrdZheS8TFwvkbLWf/G5KNJDCh6pKL5OZctEW4+0Baa5idK2ZQuELRwPznQ== + dependencies: + punycode "^2.1.0" + +v8-compile-cache@^2.0.3: + version "2.1.0" + resolved "https://registry.yarnpkg.com/v8-compile-cache/-/v8-compile-cache-2.1.0.tgz#e14de37b31a6d194f5690d67efc4e7f6fc6ab30e" + integrity sha512-usZBT3PW+LOjM25wbqIlZwPeJV+3OSz3M1k1Ws8snlW39dZyYL9lOGC5FgPVHfk0jKmjiDV8Z0mIbVQPiwFs7g== + +validate-npm-package-license@^3.0.1: + version "3.0.4" + resolved "https://registry.yarnpkg.com/validate-npm-package-license/-/validate-npm-package-license-3.0.4.tgz#fc91f6b9c7ba15c857f4cb2c5defeec39d4f410a" + integrity sha512-DpKm2Ui/xN7/HQKCtpZxoRWBhZ9Z0kqtygG8XCgNQ8ZlDnxuQmWhj566j8fN4Cu3/JmbhsDo7fcAJq4s9h27Ew== + dependencies: + spdx-correct "^3.0.0" + spdx-expression-parse "^3.0.0" + +which@^1.2.9: + version "1.3.1" + resolved "https://registry.yarnpkg.com/which/-/which-1.3.1.tgz#a45043d54f5805316da8d62f9f50918d3da70b0a" + integrity sha512-HxJdYWq1MTIQbJ3nw0cqssHoTNU267KlrDuGZ1WYlxDStUtKUhOaJmh112/TZmHxxUfuJqPXSOm7tDyas0OSIQ== + dependencies: + isexe "^2.0.0" + +wordwrap@~1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/wordwrap/-/wordwrap-1.0.0.tgz#27584810891456a4171c8d0226441ade90cbcaeb" + integrity sha1-J1hIEIkUVqQXHI0CJkQa3pDLyus= + +wrappy@1: + version "1.0.2" + resolved "https://registry.yarnpkg.com/wrappy/-/wrappy-1.0.2.tgz#b5243d8f3ec1aa35f1364605bc0d1036e30ab69f" + integrity sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8= + +write@1.0.3: + version "1.0.3" + resolved "https://registry.yarnpkg.com/write/-/write-1.0.3.tgz#0800e14523b923a387e415123c865616aae0f5c3" + integrity sha512-/lg70HAjtkUgWPVZhZcm+T4hkL8Zbtp1nFNOn3lRrxnlv50SRBv7cR7RqR+GMsd3hUXy9hWBo4CHTbFTcOYwig== + dependencies: + mkdirp "^0.5.1"