Best JavaScript code snippet using fast-check-monorepo
test-regexp-exec-lastindex.js
Source:test-regexp-exec-lastindex.js  
1/*2 *  Exec() lastIndex behavior is a bit peculiar, especially for non-global3 *  regexps (= regexps whose global flag is false).4 *5 *  For regexps with global=true, the behavior is quite straightforward:6 *  read lastIndex, and write it after matching regardless of success or7 *  failure of matching.8 *9 *  For regexps with global=false, it is a bit odd (E5 Section 15.10.6.2):10 *11 *    1. lastIndex is read from the object and coerced to integer (steps 4 and 5)12 *    2. the index is reset to zero if global=false (step 7)13 *    3. if the input is exhausted during matching, lastIndex is *written* to14 *       zero and a null is returned (step 9.a)15 *    4. if a match occurs, lastIndex is *not* written (step 11)16 */17var r, t;18var a, b;19/*20 *  Non-global regexp, normal use.21 */22/*===23===*/24try {25    r = /foo/;26    print(r.lastIndex);27    t = r.exec('bar');      /* no match -> reset to zero (but stays the same here, since it is already 0) */28    print(r.lastIndex);29    t = r.exec('foo');      /* match -> don't touch */30    print(r.lastIndex);31    t = r.exec('foofoo');   /* match -> don't touch */32    print(r.lastIndex);33    t = r.exec('foofoo');   /* match -> don't touch */34    print(r.lastIndex);35} catch (e) {36    print(e.name);37}38/*39 *  Non-global regexp, lastIndex should have no effect on matching40 *  and should only change if a match is not found.41 */42/*===43-144foo45-146999947foo48999949===*/50try {51    r = /foo/;52    print(r.lastIndex);53    r.lastIndex = -1;54    print(r.lastIndex);55    t = r.exec('foo');   /* match -> don't touch */56    print(t[0]);57    print(r.lastIndex);58    r = /foo/;59    print(r.lastIndex);60    r.lastIndex = 9999;61    print(r.lastIndex);62    t = r.exec('foo');   /* match -> don't touch */63    print(t[0]);64    print(r.lastIndex);65} catch (e) {66    print(e.name);67}68/*69 *  Non-global regexp, lastIndex is not written to if a match is found,70 *  even if lastIndex needs coercion.71 *72 *  Note: Smjs and Rhino seems to coerce lastIndex to number when73 *  it is written, so they fail this test.  lastIndex is just a74 *  normal writable property, see E5 Section 15.10.7.5.  It is75 *  coerced to integer *when used*.76 */77/*===780 number791 string801 string811 string821 string830 number841 object851 object861 object871 object88true89===*/90try {91    r = /foo/;92    print(r.lastIndex, typeof r.lastIndex);93    r.lastIndex = "1";94    print(r.lastIndex, typeof r.lastIndex);95    r.exec('foo');96    print(r.lastIndex, typeof r.lastIndex);97    r.exec('foofoo');98    print(r.lastIndex, typeof r.lastIndex);99    r.exec('foofoo');100    print(r.lastIndex, typeof r.lastIndex);101    r = /foo/;102    print(r.lastIndex, typeof r.lastIndex);103    a = new String("1");104    r.lastIndex = a;105    print(r.lastIndex, typeof r.lastIndex);106    r.exec('foo');107    print(r.lastIndex, typeof r.lastIndex);108    r.exec('foofoo');109    print(r.lastIndex, typeof r.lastIndex);110    r.exec('foofoo');111    print(r.lastIndex, typeof r.lastIndex);112    print(r.lastIndex === a);   /* instance should still be the same */113} catch (e) {114    print(e.name);115}116/*117 *  Non-global regexp, more lastIndex behavior when match is found118 *  and when it is not.119 */120/*===1210 number1220 number1230 number1241 string1251 string1260 number127-1 number128-1 number1290 number1301000000000000 number1311000000000000 number1320 number1331 string1340 number135===*/136/* match: zero is not written to */137try {138    r = /foo/;139    print(r.lastIndex, typeof r.lastIndex);140    t = r.exec('foobar');141    print(r.lastIndex, typeof r.lastIndex);142} catch (e) {143    print(e.name);144}145/* match: string '1' is not written to, and is ignored */146try {147    r = /foo/;148    print(r.lastIndex, typeof r.lastIndex);149    r.lastIndex = '1';150    print(r.lastIndex, typeof r.lastIndex);151    t = r.exec('foobar');152    print(r.lastIndex, typeof r.lastIndex);153} catch (e) {154    print(e.name);155}156/* match: number -1 is not written to, and is ignored */157try {158    r = /foo/;159    print(r.lastIndex, typeof r.lastIndex);160    r.lastIndex = -1;161    print(r.lastIndex, typeof r.lastIndex);162    t = r.exec('foobar');163    print(r.lastIndex, typeof r.lastIndex);164} catch (e) {165    print(e.name);166}167/* match: a large number is not written to, and is ignored */168try {169    r = /foo/;170    print(r.lastIndex, typeof r.lastIndex);171    r.lastIndex = 1000000000000;  /* above 2^32 */172    print(r.lastIndex, typeof r.lastIndex);173    t = r.exec('foobar');174    print(r.lastIndex, typeof r.lastIndex);175} catch (e) {176    print(e.name);177}178/* no match: previous value is overwritten with zero (step 9.a.i),179 * regardless of the global flag!180 *181 * Rhino and smjs fail this test.182 */183try {184    r = /foo/;185    print(r.lastIndex, typeof r.lastIndex);186    r.lastIndex = '1';187    print(r.lastIndex, typeof r.lastIndex);188    t = r.exec('bar');189    print(r.lastIndex, typeof r.lastIndex);190} catch (e) {191    print(e.name);192}193/*194 *  Global regexp, normal use.195 */196/*===197foo1983199null200foo2013202Foo2036204FOO2059206null207===*/208try {209    r = /foo/g;210    print(r.lastIndex);211    t = r.exec('foo');212    print(t[0]);213    print(r.lastIndex);214    t = r.exec('foo');215    print(t);216    print(r.lastIndex);217    r = /foo/gi;218    print(r.lastIndex);219    t = r.exec('fooFooFOO');220    print(t[0]);221    print(r.lastIndex);222    t = r.exec('fooFooFOO');223    print(t[0]);224    print(r.lastIndex);225    t = r.exec('fooFooFOO');226    print(t[0]);227    print(r.lastIndex);228    t = r.exec('fooFooFOO');229    print(t);230    print(r.lastIndex);231} catch (e) {232    print(e.name);233}234/*235 *  Global regexp, change input string while lastIndex changes,236 *  just a sanity check.237 */238/*===239foo2403241FOO2426243null244===*/245try {246    r = /foo/gi;247    print(r.lastIndex);248    t = r.exec('foo');    /* match, leave at 3 */249    print(t[0]);250    print(r.lastIndex);251    t = r.exec('barFOO');252    print(t[0]);253    print(r.lastIndex);254    t = r.exec('foo');    /* starts at 6, out of bounds => null and 0 */255    print(t);256    print(r.lastIndex);257} catch (e) {258    print(e.name);259}260/*261 *  Coercion and update of a non-number lastIndex.  Out of bounds lastIndex262 *  causes exec() to return null, and reset lastIndex to zero.263 */264/*===265-1266null267999268null269object2702271Foo27232736274number275===*/276try {277    r = /foo/gi;278    print(r.lastIndex);279    r.lastIndex = -1;280    print(r.lastIndex);281    t = r.exec('foo');282    print(t);283    print(r.lastIndex);284    r.lastIndex = 999;285    print(r.lastIndex);286    t = r.exec('foo');287    print(t);288    print(r.lastIndex);289    a = {};290    a.valueOf = function() { return 2; };291    r.lastIndex = a;292    print(typeof r.lastIndex);293    print(r.lastIndex.valueOf());294    t = r.exec('fooFoo');   /* start matching at 2, find match at 3 for 'Foo' */295    print(t[0]);296    print(t.index);297    print(r.lastIndex);298    print(typeof r.lastIndex);299} catch (e) {300    print(e.name);301}302/*303 *  lastIndex is coerced with ToInteger() which -allows- values304 *  larger than 32 bits.  For instance, 0x100000000 must NOT be305 *  confused with 0x00000000 as would happen if lastIndex were306 *  coerced with ToUint32() for instance.307 */308/*===3090 number310foo3114294967297 number3120 number313null3140 number315===*/316try {317    /* Non-global regexp: lastIndex is ignored (matching starts from char318     * index 0) -> match.  lastIndex is not updated for non-global regexps319     * when a match happens.320     */321    r = /foo/;322    print(r.lastIndex, typeof r.lastIndex);323    r.lastIndex = 4294967297.0;   /* 0x100000001 */324    t = r.exec('foofoofoo');325    print(t);326    print(r.lastIndex, typeof r.lastIndex);327} catch (e) {328    print(e.name);329}330try {331    /* Global regexp: respects lastIndex -> no match.  On a non-match332     * lastIndex is zeroed.333     */334    r = /foo/g;335    print(r.lastIndex, typeof r.lastIndex);336    r.lastIndex = 4294967297.0;   /* 0x100000001 */337    t = r.exec('foofoofoo');   /* no match, lastIndex is reset to zero */338    print(t);339    print(r.lastIndex, typeof r.lastIndex);340} catch (e) {341    print(e.name);342}343/*344 *  lastIndex can be NAN or +/- Infinity.  These have well defined345 *  behavior.  If the global flag is not set, they are ignored (but346 *  overwritten if there is no match).  If the global flag is set,347 *  NAN is coerced to +0.0 by ToInteger(), while +/- Infinity is used348 *  as is.  It will cause match to fail at step 9.a, and lastIndex to349 *  be overwritten with zero.350 *351 *  The sign of a zero is preserved by ToInteger().  It must be preserved352 *  for non-global regexps which -do match-.353 */354/*===3550 number356NaN number357foo358NaN number359null3600 number Infinity3610 number362NaN number363foo3643 number365null3660 number Infinity367===*/368try {369    r = /foo/;370    print(r.lastIndex, typeof r.lastIndex);371    r.lastIndex = NaN;372    print(r.lastIndex, typeof r.lastIndex);373    t = r.exec('foo');   /* match -> don't update */374    print(t[0]);375    print(r.lastIndex, typeof r.lastIndex);376    t = r.exec('bar');   /* no match -> overwrite with zero */377    print(t);378    print(r.lastIndex, typeof r.lastIndex, 1.0 / r.lastIndex);   /* check sign too */379} catch (e) {380    print(e.name);381}382try {383    r = /foo/g;384    print(r.lastIndex, typeof r.lastIndex);385    r.lastIndex = NaN;386    print(r.lastIndex, typeof r.lastIndex);387    t = r.exec('foo');   /* match -> update */388    print(t[0]);389    print(r.lastIndex, typeof r.lastIndex);390    t = r.exec('bar');   /* no match -> overwrite with zero */391    print(t);392    print(r.lastIndex, typeof r.lastIndex, 1.0 / r.lastIndex);   /* check sign too */393} catch (e) {394    print(e.name);395}396/*===3970 number398Infinity number399foo400Infinity number401null4020 number Infinity4030 number404Infinity number405null4060 number Infinity407===*/408try {409    r = /foo/;410    print(r.lastIndex, typeof r.lastIndex);411    r.lastIndex = Infinity;412    print(r.lastIndex, typeof r.lastIndex);413    t = r.exec('foo');   /* match -> don't update */414    print(t[0]);415    print(r.lastIndex, typeof r.lastIndex);416    t = r.exec('bar');   /* no match -> overwrite with zero */417    print(t);418    print(r.lastIndex, typeof r.lastIndex, 1.0 / r.lastIndex);   /* check sign too */419} catch (e) {420    print(e.name);421}422try {423    r = /foo/g;424    print(r.lastIndex, typeof r.lastIndex);425    r.lastIndex = Infinity;426    print(r.lastIndex, typeof r.lastIndex);427    t = r.exec('foo');   /* no match (since we start from after end of string -> overwrite */428    print(t);429    print(r.lastIndex, typeof r.lastIndex, 1.0 / r.lastIndex);   /* check sign too */430} catch (e) {431    print(e.name);432}433/*===4340 number435-Infinity number436foo437-Infinity number438null4390 number Infinity4400 number441-Infinity number442null4430 number Infinity444===*/445try {446    r = /foo/;447    print(r.lastIndex, typeof r.lastIndex);448    r.lastIndex = -Infinity;449    print(r.lastIndex, typeof r.lastIndex);450    t = r.exec('foo');   /* match -> don't update */451    print(t[0]);452    print(r.lastIndex, typeof r.lastIndex);453    t = r.exec('bar');   /* no match -> overwrite with zero */454    print(t);455    print(r.lastIndex, typeof r.lastIndex, 1.0 / r.lastIndex);   /* check sign too */456} catch (e) {457    print(e.name);458}459try {460    r = /foo/g;461    print(r.lastIndex, typeof r.lastIndex);462    r.lastIndex = -Infinity;463    print(r.lastIndex, typeof r.lastIndex);464    t = r.exec('foo');   /* no match (since we start from after end of string -> overwrite */465    print(t);466    print(r.lastIndex, typeof r.lastIndex, 1.0 / r.lastIndex);   /* check sign too */467} catch (e) {468    print(e.name);469}470/*===4710 number Infinity4720 number -Infinity473foo4740 number -Infinity475null4760 number Infinity4770 number Infinity4780 number -Infinity479foo4803 number481null4820 number Infinity483===*/484try {485    r = /foo/;486    print(r.lastIndex, typeof r.lastIndex, 1.0 / r.lastIndex);487    r.lastIndex = -0.0;488    print(r.lastIndex, typeof r.lastIndex, 1.0 / r.lastIndex);489    t = r.exec('foo');   /* match -> don't update */490    print(t[0]);491    print(r.lastIndex, typeof r.lastIndex, 1.0 / r.lastIndex);492    t = r.exec('bar');   /* no match -> overwrite with zero (positive) */493    print(t);494    print(r.lastIndex, typeof r.lastIndex, 1.0 / r.lastIndex);   /* check sign too */495} catch (e) {496    print(e.name);497}498try {499    r = /foo/g;500    print(r.lastIndex, typeof r.lastIndex, 1.0 / r.lastIndex);501    r.lastIndex = -0.0;502    print(r.lastIndex, typeof r.lastIndex, 1.0 / r.lastIndex);503    t = r.exec('foo');   /* match -> update */504    print(t[0]);505    print(r.lastIndex, typeof r.lastIndex);506    t = r.exec('bar');   /* no match -> overwrite with zero (positive) */507    print(t);508    print(r.lastIndex, typeof r.lastIndex, 1.0 / r.lastIndex);   /* check sign too */509} catch (e) {510    print(e.name);511}512/*513 *  The lastIndex value is floored.514 */515/*===5160 number5170.9 number518foo5190.9 number5200 number5210.9 number522foo5233 number524===*/525try {526    r = /foo/;527    print(r.lastIndex, typeof r.lastIndex);528    r.lastIndex = 0.9;529    print(r.lastIndex, typeof r.lastIndex);530    t = r.exec('foo');531    print(t[0]);532    print(r.lastIndex, typeof r.lastIndex);533} catch (e) {534    print(e.name);535}536try {537    r = /foo/g;538    print(r.lastIndex, typeof r.lastIndex);539    r.lastIndex = 0.9;540    print(r.lastIndex, typeof r.lastIndex);541    t = r.exec('foo');542    print(t[0]);543    print(r.lastIndex, typeof r.lastIndex);544} catch (e) {545    print(e.name);...regress-2437.js
Source:regress-2437.js  
1// Copyright 2012 the V8 project authors. All rights reserved.2// Redistribution and use in source and binary forms, with or without3// modification, are permitted provided that the following conditions are4// met:5//6//     * Redistributions of source code must retain the above copyright7//       notice, this list of conditions and the following disclaimer.8//     * Redistributions in binary form must reproduce the above9//       copyright notice, this list of conditions and the following10//       disclaimer in the documentation and/or other materials provided11//       with the distribution.12//     * Neither the name of Google Inc. nor the names of its13//       contributors may be used to endorse or promote products derived14//       from this software without specific prior written permission.15//16// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS17// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT18// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR19// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT20// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,21// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT22// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,23// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY24// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT25// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE26// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.27// Summary of the spec: lastIndex is reset to 0 if28// - a regexp fails to match, regardless of global or non-global.29// - a global regexp is used in a function that returns multiple results,30//   such as String.prototype.replace or String.prototype.match, since it31//   repeats the regexp until it fails to match.32// Otherwise lastIndex is only set when a global regexp matches, to the index33// after the match.34// Test Regexp.prototype.exec35r = /a/;36r.lastIndex = 1;37r.exec("zzzz");38assertEquals(0, r.lastIndex);39// Test Regexp.prototype.test40r = /a/;41r.lastIndex = 1;42r.test("zzzz");43assertEquals(0, r.lastIndex);44// Test String.prototype.match45r = /a/;46r.lastIndex = 1;47"zzzz".match(r);48assertEquals(0, r.lastIndex);49// Test String.prototype.replace with atomic regexp and empty string.50r = /a/;51r.lastIndex = 1;52"zzzz".replace(r, "");53assertEquals(0, r.lastIndex);54// Test String.prototype.replace with non-atomic regexp and empty string.55r = /\d/;56r.lastIndex = 1;57"zzzz".replace(r, "");58assertEquals(0, r.lastIndex);59// Test String.prototype.replace with atomic regexp and non-empty string.60r = /a/;61r.lastIndex = 1;62"zzzz".replace(r, "a");63assertEquals(0, r.lastIndex);64// Test String.prototype.replace with non-atomic regexp and non-empty string.65r = /\d/;66r.lastIndex = 1;67"zzzz".replace(r, "a");68assertEquals(0, r.lastIndex);69// Test String.prototype.replace with replacement function70r = /a/;71r.lastIndex = 1;72"zzzz".replace(r, function() { return ""; });73assertEquals(0, r.lastIndex);74// Regexp functions that returns multiple results:75// A global regexp always resets lastIndex regardless of whether it matches.76r = /a/g;77r.lastIndex = -1;78"0123abcd".replace(r, "x");79assertEquals(0, r.lastIndex);80r.lastIndex = -1;81"01234567".replace(r, "x");82assertEquals(0, r.lastIndex);83r.lastIndex = -1;84"0123abcd".match(r);85assertEquals(0, r.lastIndex);86r.lastIndex = -1;87"01234567".match(r);88assertEquals(0, r.lastIndex);89// A non-global regexp resets lastIndex iff it does not match.90r = /a/;91r.lastIndex = -1;92"0123abcd".replace(r, "x");93assertEquals(-1, r.lastIndex);94r.lastIndex = -1;95"01234567".replace(r, "x");96assertEquals(0, r.lastIndex);97r.lastIndex = -1;98"0123abcd".match(r);99assertEquals(-1, r.lastIndex);100r.lastIndex = -1;101"01234567".match(r);102assertEquals(0, r.lastIndex);103// Also test RegExp.prototype.exec and RegExp.prototype.test104r = /a/g;105r.lastIndex = 1;106r.exec("01234567");107assertEquals(0, r.lastIndex);108r.lastIndex = 1;109r.exec("0123abcd");110assertEquals(5, r.lastIndex);111r = /a/;112r.lastIndex = 1;113r.exec("01234567");114assertEquals(0, r.lastIndex);115r.lastIndex = 1;116r.exec("0123abcd");117assertEquals(1, r.lastIndex);118r = /a/g;119r.lastIndex = 1;120r.test("01234567");121assertEquals(0, r.lastIndex);122r.lastIndex = 1;123r.test("0123abcd");124assertEquals(5, r.lastIndex);125r = /a/;126r.lastIndex = 1;127r.test("01234567");128assertEquals(0, r.lastIndex);129r.lastIndex = 1;130r.test("0123abcd");...lastIndex.js
Source:lastIndex.js  
1description(2"This page tests that a RegExp object's lastIndex behaves like a regular property."3);4// lastIndex is not configurable5shouldBeFalse("delete /x/.lastIndex");6shouldThrow("'use strict'; delete /x/.lastIndex");7// lastIndex is not enumerable8shouldBeTrue("'lastIndex' in /x/");9shouldBeTrue("for (property in /x/) if (property === 'lastIndex') throw false; true");10// lastIndex is writable11shouldBeTrue("var re = /x/; re.lastIndex = re; re.lastIndex === re");12// Cannot redefine lastIndex as an accessor13shouldThrow("Object.defineProperty(/x/, {get:function(){}})");14// Cannot redefine lastIndex as enumerable15shouldThrow("Object.defineProperty(/x/, 'lastIndex', {enumerable:true}); true");16shouldBeTrue("Object.defineProperty(/x/, 'lastIndex', {enumerable:false}); true");17// Cannot redefine lastIndex as configurable18shouldThrow("Object.defineProperty(/x/, 'lastIndex', {configurable:true}); true");19shouldBeTrue("Object.defineProperty(/x/, 'lastIndex', {configurable:false}); true");20// Can redefine lastIndex as read-only21shouldBe("var re = Object.defineProperty(/x/, 'lastIndex', {writable:true}); re.lastIndex = 42; re.lastIndex", '42');22shouldBe("var re = Object.defineProperty(/x/, 'lastIndex', {writable:false}); re.lastIndex = 42; re.lastIndex", '0');23// Can redefine the value24shouldBe("var re = Object.defineProperty(/x/, 'lastIndex', {value:42}); re.lastIndex", '42');25// Cannot redefine read-only lastIndex as writable26shouldThrow("Object.defineProperty(Object.defineProperty(/x/, 'lastIndex', {writable:false}), 'lastIndex', {writable:true}); true");27// Can only redefine the value of a read-only lastIndex as the current value28shouldThrow("Object.defineProperty(Object.defineProperty(/x/, 'lastIndex', {writable:false}), 'lastIndex', {value:42}); true");29shouldBeTrue("Object.defineProperty(Object.defineProperty(/x/, 'lastIndex', {writable:false}), 'lastIndex', {value:0}); true");30// Trying to run a global regular expression should throw, if lastIndex is read-only31shouldBe("Object.defineProperty(/x/, 'lastIndex', {writable:false}).exec('')", 'null');32shouldBe("Object.defineProperty(/x/, 'lastIndex', {writable:false}).exec('x')", '["x"]');33shouldThrow("Object.defineProperty(/x/g, 'lastIndex', {writable:false}).exec('')");34shouldThrow("Object.defineProperty(/x/g, 'lastIndex', {writable:false}).exec('x')");35// Should be able to freeze a regular expression object....Using AI Code Generation
1{2}3{4  "plugins": {5    "node": {}6  }7}8{9  "plugins": {10    "node": {},11    "modules": {}12  }13}14{15  "plugins": {16    "node": {},Using AI Code Generation
1const fs = require('fs');2const {ArbitraryRunner} = require('fast-check');3const file = fs.readFileSync('fast-check-monorepo/packages/fast-check/src/check/runner/ArbitraryRunner.ts');4const lines = file.toString().split('5');6const lastLine = lines[lines.length - 1];7const lastIndex = lastLine.lastIndexOf('lastIndex');8console.log(lastIndex);Using AI Code Generation
1const fc = require('fast-check');2const { ArbitraryRunner } = require('@dubzzz/fast-check/lib/check/runner/ArbitraryRunner.js');3const arbitraryRunner = new ArbitraryRunner();4const { instance } = arbitraryRunner;5const { _arbs } = instance;6const arb = fc.integer(0, 100);7const { _lastIndex } = arb;8console.log(_lastIndex);9const fc = require('fast-check');10const { ArbitraryRunner } = require('@dubzzz/fast-check/lib/check/runner/ArbitraryRunner.js');11const arbitraryRunner = new ArbitraryRunner();12const { instance } = arbitraryRunner;13const { _arbs } = instance;14const arb = fc.integer(0, 100);15const { _lastIndex } = arb;16console.log(_lastIndex);17const fc = require('fast-check');18const { ArbitraryRunner } = require('@dubzzz/fast-check/lib/check/runner/ArbitraryRunner.js');19const arbitraryRunner = new ArbitraryRunner();20const { instance } = arbitraryRunner;21const { _arbs } = instance;22const arb = fc.integer(0, 100);23const { _lastIndex } = arb;24console.log(_lastIndex);25const fc = require('fast-check');26const { ArbitraryRunner } = require('@dubzzz/fast-check/lib/check/runner/ArbitraryRunner.js');27const arbitraryRunner = new ArbitraryRunner();28const { instance } = arbitraryRunner;29const { _arbs } = instance;30const arb = fc.integer(0, 100);31const { _lastIndex } = arb;32console.log(_lastIndex);33const fc = require('fast-check');34const { ArbitraryRunner } = require('@dubzzz/fast-check/lib/check/runner/ArbitraryRunner.js');35const arbitraryRunner = new ArbitraryRunner();36const { instance } = arbitraryRunner;37const { _arbs }Using AI Code Generation
1const fc = require('fast-check');2const re = new RegExp('a*b', 'g');3const arb = fc.regexp(re);4const g = arb.generator;5console.log(g.next());6console.log(g.next());7console.log(g.nUsing AI Code Generation
1const fc = require("fast-check");2const char = fc.char();3const char2 = fc.char({ fullUnicode: true });4const char3 = fc.char();5char3.lastIndex = 1;6console.log(char3.lastIndex);7char3.lastIndex = 2;8console.log(char3.lastIndex);9char3.lastIndex = 3;10console.log(char3.lastIndex);11char3.lastIndex = 4;12console.log(char3.lastIndex);13char3.lastIndex = 5;14console.log(char3.lastIndex);15char3.lastIndex = 6;16console.log(char3.lastIndex);17char3.lastIndex = 7;18console.log(char3.lastIndex);19char3.lastIndex = 8;20console.log(char3.lastIndex);21char3.lastIndex = 9;22console.log(char3.lastIndex);23char3.lastIndex = 10;24console.log(char3.lastIndex);25char3.lastIndex = 11;26console.log(char3.lastIndex);27char3.lastIndex = 12;28console.log(char3.lastIndex);29char3.lastIndex = 13;30console.log(char3.lastIndex);31char3.lastIndex = 14;32console.log(char3.lastIndex);33char3.lastIndex = 15;34console.log(char3.lastIndex);35char3.lastIndex = 16;36console.log(char3.lastIndex);37char3.lastIndex = 17;38console.log(char3.lastIndex);39char3.lastIndex = 18;40console.log(char3.lastIndex);41char3.lastIndex = 19;42console.log(char3.lastIndex);43char3.lastIndex = 20;44console.log(char3.lastIndex);45char3.lastIndex = 21;46console.log(char3.lastUsing AI Code Generation
1const fc = require('fast-check');2const {CharacterArbitrary} = require('fast-check/lib/check/arbitrary/CharacterArbitrary');3const charArb = new CharacterArbitrary();4const str = 'abcad';5for (let i = 0; i < str.length; i++) {6    charArb.canGenerate(str[i]);7}8console.log(charArb.lastIndex('a'));9const fc = require('fast-check');10const {CharacterArbitrary} = require('fast-check/lib/check/arbitrary/CharacterArbitrary');11const charArb = new CharacterArbitrary();12const str = 'abcad';13for (let i = 0; i < str.length; i++) {14    charArb.canGenerate(str[i]);15}16console.log(charArb.lastIndex('a', 2));17const fc = require('fast-check');18const {CharacterArbitrary} = require('fast-check/lib/check/arbitrary/CharacterArbitrary');19const charArb = new CharacterArbitrary();20const str = 'abcad';21for (let i = 0; i < str.length; i++) {22    charArb.canGenerate(str[i]);23}24console.log(charArb.lastIndex('a', 2, 3));25const fc = require('fast-check');26const {CharacterArbitrary} = require('fast-check/lib/check/arbitrary/CharacterArbitrary');27const charArb = new CharacterArbitrary();Using AI Code Generation
1const fc = require('fast-check');2const { lastIndexOf } = require('lodash');3const { assert } = require('chai');4const { string, integer } = fc;5const { range } = fc;6const { array } = fc;7const { property } = fc;8const { sample } = fc;9const { seed } = fc;10const { configureGlobal } = fc;11const { configureOutput } = fc;12configureOutput({13});14property(15    array(string()),16    array(string()),17    function (arr1, arr2) {18        const arr3 = arr1.concat(arr2);19        return lastIndexOf(arr3, 'a') === arr3.lastIndexOf('a');20    }21).check();22property(23    array(string()),24    array(string()),25    function (arr1, arr2) {26        const arr3 = arr1.concat(arr2);27        return lastIndexOf(arr3, 'a', 2) === arr3.lastIndexOf('a', 2);28    }29).check();30property(31    array(string()),32    array(string()),33    function (arr1, arr2) {34        const arr3 = arr1.concat(arr2);35        return lastIndexOf(arr3, 'a', -2) === arr3.lastIndexOf('a', -2);36    }37).check();38property(39    array(string()),40    array(string()),41    function (arr1, arr2) {42        const arr3 = arr1.concat(arr2);43        return lastIndexOf(arr3, 'a', 0) === arr3.lastIndexOf('a', 0);44    }45).check();46property(47    array(string()),48    array(string()),49    function (arr1, arr2) {50        const arr3 = arr1.concat(arr2);51        return lastIndexOf(arr3, 'a', 1) === arr3.lastIndexOf('a', 1);52    }53).check();54property(55    array(string()),56    array(string()),57    function (arr1, arr2) {58        const arr3 = arr1.concat(arr2);59        return lastIndexOf(arr3, 'a', -1) === arr3.lastIndexOf('a', -1);60    }61).check();62property(63    array(string()),Using AI Code Generation
1import * as fc from 'fast-check';2const myRegex = new RegExp('foo', 'g');3const lastIndex = fc.property(4  fc.string(),5  fc.nat(),6  (str, i) => {7    const newStr = str + 'foo'.repeat(i);8    myRegex.lastIndex = 0;9    myRegex.exec(newStr);10    const lastIndex = myRegex.lastIndex;11    return lastIndex === newStr.lastIndexOf('foo');12  }13);14fc.assert(lastIndex);15import * as fc from 'fast-check';16const myRegex = new RegExp('foo', 'g');17const lastIndex = fc.property(18  fc.string(),19  fc.nat(),20  (str, i) => {21    const newStr = str + 'foo'.repeat(i);22    myRegex.lastIndex = 0;23    myRegex.exec(newStr);24    const lastIndex = myRegex.lastIndex;25    return lastIndex === newStr.lastIndexOf('foo');26  }27);28fc.assert(lastIndex);29import * as fc from 'fast-check';30const myRegex = new RegExp('foo', 'g');31const lastIndex = fc.property(32  fc.string(),33  fc.nat(),34  (str, i) => {35    const newStr = str + 'foo'.repeat(i);36    myRegex.lastIndex = 0;37    myRegex.exec(newStr);38    const lastIndex = myRegex.lastIndex;39    return lastIndex === newStr.lastIndexOf('foo');40  }41);42fc.assert(lastIndex);43import * as fc from 'fast-check';44const myRegex = new RegExp('foo', 'g');45const lastIndex = fc.property(46  fc.string(),47  fc.nat(),48  (str, i) => {49    const newStr = str + 'foo'.repeat(i);50    myRegex.lastIndex = 0;51    myRegex.exec(newStr);52    const lastIndex = myRegex.lastIndex;Using AI Code Generation
1const fc = require('fast-check');2const assert = require('assert');3fc.assert(4  fc.property(fc.array(fc.integer()), fc.integer(), (arr, element) => {5    arr.push(element);6    arr.push(element);7    arr.push(element);8    assert.notStrictEqual(arr.lastIndexOf(element), -1);9  })10);11fc.assert(12  fc.property(fc.array(fc.integer()), fc.integer(), (arr, element) => {13    assert.strictEqual(arr.lastIndexOf(element), -1);14  })15);16fc.assert(17  fc.property(fc.array(fc.integer()), fc.integer(), (arr, element) => {18    arr.push(element);19    assert.notStrictEqual(arr.lastIndexOf(element), -1);20  })21);22fc.assert(23  fc.property(fc.array(fc.integer()), fc.integer(), (arr, element) => {24    arr.push(element);25    arr.push(element);26    arr.push(element);27    arr.push(element);28    assert.notStrictEqual(arr.lastIndexOf(element), -1);29  })30);Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
