How to use UnexpectedTokenException method in Cucumber-gherkin

Best JavaScript code snippet using cucumber-gherkin

try_statement_specs.js

Source:try_statement_specs.js Github

copy

Full Screen

1/* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.2* File Name : try_statement_specs.js3* Created at : 2019-02-214* Updated at : 2019-08-085* Author : jeefo6* Purpose :7* Description :8* Reference :9.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.*/10// ignore:start11"use strict";12/* globals*/13/* exported*/14// ignore:end15const expect = require("expect.js");16const { UnexpectedTokenException } = require("@jeefo/parser");17const parser = require("../parser.js");18const precedence_enum = require("../../../src/es5/enums/precedence_enum");19const {20 test_range,21 test_keyword,22 test_for_each,23 test_statement,24 test_substring,25 test_delimiter26} = require("../../helpers");27describe("Try statement >", () => {28 describe("Valid cases >", () => {29 const valid_test_cases = [30 // try {} catch (e) {}31 {32 code : "try {} catch (e) {}",33 source : "try {} catch (e) {}",34 keyword : (node, streamer) => {35 test_keyword("try", null, node, streamer);36 },37 block : (node, streamer) => {38 expect(node.id).to.be("Block statement");39 test_substring("{}", streamer, node);40 },41 handler : (node, streamer) => {42 expect(node.id).to.be("Catch block");43 expect(node.type).to.be("Statement");44 expect(node.precedence).to.be(-1);45 test_keyword("catch", null, node.keyword, streamer);46 // Parameter47 expect(node.parameter).not.to.be(null);48 expect(node.parameter.id).to.be("Identifier");49 expect(node.parameter.value).to.be('e');50 test_substring("e", streamer, node.parameter);51 // parenthesis52 test_delimiter("(", null, node.open_parenthesis, streamer);53 test_delimiter(")", null, node.close_parenthesis, streamer);54 // Block55 expect(node.block.id).to.be("Block statement");56 test_substring("catch (e) {}", streamer, node);57 },58 finalizer : statement => {59 expect(statement).to.be(null);60 }61 },62 // try {} finally {},63 {64 code : "try {} finally {}",65 source : "try {} finally {}",66 keyword : (node, streamer) => {67 test_keyword("try", null, node, streamer);68 },69 block : (node, streamer) => {70 expect(node.id).to.be("Block statement");71 test_substring("{}", streamer, node);72 },73 handler : node => {74 expect(node).to.be(null);75 },76 finalizer : (node, streamer) => {77 expect(node.id).to.be("Finally block");78 expect(node.type).to.be("Statement");79 expect(node.precedence).to.be(-1);80 test_keyword("finally", null, node.keyword, streamer);81 test_substring("finally {}", streamer, node);82 }83 },84 // try {} catch (e) {} finally {},85 {86 code : "try {} catch (e) {} finally {}",87 source : "try {} catch (e) {} finally {}",88 keyword : (node, streamer) => {89 test_keyword("try", null, node, streamer);90 },91 block : (node, streamer) => {92 expect(node.id).to.be("Block statement");93 test_substring("{}", streamer, node);94 },95 handler : (node, streamer) => {96 expect(node.id).to.be("Catch block");97 expect(node.type).to.be("Statement");98 expect(node.precedence).to.be(-1);99 test_keyword("catch", null, node.keyword, streamer);100 // Parameter101 expect(node.parameter).not.to.be(null);102 expect(node.parameter.id).to.be("Identifier");103 expect(node.parameter.value).to.be('e');104 test_substring("e", streamer, node.parameter);105 // parenthesis106 test_delimiter("(", null, node.open_parenthesis, streamer);107 test_delimiter(")", null, node.close_parenthesis, streamer);108 // Block109 expect(node.block.id).to.be("Block statement");110 test_substring("catch (e) {}", streamer, node);111 },112 finalizer : (node, streamer) => {113 expect(node.id).to.be("Finally block");114 expect(node.type).to.be("Statement");115 expect(node.precedence).to.be(-1);116 test_keyword("finally", null, node.keyword, streamer);117 test_substring("finally {}", streamer, node);118 }119 },120 // /*a*/try/*b*/{}/*c*/catch/*d*/(/*e*/e/*f*/)/*g*/{}/*h*/finally/*i*/{}121 {122 code : "try/*b*/{}/*c*/catch/*d*/(/*e*/e/*f*/)/*g*/{}/*h*/finally/*i*/{}",123 source : "/*a*/try/*b*/{}/*c*/catch/*d*/(/*e*/e/*f*/)/*g*/{}/*h*/finally/*i*/{}",124 offset : "/*a*/".length,125 keyword : (node, streamer) => {126 test_keyword("try", "/*a*/", node, streamer);127 },128 block : (node, streamer) => {129 expect(node.id).to.be("Block statement");130 test_substring("{}", streamer, node);131 },132 handler : (node, streamer) => {133 expect(node.id).to.be("Catch block");134 expect(node.type).to.be("Statement");135 expect(node.precedence).to.be(-1);136 test_keyword("catch", "/*c*/", node.keyword, streamer);137 // Parameter138 expect(node.parameter).not.to.be(null);139 expect(node.parameter.id).to.be("Identifier");140 expect(node.parameter.value).to.be('e');141 test_substring("e", streamer, node.parameter);142 // open parenthesis143 test_delimiter("(", "/*d*/", node.open_parenthesis, streamer);144 test_delimiter(")", "/*f*/", node.close_parenthesis, streamer);145 // Block146 expect(node.block.id).to.be("Block statement");147 test_substring("catch/*d*/(/*e*/e/*f*/)/*g*/{}", streamer, node);148 },149 finalizer : (node, streamer) => {150 expect(node.id).to.be("Finally block");151 expect(node.type).to.be("Statement");152 expect(node.precedence).to.be(-1);153 test_keyword("finally", "/*h*/", node.keyword, streamer);154 test_substring("finally/*i*/{}", streamer, node);155 }156 }157 ];158 test_for_each(valid_test_cases, test_case => {159 parser.tokenizer.init(test_case.source);160 parser.prepare_next_state();161 const streamer = parser.tokenizer.streamer;162 let node;163 try {164 node = parser.parse_next_node(precedence_enum.TERMINATION);165 } catch (e) {}166 test_statement(node, "Try");167 it("should be has correct keyword", () => {168 test_case.keyword(node.keyword, streamer);169 });170 it("should be has correct Block statement", () => {171 test_case.block(node.block, streamer);172 });173 it("should be has correct handler", () => {174 test_case.handler(node.handler, streamer);175 });176 it("should be has correct finalizer", () => {177 test_case.finalizer(node.finalizer, streamer);178 });179 test_range(test_case, node, streamer);180 });181 });182 describe("Invalid cases >", () => {183 const error_test_cases = [184 // try185 {186 source : "try",187 error : error => {188 it("should be throw: Unexpected end of stream", () => {189 expect(error.message).to.be("Unexpected end of stream");190 });191 it("should be instanceof SyntaxError", () => {192 expect(error instanceof SyntaxError).to.be(true);193 });194 }195 },196 // try {}197 {198 source : "try {}",199 error : error => {200 it("should be throw: Unexpected end of stream", () => {201 expect(error.message).to.be("Unexpected end of stream");202 });203 it("should be instanceof SyntaxError", () => {204 expect(error instanceof SyntaxError).to.be(true);205 });206 }207 },208 // try /*c*/ a209 {210 source : "try /*c*/ a",211 error : error => {212 it("should be throw: Expected { instead saw: a", () => {213 expect(error.message).to.be("Expected { instead saw: a");214 });215 it("should be has token value: a", () => {216 expect(error.token.value).to.be("a");217 });218 it("should be instanceof UnexpectedTokenException", () => {219 expect(error instanceof UnexpectedTokenException).to.be(true);220 });221 }222 },223 // try {} /*c*/ a224 {225 source : "try {} /*c*/ a",226 error : error => {227 it("should be throw: Expected catch or finally after try instead saw: a", () => {228 expect(error.message).to.be("Expected catch or finally after try instead saw: a");229 });230 it("should be has token value: a", () => {231 expect(error.token.value).to.be("a");232 });233 it("should be instanceof UnexpectedTokenException", () => {234 expect(error instanceof UnexpectedTokenException).to.be(true);235 });236 }237 },238 // try {} catch239 {240 source : "try {} catch",241 error : error => {242 it("should be throw: Unexpected end of stream", () => {243 expect(error.message).to.be("Unexpected end of stream");244 });245 it("should be instanceof SyntaxError", () => {246 expect(error instanceof SyntaxError).to.be(true);247 });248 }249 },250 // try {} catch /*c*/ a251 {252 source : "try {} catch /*c*/ a",253 error : error => {254 it("should be throw: Expected ( instead saw: a", () => {255 expect(error.message).to.be("Expected ( instead saw: a");256 });257 it("should be has token value: a", () => {258 expect(error.token.value).to.be("a");259 });260 it("should be instanceof UnexpectedTokenException", () => {261 expect(error instanceof UnexpectedTokenException).to.be(true);262 });263 }264 },265 // try {} catch (/* comment */)266 {267 source : "try {} catch (/* comment */)",268 error : error => {269 it("should be throw: Missing identifier", () => {270 expect(error.message).to.be("Missing identifier");271 });272 it("should be has token value: )", () => {273 expect(error.token.value).to.be(")");274 });275 it("should be instanceof UnexpectedTokenException", () => {276 expect(error instanceof UnexpectedTokenException).to.be(true);277 });278 }279 },280 // try {} catch (e)281 {282 source : "try {} catch (e)",283 error : error => {284 it("should be throw: Unexpected end of stream", () => {285 expect(error.message).to.be("Unexpected end of stream");286 });287 it("should be instanceof SyntaxError", () => {288 expect(error instanceof SyntaxError).to.be(true);289 });290 }291 },292 // try {} catch (e) /*c*/ a293 {294 source : "try {} catch (e) /*c*/ a",295 error : error => {296 it("should be throw: Expected { instead saw: a", () => {297 expect(error.message).to.be("Expected { instead saw: a");298 });299 it("should be has token value: a", () => {300 expect(error.token.value).to.be("a");301 });302 it("should be instanceof UnexpectedTokenException", () => {303 expect(error instanceof UnexpectedTokenException).to.be(true);304 });305 }306 },307 // try {} finally308 {309 source : "try {} finally",310 error : error => {311 it("should be throw: Unexpected end of stream", () => {312 expect(error.message).to.be("Unexpected end of stream");313 });314 it("should be instanceof SyntaxError", () => {315 expect(error instanceof SyntaxError).to.be(true);316 });317 }318 },319 // try {} finally /*c*/ a320 {321 source : "try {} finally /*c*/ a",322 error : error => {323 it("should be throw: Expected { instead saw: a", () => {324 expect(error.message).to.be("Expected { instead saw: a");325 });326 it("should be has token value: a", () => {327 expect(error.token.value).to.be("a");328 });329 it("should be instanceof UnexpectedTokenException", () => {330 expect(error instanceof UnexpectedTokenException).to.be(true);331 });332 }333 },334 // try {} catch (e) {} finally /*c*/ a335 {336 source : "try {} catch (e) {} finally /*c*/ a",337 error : error => {338 it("should be throw: Expected { instead saw: a", () => {339 expect(error.message).to.be("Expected { instead saw: a");340 });341 it("should be has token value: a", () => {342 expect(error.token.value).to.be("a");343 });344 it("should be instanceof UnexpectedTokenException", () => {345 expect(error instanceof UnexpectedTokenException).to.be(true);346 });347 }348 }349 ];350 test_for_each(error_test_cases, test_case => {351 parser.tokenizer.init(test_case.source);352 parser.prepare_next_state();353 try {354 parser.parse_next_node(precedence_enum.TERMINATION);355 expect("throw").to.be("failed");356 } catch (e) {357 test_case.error(e);358 }359 });360 });...

Full Screen

Full Screen

while_statement_specs.js

Source:while_statement_specs.js Github

copy

Full Screen

1/* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.2* File Name : while_statement_specs.js3* Created at : 2019-02-214* Updated at : 2019-03-315* Author : jeefo6* Purpose :7* Description :8* Reference :9.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.*/10// ignore:start11"use strict";12/* globals */13/* exported */14// ignore:end15const expect = require("expect.js"),16 UnexpectedTokenException = require("@jeefo/parser/src/unexpected_token_exception"),17 parser = require("../parser.js"),18 precedence_enum = require("../../../src/es5/enums/precedence_enum");19describe("While statement >", () => {20 describe("Valid cases >", () => {21 const valid_test_cases = [22 // {{{1 while (true);23 {24 code : "while (true);",25 source : "while (true);",26 pre_comment : comment => {27 expect(comment).to.be(null);28 },29 expression : expression => {30 expect(expression.id).to.be("Surrounded expression");31 expect(expression.type).to.be("Expression");32 expect(expression.expression.id).to.be("Boolean literal");33 expect(expression.expression.token.value).to.be("true");34 },35 statement : statement => {36 expect(statement.id).to.be("Empty statement");37 expect(statement.type).to.be("Statement");38 }39 },40 // {{{1 while (true) {}41 {42 code : "while (true) {}",43 source : "while (true) {}",44 pre_comment : comment => {45 expect(comment).to.be(null);46 },47 expression : expression => {48 expect(expression.id).to.be("Surrounded expression");49 expect(expression.type).to.be("Expression");50 expect(expression.expression.id).to.be("Boolean literal");51 expect(expression.expression.token.value).to.be("true");52 },53 statement : statement => {54 expect(statement.id).to.be("Block statement");55 expect(statement.type).to.be("Statement");56 }57 },58 // {{{1 "while (true) /*comment*/ a /*comment*/\nb",59 {60 code : "while (true) /*comment*/ a",61 source : "while (true) /*comment*/ a /*comment*/\nb",62 pre_comment : comment => {63 expect(comment).to.be(null);64 },65 expression : expression => {66 expect(expression.id).to.be("Surrounded expression");67 expect(expression.type).to.be("Expression");68 expect(expression.expression.id).to.be("Boolean literal");69 expect(expression.expression.token.value).to.be("true");70 },71 statement : (statement, streamer) => {72 expect(statement.id).to.be("Expression statement");73 expect(statement.type).to.be("Statement");74 expect(streamer.substring_from_token(statement)).to.be("/*comment*/ a");75 }76 },77 // {{{1 /*a*/while/*b*/(/*c*/true/*d*/)/*e*/;78 {79 code : "/*a*/while/*b*/(/*c*/true/*d*/)/*e*/;",80 source : "/*a*/while/*b*/(/*c*/true/*d*/)/*e*/;",81 pre_comment : (comment, streamer) => {82 expect(streamer.substring_from_token(comment)).to.be("/*a*/");83 expect(comment.value).to.be("a");84 expect(comment.is_inline).to.be(false);85 },86 expression : (expression, streamer) => {87 expect(expression.id).to.be("Surrounded expression");88 expect(expression.type).to.be("Expression");89 expect(expression.expression.id).to.be("Boolean literal");90 expect(expression.expression.token.value).to.be("true");91 expect(streamer.substring_from_token(expression.expression.pre_comment)).to.be("/*c*/");92 expect(streamer.substring_from_token(expression.expression)).to.be("/*c*/true");93 expect(streamer.substring_from_token(expression.open_parenthesis)).to.be("/*b*/(");94 expect(streamer.substring_from_token(expression.close_parenthesis)).to.be("/*d*/)");95 },96 statement : (statement, streamer) => {97 expect(statement.id).to.be("Empty statement");98 expect(statement.type).to.be("Statement");99 expect(statement.pre_comment).not.to.be(null);100 expect(streamer.substring_from_token(statement)).to.be("/*e*/;");101 }102 },103 // }}}1104 ];105 valid_test_cases.forEach(test_case => {106 describe(`Test against source text '${ test_case.source.replace(/\n/g, "\\n") }'`, () => {107 parser.tokenizer.init(test_case.source);108 parser.prepare_next_state();109 let symbol;110 try {111 symbol = parser.get_next_symbol(precedence_enum.TERMINATION);112 } catch (e) {}113 const streamer = parser.tokenizer.streamer;114 it("should be While statement", () => {115 expect(symbol.id).to.be("While statement");116 expect(symbol.type).to.be("Statement");117 });118 it("should be has correct pre_comment", () => {119 test_case.pre_comment(symbol.pre_comment, streamer);120 });121 it("should be has correct Surrounded expression", () => {122 test_case.expression(symbol.expression, streamer);123 });124 it("should be has correct Statement", () => {125 test_case.statement(symbol.statement, streamer);126 });127 it(`cursor index should be move ${ test_case.source.length } characters to right`, () => {128 const last_index = test_case.code.length - 1;129 expect(streamer.get_current_character()).to.be(test_case.source.charAt(last_index));130 expect(streamer.cursor.index).to.be(last_index);131 });132 it(`should be in correct range`, () => {133 expect(streamer.substring_from_token(symbol)).to.be(test_case.code);134 });135 });136 });137 });138 describe("Invalid cases >", () => {139 const error_test_cases = [140 // {{{1 while141 {142 source : "while",143 error : error => {144 it("should be throw: Unexpected end of stream", () => {145 expect(error.message).to.be("Unexpected end of stream");146 });147 it("should be instanceof SyntaxError", () => {148 expect(error instanceof SyntaxError).to.be(true);149 });150 }151 },152 // {{{1 while ;153 {154 source : "while ;",155 error : error => {156 it("should be throw: Expected ( instead saw: ;", () => {157 expect(error.message).to.be("Expected ( instead saw: ;");158 });159 it("should be has token value: ;", () => {160 expect(error.token.value).to.be(";");161 });162 it("should be instanceof UnexpectedTokenException", () => {163 expect(error instanceof UnexpectedTokenException).to.be(true);164 });165 }166 },167 // {{{1 while /* comment */ a168 {169 source : "while /* comment */ a",170 error : error => {171 it("should be throw: Expected ( instead saw: a", () => {172 expect(error.message).to.be("Expected ( instead saw: a");173 });174 it("should be has token value: a", () => {175 expect(error.token.value).to.be("a");176 });177 it("should be instanceof UnexpectedTokenException", () => {178 expect(error instanceof UnexpectedTokenException).to.be(true);179 });180 }181 },182 // {{{1 while ()183 {184 source : "while ()",185 error : error => {186 it("should be throw: Missing expression", () => {187 expect(error.message).to.be("Missing expression");188 });189 it("should be has token value: )", () => {190 expect(error.token.value).to.be(")");191 });192 it("should be instanceof UnexpectedTokenException", () => {193 expect(error instanceof UnexpectedTokenException).to.be(true);194 });195 }196 },197 // {{{1 while (/* comment */)198 {199 source : "while (/* comment */)",200 error : error => {201 it("should be throw: Missing expression", () => {202 expect(error.message).to.be("Missing expression");203 });204 it("should be has token value: )", () => {205 expect(error.token.value).to.be(")");206 });207 it("should be instanceof UnexpectedTokenException", () => {208 expect(error instanceof UnexpectedTokenException).to.be(true);209 });210 }211 },212 // {{{1 while (false)213 {214 source : "while (false)",215 error : error => {216 it("should be throw: Unexpected end of stream", () => {217 expect(error.message).to.be("Unexpected end of stream");218 });219 it("should be instanceof SyntaxError", () => {220 expect(error instanceof SyntaxError).to.be(true);221 });222 }223 },224 // }}}1225 ];226 error_test_cases.forEach(test_case => {227 describe(`Test against source text '${ test_case.source }'`, () => {228 parser.tokenizer.init(test_case.source);229 parser.prepare_next_state();230 try {231 parser.get_next_symbol(precedence_enum.TERMINATION);232 expect("throw").to.be("failed");233 } catch (e) {234 test_case.error(e);235 }236 });237 });238 });...

Full Screen

Full Screen

for_iterator_statement_specs.js

Source:for_iterator_statement_specs.js Github

copy

Full Screen

1/* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.2* File Name : for_iterator_statement_specs.js3* Created at : 2019-09-014* Updated at : 2019-09-015* Author : jeefo6* Purpose :7* Description :8* Reference :9.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.*/10// ignore:start11"use strict";12/* globals*/13/* exported*/14// ignore:end15const expect = require("expect.js");16const { UnexpectedTokenException } = require("@jeefo/parser");17const parser = require("../parser.js");18const {19 test_range,20 test_for_each,21 test_terminal,22 test_statement,23 test_substring,24} = require("../../helpers");25describe("For iterator statement >", () => {26 const valid_test_cases = [27 // for (;;) {}28 {29 code : "for (;;) {}",30 source : "for (;;) {}",31 expression (node, streamer) {32 expect(node.id).to.be("For iterator header");33 expect(node.initializer.id).to.be("For iterator initializer");34 expect(node.condition.id).to.be("For iterator condition");35 expect(node.update).to.be(null);36 test_substring(node, ";;", streamer);37 },38 },39 // for (init;cond;update) {}40 {41 code : "for (init;cond;update) {}",42 source : "for (init;cond;update) {}",43 expression (node, streamer) {44 expect(node.id).to.be("For iterator header");45 expect(node.initializer.id).to.be("For iterator initializer");46 expect(node.condition.id).to.be("For iterator condition");47 expect(node.update).not.to.be(null);48 expect(node.update.id).to.be("Identifier");49 test_substring(node, "init;cond;update", streamer);50 },51 },52 // for (var init;cond;update) {}53 {54 code : "for (var init;cond;update) {}",55 source : "for (var init;cond;update) {}",56 expression (node, streamer) {57 expect(node.id).to.be("For iterator header");58 expect(node.initializer.id).to.be(59 "Variable declaration list no in"60 );61 expect(node.condition.id).to.be("For iterator condition");62 expect(node.update).not.to.be(null);63 expect(node.update.id).to.be("Identifier");64 test_substring(node, "var init;cond;update", streamer);65 },66 },67 // for (let init;cond;update) {}68 {69 code : "for (let init;cond;update) {}",70 source : "for (let init;cond;update) {}",71 expression (node, streamer) {72 expect(node.id).to.be("For iterator header");73 expect(node.initializer.id).to.be("Lexical declaration no in");74 expect(node.condition.id).to.be("For iterator condition");75 expect(node.update).not.to.be(null);76 expect(node.update.id).to.be("Identifier");77 test_substring(node, "let init;cond;update", streamer);78 },79 },80 // for (const init = value;cond;update) {}81 {82 code : "for (const init = value;cond;update) {}",83 source : "for (const init = value;cond;update) {}",84 expression (node, streamer) {85 expect(node.id).to.be("For iterator header");86 expect(node.initializer.id).to.be("Lexical declaration no in");87 expect(node.condition.id).to.be("For iterator condition");88 expect(node.update).not.to.be(null);89 expect(node.update.id).to.be("Identifier");90 test_substring(node, "const init = value;cond;update", streamer);91 },92 },93 ];94 test_for_each(valid_test_cases, test_case => {95 parser.tokenizer.init(test_case.source);96 const streamer = parser.tokenizer.streamer;97 let node;98 try {99 parser.prepare_next_state();100 node = parser.generate_next_node();101 } catch (e) {}102 test_statement("For", node);103 it("should be has correct terminal symbols", () => {104 test_terminal(node.keyword, "for");105 test_terminal(node.open_parenthesis, '(');106 test_terminal(node.close_parenthesis, ')');107 });108 it("should be has correct expression", () => {109 test_case.expression(node.expression, streamer);110 });111 it("should be has correct statement", () => {112 expect(node.statement.id).to.be("Block statement");113 });114 test_range(test_case, node, streamer);115 });116 describe("Error cases >", () => {117 const error_test_cases = [118 // for (var $var;119 {120 source : "for (var $var;",121 message : "Unexpected end of stream",122 error (error) {123 it(`should be throw: '${ this.message }'`, () => {124 expect(error.message).to.be(this.message);125 });126 it("should be instanceof SyntaxError", () => {127 expect(error).to.be.a(SyntaxError);128 });129 }130 },131 // for (var $var;;132 {133 source : "for (var $var;;",134 message : "Unexpected end of stream",135 error (error) {136 it(`should be throw: '${ this.message }'`, () => {137 expect(error.message).to.be(this.message);138 });139 it("should be instanceof SyntaxError", () => {140 expect(error).to.be.a(SyntaxError);141 });142 }143 },144 // for (var i = 1, z = f in expr145 {146 source : "for (var i = 1, z = f in expr",147 message : "Invalid left-hand side in for-in loop: Must have a single binding.",148 error (error) {149 it(`should be throw: '${ this.message }'`, () => {150 expect(error.message).to.be(this.message);151 });152 it("should be instanceof UnexpectedTokenException", ()=>{153 expect(error).to.be.a(UnexpectedTokenException);154 });155 }156 },157 // for (let i = 1, z = f in expr158 {159 source : "for (let i = 1, z = f in expr",160 message : "Invalid left-hand side in for-in loop: Must have a single binding.",161 error (error) {162 it(`should be throw: '${ this.message }'`, () => {163 expect(error.message).to.be(this.message);164 });165 it("should be instanceof UnexpectedTokenException", ()=>{166 expect(error).to.be.a(UnexpectedTokenException);167 });168 }169 },170 // for (const i = 1, z = f in expr171 {172 source : "for (const i = 1, z = f in expr",173 message : "Invalid left-hand side in for-in loop: Must have a single binding.",174 error (error) {175 it(`should be throw: '${ this.message }'`, () => {176 expect(error.message).to.be(this.message);177 });178 it("should be instanceof UnexpectedTokenException", ()=>{179 expect(error).to.be.a(UnexpectedTokenException);180 });181 }182 },183 // for (var i = 1, z = f of expr184 {185 source : "for (var i = 1, z = f of expr",186 message : "Invalid left-hand side in for-of loop: Must have a single binding.",187 error (error) {188 it(`should be throw: '${ this.message }'`, () => {189 expect(error.message).to.be(this.message);190 });191 it("should be instanceof UnexpectedTokenException", ()=>{192 expect(error).to.be.a(UnexpectedTokenException);193 });194 }195 },196 // for (let i = 1, z = f of expr197 {198 source : "for (let i = 1, z = f of expr",199 message : "Invalid left-hand side in for-of loop: Must have a single binding.",200 error (error) {201 it(`should be throw: '${ this.message }'`, () => {202 expect(error.message).to.be(this.message);203 });204 it("should be instanceof UnexpectedTokenException", ()=>{205 expect(error).to.be.a(UnexpectedTokenException);206 });207 }208 },209 // for (const i = 1, z = f of expr210 {211 source : "for (const i = 1, z = f of expr",212 message : "Invalid left-hand side in for-of loop: Must have a single binding.",213 error (error) {214 it(`should be throw: '${ this.message }'`, () => {215 expect(error.message).to.be(this.message);216 });217 it("should be instanceof UnexpectedTokenException", ()=>{218 expect(error).to.be.a(UnexpectedTokenException);219 });220 }221 },222 ];223 test_for_each(error_test_cases, test_case => {224 parser.tokenizer.init(test_case.source);225 parser.prepare_next_state();226 try {227 parser.generate_next_node();228 expect("throw").to.be("failed");229 } catch (e) {230 test_case.error(e);231 }232 });233 });...

Full Screen

Full Screen

for_of_statement_specs.js

Source:for_of_statement_specs.js Github

copy

Full Screen

1/* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.2* File Name : for_of_statement_specs.js3* Created at : 2019-09-014* Updated at : 2019-09-015* Author : jeefo6* Purpose :7* Description :8* Reference :9.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.*/10// ignore:start11"use strict";12/* globals*/13/* exported*/14// ignore:end15const expect = require("expect.js");16const { UnexpectedTokenException } = require("@jeefo/parser");17const parser = require("../parser.js");18const {19 test_range,20 test_for_each,21 test_terminal,22 test_statement,23 test_substring,24} = require("../../helpers");25describe("For of statement >", () => {26 const valid_test_cases = [27 // for ($var of expr) {}28 {29 code : "for ($var of expr) {}",30 source : "for ($var of expr) {}",31 expression (node, streamer) {32 expect(node.id).to.be("For of header");33 expect(node.binding.id).to.be(34 "Assignable left hand side expression"35 );36 test_terminal(node.operator, "of");37 test_substring(node.expression, "expr", streamer);38 test_substring(node, "$var of expr", streamer);39 },40 },41 // for (var $var of expr) {}42 {43 code : "for (var $var of expr) {}",44 source : "for (var $var of expr) {}",45 expression (node, streamer) {46 expect(node.id).to.be("For of header");47 expect(node.binding.id).to.be("For binding");48 test_terminal(node.operator, "of");49 test_substring(node.expression, "expr", streamer);50 test_substring(node, "var $var of expr", streamer);51 },52 },53 // for (let $var of expr) {}54 {55 code : "for (let $var of expr) {}",56 source : "for (let $var of expr) {}",57 expression (node, streamer) {58 expect(node.id).to.be("For of header");59 expect(node.binding.id).to.be("For declaration");60 test_terminal(node.operator, "of");61 test_substring(node.expression, "expr", streamer);62 test_substring(node, "let $var of expr", streamer);63 },64 },65 // for (const $var in expr) {}66 {67 code : "for (const $var of expr) {}",68 source : "for (const $var of expr) {}",69 expression (node, streamer) {70 expect(node.id).to.be("For of header");71 expect(node.binding.id).to.be("For declaration");72 test_terminal(node.operator, "of");73 test_substring(node.expression, "expr", streamer);74 test_substring(node, "const $var of expr", streamer);75 },76 },77 ];78 test_for_each(valid_test_cases, test_case => {79 parser.tokenizer.init(test_case.source);80 const streamer = parser.tokenizer.streamer;81 let node;82 try {83 parser.prepare_next_state();84 node = parser.generate_next_node();85 } catch (e) {}86 test_statement("For", node);87 it("should be has correct terminal symbols", () => {88 test_terminal(node.keyword, "for");89 test_terminal(node.open_parenthesis, '(');90 test_terminal(node.close_parenthesis, ')');91 });92 it("should be has correct expression", () => {93 test_case.expression(node.expression, streamer);94 });95 it("should be has correct statement", () => {96 expect(node.statement.id).to.be("Block statement");97 });98 test_range(test_case, node, streamer);99 });100 describe("Error cases >", () => {101 const error_test_cases = [102 // for (var $var of103 {104 source : "for (var $var of",105 message : "Unexpected end of stream",106 error (error) {107 it(`should be throw: '${ this.message }'`, () => {108 expect(error.message).to.be(this.message);109 });110 it("should be instanceof SyntaxError", () => {111 expect(error).to.be.a(SyntaxError);112 });113 }114 },115 // for (i = z of expr116 {117 source : "for (i = z of expr",118 message : "Invalid left-hand side in for-of loop",119 error (error) {120 it(`should be throw: '${ this.message }'`, () => {121 expect(error.message).to.be(this.message);122 });123 it("should be instanceof UnexpectedTokenException", ()=>{124 expect(error).to.be.a(UnexpectedTokenException);125 });126 it("should be instanceof SyntaxError", () => {127 expect(error).to.be.a(SyntaxError);128 });129 }130 },131 // for (var i = z of expr132 {133 source : "for (var i = z of expr",134 message : "for-of loop variable declaration may not have an initializer.",135 error (error) {136 it(`should be throw: '${ this.message }'`, () => {137 expect(error.message).to.be(this.message);138 });139 it("should be instanceof UnexpectedTokenException", ()=>{140 expect(error).to.be.a(UnexpectedTokenException);141 });142 it("should be instanceof SyntaxError", () => {143 expect(error).to.be.a(SyntaxError);144 });145 }146 },147 // for (let i = z of expr148 {149 source : "for (let i = z of expr",150 message : "for-of loop variable declaration may not have an initializer.",151 error (error) {152 it(`should be throw: '${ this.message }'`, () => {153 expect(error.message).to.be(this.message);154 });155 it("should be instanceof UnexpectedTokenException", ()=>{156 expect(error).to.be.a(UnexpectedTokenException);157 });158 it("should be instanceof SyntaxError", () => {159 expect(error).to.be.a(SyntaxError);160 });161 }162 },163 // for (const i = z of expr164 {165 source : "for (const i = z of expr",166 message : "for-of loop variable declaration may not have an initializer.",167 error (error) {168 it(`should be throw: '${ this.message }'`, () => {169 expect(error.message).to.be(this.message);170 });171 it("should be instanceof UnexpectedTokenException", ()=>{172 expect(error).to.be.a(UnexpectedTokenException);173 });174 it("should be instanceof SyntaxError", () => {175 expect(error).to.be.a(SyntaxError);176 });177 }178 },179 ];180 test_for_each(error_test_cases, test_case => {181 parser.tokenizer.init(test_case.source);182 parser.prepare_next_state();183 try {184 parser.generate_next_node();185 expect("throw").to.be("failed");186 } catch (e) {187 test_case.error(e);188 }189 });190 });...

Full Screen

Full Screen

variable_declaration_no_in_specs.js

Source:variable_declaration_no_in_specs.js Github

copy

Full Screen

1/* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.2* File Name : variable_declaration_no_in_specs.js3* Created at : 2019-08-304* Updated at : 2019-09-015* Author : jeefo6* Purpose :7* Description :8* Reference :9.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.*/10// ignore:start11"use strict";12/* globals*/13/* exported*/14// ignore:end15const expect = require("expect.js");16const { UnexpectedTokenException } = require("@jeefo/parser");17const parser = require("../parser.js");18const {19 test_range,20 test_for_each,21 test_declaration,22} = require("../../helpers");23describe("Variable declaration no in >", () => {24 const valid_test_cases = [25 // id,26 {27 code : "id",28 source : "id,",29 binding : (node) => {30 expect(node.id).to.be("Identifier");31 },32 initializer : (node) => {33 expect(node).to.be(null);34 }35 },36 // id;37 {38 code : "id",39 source : "id;",40 binding : (node) => {41 expect(node.id).to.be("Identifier");42 },43 initializer : (node) => {44 expect(node).to.be(null);45 }46 },47 // id = value,48 {49 code : "id = value",50 source : "id = value,",51 binding : (node) => {52 expect(node.id).to.be("Identifier");53 },54 initializer : (node) => {55 expect(node).not.to.be(null);56 expect(node.id).to.be("Initializer");57 }58 },59 // {} = {};60 {61 code : "{} = {}",62 source : "{} = {};",63 binding : (node) => {64 expect(node.id).to.be("Object binding pattern");65 },66 initializer : (node) => {67 expect(node).not.to.be(null);68 expect(node.id).to.be("Initializer");69 }70 },71 // [] = [];72 {73 code : "[] = []",74 source : "[] = [];",75 binding : (node) => {76 expect(node.id).to.be("Array binding pattern");77 },78 initializer : (node) => {79 expect(node).not.to.be(null);80 expect(node.id).to.be("Initializer");81 }82 },83 // id in expr;84 {85 code : "id",86 source : "id in expr",87 binding : (node) => {88 expect(node.id).to.be("Identifier");89 },90 initializer : (node) => {91 expect(node).to.be(null);92 }93 },94 // id of expr;95 {96 code : "id",97 source : "id of expr",98 binding : (node) => {99 expect(node.id).to.be("Identifier");100 },101 initializer : (node) => {102 expect(node).to.be(null);103 }104 },105 ];106 test_for_each(valid_test_cases, test_case => {107 parser.tokenizer.init(test_case.source);108 parser.prepare_next_state();109 const streamer = parser.tokenizer.streamer;110 let node;111 try {112 parser.change_state("variable_declaration_no_in");113 node = parser.generate_next_node();114 } catch (e) {}115 test_declaration("Variable declaration no in", node);116 it("should be has correct binding", () => {117 test_case.binding(node.binding);118 });119 it("should be has correct initializer", () => {120 test_case.initializer(node.initializer);121 });122 test_range(test_case, node, streamer);123 });124 describe("Invalid cases >", () => {125 const error_test_cases = [126 // ;127 {128 source : ";",129 message : "Unexpected token",130 error (error) {131 it(`should be throw: '${ this.message }'`, () => {132 expect(error.message).to.be(this.message);133 });134 it("should be instanceof UnexpectedTokenException", () => {135 expect(error).to.be.a(UnexpectedTokenException);136 });137 it("should be instanceof SyntaxError", () => {138 expect(error).to.be.a(SyntaxError);139 });140 }141 },142 // 123 = value143 {144 source : "123 = value",145 message : "Unexpected token",146 error (error) {147 it(`should be throw: '${ this.message }'`, () => {148 expect(error.message).to.be(this.message);149 });150 it("should be instanceof UnexpectedTokenException", () => {151 expect(error).to.be.a(UnexpectedTokenException);152 });153 it("should be instanceof SyntaxError", () => {154 expect(error).to.be.a(SyntaxError);155 });156 }157 },158 // id159 {160 source : "id",161 message : "Unexpected end of stream",162 error (error) {163 it(`should be throw: '${ this.message }'`, () => {164 expect(error.message).to.be(this.message);165 });166 it("should be instanceof SyntaxError", () => {167 expect(error).to.be.a(SyntaxError);168 });169 }170 },171 // [],172 {173 source : "[],",174 message : "Missing initializer in destructuring declaration",175 error (error) {176 it(`should be throw: '${ this.message }'`, () => {177 expect(error.message).to.be(this.message);178 });179 it("should be instanceof UnexpectedTokenException", () => {180 expect(error).to.be.a(UnexpectedTokenException);181 });182 it("should be instanceof SyntaxError", () => {183 expect(error).to.be.a(SyntaxError);184 });185 }186 },187 // {},188 {189 source : "{},",190 message : "Missing initializer in destructuring declaration",191 error (error) {192 it(`should be throw: '${ this.message }'`, () => {193 expect(error.message).to.be(this.message);194 });195 it("should be instanceof UnexpectedTokenException", () => {196 expect(error).to.be.a(UnexpectedTokenException);197 });198 it("should be instanceof SyntaxError", () => {199 expect(error).to.be.a(SyntaxError);200 });201 }202 },203 ];204 test_for_each(error_test_cases, test_case => {205 parser.tokenizer.init(test_case.source);206 parser.prepare_next_state();207 try {208 parser.change_state("variable_declaration_no_in");209 parser.generate_next_node();210 expect("throw").to.be("failed");211 } catch (e) {212 test_case.error(e);213 }214 });215 });...

Full Screen

Full Screen

lexical_binding_no_in_specs.js

Source:lexical_binding_no_in_specs.js Github

copy

Full Screen

1/* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.2* File Name : lexical_binding_no_in.js3* Created at : 2019-09-014* Updated at : 2019-09-015* Author : jeefo6* Purpose :7* Description :8* Reference :9.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.*/10// ignore:start11"use strict";12/* globals*/13/* exported*/14// ignore:end15const expect = require("expect.js");16const { UnexpectedTokenException } = require("@jeefo/parser");17const parser = require("../parser.js");18const {19 test_range,20 test_for_each,21 test_declaration,22} = require("../../helpers");23describe("Lexical binding no in >", () => {24 const valid_test_cases = [25 // id,26 {27 code : "id",28 source : "id,",29 binding : (node) => {30 expect(node.id).to.be("Identifier");31 },32 initializer : (node) => {33 expect(node).to.be(null);34 }35 },36 // id;37 {38 code : "id",39 source : "id;",40 binding : (node) => {41 expect(node.id).to.be("Identifier");42 },43 initializer : (node) => {44 expect(node).to.be(null);45 }46 },47 // id = value,48 {49 code : "id = value",50 source : "id = value,",51 binding : (node) => {52 expect(node.id).to.be("Identifier");53 },54 initializer : (node) => {55 expect(node).not.to.be(null);56 expect(node.id).to.be("Initializer");57 }58 },59 // {} = {};60 {61 code : "{} = {}",62 source : "{} = {};",63 binding : (node) => {64 expect(node.id).to.be("Object binding pattern");65 },66 initializer : (node) => {67 expect(node).not.to.be(null);68 expect(node.id).to.be("Initializer");69 }70 },71 // [] = [];72 {73 code : "[] = []",74 source : "[] = [];",75 binding : (node) => {76 expect(node.id).to.be("Array binding pattern");77 },78 initializer : (node) => {79 expect(node).not.to.be(null);80 expect(node.id).to.be("Initializer");81 }82 },83 // id in expr;84 {85 code : "id",86 source : "id in expr",87 binding : (node) => {88 expect(node.id).to.be("Identifier");89 },90 initializer : (node) => {91 expect(node).to.be(null);92 }93 },94 // id of expr;95 {96 code : "id",97 source : "id of expr",98 binding : (node) => {99 expect(node.id).to.be("Identifier");100 },101 initializer : (node) => {102 expect(node).to.be(null);103 }104 },105 ];106 test_for_each(valid_test_cases, test_case => {107 parser.tokenizer.init(test_case.source);108 parser.prepare_next_state();109 const streamer = parser.tokenizer.streamer;110 let node;111 try {112 parser.change_state("lexical_binding_no_in");113 node = parser.generate_next_node();114 } catch (e) {}115 test_declaration("Lexical binding no in", node);116 it("should be has correct binding", () => {117 test_case.binding(node.binding);118 });119 it("should be has correct initializer", () => {120 test_case.initializer(node.initializer);121 });122 test_range(test_case, node, streamer);123 });124 describe("Invalid cases >", () => {125 const error_test_cases = [126 // ;127 {128 source : ";",129 message : "Unexpected token",130 error (error) {131 it(`should be throw: '${ this.message }'`, () => {132 expect(error.message).to.be(this.message);133 });134 it("should be instanceof UnexpectedTokenException", () => {135 expect(error).to.be.a(UnexpectedTokenException);136 });137 it("should be instanceof SyntaxError", () => {138 expect(error).to.be.a(SyntaxError);139 });140 }141 },142 // 123 = value143 {144 source : "123 = value",145 message : "Unexpected token",146 error (error) {147 it(`should be throw: '${ this.message }'`, () => {148 expect(error.message).to.be(this.message);149 });150 it("should be instanceof UnexpectedTokenException", () => {151 expect(error).to.be.a(UnexpectedTokenException);152 });153 it("should be instanceof SyntaxError", () => {154 expect(error).to.be.a(SyntaxError);155 });156 }157 },158 // id159 {160 source : "id",161 message : "Unexpected end of stream",162 error (error) {163 it(`should be throw: '${ this.message }'`, () => {164 expect(error.message).to.be(this.message);165 });166 it("should be instanceof SyntaxError", () => {167 expect(error).to.be.a(SyntaxError);168 });169 }170 },171 // [],172 {173 source : "[],",174 message : "Missing initializer in destructuring declaration",175 error (error) {176 it(`should be throw: '${ this.message }'`, () => {177 expect(error.message).to.be(this.message);178 });179 it("should be instanceof UnexpectedTokenException", () => {180 expect(error).to.be.a(UnexpectedTokenException);181 });182 it("should be instanceof SyntaxError", () => {183 expect(error).to.be.a(SyntaxError);184 });185 }186 },187 // {},188 {189 source : "{},",190 message : "Missing initializer in destructuring declaration",191 error (error) {192 it(`should be throw: '${ this.message }'`, () => {193 expect(error.message).to.be(this.message);194 });195 it("should be instanceof UnexpectedTokenException", () => {196 expect(error).to.be.a(UnexpectedTokenException);197 });198 it("should be instanceof SyntaxError", () => {199 expect(error).to.be.a(SyntaxError);200 });201 }202 },203 ];204 test_for_each(error_test_cases, test_case => {205 parser.tokenizer.init(test_case.source);206 parser.prepare_next_state();207 try {208 parser.change_state("lexical_binding_no_in");209 parser.generate_next_node();210 expect("throw").to.be("failed");211 } catch (e) {212 test_case.error(e);213 }214 });215 });...

Full Screen

Full Screen

variable_statement_specs.js

Source:variable_statement_specs.js Github

copy

Full Screen

1/* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.2* File Name : variable_statement_specs.js3* Created at : 2019-08-124* Updated at : 2019-09-015* Author : jeefo6* Purpose :7* Description :8* Reference :9.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.*/10// ignore:start11"use strict";12/* globals*/13/* exported*/14// ignore:end15const expect = require("expect.js");16const { UnexpectedTokenException } = require("@jeefo/parser");17const parser = require("../parser.js");18const {19 test_range,20 test_for_each,21 test_terminal,22 test_statement,23} = require("../../helpers");24describe("Variable statement >", () => {25 const test = test_cases => {26 test_for_each(test_cases, test_case => {27 parser.tokenizer.init(test_case.source);28 const streamer = parser.tokenizer.streamer;29 let node;30 try {31 parser.prepare_next_state();32 node = parser.generate_next_node();33 } catch (e) {}34 test_statement("Variable", node);35 it("should be has correct declaration list", () => {36 expect(node.declaration_list.id).to.be(37 "Variable declaration list"38 );39 });40 it("should be has correct terminator", () => {41 test_case.terminator(node.terminator);42 });43 test_range(test_case, node, streamer);44 });45 };46 describe("Semicolon terminated >", () => {47 const test_cases = [48 // var id;49 {50 code : "var id;",51 source : "var id;",52 terminator (node) {53 test_terminal(node, ';');54 }55 },56 // var {} = {};57 {58 code : "var {} = {};",59 source : "var {} = {};",60 terminator (node) {61 test_terminal(node, ';');62 }63 },64 // var [] = [];65 {66 code : "var [] = [];",67 source : "var [] = [];",68 terminator (node) {69 test_terminal(node, ';');70 }71 },72 ];73 test(test_cases);74 });75 describe("Automatic semicolon insertion >", () => {76 const test_cases = [77 // var id78 {79 code : "var id",80 source : "var id",81 terminator (node) {82 expect(node).to.be(null);83 }84 },85 // var {} = {}86 {87 code : "var {} = {}",88 source : "var {} = {}",89 terminator (node) {90 expect(node).to.be(null);91 }92 },93 // var [] = []94 {95 code : "var [] = []",96 source : "var [] = []",97 terminator (node) {98 expect(node).to.be(null);99 }100 },101 // var\nterminated\ndont_care102 {103 code : "var\nterminated",104 source : "var\nterminated\ndont_care",105 terminator (node) {106 expect(node).to.be(null);107 }108 },109 ];110 test(test_cases);111 });112 describe("Invalid cases >", () => {113 const error_test_cases = [114 // var115 {116 source : "var",117 error : error => {118 it("should be throw: Unexpected end of stream", () => {119 expect(error.message).to.be("Unexpected end of stream");120 });121 it("should be instanceof SyntaxError", () => {122 expect(error instanceof SyntaxError).to.be(true);123 });124 }125 },126 // var a a127 {128 source : "var a a",129 error : error => {130 it("should be throw: Unexpected token", () => {131 expect(error.message).to.be("Unexpected token");132 });133 it("should be instanceof UnexpectedTokenException", () => {134 expect(error).to.be.an(UnexpectedTokenException);135 });136 }137 },138 // var a =139 {140 source : "var a =",141 error : error => {142 it("should be throw: Unexpected end of stream", () => {143 expect(error.message).to.be("Unexpected end of stream");144 });145 it("should be instanceof SyntaxError", () => {146 expect(error).to.be.a(SyntaxError);147 });148 }149 },150 // var a,151 {152 source : "var a,",153 error : error => {154 it("should be throw: Unexpected end of stream", () => {155 expect(error.message).to.be("Unexpected end of stream");156 });157 it("should be instanceof SyntaxError", () => {158 expect(error).to.be.a(SyntaxError);159 });160 }161 },162 // var 3163 {164 source : "var 3",165 error : error => {166 it("should be throw: 'Unexpected token'", () => {167 expect(error.message).to.be("Unexpected token");168 });169 it("should be instanceof UnexpectedTokenException", () => {170 expect(error).to.be.an(UnexpectedTokenException);171 });172 }173 },174 // var a, ,175 {176 source : "var a, ,",177 error : error => {178 it("should be throw: 'Unexpected token'", () => {179 expect(error.message).to.be("Unexpected token");180 });181 it("should be instanceof UnexpectedTokenException", () => {182 expect(error).to.be.an(UnexpectedTokenException);183 });184 }185 },186 ];187 error_test_cases.forEach(test_case => {188 describe(`Test against source text '${ test_case.source }'`, () => {189 parser.tokenizer.init(test_case.source);190 parser.prepare_next_state();191 try {192 parser.generate_next_node();193 expect("throw").to.be("failed");194 } catch (e) {195 test_case.error(e);196 }197 });198 });199 });...

Full Screen

Full Screen

errors.js

Source:errors.js Github

copy

Full Screen

1var error = require('tea-error');2var Errors = {3 ParserException: error('ParserException'),4 CompositeParserException: error('CompositeParserException'),5 UnexpectedTokenException: error('UnexpectedTokenException'),6 UnexpectedEOFException: error('UnexpectedEOFException'),7 AstBuilderException: error('AstBuilderException'),8 NoSuchLanguageException: error('NoSuchLanguageException')9};10Errors.CompositeParserException.create = function(errors) {11 var message = "Parser errors:\n" + errors.map(function (e) { return e.message; }).join("\n");12 return new Errors.CompositeParserException(message);13};14Errors.UnexpectedTokenException.create = function(token, expectedTokenTypes, stateComment) {15 var message = "expected: " + expectedTokenTypes.join(', ') + ", got '" + token.getTokenValue().trim() + "'";16 return createError(Errors.UnexpectedEOFException, message, token.location);17};18Errors.UnexpectedEOFException.create = function(token, expectedTokenTypes, stateComment) {19 var message = "unexpected end of file, expected: " + expectedTokenTypes.join(', ');20 return createError(Errors.UnexpectedTokenException, message, token.location);21};22Errors.AstBuilderException.create = function(message, location) {23 return createError(Errors.AstBuilderException, message, location);24};25Errors.NoSuchLanguageException.create = function(language, location) {26 var message = "Language not supported: " + language;27 return createError(Errors.NoSuchLanguageException, message, location);28};29function createError(Ctor, message, location) {30 var fullMessage = "(" + location.line + ":" + location.column + "): " + message;31 var error = new Ctor(fullMessage);32 error.location = location;33 return error;34}...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const { UnexpectedTokenException } = require('cucumber-gherkin')2const { UnexpectedEOFException } = require('cucumber-gherkin')3const { Parser } = require('cucumber-gherkin')4const { TokenScanner } = require('cucumber-gherkin')5const { AstBuilder } = require('cucumber-gherkin')6const { ParserException } = require('cucumber-gherkin')7const { TokenMatcher } = require('cucumber-gherkin')8const { Token } = require('cucumber-gherkin')9const { TokenType } = require('cucumber-gherkin')10const { GherkinDialect } = require('cucumber-gherkin')11const { GherkinDialectProvider } = require('cucumber-gherkin')12const { GherkinDocumentBuilder } = require('cucumber-gherkin')13const { GherkinDocument } = require('cucumber-gherkin')14const { Pickle } = require('cucumber-gherkin')15const { PickleStep } = require('cucumber-gherkin')16const { PickleTable } = require('cucumber-gherkin')17const { PickleDocString } = require('cucumber-gherkin')18const { PickleLocation } = require('cucumber-gherkin')19const { PickleTag } = require('cucumber-gherkin')20const { ParserConfig } = require('cucumber-gherkin')21const { ParserOptions } = require('cucumber-gherkin')22const { AstBuilderConfig } = require('cucumber-gherkin')23const { AstBuilderOptions } = require('cucumber-gherkin')24const { GherkinDialectProviderConfig } = require('cucumber-gherkin')25const { GherkinDialectProviderOptions } = require('cucumber-gherkin')26const { GherkinDialectConfig } = require('cucumber-gherkin')27const { GherkinDialectOptions } = require('cucumber-gherkin')28const { GherkinDocumentConfig } = require('cucumber-gherkin')29const { GherkinDocumentOptions } = require('cucumber-gherkin')30const { PickleConfig } = require('cucumber-gherkin')31const { Pick

Full Screen

Using AI Code Generation

copy

Full Screen

1var gherkin = require('gherkin');2var parser = new gherkin.Parser();3var lexer = new gherkin.Lexer();4var fs = require('fs');5var data = fs.readFileSync('test.feature', 'utf8');6var tokens = lexer.lex(data);7var ast = parser.parse(tokens);8console.log(ast);9{ type: 'Feature',10 location: { line: 1, column: 1 },11 [ { type: 'Scenario',12 location: { line: 3, column: 3 },13 [ { type: 'Step',14 location: { line: 4, column: 5 },15 argument: undefined } ] } ] }16{17 {18 {19 }20 }21}

Full Screen

Using AI Code Generation

copy

Full Screen

1var gherkin = require('gherkin');2var parser = new gherkin.Parser();3var lexer = new gherkin.Lexer('en');4';5var tokenMatcher = new gherkin.TokenMatcher(lexer.getGherkinDialect('en'), 'en');6var tokens = lexer.lex(source);7var ast = parser.parse(tokens, tokenMatcher);8console.log(ast.feature.name);9console.log(ast.feature.children[0].steps[0].text);10console.log(ast.feature.children[0].steps[0].keyword);11var gherkin = require('gherkin');12var parser = new gherkin.Parser();13var lexer = new gherkin.Lexer('en');14';15var tokenMatcher = new gherkin.TokenMatcher(lexer.getGherkinDialect('en'), 'en');16var tokens = lexer.lex(source);17var ast = parser.parse(tokens, tokenMatcher);18console.log(ast.feature.name);19console.log(ast.feature.children[0].steps[0].text);20console.log(ast.feature.children[0].steps[0].keyword);21var gherkin = require('gherkin');22var parser = new gherkin.Parser();23var lexer = new gherkin.Lexer('en');24';25var tokenMatcher = new gherkin.TokenMatcher(lexer.getGherkinDialect('en'), 'en');26var tokens = lexer.lex(source);27var ast = parser.parse(tokens, tokenMatcher);

Full Screen

Using AI Code Generation

copy

Full Screen

1var gherkin = require('gherkin');2var parser = new gherkin.Parser();3try {4 parser.parse("Feature: test5Given a step definition is missing");6} catch (e) {7 if (e instanceof gherkin.UnexpectedTokenException) {8 console.log('test passed');9 } else {10 console.log('test failed');11 }12}13var gherkin = require('gherkin');14var parser = new gherkin.Parser();15parser.parse('Feature: Create a new account16| First Name | Last Name | Email | Password | Confirm Password |');17I have a similar question. I am trying to parse a feature file using the gherkin parser. I am getting the following error: Error: Line 1, column 1: expected: #EOF, #TableRow, #DocStringSeparator, #StepLine, #TagLine, #Empty, got 'Feature: Create a new account' I have the following code: var gherkin = require('gherkin'); var parser = new gherkin.Parser(); parser.parse('Feature: Create a new account Scenario: Create a new account Given I am on the home page When I click on the create new account link Then I should be on the create new account page And I should see the following fields | First Name | Last Name | Email | Password | Confirm Password |'); I am not sure what I am doing wrong. Can someone please help me out?18it('should throw an exception if the user has no permissions', function() {

Full Screen

Using AI Code Generation

copy

Full Screen

1const { UnexpectedTokenException } = require('cucumber-gherkin');2throw new UnexpectedTokenException('Unexpected token', 'test.js', 1);3const { UnexpectedEOFException } = require('cucumber-gherkin');4throw new UnexpectedEOFException('Unexpected end of file', 'test.js', 1);5const { AmbiguousTableException } = require('cucumber-gherkin');6throw new AmbiguousTableException('Ambiguous table', 'test.js', 1);7const { DuplicateStepException } = require('cucumber-gherkin');8throw new DuplicateStepException('Duplicate step', 'test.js', 1);9const { DuplicateHookException } = require('cucumber-gherkin');10throw new DuplicateHookException('Duplicate hook', 'test.js', 1);11const { UndefinedStepException } = require('cucumber-gherkin');12throw new UndefinedStepException('Undefined step', 'test.js', 1);13const { PendingStepException } = require('cucumber-gherkin');14throw new PendingStepException('Pending step', 'test.js', 1);15const { AmbiguousStepException } = require('cucumber-gherkin');16throw new AmbiguousStepException('Ambiguous step', 'test.js', 1);17const { InvalidHookException } = require('cucumber-gherkin');

Full Screen

Using AI Code Generation

copy

Full Screen

1const { UnexpectedTokenException } = require('cucumber-gherkin')2throw new UnexpectedTokenException('Unexpected token', 'string', 'string', 'string', 1, 1)3{4 "scripts": {5 },6 "dependencies": {7 }8}9 at new UnexpectedTokenException (/Users/username/test/node_modules/cucumber-gherkin/src/UnexpectedTokenException.js:6:9)10 at Object.<anonymous> (/Users/username/test/test.js:3:11)11 at Module._compile (module.js:652:30)12 at Object.Module._extensions..js (module.js:663:10)13 at Module.load (module.js:565:32)14 at tryModuleLoad (module.js:505:12)15 at Function.Module._load (module.js:497:3)16 at Function.Module.runMain (module.js:693:10)17 at startup (bootstrap_node.js:188:16)

Full Screen

Using AI Code Generation

copy

Full Screen

1var Cucumber = require('cucumber');2var UnexpectedTokenException = Cucumber.Parser.UnexpectedTokenException;3var gherkinDocument = Cucumber.Parser.GherkinDocumentParser.parse(gherkinSource);4var feature = gherkinDocument.feature;5var scenario = feature.children[0];6var step = scenario.steps[0];7try {8 Cucumber.Parser.GherkinDocumentParser.parseStep(step);9} catch (e) {10 if (e instanceof UnexpectedTokenException) {11 console.log("Unexpected token: " + e.token);12 console.log("Line number: " + e.lineNumber);13 }14}

Full Screen

Cucumber Tutorial:

LambdaTest offers a detailed Cucumber testing tutorial, explaining its features, importance, best practices, and more to help you get started with running your automation testing scripts.

Cucumber Tutorial Chapters:

Here are the detailed Cucumber testing chapters to help you get started:

  • Importance of Cucumber - Learn why Cucumber is important in Selenium automation testing during the development phase to identify bugs and errors.
  • Setting Up Cucumber in Eclipse and IntelliJ - Learn how to set up Cucumber in Eclipse and IntelliJ.
  • Running First Cucumber.js Test Script - After successfully setting up your Cucumber in Eclipse or IntelliJ, this chapter will help you get started with Selenium Cucumber testing in no time.
  • Annotations in Cucumber - To handle multiple feature files and the multiple scenarios in each file, you need to use functionality to execute these scenarios. This chapter will help you learn about a handful of Cucumber annotations ranging from tags, Cucumber hooks, and more to ease the maintenance of the framework.
  • Automation Testing With Cucumber And Nightwatch JS - Learn how to build a robust BDD framework setup for performing Selenium automation testing by integrating Cucumber into the Nightwatch.js framework.
  • Automation Testing With Selenium, Cucumber & TestNG - Learn how to perform Selenium automation testing by integrating Cucumber with the TestNG framework.
  • Integrate Cucumber With Jenkins - By using Cucumber with Jenkins integration, you can schedule test case executions remotely and take advantage of the benefits of Jenkins. Learn how to integrate Cucumber with Jenkins with this detailed chapter.
  • Cucumber Best Practices For Selenium Automation - Take a deep dive into the advanced use cases, such as creating a feature file, separating feature files, and more for Cucumber testing.

Run Cucumber-gherkin automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful