UNPKG

react-native-integrate

Version:

Automate integration of additional code into React Native projects

62 lines (61 loc) 2.46 kB
"use strict"; /* eslint-disable @typescript-eslint/no-unsafe-call */ Object.defineProperty(exports, "__esModule", { value: true }); require('../../mocks/mockAll'); const findInsertionPoint_1 = require("../../../utils/findInsertionPoint"); describe('findInsertionPoint', () => { it('should return insertion point index', () => { const preContent = 'fn() { '; const findContent = 'test1;'; const postContent = ' test2; }'; const content = preContent + findContent + postContent; const insertionPoint = (0, findInsertionPoint_1.findInsertionPoint)(content, findContent); expect(insertionPoint).toEqual({ start: preContent.length, end: preContent.length + findContent.length, match: findContent, }); }); it('should return negative on fail', () => { const preContent = 'fn() { '; const findContent = 'test1;'; const postContent = ' test2; }'; const content = preContent + findContent + postContent; const insertionPoint = (0, findInsertionPoint_1.findInsertionPoint)(content, 'random'); expect(insertionPoint).toEqual({ start: -1, end: -1, match: null, }); }); it('should return insertion point index with regex search', () => { const preContent = 'fn() { '; const findContent = 'test1; random \n more random strings;'; const postContent = ' test2; }'; const content = preContent + findContent + postContent; const insertionPoint = (0, findInsertionPoint_1.findInsertionPoint)(content, { regex: 'test1;.*?strings;', flags: 's', }); expect(insertionPoint).toEqual({ start: preContent.length, end: preContent.length + findContent.length, match: findContent, }); }); it('should return negative on fail with regex search', () => { const preContent = 'fn() { '; const findContent = 'test1; random \n more random strings;'; const postContent = ' test2; }'; const content = preContent + findContent + postContent; const insertionPoint = (0, findInsertionPoint_1.findInsertionPoint)(content, { regex: 'test_random', flags: 's', }); expect(insertionPoint).toEqual({ start: -1, end: -1, match: null, }); }); });