How to use mixedCaseBuilder method in fast-check-monorepo

Best JavaScript code snippet using fast-check-monorepo

MixedCaseArbitrary.spec.ts

Source:MixedCaseArbitrary.spec.ts Github

copy

Full Screen

1import fc from 'fast-check';2import {3 assertProduceValuesShrinkableWithoutContext,4 assertProduceCorrectValues,5 assertShrinkProducesSameValueWithoutInitialContext,6 assertShrinkProducesStrictlySmallerValue,7 assertProduceSameValueGivenSameSeed,8} from '../__test-helpers__/ArbitraryAssertions';9import { MixedCaseArbitrary } from '../../../../src/arbitrary/_internals/MixedCaseArbitrary';10import { stringOf } from '../../../../src/arbitrary/stringOf';11import { nat } from '../../../../src/arbitrary/nat';12import * as BigUintNMock from '../../../../src/arbitrary/bigUintN';13import { fakeArbitrary } from '../__test-helpers__/ArbitraryHelpers';14import { Value } from '../../../../src/check/arbitrary/definition/Value';15import { fakeRandom } from '../__test-helpers__/RandomHelpers';16function beforeEachHook() {17 jest.resetModules();18 jest.restoreAllMocks();19 fc.configureGlobal({ beforeEach: beforeEachHook });20}21beforeEach(beforeEachHook);22describe('MixedCaseArbitrary (integration)', () => {23 if (typeof BigInt === 'undefined') {24 it('no test', () => {25 expect(true).toBe(true);26 });27 return;28 }29 describe('generate', () => {30 it('should not toggle any character if flags equal zero', () => {31 // Arrange32 const { instance: mrng } = fakeRandom();33 const { bigUintN, stringInstance } = mockSourceArbitrariesForGenerate(BigInt(0), 'azerty');34 const toggleCase = jest.fn().mockImplementation((c) => c.toUpperCase());35 const untoggleAll = jest.fn().mockImplementation((s) => s.toLowerCase());36 // Act37 const arb = new MixedCaseArbitrary(stringInstance, toggleCase, untoggleAll);38 const g = arb.generate(mrng, undefined);39 // Assert40 expect(g.value).toBe('azerty');41 expect(bigUintN).toHaveBeenCalledWith(6); // num toggleable chars in string = 642 expect(toggleCase).toHaveBeenCalledTimes(6); // length string = 6, to be toggled = 043 expect(untoggleAll).not.toHaveBeenCalled();44 });45 it('should toggle characters according to flags', () => {46 // Arrange47 const { instance: mrng } = fakeRandom();48 const { bigUintN, stringInstance } = mockSourceArbitrariesForGenerate(BigInt(9) /* 001001 */, 'azerty');49 const toggleCase = jest.fn().mockImplementation((c) => c.toUpperCase());50 const untoggleAll = jest.fn().mockImplementation((s) => s.toLowerCase());51 // Act52 const arb = new MixedCaseArbitrary(stringInstance, toggleCase, untoggleAll);53 const g = arb.generate(mrng, undefined);54 // Assert55 expect(g.value).toBe('azErtY');56 expect(bigUintN).toHaveBeenCalledWith(6); // num toggleable chars in string = 657 expect(toggleCase).toHaveBeenCalledTimes(6 + 2); // length string = 6, to be toggled = 258 expect(untoggleAll).not.toHaveBeenCalled();59 });60 it('should not try to toggle characters that do not have toggled versions', () => {61 // Arrange62 const { instance: mrng } = fakeRandom();63 const { bigUintN, stringInstance } = mockSourceArbitrariesForGenerate(BigInt(10) /* 1010 */, 'az01ty');64 const toggleCase = jest.fn().mockImplementation((c) => c.toUpperCase());65 const untoggleAll = jest.fn().mockImplementation((s) => s.toLowerCase());66 // Act67 const arb = new MixedCaseArbitrary(stringInstance, toggleCase, untoggleAll);68 const g = arb.generate(mrng, undefined);69 // Assert70 expect(g.value).toBe('Az01Ty');71 expect(bigUintN).toHaveBeenCalledWith(4); // // num toggleable chars in string = 4 as 01 upper version is the same -> only 4 can be toggled not 672 expect(toggleCase).toHaveBeenCalledTimes(6 + 2); // length string = 6, to be toggled = 273 expect(untoggleAll).not.toHaveBeenCalled();74 });75 it('should properly deal with toggle mapping to multiple characters', () => {76 // Arrange77 const { instance: mrng } = fakeRandom();78 const { bigUintN, stringInstance } = mockSourceArbitrariesForGenerate(BigInt(63) /* 111111 */, 'azerty');79 const toggleCase = jest.fn().mockImplementation((c: string) => {80 if (c === 'a' || c === 't') return '<Hello>';81 else return c;82 });83 const untoggleAll = jest.fn().mockImplementation((s) => s.toLowerCase());84 // Act85 const arb = new MixedCaseArbitrary(stringInstance, toggleCase, untoggleAll);86 const g = arb.generate(mrng, undefined);87 // Assert88 expect(g.value).toBe('<Hello>zer<Hello>y');89 expect(bigUintN).toHaveBeenCalledWith(2); // num toggleable chars in string = 2, only a and t90 expect(toggleCase).toHaveBeenCalledTimes(6 + 2); // length string = 6, to be toggled = 291 expect(untoggleAll).not.toHaveBeenCalled();92 });93 });94 describe('canShrinkWithoutContext', () => {95 it('should always check against the arbitrary of string with raw when no untoggleAll', () => {96 fc.assert(97 fc.property(fc.string(), fc.boolean(), fc.func(fc.string()), (rawValue, isShrinkable, toggleCase) => {98 // Arrange99 const { instance, canShrinkWithoutContext } = fakeArbitrary();100 canShrinkWithoutContext.mockReturnValueOnce(isShrinkable);101 // Act102 const arb = new MixedCaseArbitrary(instance, toggleCase, undefined);103 const out = arb.canShrinkWithoutContext(rawValue);104 // Assert105 expect(out).toBe(isShrinkable);106 expect(canShrinkWithoutContext).toHaveBeenCalledTimes(1);107 expect(canShrinkWithoutContext).toHaveBeenCalledWith(rawValue);108 })109 );110 });111 it('should always check against the arbitrary of string with untoggled when untoggleAll', () => {112 fc.assert(113 fc.property(114 fc.string(),115 fc.string(),116 fc.boolean(),117 fc.func(fc.string()),118 (rawValue, untoggledValue, isShrinkable, toggleCase) => {119 // Arrange120 const { instance, canShrinkWithoutContext } = fakeArbitrary();121 canShrinkWithoutContext.mockReturnValueOnce(isShrinkable);122 const untoggleAll = jest.fn();123 untoggleAll.mockReturnValue(untoggledValue);124 // Act125 const arb = new MixedCaseArbitrary(instance, toggleCase, untoggleAll);126 const out = arb.canShrinkWithoutContext(rawValue);127 // Assert128 expect(out).toBe(isShrinkable);129 expect(canShrinkWithoutContext).toHaveBeenCalledTimes(1);130 expect(canShrinkWithoutContext).toHaveBeenCalledWith(untoggledValue);131 }132 )133 );134 });135 });136});137describe('MixedCaseArbitrary (integration)', () => {138 if (typeof BigInt === 'undefined') {139 it('no test', () => {140 expect(true).toBe(true);141 });142 return;143 }144 type Extra = { withoutToggle: boolean };145 const extraParameters: fc.Arbitrary<Extra> = fc.record({ withoutToggle: fc.boolean() });146 const mixedCaseBaseChars = ['A', 'B', '|', '~'];147 const isCorrect = (value: string, extra: Extra) => {148 const acceptedChars = extra.withoutToggle149 ? mixedCaseBaseChars150 : [...mixedCaseBaseChars, ...mixedCaseBaseChars.map((c) => c.toLowerCase())];151 return typeof value === 'string' && [...value].every((c) => acceptedChars.includes(c));152 };153 const isStrictlySmaller = (v1: string, v2: string) => v1.length < v2.length || v1 < v2; /* 'A' < 'a' < '|' < '~' */154 const mixedCaseBuilder = (extra: Extra) =>155 new MixedCaseArbitrary(156 stringOf(157 nat(mixedCaseBaseChars.length - 1).map(158 (id) => mixedCaseBaseChars[id],159 (c) => mixedCaseBaseChars.indexOf(c as string)160 )161 ),162 extra.withoutToggle ? (rawChar) => rawChar : (rawChar) => rawChar.toLowerCase(),163 (rawString) => rawString.toUpperCase()164 );165 it('should produce the same values given the same seed', () => {166 assertProduceSameValueGivenSameSeed(mixedCaseBuilder, { extraParameters });167 });168 it('should only produce correct values', () => {169 assertProduceCorrectValues(mixedCaseBuilder, isCorrect, { extraParameters });170 });171 it('should produce values seen as shrinkable without any context', () => {172 assertProduceValuesShrinkableWithoutContext(mixedCaseBuilder, { extraParameters });173 });174 it('should be able to shrink to the same values without initial context (if underlyings do)', () => {175 assertShrinkProducesSameValueWithoutInitialContext(mixedCaseBuilder, { extraParameters });176 });177 it('should preserve strictly smaller ordering in shrink (if underlyings do)', () => {178 assertShrinkProducesStrictlySmallerValue(mixedCaseBuilder, isStrictlySmaller, { extraParameters });179 });180});181// Helpers182function mockSourceArbitrariesForGenerate(bigIntOutput: bigint, stringOutput: string) {183 const { instance: bigUintNInstance, generate: bigUintNGenerate } = fakeArbitrary();184 const bigUintN = jest.spyOn(BigUintNMock, 'bigUintN');185 bigUintN.mockReturnValue(bigUintNInstance);186 bigUintNGenerate.mockReturnValueOnce(new Value(bigIntOutput, undefined));187 const { instance: stringInstance, generate: stringGenerate } = fakeArbitrary();188 stringGenerate.mockReturnValueOnce(new Value(stringOutput, undefined));189 return { bigUintN, stringInstance };...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const mixedCaseBuilder = require('fast-check-monorepo').mixedCaseBuilder;2const mixedCaseBuilder = require('fast-check').mixedCaseBuilder;3const fastCheck = require('fast-check');4const mixedCaseBuilder = fastCheck.mixedCaseBuilder;5const fastCheckMonorepo = require('fast-check-monorepo');6const mixedCaseBuilder = fastCheckMonorepo.mixedCaseBuilder;7const fastCheckMonorepo = require('fast-check-monorepo');8const mixedCaseBuilder = fastCheckMonorepo.default.mixedCaseBuilder;9const fastCheck = require('fast-check');10const mixedCaseBuilder = fastCheck.default.mixedCaseBuilder;11const fastCheck = require('fast-check');12const mixedCaseBuilder = fastCheck.default.default.mixedCaseBuilder;13const fastCheckMonorepo = require('fast-check-monorepo');14const mixedCaseBuilder = fastCheckMonorepo.default.default.mixedCaseBuilder;15const fastCheckMonorepo = require('fast-check-monorepo');16const mixedCaseBuilder = fastCheckMonorepo.default.default.default.mixedCaseBuilder;17const fastCheck = require('fast-check');18const mixedCaseBuilder = fastCheck.default.default.default.mixedCaseBuilder;19const fastCheck = require('fast-check');20const mixedCaseBuilder = fastCheck.default.default.default.default.mixedCaseBuilder;21const fastCheckMonorepo = require('fast-check-monorepo');22const mixedCaseBuilder = fastCheckMonorepo.default.default.default.default.mixedCaseBuilder;23const fastCheckMonorepo = require('fast-check-monorepo');

Full Screen

Using AI Code Generation

copy

Full Screen

1const mixedCaseBuilder = require('fast-check-monorepo').mixedCaseBuilder;2console.log(mixedCaseBuilder('abc'));3console.log(mixedCaseBuilder('123'));4console.log(mixedCaseBuilder('ABC'));5console.log(mixedCaseBuilder('ABC123'));6console.log(mixedCaseBuilder('abc123'));7console.log(mixedCaseBuilder('ABCabc123'));8console.log(mixedCaseBuilder('ABCabc123!@#$%^&*()'));

Full Screen

Using AI Code Generation

copy

Full Screen

1import mixedCaseBuilder from 'fast-check-monorepo'2import mixedCaseBuilder from 'fast-check'3import {mixedCaseBuilder} from 'fast-check-monorepo'4import {mixedCaseBuilder} from 'fast-check'5import {mixedCaseBuilder} from 'fast-check-monorepo/build/lib/arbitrary/mixedCaseArbitrary'6import {mixedCaseBuilder} from 'fast-check/build/lib/arbitrary/mixedCaseArbitrary'7import mixedCaseBuilder from 'fast-check-monorepo/lib/arbitrary/mixedCaseArbitrary'8import mixedCaseBuilder from 'fast-check/lib/arbitrary/mixedCaseArbitrary'9import mixedCaseBuilder from 'fast-check-monorepo/build/lib/arbitrary/mixedCaseArbitrary'10import mixedCaseBuilder from 'fast-check/build/lib/arbitrary/mixedCaseArbitrary'11import mixedCaseBuilder from 'fast-check-monorepo/build/lib/arbitrary/mixedCaseArbitrary.js'12import mixedCaseBuilder from 'fast-check/build/lib/arbitrary/mixedCaseArbitrary.js'13import mixedCaseBuilder from 'fast-check-monorepo/lib/arbitrary/mixedCaseArbitrary.js'14import mixedCaseBuilder from 'fast-check/lib/arbitrary/mixedCaseArbitrary.js'15import mixedCaseBuilder from 'fast-check-monorepo/build/lib/arbitrary/mixedCaseArbitrary.mjs

Full Screen

Using AI Code Generation

copy

Full Screen

1const fc = require('fast-check');2const mixedCaseBuilder = require('fast-check-monorepo').mixedCaseBuilder;3const mixedCase = mixedCaseBuilder()4 .withLowerCase()5 .withUpperCase()6 .withNumbers()7 .withSpecialCharacters()8 .withSpaces()9 .withMinLength(6)10 .withMaxLength(20)11 .build();12fc.assert(13 fc.property(mixedCase, (s) => {14 return s.length >= 6 && s.length <= 20;15 })16);

Full Screen

Using AI Code Generation

copy

Full Screen

1const { mixedCaseBuilder } = require('fast-check-monorepo');2const mixedCase = mixedCaseBuilder().build();3console.log(mixedCase);4const { mixedCaseBuilder } = require('fast-check');5const mixedCase = mixedCaseBuilder().build();6console.log(mixedCase);7const { mixedCaseBuilder } = require('fast-check');8const mixedCase = mixedCaseBuilder().build();9console.log(mixedCase);10const { mixedCaseBuilder } = require('fast-check');11const mixedCase = mixedCaseBuilder().build();12console.log(mixedCase);13const { mixedCaseBuilder } = require('fast-check');14const mixedCase = mixedCaseBuilder().build();15console.log(mixedCase);16const { mixedCaseBuilder } = require('fast-check');17const mixedCase = mixedCaseBuilder().build();18console.log(mixedCase);19const { mixedCaseBuilder } = require('fast-check');20const mixedCase = mixedCaseBuilder().build();21console.log(mixedCase);22const { mixedCaseBuilder } = require('fast-check');23const mixedCase = mixedCaseBuilder().build();24console.log(mixedCase);25const { mixedCaseBuilder } = require('fast-check');26const mixedCase = mixedCaseBuilder().build();27console.log(mixedCase);28const { mixedCaseBuilder } = require('fast-check');29const mixedCase = mixedCaseBuilder().build();30console.log(mixedCase);31const { mixedCaseBuilder } = require('fast-check');32const mixedCase = mixedCaseBuilder().build();33console.log(mixedCase);34const { mixedCaseBuilder } = require('fast-check');35const mixedCase = mixedCaseBuilder().build();36console.log(mixedCase);37const { mixedCaseBuilder } = require('fast-check');

Full Screen

Using AI Code Generation

copy

Full Screen

1const mixedCaseBuilder = require('../src/mixedCaseBuilder');2const mixedCaseString = mixedCaseBuilder();3const mixedCaseBuilder = require('fast-check-monorepo');4const mixedCaseString = mixedCaseBuilder();5const mixedCaseBuilder = require('fast-check-monorepo');6const mixedCaseString = mixedCaseBuilder();7const mixedCaseBuilder = require('fast-check-monorepo');8const mixedCaseString = mixedCaseBuilder();9const mixedCaseBuilder = require('fast-check-monorepo');10const mixedCaseString = mixedCaseBuilder();11const mixedCaseBuilder = require('fast-check-monorepo');12const mixedCaseString = mixedCaseBuilder();13const mixedCaseBuilder = require('fast-check-monorepo');14const mixedCaseString = mixedCaseBuilder();15const mixedCaseBuilder = require('fast-check-monorepo');16const mixedCaseString = mixedCaseBuilder();17const mixedCaseBuilder = require('fast-check-monorepo');18const mixedCaseString = mixedCaseBuilder();19const mixedCaseBuilder = require('fast-check-monorepo');20const mixedCaseString = mixedCaseBuilder();21const mixedCaseBuilder = require('fast-check-monorepo');22const mixedCaseString = mixedCaseBuilder();23const mixedCaseBuilder = require('fast-check-monorepo');24const mixedCaseString = mixedCaseBuilder();25const mixedCaseBuilder = require('fast-check-monorepo');26const mixedCaseString = mixedCaseBuilder();27const mixedCaseBuilder = require('fast-check-monorepo');

Full Screen

Using AI Code Generation

copy

Full Screen

1import { mixedCaseBuilder } from 'fast-check-monorepo';2console.log(mixedCaseBuilder('hello world'));3import { mixedCaseBuilder } from 'fast-check-monorepo';4import { expect } from 'chai';5describe('Mixed Case Builder', () => {6 it('should return mixed case string', () => {7 expect(mixedCaseBuilder('hello world')).to.equal('hElLo wOrLd');8 });9});

Full Screen

Using AI Code Generation

copy

Full Screen

1const { mixedCaseBuilder } = require('fast-check-monorepo');2const mixedCaseString = mixedCaseBuilder();3console.log(mixedCaseString);4const { mixedCaseBuilder } = require('fast-check-monorepo');5const mixedCaseString = mixedCaseBuilder();6console.log(mixedCaseString);

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run fast-check-monorepo 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