continue-custom/core/test/diff.test.ts
Nate Sesti ca884b8212
fix ollama onboarding (#1539)
* allow setting apiBase for bedrock provider

* ⚡️ better linking

* ✨ new prompt file action

* ⚡️ strip <COMPLETION> from GPT-4 completion

* continue proxy FIM support

* warn user if potentially dangerous command is generated

* tab autocomplete docs

* docs: update PR template (#1531)

* chore: add docs to install script (#1533)

* fix(extensions): schema for db ctx provider (#1534)

* fix(extensions): schema for db ctx provider

* fix: invalid enum

* prettierignore

* docs: add docs and schema for "OS" provider (#1536)

* tests (#1501)

* 👷 CI for jetbrains

* default working dir

* changelog

* build binaries

* binary testing setup

* idesettings

* core binary testing

* run binary tests in ci

* remove unused targets

* needs build

* console.log bin contents

* fix ci

* fix win32 binary download

* test

* no linux arm64

* macos latest

* macos-12

* binary permissions

* upload logs

* fix

* upload full folder as binary artifact

* test

* test macos only

* set full execute permissions

* copy sqlite binary

* cd

* it worked!

* build again in test job

* debug

* remove timeout

* info

* log

* log2

* more logs

* catch

* fewer logs

* test all platforms

* test downloaded artifact

* needs build

* updates

* build

* false

* release

* add tag and upload binaryes

* change tag name

* proper artifact upload

* jest updates

* ✅ generate a few unit tests with Continue

* fix imports related to IdeSettings

* run tsc on PRs

* remove shareSession command (unused)

* update release process

* update plugin version

* don't show ghost text when jetbrains completion visible

* run jetbrains ci in main

* check ts in dev

* ignore .env

* 🚑 fix constant warnings when onboarding with Ollama

---------

Co-authored-by: Patrick Erichsen <patrick.a.erichsen@gmail.com>
2024-06-21 11:09:03 -07:00

150 lines
3.3 KiB
TypeScript

import { streamDiff } from "../diff/streamDiff.js";
const oldCode = [
`A
B`,
`A
B
C`,
`A
B
C
A
B
B
A`,
`function mergeSortAlgorithm() {
// TODO: implement
}`,
`function mergeSortAlgorithm() {
// TODO: implement
}`,
];
const newCode = [
`C
D`,
`D
E
C
F
C`,
`C
B
A
B
A
C`,
`function mergeSortAlgorithm(arr: number[]): number[] {
if (arr.length <= 1) {
return arr;
}
const middle = Math.floor(arr.length / 2);
const left = arr.slice(0, middle);
const right = arr.slice(middle);
return merge(mergeSortAlgorithm(left), mergeSortAlgorithm(right));
}
function merge(left: number[], right: number[]): number[] {
let resultArray = [], leftIndex = 0, rightIndex = 0;
while (leftIndex < left.length && rightIndex < right.length) {
if (left[leftIndex] < right[rightIndex]) {
resultArray.push(left[leftIndex]);
leftIndex++;
} else {
resultArray.push(right[rightIndex]);
rightIndex++;
}
}
return resultArray
.concat(left.slice(leftIndex))
.concat(right.slice(rightIndex));
}`,
`function mergeSortAlgorithm(array) {
if (array.length <= 1) {
return array;
}
const mid = Math.floor(array.length / 2);
const left = array.slice(0, mid);
const right = array.slice(mid);
return merge(mergeSortAlgorithm(left), mergeSortAlgorithm(right));
}
function merge(left, right) {
let resultArray = [], leftIndex = 0, rightIndex = 0;
while (leftIndex < left.length && rightIndex < right.length) {
if (left[leftIndex] < right[rightIndex]) {
resultArray.push(left[leftIndex]);
leftIndex++;
} else {
resultArray.push(right[rightIndex]);
rightIndex++;
}
}
return resultArray
.concat(left.slice(leftIndex))
.concat(right.slice(rightIndex));
}
`,
];
async function* generateLines(lines: string[]): AsyncGenerator<string> {
for (const line of lines) {
yield line;
}
}
describe.skip("streamDiff", () => {
for (let i = 0; i < oldCode.length; i++) {
test(`outputs valid diff #${i}`, async () => {
const oldLines = oldCode[i].split("\n");
const newLines = newCode[i].split("\n");
const diff = [];
for await (const diffLine of streamDiff(
oldLines,
generateLines(newLines),
)) {
diff.push(diffLine);
}
console.log(
diff
.map((dl) => {
return (
(dl.type === "old" ? "- " : dl.type === "new" ? "+ " : " ") +
dl.line
);
})
.join("\n"),
);
const numSame = diff.filter((dl) => dl.type === "same").length;
const numOld = diff.filter((dl) => dl.type === "old").length;
const numNew = diff.filter((dl) => dl.type === "new").length;
// Check that every line is represented
expect(oldLines.length).toEqual(numOld + numSame);
expect(newLines.length).toEqual(numNew + numSame);
// Check that there are no red lines immediately following green (they should always be above)
for (let i = 1; i < diff.length; i++) {
if (diff[i].type === "old" && diff[i - 1].type === "new") {
throw new Error(
`Found red '${diff[i].line}' immediately after green line '${
diff[i - 1].line
}`,
);
}
}
});
}
});