MCPcopy
hub / github.com/jestjs/jest / findCommonSubstrings

Function findCommonSubstrings

packages/diff-sequences/src/__tests__/index.test.ts:739–762  ·  view source on GitHub ↗
(a: string, b: string)

Source from the content-addressed store, hash-verified

737
738// Return array of substrings in a longest common subsequence of strings.
739const findCommonSubstrings = (a: string, b: string): Array<string> => {
740 const array: Array<string> = [];
741 diff(
742 a.length,
743 b.length,
744 (aIndex: number, bIndex: number) => {
745 assertMin('input aIndex', aIndex, 0);
746 assertEnd('input aIndex', aIndex, a.length);
747 assertMin('input bIndex', bIndex, 0);
748 assertEnd('input bIndex', bIndex, b.length);
749 return a[aIndex] === b[bIndex];
750 },
751 (nCommon: number, aCommon: number, bCommon: number) => {
752 assertMin('output nCommon', nCommon, 1);
753 assertMin('output aCommon', aCommon, 0);
754 assertMax('output aCommon + nCommon', aCommon + nCommon, a.length);
755 assertMin('output bCommon', bCommon, 0);
756 assertMax('output bCommon + nCommon', bCommon + nCommon, b.length);
757 assertCommonSubstring(a, b, nCommon, aCommon, bCommon);
758 array.push(a.slice(aCommon, aCommon + nCommon));
759 },
760 );
761 return array;
762};
763
764describe('common substrings', () => {
765 // Find changed and unchanged substrings within adjacent changed lines

Callers 1

index.test.tsFile · 0.85

Calls 5

assertMinFunction · 0.85
assertEndFunction · 0.85
assertMaxFunction · 0.85
assertCommonSubstringFunction · 0.85
diffFunction · 0.50

Tested by

no test coverage detected