Skip to content

Commit

Permalink
more test
Browse files Browse the repository at this point in the history
  • Loading branch information
army8735 committed Jun 6, 2014
1 parent 20309e4 commit ed95ee1
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 6 deletions.
6 changes: 3 additions & 3 deletions dist/lexer/rule/EcmascriptRule.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,19 @@
self.addMatch(new LineParse(Token.STRING, "'", "'", false, Lexer.IS_REG));
self.addMatch(new LineParse(Token.TEMPLATE, '`', '`', true, Lexer.IS_REG));

var regMatch = new RegMatch(Token.ID, /^[$a-zA-Z_][$\w]*/, Lexer.SPECIAL, function() {
var id = new RegMatch(Token.ID, /^[$a-zA-Z_][$\w]*/, Lexer.SPECIAL, function() {
return !!(self.keyWords().hasOwnProperty(this.content()));
}, function() {
return ['if', 'for', 'while'].indexOf(this.content()) != -1;
});
regMatch.callback = function(token) {
id.callback = function(token) {
var s = token.content();
if(isProperty) {
token.type(Token.ID);
}
isProperty = false;
};
self.addMatch(regMatch);
self.addMatch(id);

self.addMatch(new RegMatch(Token.NUMBER, /^\.\d+(?:E[+-]?\d*)?/i, {
'SyntaxError: missing exponent': /E[+-]?$/i
Expand Down
6 changes: 3 additions & 3 deletions src/lexer/rule/EcmascriptRule.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,19 @@ var EcmascriptRule = Rule.extend(function() {
self.addMatch(new LineParse(Token.STRING, "'", "'", false, Lexer.IS_REG));
self.addMatch(new LineParse(Token.TEMPLATE, '`', '`', true, Lexer.IS_REG));

var regMatch = new RegMatch(Token.ID, /^[$a-zA-Z_][$\w]*/, Lexer.SPECIAL, function() {
var id = new RegMatch(Token.ID, /^[$a-zA-Z_][$\w]*/, Lexer.SPECIAL, function() {
return !!(self.keyWords().hasOwnProperty(this.content()));
}, function() {
return ['if', 'for', 'while'].indexOf(this.content()) != -1;
});
regMatch.callback = function(token) {
id.callback = function(token) {
var s = token.content();
if(isProperty) {
token.type(Token.ID);
}
isProperty = false;
};
self.addMatch(regMatch);
self.addMatch(id);

self.addMatch(new RegMatch(Token.NUMBER, /^\.\d+(?:E[+-]?\d*)?/i, {
'SyntaxError: missing exponent': /E[+-]?$/i
Expand Down
18 changes: 18 additions & 0 deletions tests/es6parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,18 @@ describe('es6parser', function() {
parser.parse('var {a ');
}).to.throwError();
});
it('destructuring object error: kw can not in array 1', function() {
var parser = homunculus.getParser('es6');
expect(function() {
parser.parse('var [var] = [1]');
}).to.throwError();
});
it('destructuring object error: kw can not in array 2', function() {
var parser = homunculus.getParser('es6');
expect(function() {
parser.parse('var [x, {"a":[var=1,{z=2},...o]}] = []');
}).to.throwError();
});
it('letdecl 1', function() {
var parser = homunculus.getParser('es6');
var node = parser.parse('let a');
Expand Down Expand Up @@ -476,6 +488,12 @@ describe('es6parser', function() {
var node = parser.parse('var o = {var:1}');
expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.VARSTMT,["var",JsNode.VARDECL,[JsNode.BINDID,["o"],JsNode.INITLZ,["=",JsNode.PRMREXPR,[JsNode.OBJLTR,["{",JsNode.PROPTDEF,[JsNode.PROPTNAME,[JsNode.LTRPROPT,["var"]],":",JsNode.PRMREXPR,["1"]],"}"]]]]]]]]);
});
it('keyword can not be label', function() {
var parser = homunculus.getParser('es6');
expect(function() {
parser.parse('var:');
}).to.throwError();
});
it('keyword after get/set', function() {
var parser = homunculus.getParser('es6');
var node = parser.parse('~{get var(){}}');
Expand Down
6 changes: 6 additions & 0 deletions tests/jsparser.js
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,12 @@ describe('jsparser', function() {
var node = parser.parse('var o = {var:1}');
expect(tree(node)).to.eql([JsNode.PROGRAM,[JsNode.VARSTMT,["var",JsNode.VARDECL,["o",JsNode.ASSIGN,["=",JsNode.PRMREXPR,[JsNode.OBJLTR,["{",JsNode.PROPTASSIGN,["var",":",JsNode.PRMREXPR,["1"]],"}"]]]]]]]);
});
it('keyword can not be label', function() {
var parser = homunculus.getParser('js');
expect(function() {
parser.parse('var:');
}).to.throwError();
});
it('keyword after get/set', function() {
var parser = homunculus.getParser('js');
var node = parser.parse('~{get var(){}}');
Expand Down

0 comments on commit ed95ee1

Please sign in to comment.