Best JavaScript code snippet using stryker-parent
StringTypes.ts
Source:StringTypes.ts
1import {2 mapMap,3 iterableFirst,4 setIntersect,5 hashCodeOf,6 areEqual,7 mapMergeWithInto,8 definedMap,9 addHashCode,10 setUnionInto11} from "collection-utils";12import { TypeAttributeKind } from "./TypeAttributes";13import { defined, assert } from "../support/Support";14import { StringTypeMapping, stringTypeMappingGet } from "../TypeBuilder";15import { TransformedStringTypeKind } from "../Type";16import { DateTimeRecognizer } from "../DateTime";17export class StringTypes {18 static readonly unrestricted: StringTypes = new StringTypes(undefined, new Set());19 static fromCase(s: string, count: number): StringTypes {20 const caseMap: { [name: string]: number } = {};21 caseMap[s] = count;22 return new StringTypes(new Map([[s, count] as [string, number]]), new Set());23 }24 static fromCases(cases: string[]): StringTypes {25 const caseMap: { [name: string]: number } = {};26 for (const s of cases) {27 caseMap[s] = 1;28 }29 return new StringTypes(new Map(cases.map(s => [s, 1] as [string, number])), new Set());30 }31 // undefined means no restrictions32 constructor(33 readonly cases: ReadonlyMap<string, number> | undefined,34 readonly transformations: ReadonlySet<TransformedStringTypeKind>35 ) {36 if (cases === undefined) {37 assert(transformations.size === 0, "We can't have an unrestricted string that also allows transformations");38 }39 }40 get isRestricted(): boolean {41 return this.cases !== undefined;42 }43 union(othersArray: StringTypes[], startIndex: number): StringTypes {44 if (this.cases === undefined) return this;45 const cases = new Map(this.cases);46 const transformations = new Set(this.transformations);47 for (let i = startIndex; i < othersArray.length; i++) {48 const other = othersArray[i];49 if (other.cases === undefined) return other;50 mapMergeWithInto(cases, (x, y) => x + y, other.cases);51 setUnionInto(transformations, other.transformations);52 }53 return new StringTypes(cases, transformations);54 }55 intersect(othersArray: StringTypes[], startIndex: number): StringTypes {56 let cases = this.cases;57 let transformations = this.transformations;58 for (let i = startIndex; i < othersArray.length; i++) {59 const other = othersArray[i];60 if (cases === undefined) {61 cases = definedMap(other.cases, m => new Map(m));62 } else if (other.cases !== undefined) {63 const thisCases = cases;64 const otherCases = other.cases;65 cases = mapMap(setIntersect(thisCases.keys(), new Set(otherCases.keys())).entries(), k =>66 Math.min(defined(thisCases.get(k)), defined(otherCases.get(k)))67 );68 }69 transformations = setIntersect(transformations, other.transformations);70 }71 return new StringTypes(cases, transformations);72 }73 applyStringTypeMapping(mapping: StringTypeMapping): StringTypes {74 if (!this.isRestricted) return this;75 const kinds = new Set<TransformedStringTypeKind>();76 for (const kind of this.transformations) {77 const mapped = stringTypeMappingGet(mapping, kind);78 if (mapped === "string") return StringTypes.unrestricted;79 kinds.add(mapped);80 }81 return new StringTypes(this.cases, new Set(kinds));82 }83 equals(other: any): boolean {84 if (!(other instanceof StringTypes)) return false;85 return areEqual(this.cases, other.cases) && areEqual(this.transformations, other.transformations);86 }87 hashCode(): number {88 let h = hashCodeOf(this.cases);89 h = addHashCode(h, hashCodeOf(this.transformations));90 return h;91 }92 toString(): string {93 const parts: string[] = [];94 const enumCases = this.cases;95 if (enumCases === undefined) {96 parts.push("unrestricted");97 } else {98 const firstKey = iterableFirst(enumCases.keys());99 if (firstKey === undefined) {100 parts.push("enum with no cases");101 } else {102 parts.push(`${enumCases.size.toString()} enums: ${firstKey} (${enumCases.get(firstKey)}), ...`);103 }104 }105 return parts.concat(Array.from(this.transformations)).join(",");106 }107}108class StringTypesTypeAttributeKind extends TypeAttributeKind<StringTypes> {109 constructor() {110 super("stringTypes");111 }112 get inIdentity(): boolean {113 return true;114 }115 requiresUniqueIdentity(st: StringTypes): boolean {116 return st.cases !== undefined && st.cases.size > 0;117 }118 combine(arr: StringTypes[]): StringTypes {119 assert(arr.length > 0);120 return arr[0].union(arr, 1);121 }122 intersect(arr: StringTypes[]): StringTypes {123 assert(arr.length > 0);124 return arr[0].intersect(arr, 1);125 }126 makeInferred(_: StringTypes): undefined {127 return undefined;128 }129 stringify(st: StringTypes): string {130 return st.toString();131 }132}133export const stringTypesTypeAttributeKind: TypeAttributeKind<StringTypes> = new StringTypesTypeAttributeKind();134const INTEGER_STRING = /^(0|-?[1-9]\d*)$/;135// We're restricting numbers to what's representable as 32 bit136// signed integers, to be on the safe side of most languages.137const MIN_INTEGER_STRING = 1 << 31;138const MAX_INTEGER_STRING = -(MIN_INTEGER_STRING + 1);139function isIntegerString(s: string): boolean {140 if (s.match(INTEGER_STRING) === null) {141 return false;142 }143 const i = parseInt(s, 10);144 return i >= MIN_INTEGER_STRING && i <= MAX_INTEGER_STRING;145}146const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;147function isUUID(s: string): boolean {148 return s.match(UUID) !== null;149}150// FIXME: This is obviously not a complete URI regex. The exclusion of151// `{}` is a hack to make `github-events.json` work, which contains URLs152// with those characters which ajv refuses to accept as `uri`.153const URI = /^(https?|ftp):\/\/[^{}]+$/;154function isURI(s: string): boolean {155 return s.match(URI) !== null;156}157/**158 * JSON inference calls this function to figure out whether a given string is to be159 * transformed into a higher level type. Must return undefined if not, otherwise the160 * type kind of the transformed string type.161 *162 * @param s The string for which to determine the transformed string type kind.163 */164export function inferTransformedStringTypeKindForString(165 s: string,166 recognizer: DateTimeRecognizer167): TransformedStringTypeKind | undefined {168 if (s.length === 0 || "0123456789-abcdefth".indexOf(s[0]) < 0) return undefined;169 if (recognizer.isDate(s)) {170 return "date";171 } else if (recognizer.isTime(s)) {172 return "time";173 } else if (recognizer.isDateTime(s)) {174 return "date-time";175 } else if (isIntegerString(s)) {176 return "integer-string";177 } else if (s === "false" || s === "true") {178 return "bool-string";179 } else if (isUUID(s)) {180 return "uuid";181 } else if (isURI(s)) {182 return "uri";183 }184 return undefined;...
strings.ts
Source:strings.ts
1import { expect } from '@jest/globals';2import dedent from 'dedent-js';3import { FormatFn } from 'src/sqlFormatter';4type StringType =5 // Note: ""-qq and ""-bs can be combined to allow for both types of escaping6 | '""-qq' // with repeated-quote escaping7 | '""-bs' // with backslash escaping8 // Note: ''-qq and ''-bs can be combined to allow for both types of escaping9 | "''-qq" // with repeated-quote escaping10 | "''-bs" // with backslash escaping11 | "U&''" // with repeated-quote escaping12 | "N''" // with escaping style depending on whether also ''-qq or ''-bs was specified13 | "X''" // no escaping14 | 'X""' // no escaping15 | "B''" // no escaping16 | 'B""' // no escaping17 | "R''" // no escaping18 | 'R""'; // no escaping19export default function supportsStrings(format: FormatFn, stringTypes: StringType[]) {20 if (stringTypes.includes('""-qq') || stringTypes.includes('""-bs')) {21 it('supports double-quoted strings', () => {22 expect(format('"foo JOIN bar"')).toBe('"foo JOIN bar"');23 expect(format('SELECT "where" FROM "update"')).toBe(dedent`24 SELECT25 "where"26 FROM27 "update"28 `);29 });30 }31 if (stringTypes.includes('""-qq')) {32 it('supports escaping double-quote by doubling it', () => {33 expect(format('"foo""bar"')).toBe('"foo""bar"');34 });35 if (!stringTypes.includes('""-bs')) {36 it('does not support escaping double-quote with a backslash', () => {37 expect(() => format('"foo \\" JOIN bar"')).toThrowError('Parse error: Unexpected """');38 });39 }40 }41 if (stringTypes.includes('""-bs')) {42 it('supports escaping double-quote with a backslash', () => {43 expect(format('"foo \\" JOIN bar"')).toBe('"foo \\" JOIN bar"');44 });45 if (!stringTypes.includes('""-qq')) {46 it('does not support escaping double-quote by doubling it', () => {47 expect(format('"foo "" JOIN bar"')).toBe('"foo " " JOIN bar"');48 });49 }50 }51 if (stringTypes.includes("''-qq") || stringTypes.includes("''-bs")) {52 it('supports single-quoted strings', () => {53 expect(format("'foo JOIN bar'")).toBe("'foo JOIN bar'");54 expect(format("SELECT 'where' FROM 'update'")).toBe(dedent`55 SELECT56 'where'57 FROM58 'update'59 `);60 });61 }62 if (stringTypes.includes("''-qq")) {63 it('supports escaping single-quote by doubling it', () => {64 expect(format("'foo''bar'")).toBe("'foo''bar'");65 });66 if (!stringTypes.includes("''-bs")) {67 it('does not support escaping single-quote with a backslash', () => {68 expect(() => format("'foo \\' JOIN bar'")).toThrowError(`Parse error: Unexpected "'"`);69 });70 }71 }72 if (stringTypes.includes("''-bs")) {73 it('supports escaping single-quote with a backslash', () => {74 expect(format("'foo \\' JOIN bar'")).toBe("'foo \\' JOIN bar'");75 });76 if (!stringTypes.includes("''-qq")) {77 it('does not support escaping single-quote by doubling it', () => {78 expect(format("'foo '' JOIN bar'")).toBe("'foo ' ' JOIN bar'");79 });80 }81 }82 if (stringTypes.includes("U&''")) {83 it('supports unicode single-quoted strings', () => {84 expect(format("U&'foo JOIN bar'")).toBe("U&'foo JOIN bar'");85 expect(format("SELECT U&'where' FROM U&'update'")).toBe(dedent`86 SELECT87 U&'where'88 FROM89 U&'update'90 `);91 });92 it("supports escaping in U&'' strings with repeated quote", () => {93 expect(format("U&'foo '' JOIN bar'")).toBe("U&'foo '' JOIN bar'");94 });95 it("detects consecutive U&'' strings as separate ones", () => {96 expect(format("U&'foo'U&'bar'")).toBe("U&'foo' U&'bar'");97 });98 }99 if (stringTypes.includes("N''")) {100 it('supports T-SQL unicode strings', () => {101 expect(format("N'foo JOIN bar'")).toBe("N'foo JOIN bar'");102 expect(format("SELECT N'where' FROM N'update'")).toBe(dedent`103 SELECT104 N'where'105 FROM106 N'update'107 `);108 });109 if (stringTypes.includes("''-qq")) {110 it("supports escaping in N'' strings with repeated quote", () => {111 expect(format("N'foo '' JOIN bar'")).toBe("N'foo '' JOIN bar'");112 });113 }114 if (stringTypes.includes("''-bs")) {115 it("supports escaping in N'' strings with a backslash", () => {116 expect(format("N'foo \\' JOIN bar'")).toBe("N'foo \\' JOIN bar'");117 });118 }119 it("detects consecutive N'' strings as separate ones", () => {120 expect(format("N'foo'N'bar'")).toBe("N'foo' N'bar'");121 });122 }123 if (stringTypes.includes("X''")) {124 it('supports hex byte sequences', () => {125 expect(format("x'0E'")).toBe("x'0E'");126 expect(format("X'1F0A89C3'")).toBe("X'1F0A89C3'");127 expect(format("SELECT x'2B' FROM foo")).toBe(dedent`128 SELECT129 x'2B'130 FROM131 foo132 `);133 });134 it("detects consecutive X'' strings as separate ones", () => {135 expect(format("X'AE01'X'01F6'")).toBe("X'AE01' X'01F6'");136 });137 }138 if (stringTypes.includes('X""')) {139 it('supports hex byte sequences', () => {140 expect(format(`x"0E"`)).toBe(`x"0E"`);141 expect(format(`X"1F0A89C3"`)).toBe(`X"1F0A89C3"`);142 expect(format(`SELECT x"2B" FROM foo`)).toBe(dedent`143 SELECT144 x"2B"145 FROM146 foo147 `);148 });149 it(`detects consecutive X" strings as separate ones`, () => {150 expect(format(`X"AE01"X"01F6"`)).toBe(`X"AE01" X"01F6"`);151 });152 }153 if (stringTypes.includes("B''")) {154 it('supports bit sequences', () => {155 expect(format("b'01'")).toBe("b'01'");156 expect(format("B'10110'")).toBe("B'10110'");157 expect(format("SELECT b'0101' FROM foo")).toBe(dedent`158 SELECT159 b'0101'160 FROM161 foo162 `);163 });164 it("detects consecutive B'' strings as separate ones", () => {165 expect(format("B'1001'B'0110'")).toBe("B'1001' B'0110'");166 });167 }168 if (stringTypes.includes('B""')) {169 it('supports bit sequences (with double-qoutes)', () => {170 expect(format(`b"01"`)).toBe(`b"01"`);171 expect(format(`B"10110"`)).toBe(`B"10110"`);172 expect(format(`SELECT b"0101" FROM foo`)).toBe(dedent`173 SELECT174 b"0101"175 FROM176 foo177 `);178 });179 it(`detects consecutive B"" strings as separate ones`, () => {180 expect(format(`B"1001"B"0110"`)).toBe(`B"1001" B"0110"`);181 });182 }183 if (stringTypes.includes("R''")) {184 it('supports no escaping in raw strings', () => {185 expect(format("SELECT r'some \\',R'text' FROM foo")).toBe(dedent`186 SELECT187 r'some \\',188 R'text'189 FROM190 foo191 `);192 });193 it("detects consecutive r'' strings as separate ones", () => {194 expect(format("r'a ha'r'hm mm'")).toBe("r'a ha' r'hm mm'");195 });196 }197 if (stringTypes.includes('R""')) {198 it('supports no escaping in raw strings (with double-quotes)', () => {199 expect(format(`SELECT r"some \\", R"text" FROM foo`)).toBe(dedent`200 SELECT201 r"some \\",202 R"text"203 FROM204 foo205 `);206 });207 it(`detects consecutive r"" strings as separate ones`, () => {208 expect(format(`r"a ha"r"hm mm"`)).toBe(`r"a ha" r"hm mm"`);209 });210 }...
Using AI Code Generation
1var strykerParent = require('stryker-parent');2console.log(strykerParent.stringTypes());3var strykerParent = require('stryker-parent');4console.log(strykerParent.stringTypes());5var strykerParent = require('stryker-parent');6console.log(strykerParent.stringTypes());7var strykerParent = require('stryker-parent');8console.log(strykerParent.stringTypes());9var strykerParent = require('stryker-parent');10console.log(strykerParent.stringTypes());11var strykerParent = require('stryker-parent');12console.log(strykerParent.stringTypes());13var strykerParent = require('stryker-parent');14console.log(strykerParent.stringTypes());15var strykerParent = require('stryker-parent');16console.log(strykerParent.stringTypes());17var strykerParent = require('stryker-parent');18console.log(strykerParent.stringTypes());19var strykerParent = require('stryker-parent');20console.log(strykerParent.stringTypes());21var strykerParent = require('stryker-parent');22console.log(strykerParent.stringTypes());23var strykerParent = require('stryker-parent');24console.log(strykerParent.stringTypes());25var strykerParent = require('stryker-parent');26console.log(strykerParent.string
Using AI Code Generation
1const strykerParent = require('stryker-parent');2console.log(strykerParent.stringTypes);3const strykerParent = require('stryker-parent');4console.log(strykerParent.stringTypes);5const strykerParent = require('stryker-parent');6console.log(strykerParent.stringTypes);7const strykerParent = require('stryker-parent');8console.log(strykerParent.stringTypes);9const strykerParent = require('stryker-parent');10console.log(strykerParent.stringTypes);11const strykerParent = require('stryker-parent');12console.log(strykerParent.stringTypes);13const strykerParent = require('stryker-parent');14console.log(strykerParent.stringTypes);15const strykerParent = require('stryker-parent');16console.log(strykerParent.stringTypes);17const strykerParent = require('stryker-parent');18console.log(strykerParent.stringTypes);19const strykerParent = require('stryker-parent');20console.log(strykerParent.stringTypes);21const strykerParent = require('stryker-parent');22console.log(strykerParent.stringTypes);23const strykerParent = require('stryker-parent');24console.log(strykerParent.stringTypes);25const strykerParent = require('stryker-parent');26console.log(strykerParent.string
Using AI Code Generation
1var strykerParent = require('stryker-parent');2var stringTypes = strykerParent.stringTypes;3var strykerParent = require('stryker-parent');4var stringTypes = strykerParent.stringTypes;5var strykerParent = require('stryker-parent');6var stringTypes = strykerParent.stringTypes;7var strykerParent = require('stryker-parent');8var stringTypes = strykerParent.stringTypes;9var strykerParent = require('stryker-parent');10var stringTypes = strykerParent.stringTypes;11var strykerParent = require('stryker-parent');12var stringTypes = strykerParent.stringTypes;13var strykerParent = require('stryker-parent');14var stringTypes = strykerParent.stringTypes;15var strykerParent = require('stryker-parent');16var stringTypes = strykerParent.stringTypes;17var strykerParent = require('stryker-parent');18var stringTypes = strykerParent.stringTypes;19var strykerParent = require('stryker-parent');20var stringTypes = strykerParent.stringTypes;21var strykerParent = require('stryker-parent');22var stringTypes = strykerParent.stringTypes;23var strykerParent = require('stryker-parent');24var stringTypes = strykerParent.stringTypes;25var strykerParent = require('stryker-parent');26var stringTypes = strykerParent.stringTypes;27var strykerParent = require('stryker-parent');28var stringTypes = strykerParent.stringTypes;
Using AI Code Generation
1var stringTypes = require('stryker-parent').stringTypes;2var stringTypes = require('stryker-parent').stringTypes;3var stringTypes = require('stryker-parent').stringTypes;4var stringTypes = require('stryker-parent').stringTypes;5var stringTypes = require('stryker-parent').stringTypes;6var stringTypes = require('stryker-parent').stringTypes;7var stringTypes = require('stryker-parent').stringTypes;8var stringTypes = require('stryker-parent').stringTypes;9var stringTypes = require('stryker-parent').stringTypes;10var stringTypes = require('stryker-parent').stringTypes;11var stringTypes = require('stryker-parent').stringTypes;12var stringTypes = require('stryker-parent').stringTypes;13var stringTypes = require('stryker-parent').stringTypes;14var stringTypes = require('stryker-parent').stringTypes;15var stringTypes = require('stryker-parent').stringTypes;16var stringTypes = require('stryker-parent').stringTypes;17var stringTypes = require('stryker-parent').stringTypes;18var stringTypes = require('stryker-parent
Using AI Code Generation
1const stryker = require('stryker-parent');2console.log(stryker.stringTypes());3const stryker = require('stryker-parent');4console.log(stryker.stringTypes());5const stryker = require('stryker-parent');6console.log(stryker.stringTypes());7const stryker = require('stryker-parent');8console.log(stryker.stringTypes());9const stryker = require('stryker-parent');10console.log(stryker.stringTypes());11const stryker = require('stryker-parent');12console.log(stryker.stringTypes());13const stryker = require('stryker-parent');14console.log(stryker.stringTypes());15const stryker = require('stryker-parent');16console.log(stryker.stringTypes());17const stryker = require('stryker-parent');18console.log(stryker.stringTypes());19const stryker = require('stryker-parent');20console.log(stryker.stringTypes());21const stryker = require('stryker-parent');22console.log(stryker.stringTypes());23const stryker = require('stryker-parent');24console.log(stryker.stringTypes());25const stryker = require('stryker-parent');26console.log(stryker.stringTypes());
Using AI Code Generation
1var strykerParent = require('stryker-parent');2var stringTypes = strykerParent.stringTypes;3stringTypes('Hello');4var strykerParent = require('stryker-parent');5var stringTypes = strykerParent.stringTypes;6stringTypes('Hello');
Using AI Code Generation
1var stringTypes = require('stryker-parent').stringTypes;2var result = stringTypes('hello');3console.log(result);4module.exports = {5 stringTypes: function (str) {6 return typeof str;7 }8}9[2018-07-12 16:52:49.575] [INFO] SandboxPool - Creating 1 test runners (based on CPU count)10[2018-07-12 16:52:49.582] [INFO] MutatorFacade - 2 Mutant(s) generated
Using AI Code Generation
1var strykerParent = require('stryker-parent');2console.log(strykerParent.stringTypes);3var strykerParent = require('stryker-parent');4console.log(strykerParent.stringTypes);5var strykerParent = require('stryker-parent');6console.log(strykerParent.stringTypes);7var strykerParent = require('stryker-parent');8console.log(strykerParent.stringTypes);9var strykerParent = require('stryker-parent');10console.log(strykerParent.stringTypes);11var strykerParent = require('stryker-parent');12console.log(strykerParent.stringTypes);13var strykerParent = require('stryker-parent');14console.log(strykerParent.stringTypes);15var strykerParent = require('stryker-parent');16console.log(strykerParent.stringTypes);17var strykerParent = require('stryker-parent');18console.log(strykerParent.stringTypes);
Using AI Code Generation
1const str = require('stryker-parent');2console.log(str.stringTypes);3const str = require('stryker-parent');4console.log(str.stringTypes);5const str = require('stryker-parent');6console.log(str.stringTypes);7const str = require('stryker-parent');8console.log(str.stringTypes);9const str = require('stryker-parent');10console.log(str.stringTypes);11const str = require('stryker-parent');12console.log(str.stringTypes);13const str = require('stryker-parent');14console.log(str.stringTypes);15const str = require('stryker-parent');16console.log(str.stringTypes);
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!!