mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-24 16:09:30 +00:00
refactor(diffs): drop unused language hint filter
This commit is contained in:
@@ -2,13 +2,17 @@
|
||||
import type { FileDiffMetadata } from "@pierre/diffs";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import {
|
||||
filterSupportedLanguageHints,
|
||||
normalizeDiffViewerPayloadLanguages,
|
||||
normalizeSupportedLanguageHint,
|
||||
} from "./language-hints.js";
|
||||
|
||||
describe("filterSupportedLanguageHints", () => {
|
||||
async function normalizeHints(values: readonly string[], options = {}) {
|
||||
return await Promise.all(values.map((value) => normalizeSupportedLanguageHint(value, options)));
|
||||
}
|
||||
|
||||
describe("normalizeSupportedLanguageHint", () => {
|
||||
it("keeps supported languages", async () => {
|
||||
await expect(filterSupportedLanguageHints(["typescript", "cpp", "text"])).resolves.toEqual([
|
||||
await expect(normalizeHints(["typescript", "cpp", "text"])).resolves.toEqual([
|
||||
"typescript",
|
||||
"cpp",
|
||||
"text",
|
||||
@@ -17,7 +21,7 @@ describe("filterSupportedLanguageHints", () => {
|
||||
|
||||
it("normalizes common aliases to base viewer languages", async () => {
|
||||
await expect(
|
||||
filterSupportedLanguageHints(["ts", "c++", "c#", "bash", "dockerfile", "rb", "kt", "ps1"]),
|
||||
normalizeHints(["ts", "c++", "c#", "bash", "dockerfile", "rb", "kt", "ps1"]),
|
||||
).resolves.toEqual([
|
||||
"typescript",
|
||||
"cpp",
|
||||
@@ -32,7 +36,7 @@ describe("filterSupportedLanguageHints", () => {
|
||||
|
||||
it("keeps mainstream languages in the base viewer without the language pack", async () => {
|
||||
await expect(
|
||||
filterSupportedLanguageHints([
|
||||
normalizeHints([
|
||||
"ruby",
|
||||
"swift",
|
||||
"kotlin",
|
||||
@@ -57,23 +61,24 @@ describe("filterSupportedLanguageHints", () => {
|
||||
});
|
||||
|
||||
it("drops uncommon languages without the language pack", async () => {
|
||||
await expect(filterSupportedLanguageHints(["abap"])).resolves.toEqual(["text"]);
|
||||
await expect(normalizeSupportedLanguageHint("abap")).resolves.toBeUndefined();
|
||||
});
|
||||
|
||||
it("keeps uncommon languages when the language pack is available", async () => {
|
||||
await expect(
|
||||
filterSupportedLanguageHints(["abap"], { languagePackAvailable: true }),
|
||||
).resolves.toEqual(["abap"]);
|
||||
normalizeSupportedLanguageHint("abap", { languagePackAvailable: true }),
|
||||
).resolves.toBe("abap");
|
||||
});
|
||||
|
||||
it("drops invalid languages and falls back to text", async () => {
|
||||
await expect(filterSupportedLanguageHints(["not-a-real-language"])).resolves.toEqual(["text"]);
|
||||
it("drops invalid languages", async () => {
|
||||
await expect(normalizeSupportedLanguageHint("not-a-real-language")).resolves.toBeUndefined();
|
||||
});
|
||||
|
||||
it("keeps valid languages when invalid hints are mixed in", async () => {
|
||||
await expect(
|
||||
filterSupportedLanguageHints(["typescript", "not-a-real-language"]),
|
||||
).resolves.toEqual(["typescript"]);
|
||||
await expect(normalizeHints(["typescript", "not-a-real-language"])).resolves.toEqual([
|
||||
"typescript",
|
||||
undefined,
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -57,13 +57,6 @@ export async function normalizeSupportedLanguageHint(
|
||||
}
|
||||
}
|
||||
|
||||
export async function filterSupportedLanguageHints(
|
||||
values: Iterable<string>,
|
||||
options: { languagePackAvailable?: boolean } = {},
|
||||
): Promise<SupportedLanguages[]> {
|
||||
return normalizeSupportedLanguageHints(values, { fallbackToText: true, ...options });
|
||||
}
|
||||
|
||||
async function normalizeSupportedLanguageHints(
|
||||
values: Iterable<string>,
|
||||
options: { fallbackToText: boolean; languagePackAvailable?: boolean },
|
||||
|
||||
Reference in New Issue
Block a user