How to use getTokens method in Cucumber-gherkin

Best JavaScript code snippet using cucumber-gherkin

Template.js

Source:Template.js Github

copy

Full Screen

...24 describe('tokens', function () {25 it('should parse on first use', function () {26 var tpl = new BindTemplate('Hello {foo}');27 expect(tpl.tokens).toBe(null);28 var tokens = tpl.getTokens();29 expect(tokens).toEqual(['foo']);30 expect(getNumFragments(tpl)).toBe(1);31 expect(getNumSlots(tpl)).toBe(1);32 });33 it('should parse simple names', function () {34 var tpl = new BindTemplate('Hello {foo} {bar}');35 var tokens = tpl.getTokens();36 expect(tokens).toEqual(['foo', 'bar']);37 expect(getNumFragments(tpl)).toBe(2);38 expect(getNumSlots(tpl)).toBe(2);39 });40 it('should parse dotted names', function () {41 var tpl = new BindTemplate('Hello {foo.bar} {bar.foo}');42 var tokens = tpl.getTokens();43 expect(tokens).toEqual(['foo.bar', 'bar.foo']);44 expect(getNumFragments(tpl)).toBe(2);45 expect(getNumSlots(tpl)).toBe(2);46 });47 it('should consolidate tokens', function () {48 var tpl = new BindTemplate('Hello {foo.bar} {bar} {foo.bar} {bar}');49 var tokens = tpl.getTokens();50 expect(tokens).toEqual(['foo.bar', 'bar']);51 expect(getNumFragments(tpl)).toBe(4);52 expect(getNumSlots(tpl)).toBe(4);53 });54 it('should match slots to consolidated tokens', function () {55 // 1 2 3 4 5 656 var tpl = new BindTemplate('Hello {foo.bar}{bar} - {foo.bar}{bar}');57 tpl.parse();58 expect(getNumFragments(tpl)).toBe(2);59 expect(getNumSlots(tpl)).toBe(4);60 expect(typeof tpl.slots[1]).toBe('function');61 expect(typeof tpl.slots[2]).toBe('function');62 // slots[3] is null due to " - " in buffer[3]63 expect(typeof tpl.slots[4]).toBe('function');64 expect(typeof tpl.slots[5]).toBe('function');65 });66 it("should not attempt to parse outside of curly braces", function() {67 var tpl = new BindTemplate('Hello `{foo}`!'),68 tokens = tpl.getTokens();69 expect(tokens).toEqual(['foo']);70 var s = tpl.apply([5]);71 expect(s).toBe('Hello `5`!');72 });73 });74 describe('unary operators', function(){75 it('should parse -', function(){76 var tpl = new BindTemplate('Hello {foo.bar + -5}!');77 var tokens = tpl.getTokens();78 expect(tokens).toEqual(['foo.bar']);79 var s = tpl.apply([10]);80 expect(s).toBe('Hello 5!');81 });82 it('should parse - before an expression', function(){83 var tpl = new BindTemplate('Hello {foo.bar + -(bar + 3):number("0.00")}!');84 var tokens = tpl.getTokens();85 expect(tokens).toEqual(['foo.bar', 'bar']);86 var s = tpl.apply([10, 7]);87 expect(s).toBe('Hello 0!'); // 10 - '10.00'88 });89 it('should parse - before an expression and follow parans', function(){90 var tpl = new BindTemplate('Hello {(foo.bar + -(bar + 3)):number("0.00")}!');91 var tokens = tpl.getTokens();92 expect(tokens).toEqual(['foo.bar', 'bar']);93 var s = tpl.apply([10, 7]);94 expect(s).toBe('Hello 0.00!');95 });96 it('should parse - before parans and before literal', function(){97 var tpl = new BindTemplate('Hello {(foo.bar + -(bar +- 3)):number("0.00")}!');98 var tokens = tpl.getTokens();99 expect(tokens).toEqual(['foo.bar', 'bar']);100 var s = tpl.apply([10, 7]);101 expect(s).toBe('Hello 6.00!');102 });103 it('should parse - before parans and before token', function(){104 var tpl = new BindTemplate('Hello {(foo.bar + -(bar -- foo)):number("0.00")}!');105 var tokens = tpl.getTokens();106 expect(tokens).toEqual(['foo.bar', 'bar', 'foo']);107 var s = tpl.apply([10, 7, 4]);108 expect(s).toBe('Hello -1.00!');109 });110 it('should parse @ unary operator', function(){111 var tpl = new BindTemplate('Hello {@Ext.justTemp}!');112 Ext.justTemp = 'foo';113 var s = tpl.apply();114 expect(s).toBe('Hello foo!');115 Ext.justTemp = 'bar';116 s = tpl.apply();117 expect(s).toBe('Hello bar!');118 expect(tpl.isStatic()).toBe(false);119 Ext.justTemp = null;120 });121 });122 describe('binary operators', function(){123 it('should parse + operations', function(){124 var tpl = new BindTemplate('Hello {foo.bar + bar.foo}!');125 var tokens = tpl.getTokens();126 expect(tokens).toEqual(['foo.bar', 'bar.foo']);127 var s = tpl.apply([5, 7]);128 expect(s).toBe('Hello 12!');129 });130 it('should parse - operations', function(){131 var tpl = new BindTemplate('Hello {foo.bar - bar.foo}!');132 var tokens = tpl.getTokens();133 expect(tokens).toEqual(['foo.bar', 'bar.foo']);134 var s = tpl.apply([5, 7]);135 expect(s).toBe('Hello -2!');136 });137 it('should parse * operations', function(){138 var tpl = new BindTemplate('Hello {foo.bar * bar.foo}!');139 var tokens = tpl.getTokens();140 expect(tokens).toEqual(['foo.bar', 'bar.foo']);141 var s = tpl.apply([5, 7]);142 expect(s).toBe('Hello 35!');143 });144 it('should parse / operations', function(){145 var tpl = new BindTemplate('Hello {foo.bar / bar.foo}!');146 var tokens = tpl.getTokens();147 expect(tokens).toEqual(['foo.bar', 'bar.foo']);148 var s = tpl.apply([10, 2]);149 expect(s).toBe('Hello 5!');150 });151 it('should parse > operations', function(){152 var tpl = new BindTemplate('{foo.bar > bar.foo}!');153 var tokens = tpl.getTokens();154 expect(tokens).toEqual(['foo.bar', 'bar.foo']);155 var s = tpl.apply([10, 2]);156 expect(s).toBe('true!');157 });158 it('should parse < operations', function(){159 var tpl = new BindTemplate('{foo.bar < bar.foo}!');160 var tokens = tpl.getTokens();161 expect(tokens).toEqual(['foo.bar', 'bar.foo']);162 var s = tpl.apply([2, 10]);163 expect(s).toBe('true!');164 });165 it('should parse >= operations', function(){166 var tpl = new BindTemplate('{foo.bar >= bar.foo}!');167 var tokens = tpl.getTokens();168 expect(tokens).toEqual(['foo.bar', 'bar.foo']);169 var s = tpl.apply([10, 10]);170 expect(s).toBe('true!');171 });172 it('should parse <= operations', function(){173 var tpl = new BindTemplate('{foo.bar <= bar.foo}!');174 var tokens = tpl.getTokens();175 expect(tokens).toEqual(['foo.bar', 'bar.foo']);176 var s = tpl.apply([10, 10]);177 expect(s).toBe('true!');178 });179 it('should parse === operations', function(){180 var tpl = new BindTemplate('{foo.bar === bar.foo}!');181 var tokens = tpl.getTokens();182 expect(tokens).toEqual(['foo.bar', 'bar.foo']);183 var s = tpl.apply([10, '10']);184 expect(s).toBe('false!');185 });186 it('should parse == operations', function(){187 var tpl = new BindTemplate('{foo.bar == bar.foo}!');188 var tokens = tpl.getTokens();189 expect(tokens).toEqual(['foo.bar', 'bar.foo']);190 var s = tpl.apply([10, '10']);191 expect(s).toBe('true!');192 });193 it('should parse !== operations', function(){194 var tpl = new BindTemplate('{foo.bar !== bar.foo}!');195 var tokens = tpl.getTokens();196 expect(tokens).toEqual(['foo.bar', 'bar.foo']);197 var s = tpl.apply([10, '10']);198 expect(s).toBe('true!');199 });200 it('should parse != operations', function(){201 var tpl = new BindTemplate('{foo.bar != bar.foo}!');202 var tokens = tpl.getTokens();203 expect(tokens).toEqual(['foo.bar', 'bar.foo']);204 var s = tpl.apply([10, '10']);205 expect(s).toBe('false!');206 });207 it('should parse && operations', function(){208 var tpl = new BindTemplate('{foo.bar > bar.foo && bar > 5}!');209 var tokens = tpl.getTokens();210 expect(tokens).toEqual(['foo.bar', 'bar.foo', 'bar']);211 var s = tpl.apply([10, 5, 3]);212 expect(s).toBe('false!');213 });214 it('should parse || operations', function(){215 var tpl = new BindTemplate('{foo.bar > bar.foo || bar > 5}!');216 var tokens = tpl.getTokens();217 expect(tokens).toEqual(['foo.bar', 'bar.foo', 'bar']);218 var s = tpl.apply([10, 5, 3]);219 expect(s).toBe('true!');220 });221 it('should parse operations by priority', function(){222 var tpl = new BindTemplate('Hello {foo.bar * foo + bar / bar.foo}!');223 var tokens = tpl.getTokens();224 expect(tokens).toEqual(['foo.bar', 'foo', 'bar', 'bar.foo']);225 var s = tpl.apply([10, 2, 5, 2]);226 expect(s).toBe('Hello 22.5!');227 });228 });229 describe('ternary operator', function(){230 it('should parse token condition', function () {231 var tpl = new BindTemplate('Hello {foo ? 5 : 6}');232 var tokens = tpl.getTokens();233 expect(tokens).toEqual(['foo']);234 var s = tpl.apply([true]);235 expect(s).toBe('Hello 5');236 });237 it('should parse binary condition >', function () {238 var tpl = new BindTemplate('Hello {foo > 3 ? 5 : 6}');239 var tokens = tpl.getTokens();240 expect(tokens).toEqual(['foo']);241 var s = tpl.apply([2]);242 expect(s).toBe('Hello 6');243 });244 it('should parse binary condition >=', function () {245 var tpl = new BindTemplate('Hello {foo >= 3 ? 5 : 6}');246 var tokens = tpl.getTokens();247 expect(tokens).toEqual(['foo']);248 var s = tpl.apply([3]);249 expect(s).toBe('Hello 5');250 });251 it('should parse binary condition <', function () {252 var tpl = new BindTemplate('Hello {foo < 3 ? 5 : 6}');253 var tokens = tpl.getTokens();254 expect(tokens).toEqual(['foo']);255 var s = tpl.apply([2]);256 expect(s).toBe('Hello 5');257 });258 it('should parse binary condition <=', function () {259 var tpl = new BindTemplate('Hello {foo <= 3 ? 5 : 6}');260 var tokens = tpl.getTokens();261 expect(tokens).toEqual(['foo']);262 var s = tpl.apply([4]);263 expect(s).toBe('Hello 6');264 });265 it('should parse binary condition ==', function () {266 var tpl = new BindTemplate('Hello {foo == "3" ? 5 : 6}');267 var tokens = tpl.getTokens();268 expect(tokens).toEqual(['foo']);269 var s = tpl.apply([3]);270 expect(s).toBe('Hello 5');271 });272 it('should parse binary condition ===', function () {273 var tpl = new BindTemplate('Hello {foo === "3" ? 5 : 6}');274 var tokens = tpl.getTokens();275 expect(tokens).toEqual(['foo']);276 var s = tpl.apply([3]);277 expect(s).toBe('Hello 6');278 });279 it('should parse binary condition !=', function () {280 var tpl = new BindTemplate('Hello {foo != "3" ? 5 : 6}');281 var tokens = tpl.getTokens();282 expect(tokens).toEqual(['foo']);283 var s = tpl.apply([3]);284 expect(s).toBe('Hello 6');285 });286 it('should parse binary condition !==', function () {287 var tpl = new BindTemplate('Hello {foo !== "3" ? 5 : 6}');288 var tokens = tpl.getTokens();289 expect(tokens).toEqual(['foo']);290 var s = tpl.apply([3]);291 expect(s).toBe('Hello 5');292 });293 it('should parse condition with format fn', function () {294 var tpl = new BindTemplate('Hello {foo:this.fn ? 5 : 6}');295 var tokens = tpl.getTokens();296 expect(tokens).toEqual(['foo']);297 var s = tpl.apply([4], {298 fn: function(){ return false; }299 });300 expect(s).toBe('Hello 6');301 });302 it('should parse condition with format fn and args', function () {303 var tpl = new BindTemplate('Hello {foo:this.fn("testing", 4) ? 5 : 6}');304 var tokens = tpl.getTokens();305 expect(tokens).toEqual(['foo']);306 var s = tpl.apply([4], {307 fn: function(){ return false; }308 });309 expect(s).toBe('Hello 6');310 });311 it('should parse condition with chained format fn and args', function () {312 var tpl = new BindTemplate('Hello {foo:this.fn("testing", 4):this.fn2 ? 5 : 6}');313 var tokens = tpl.getTokens();314 expect(tokens).toEqual(['foo']);315 var s = tpl.apply([4], {316 fn: function(){ return false; },317 fn2: function(){ return true; }318 });319 expect(s).toBe('Hello 5');320 });321 it('should parse condition with chained and nested format fn and args', function () {322 var tpl = new BindTemplate('Hello {foo:this.fn("testing", bar:this.fn3(null, true)):this.fn2 ? 5 : 6}');323 var tokens = tpl.getTokens();324 expect(tokens).toEqual(['foo', 'bar']);325 var s = tpl.apply([4], {326 fn: function(){ return false; },327 fn2: function(){ return true; },328 fn3: function(){ return 5; }329 });330 expect(s).toBe('Hello 5');331 });332 it('should parse true part with literal', function () {333 var tpl = new BindTemplate('Hello {foo ? "test" : 6}');334 var tokens = tpl.getTokens();335 expect(tokens).toEqual(['foo']);336 var s = tpl.apply([true]);337 expect(s).toBe('Hello test');338 });339 it('should parse true part with number', function () {340 var tpl = new BindTemplate('Hello {foo ? .04 : 6}');341 var tokens = tpl.getTokens();342 expect(tokens).toEqual(['foo']);343 var s = tpl.apply([true]);344 expect(s).toBe('Hello 0.04');345 });346 it('should parse true part with null', function () {347 var tpl = new BindTemplate('Hello {foo ? null : 6}');348 var tokens = tpl.getTokens();349 expect(tokens).toEqual(['foo']);350 var s = tpl.apply([true]);351 expect(s).toBe('Hello ');352 });353 it('should parse true part with boolean', function () {354 var tpl = new BindTemplate('Hello {foo ? true : 6}');355 var tokens = tpl.getTokens();356 expect(tokens).toEqual(['foo']);357 var s = tpl.apply([true]);358 expect(s).toBe('Hello true');359 });360 it('should parse true part enclosed in parans with simple format fn', function () {361 var tpl = new BindTemplate('Hello {foo ? (bar:number) : 6}');362 var tokens = tpl.getTokens();363 expect(tokens).toEqual(['foo', 'bar']);364 var s = tpl.apply([true, 5]);365 expect(s).toBe('Hello 5');366 });367 it('should parse true part enclosed in parans with format fn and args', function () {368 var tpl = new BindTemplate('Hello {foo ? (bar:number("0.00")) : 6}');369 var tokens = tpl.getTokens();370 expect(tokens).toEqual(['foo', 'bar']);371 var s = tpl.apply([true, 5]);372 expect(s).toBe('Hello 5.00');373 });374 it('should parse true part with basic algebra inside parans', function () {375 var tpl = new BindTemplate('Hello {foo ? (bar + 5 * foo.bar) : 6}');376 var tokens = tpl.getTokens();377 expect(tokens).toEqual(['foo', 'bar', 'foo.bar']);378 var s = tpl.apply([true, 4, 3]);379 expect(s).toBe('Hello 19');380 });381 it('should parse true part with basic algebra and no parans', function () {382 var tpl = new BindTemplate('Hello {foo ? bar + 5 * foo.bar : 6}');383 var tokens = tpl.getTokens();384 expect(tokens).toEqual(['foo', 'bar', 'foo.bar']);385 var s = tpl.apply([true, 4, 3]);386 expect(s).toBe('Hello 19');387 });388 it('should parse true part with basic algebra and format fn', function () {389 var tpl = new BindTemplate('Hello {foo ? ( ( bar + 5 * foo.bar:this.fn( 2 ) / 4 ):round:number("0.00") ) : 6}');390 var tokens = tpl.getTokens();391 expect(tokens).toEqual(['foo', 'bar', 'foo.bar']);392 var s = tpl.apply([true, 4, 3], {393 fn: function(v, factor){394 return v * factor;395 }396 });397 expect(s).toBe('Hello 12.00');398 });399 it('should parse true part with nested ternary', function () {400 var tpl = new BindTemplate('Hello {foo ? (bar ? (foo.bar + 9) : "failed") : 6}');401 var tokens = tpl.getTokens();402 expect(tokens).toEqual(['foo', 'bar', 'foo.bar']);403 var s = tpl.apply([true, 4, 3]);404 expect(s).toBe('Hello 12');405 });406 it('should parse true part with nested ternary and no parans', function () {407 var tpl = new BindTemplate('Hello {foo ? bar ? foo.bar + 9 : "failed" : 6}');408 var tokens = tpl.getTokens();409 expect(tokens).toEqual(['foo', 'bar', 'foo.bar']);410 var s = tpl.apply([true, 4, 3]);411 expect(s).toBe('Hello 12');412 });413 });414 describe('combined unary and binary operators', function(){415 it('should parse binary and unary -', function(){416 var tpl = new BindTemplate('Hello {foo.bar --5}!');417 var tokens = tpl.getTokens();418 expect(tokens).toEqual(['foo.bar']);419 var s = tpl.apply([10]);420 expect(s).toBe('Hello 15!');421 });422 it('should parse binary + and unary -', function(){423 var tpl = new BindTemplate('Hello {foo.bar +-5}!');424 var tokens = tpl.getTokens();425 expect(tokens).toEqual(['foo.bar']);426 var s = tpl.apply([10]);427 expect(s).toBe('Hello 5!');428 });429 it('should parse binary + and unary ! and -', function(){430 var tpl = new BindTemplate('Hello {foo.bar + !-5}!');431 var tokens = tpl.getTokens();432 expect(tokens).toEqual(['foo.bar']);433 var s = tpl.apply([10]);434 expect(s).toBe('Hello 10!'); // 10 + false435 });436 it('should parse ! operator in front of open paran', function(){437 var tpl = new BindTemplate('Hello {foo.bar + !(bar:number("0.00"))}!');438 var tokens = tpl.getTokens();439 expect(tokens).toEqual(['foo.bar', 'bar']);440 var s = tpl.apply([10, 4]);441 expect(s).toBe('Hello 10!'); // 10 + false442 });443 it('should parse ! operator in front of a token', function(){444 var tpl = new BindTemplate('Hello {foo.bar + !bar}!');445 var tokens = tpl.getTokens();446 expect(tokens).toEqual(['foo.bar', 'bar']);447 var s = tpl.apply([10, false]);448 expect(s).toBe('Hello 11!'); // 10 + true449 });450 it('should parse ! operator in front of a @', function(){451 var tpl = new BindTemplate('Hello {foo.bar + !@Ext.versions.core}!');452 var tokens = tpl.getTokens();453 expect(tokens).toEqual(['foo.bar']);454 var s = tpl.apply([10]);455 expect(s).toBe('Hello 10!'); // 10 + false456 });457 });458 describe('algebra', function(){459 it('should parse basic algebra', function(){460 var tpl = new BindTemplate('{foo:round + 2}');461 var tokens = tpl.getTokens();462 expect(tokens).toEqual(['foo']);463 var s = tpl.apply([15.6]);464 expect(s).toBe(18);465 });466 it('should parse operations by priority', function(){467 var tpl = new BindTemplate('Hello {(foo.bar * foo + bar +-test ? 7 : 1):this.thing(3) / bar.foo}!');468 var tokens = tpl.getTokens();469 expect(tokens).toEqual(['foo.bar', 'foo', 'bar', 'test', 'bar.foo']);470 var s = tpl.apply([10, 2, 5, 25, 2], {471 thing: function(v, factor){472 return v * factor;473 }474 });475 expect(s).toBe('Hello 1.5!');476 });477 it('should parse operations and apply formulas', function(){478 var tpl = new BindTemplate('Hello {(foo.bar * foo + bar):this.thing(3) / bar.foo}!');479 var tokens = tpl.getTokens();480 expect(tokens).toEqual(['foo.bar', 'foo', 'bar', 'bar.foo']);481 var s = tpl.apply([10, 2, 5, 2], {482 thing: function(v, factor){483 return v * factor;484 }485 });486 expect(s).toBe('Hello 37.5!');487 });488 it('should parse operations in formula arguments', function(){489 var tpl = new BindTemplate('Hello {((foo.bar * foo + bar):this.thing(bar + test:this.thing(3)) / bar.foo):number("0.00")}!');490 var tokens = tpl.getTokens();491 expect(tokens).toEqual(['foo.bar', 'foo', 'bar', 'test', 'bar.foo']);492 var s = tpl.apply([10, 2, 5, 7, 25], {493 thing: function(v, factor){494 return v * factor;495 }496 });497 expect(s).toBe('Hello 26.00!');498 });499 it('should parse complex operations', function(){500 var tpl = new BindTemplate('Hello {(foo.bar + bar.foo:this.thing):number("0.00")}!');501 var s = tpl.apply([5, 7], {502 thing: function(v){503 return v * 2;504 }505 });506 expect(s).toBe('Hello 19.00!');507 });508 });509 describe('default formatters', function () {510 it('should parse', function () {511 var tpl = new BindTemplate('Hello {foo:number} {bar.foo:lowercase}');512 expect(tpl.getTokens()).toEqual(['foo', 'bar.foo']);513 var s = tpl.apply([5, 'SENCHA']);514 expect(s).toBe('Hello 5 sencha');515 });516 it('should parse chained formatters', function(){517 var tpl = new BindTemplate('Hello {foo:lowercase:capitalize} {bar.foo:number("0.00")}');518 expect(tpl.getTokens()).toEqual(['foo', 'bar.foo']);519 var s = tpl.apply(['SENCHA', 23]);520 expect(s).toBe('Hello Sencha 23.00');521 });522 it('should parse nested formatters', function(){523 var tpl = new BindTemplate('Hello {foo:format(bar:pick("First: \\"param\\"", foo.bar:number("0")))}');524 expect(tpl.getTokens()).toEqual(['foo', 'bar', 'foo.bar']);525 var s = tpl.apply(['Result: {0}', false, 5]);526 expect(s).toBe('Hello Result: First: "param"');527 });528 it('should parse complex nested formatters', function(){529 var tpl = new BindTemplate('Hello {foo:format(bar:capitalize:leftPad(5, "x"))}');530 expect(tpl.getTokens()).toEqual(['foo', 'bar']);531 var s = tpl.apply(['there, {0}', 'john']);532 expect(s).toBe('Hello there, xJohn');533 });534 it('should parse nested and chained formatters', function(){535 var tpl = new BindTemplate('Hello {foo.bar:leftPad(!foo.test:pick(bar,foo), "X"):uppercase:ellipsis(8)} there and {foo:capitalize}!');536 expect(tpl.getTokens()).toEqual(['foo.bar', 'foo.test', 'bar', 'foo']);537 var s = tpl.apply(['sencha', true, 10, 'sencha']);538 expect(s).toBe('Hello XXXXS... there and Sencha!');539 });540 it('should parse escaped strings', function(){541 var tpl = new BindTemplate("{foo:leftPad(13, 'You\\'re ok ')}");542 // this expressions will fail: {foo:leftPad("You\", hi!",2)} or {foo:leftPad("(You\")",2)}543 expect(tpl.getTokens()).toEqual(['foo']);544 var s = tpl.apply(['now']);545 expect(s).toBe('You\'re ok now');546 });547 it('should parse more escaped strings', function(){548 var tpl = new BindTemplate('{foo:leftPad(10, "Y\\"): ")}');549 // this expression will fail: {foo:date("Y\"",2)}550 expect(tpl.getTokens()).toEqual(['foo']);551 var s = tpl.apply(['hello']);552 expect(s).toBe('Y"): hello');553 });554 it('should parse arguments', function () {555 var tpl = new BindTemplate('Hello {foo:number("0.00")} {bar.foo:number("0,000.00")}');556 expect(tpl.getTokens()).toEqual(['foo', 'bar.foo']);557 var s = tpl.apply([4554, 4554]);558 expect(s).toBe('Hello 4554.00 4,554.00');559 });560 it('should parse boolean arguments', function () {561 var tpl = new BindTemplate('Hello {foo:toggle("Flex", false)} {bar.foo:defaultValue(true)}');562 expect(tpl.getTokens()).toEqual(['foo', 'bar.foo']);563 var s = tpl.apply(['Flex', undefined]);564 expect(s).toBe('Hello false true');565 });566 it('should parse arguments that are functions', function(){567 var tpl = new BindTemplate('Hello {foo:defaultValue(bar.foo:lowercase)}');568 expect(tpl.getTokens()).toEqual(['foo', 'bar.foo']);569 var s = tpl.apply([undefined, 'THERE']);570 expect(s).toBe('Hello there');571 });572 it('should apply simple formatting', function () {573 var tpl = new BindTemplate('Hello {foo:number} {bar.foo:date("Y-m-d")} '+574 '-- {foo:number("0.00")}');575 var s = tpl.apply([123.456, new Date(2013, 2, 2)]);576 expect(s).toBe('Hello 123.456 2013-03-02 -- 123.46');577 });578 it('should apply complex formatting', function () {579 // The "," inside a string argument makes splitting on commas and producing an580 // args array early impossible (if we are to respect global references in them581 // as well)... but still needs to work.582 var tpl = new BindTemplate('Hello {foo:number} {bar.foo:date("Y-m-d")} '+583 '-- {foo:number("0,000.00")}');584 var s = tpl.apply([123456.789, new Date(2013, 2, 2)]);585 expect(s).toBe('Hello 123456.789 2013-03-02 -- 123,456.79');586 });587 });588 describe('scoped formatters', function () {589 it('should parse', function () {590 var tpl = new BindTemplate('Hello {foo:this.fn} {bar.foo:this.fn2}');591 expect(tpl.getTokens()).toEqual(['foo', 'bar.foo']);592 var s = tpl.apply([5, 6], {593 fn: function(v){594 return v + 1;595 },596 fn2: function(v){597 return v * 2;598 }599 });600 expect(s).toBe('Hello 6 12');601 });602 it('should parse arguments', function () {603 var tpl = new BindTemplate('Hello {foo:this.fn(4)} {bar.foo:this.fn2(20)}');604 expect(tpl.getTokens()).toEqual(['foo', 'bar.foo']);605 var s = tpl.apply([5, 6], {606 fn: function(v, a){607 return v + a;608 },609 fn2: function(v, a){610 return v * a;611 }612 });613 expect(s).toBe('Hello 9 120');614 });615 it('should apply simple formatting', function () {616 var tpl = new BindTemplate('Hello {foo:number} {bar.foo:date("Y-m-d")} '+617 '-- {foo:this.number("0.00")}');618 var s = tpl.apply([123.456, new Date(2013, 2, 2)], {619 scale: 2,620 number: function (v, str) {621 return '[[' + Ext.util.Format.number(v * this.scale, str) + ']]';622 }623 });624 expect(s).toBe('Hello 123.456 2013-03-02 -- [[246.91]]');625 });626 it('should apply complex formatting', function () {627 // This template uses a global reference as an argument. Odd but it works in628 // other templates.629 var tpl = new BindTemplate('Hello {foo:number} {bar.foo:date("Y-m-d")} '+630 '-- {foo:this.thing(@Ext.versions.core)}');631 var s = tpl.apply([123.456, new Date(2013, 2, 2)], {632 text: '::',633 thing: function (v, str) {634 return this.text + v + '=' + str + this.text;635 }636 });637 expect(s).toBe('Hello 123.456 2013-03-02 -- ::123.456=' +638 Ext.getVersion('core') + '::');639 });640 it('should apply chained and nested formatting', function(){641 var tpl = new BindTemplate('Hello {!foo.bar:pick(bar:number, "test"):number(\'0,000.00\')}, this is a {foo.test:this.thing("test", !test:pick("\\"man{}\\"",\'(joe)\'))}!');642 var s = tpl.apply([true, 123.456, 'complex', true], {643 text: '::',644 thing: function(v, str, a){645 return this.text + v + '=' + str + this.text + ' (' + a + ')';646 }647 });648 expect(s).toBe('Hello 123.46, this is a ::complex=test:: ("man{}")!');649 });650 });651 describe('syntax errors', function(){652 it('should fail when there\'s a format fn without prefixed token', function () {653 var tpl = new BindTemplate('Hello { :number }!');654 expect(function() {655 tpl.getTokens();656 }).toThrow();657 });658 it('should fail when @ prefixes an ! operator', function () {659 var tpl = new BindTemplate('Hello {foo.bar + @!Ext.versions.core}!');660 expect(function() {661 tpl.getTokens();662 }).toThrow();663 });664 it('should fail when @ prefixes a number', function () {665 var tpl = new BindTemplate('Hello {foo.bar + @5}!');666 expect(function() {667 tpl.getTokens();668 }).toThrow();669 });670 it('should fail when @ prefixes a string', function () {671 var tpl = new BindTemplate('Hello {foo.bar + @"test"}!');672 expect(function() {673 tpl.getTokens();674 }).toThrow();675 });676 it('should fail when @ prefixes other operators', function () {677 var tpl = new BindTemplate('Hello {foo.bar + @("test"}!');678 expect(function() {679 tpl.getTokens();680 }).toThrow();681 });682 it('should fail when there\'s a missing paran', function () {683 var tpl = new BindTemplate('Hello {foo.bar + (foo:number}!');684 expect(function() {685 tpl.getTokens();686 }).toThrow();687 });688 it('should fail when specifying an invalid Ext.util.Format fn', function () {689 var tpl = new BindTemplate('Hello {foo.bar + (foo:justTesting}!');690 expect(function() {691 tpl.getTokens();692 }).toThrow();693 });694 it('should fail when there is an unexpected operator', function () {695 var tpl = new BindTemplate('Hello {foo.bar + ! $ (foo:number)}!');696 expect(function() {697 tpl.getTokens();698 }).toThrow();699 });700 it('should fail when there is an unknown operator', function () {701 var tpl = new BindTemplate('Hello {foo.bar + dd[foo:number]}!');702 expect(function() {703 tpl.getTokens();704 }).toThrow();705 });706 it('should fail on unexpected . token', function () {707 var tpl = new BindTemplate('Hello {foo.bar + dd.(foo:number)}!');708 expect(function() {709 tpl.getTokens();710 }).toThrow();711 });712 it('should fail on not defined unary * operator', function () {713 var tpl = new BindTemplate('Hello {foo.bar + * 5}!');714 expect(function() {715 tpl.getTokens();716 }).toThrow();717 });718 it('should fail on undefined unary in format fn name', function () {719 var tpl = new BindTemplate('Hello {foo.bar:*number}!');720 expect(function() {721 tpl.getTokens();722 }).toThrow();723 });724 it('should fail when starting with an unknown operator', function () {725 var tpl = new BindTemplate('Hello { % foo.bar:number }!');726 expect(function() {727 tpl.getTokens();728 }).toThrow();729 });730 it('should fail when using open curly inside expression', function () {731 var tpl = new BindTemplate('Hello { { foo.bar:number }!');732 expect(function() {733 tpl.getTokens();734 }).toThrow();735 });736 it('should fail when using close curly inside expression', function () {737 var tpl = new BindTemplate('Hello { foo.bar:}number }!');738 expect(function() {739 tpl.getTokens();740 }).toThrow();741 });742 it('should fail on wrong literals', function () {743 var tpl = new BindTemplate('Hello { foo.bar:this.test("yep\" it fails") }!');744 expect(function() {745 tpl.getTokens();746 }).toThrow();747 });748 it('should fail when ending with an operator', function () {749 var tpl = new BindTemplate('Hello {foo.bar:number + }!');750 expect(function() {751 tpl.getTokens();752 }).toThrow();753 });754 it('should fail on undefined unary / operator', function () {755 var tpl = new BindTemplate('Hello {foo.bar + / 5}!');756 expect(function() {757 tpl.getTokens();758 }).toThrow();759 });760 it('should fail on undefined unary * operator', function () {761 var tpl = new BindTemplate('Hello {foo.bar + * 5}!');762 expect(function() {763 tpl.getTokens();764 }).toThrow();765 });766 it('should fail on undefined unary && operator', function () {767 var tpl = new BindTemplate('Hello {foo.bar + && 5}!');768 expect(function() {769 tpl.getTokens();770 }).toThrow();771 });772 it('should fail on undefined unary || operator', function () {773 var tpl = new BindTemplate('Hello {foo.bar + || 5}!');774 expect(function() {775 tpl.getTokens();776 }).toThrow();777 });778 it('should fail on undefined unary > operator', function () {779 var tpl = new BindTemplate('Hello {foo.bar + > 5}!');780 expect(function() {781 tpl.getTokens();782 }).toThrow();783 });784 it('should fail on undefined unary >= operator', function () {785 var tpl = new BindTemplate('Hello {foo.bar + >= 5}!');786 expect(function() {787 tpl.getTokens();788 }).toThrow();789 });790 it('should fail on undefined unary < operator', function () {791 var tpl = new BindTemplate('Hello {foo.bar + < 5}!');792 expect(function() {793 tpl.getTokens();794 }).toThrow();795 });796 it('should fail on undefined unary <= operator', function () {797 var tpl = new BindTemplate('Hello {foo.bar + <= 5}!');798 expect(function() {799 tpl.getTokens();800 }).toThrow();801 });802 it('should fail on undefined unary == operator', function () {803 var tpl = new BindTemplate('Hello {foo.bar + == 5}!');804 expect(function() {805 tpl.getTokens();806 }).toThrow();807 });808 it('should fail on undefined unary === operator', function () {809 var tpl = new BindTemplate('Hello {foo.bar + === 5}!');810 expect(function() {811 tpl.getTokens();812 }).toThrow();813 });814 it('should fail on undefined unary != operator', function () {815 var tpl = new BindTemplate('Hello {foo.bar + != 5}!');816 expect(function() {817 tpl.getTokens();818 }).toThrow();819 });820 it('should fail on undefined unary !== operator', function () {821 var tpl = new BindTemplate('Hello {foo.bar + !== 5}!');822 expect(function() {823 tpl.getTokens();824 }).toThrow();825 });826 it('should fail when the compiled function fails on global objects', function () {827 var tpl = new BindTemplate('Hello {foo.bar + @Something.b}!');828 expect(tpl.getTokens()).toEqual(['foo.bar']);829 expect(function() {830 tpl.apply([3]);831 }).toThrow();832 });833 it('should fail when the compiled function fails on missing scope function', function () {834 var tpl = new BindTemplate('Hello {foo.bar:this.test}!');835 expect(tpl.getTokens()).toEqual(['foo.bar']);836 expect(function() {837 tpl.apply([3]);838 }).toThrow();839 });840 it('should fail when ambiguous ternary provided', function () {841 var tpl = new BindTemplate('Hello {foo ? bar:number : 6}');842 expect(function() {843 tpl.getTokens();844 }).toThrow();845 });846 });...

Full Screen

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 path = require('path');6var feature = fs.readFileSync(path.resolve(__dirname, "test.feature"), "utf8");7var tokens = lexer.lex(feature);8var result = parser.parse(tokens);9console.log(result);10{ type: 'Feature',11 location: { line: 1, column: 1 },12 [ { type: 'Scenario',13 location: { line: 2, column: 3 },14 [ { type: 'Step',15 location: { line: 3, column: 5 },16 text: 'I have a test feature' },17 { type: 'Step',18 location: { line: 4, column: 5 },19 text: 'I have a test scenario' } ],20 tags: [] } ],21 tags: [] }22var Cucumber = require('cucumber');23var cucumber = Cucumber.Cli(process.argv.slice(2));24cucumber.run(function(succeeded) {25 process.exit(succeeded ? 0 : 1);26});

Full Screen

Using AI Code Generation

copy

Full Screen

1var gherkin = require('gherkin');2var fs = require('fs');3var parser = new gherkin.Parser();4var lexer = new gherkin.Lexer('en');5var feature = fs.readFileSync('test.feature', 'utf8');6var tokens = lexer.lex(feature);7var ast = parser.parse(tokens);8console.log(ast);9var gherkin = require('gherkin');10var fs = require('fs');11var parser = new gherkin.Parser();12var lexer = new gherkin.Lexer('en');13var feature = fs.readFileSync('test.feature', 'utf8');14var tokens = lexer.lex(feature);15var ast = parser.parse(tokens);16console.log(ast);

Full Screen

Using AI Code Generation

copy

Full Screen

1var gherkin = require('gherkin');2var parser = new gherkin.Parser();3var lexer = new gherkin.Lexer(gherkin);4var tokens = lexer.lex('Feature: test5');6console.log(tokens);7tokens = parser.parse(tokens);8console.log(tokens);9var gherkin = require('gherkin');10var parser = new gherkin.Parser();11var lexer = new gherkin.Lexer(gherkin);12var tokens = lexer.lex('Feature: test13');14console.log(tokens);15tokens = parser.parse(tokens);16console.log(tokens);17var messages = require('cucumber-messages');18var gherkinDocument = messages.GherkinDocument.fromObject({19 feature: {20 location: {21 },22 {23 scenario: {24 location: {25 },26 {27 location: {28 },29 }30 }31 }32 }33});34console.log(gherkinDocument);35var {defineSupportCode} = require('cucumber');36defineSupportCode(function({Given, Then}) {37 Given('I have a custom step', function() {38 });39});

Full Screen

Using AI Code Generation

copy

Full Screen

1var gherkin = require('gherkin');2var parser = new gherkin.Parser();3var lexer = new gherkin.Lexer();4var tokens = lexer.lex('Feature: Test');5var features = parser.parse(tokens);6console.log(features[0].name);7console.log(features[0].description);8{9 "dependencies": {10 }11}12var gherkin = require('gherkin');13var parser = new gherkin.Parser();14var lexer = new gherkin.Lexer();15var tokens = lexer.lex('Feature: Test');16var features = parser.parse(tokens);17console.log(features[0].name);18console.log(features[0].description);19 at Object.<anonymous> (C:\Users\user\Documents\test.js:7:20)20 at Module._compile (module.js:413:34)21 at Object.Module._extensions..js (module.js:422:10)22 at Module.load (module.js:357:32)23 at Function.Module._load (module.js:314:12)24 at Function.Module.runMain (module.js:447:10)25 at startup (node.js:139:18)

Full Screen

Using AI Code Generation

copy

Full Screen

1var gherkin = require('gherkin');2var parser = new gherkin.Parser();3var lexer = new gherkin.Lexer();4var tokens = lexer.lex("Feature: Test");5var result = parser.parse(tokens);6console.log(result);7{8 "scripts": {9 },10 "dependencies": {11 }12}13{14 "dependencies": {15 "gherkin": {16 "requires": {17 }18 },19 "json-stable-stringify": {20 "requires": {21 }22 },23 "minimatch": {

Full Screen

Using AI Code Generation

copy

Full Screen

1const gherkin = require('gherkin');2const parser = new gherkin.Parser();3const tokens = parser.getTokens('Feature: test');4const gherkin = require('gherkin');5const dialect = gherkin.getGherkinDialect('en');6console.log(dialect)7const gherkin = require('gherkin');8const dialects = gherkin.getGherkinDialects();9console.log(dialects)10const gherkin = require('gherkin');11const dialects = gherkin.getGherkinDialects();12console.log(dialects)13const gherkin = require('gherkin');14const dialects = gherkin.getGherkinDialects();15console.log(dialects)16const gherkin = require('gherkin');17const dialects = gherkin.getGherkinDialects();18console.log(dialects)19const gherkin = require('gherkin');20const dialects = gherkin.getGherkinDialects();21console.log(dialects)22const gherkin = require('gherkin');23const dialects = gherkin.getGherkinDialects();24console.log(dialects)25const gherkin = require('gherkin');26const dialects = gherkin.getGherkinDialects();27console.log(dialects)28const gherkin = require('gherkin');29const dialects = gherkin.getGherkinDialects();30console.log(dialects)

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