diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2018-06-22 01:04:15 +0800 |
---|---|---|
committer | alexlamsl <alexlamsl@gmail.com> | 2018-06-24 04:00:36 +0800 |
commit | 28330913d871dd4bdb4e59464c7230f9ae4174fa (patch) | |
tree | 32fba882ce0d546d14f461677c56e771e10f02e1 /test/mocha/tokens.js | |
parent | 766a4147d4891a093b550e958268c48104330b52 (diff) | |
download | tracifyjs-28330913d871dd4bdb4e59464c7230f9ae4174fa.tar.gz tracifyjs-28330913d871dd4bdb4e59464c7230f9ae4174fa.zip |
improve `mocha` tests (#3195)
Diffstat (limited to 'test/mocha/tokens.js')
-rw-r--r-- | test/mocha/tokens.js | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/test/mocha/tokens.js b/test/mocha/tokens.js new file mode 100644 index 00000000..6241f25d --- /dev/null +++ b/test/mocha/tokens.js @@ -0,0 +1,26 @@ +var assert = require("assert"); +var UglifyJS = require("../.."); + +describe("tokens", function() { + it("Should give correct positions for accessors", function() { + // location 0 1 2 3 4 + // 01234567890123456789012345678901234567890123456789 + var ast = UglifyJS.parse("var obj = { get latest() { return undefined; } }"); + // test all AST_ObjectProperty tokens are set as expected + var found = false; + ast.walk(new UglifyJS.TreeWalker(function(node) { + if (node instanceof UglifyJS.AST_ObjectProperty) { + found = true; + assert.equal(node.start.pos, 12); + assert.equal(node.end.endpos, 46); + assert(node.key instanceof UglifyJS.AST_SymbolAccessor); + assert.equal(node.key.start.pos, 16); + assert.equal(node.key.end.endpos, 22); + assert(node.value instanceof UglifyJS.AST_Accessor); + assert.equal(node.value.start.pos, 22); + assert.equal(node.value.end.endpos, 46); + } + })); + assert(found, "AST_ObjectProperty not found"); + }); +}); |