Refactor installation process and enhance configuration management; add locale detection and autostart support
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
import { test } from "node:test";
|
||||
import assert from "node:assert";
|
||||
import { mkdtempSync, writeFileSync } from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { detectKeyboardLayout, detectLang } from "../src/locale.js";
|
||||
|
||||
function withFakeLocalectl(output: string, fn: () => void) {
|
||||
const dir = mkdtempSync(join(tmpdir(), "fake-localectl-"));
|
||||
writeFileSync(join(dir, "localectl"), `#!/bin/sh\ncat <<'EOF'\n${output}\nEOF\n`, { mode: 0o755 });
|
||||
const originalPath = process.env.PATH;
|
||||
process.env.PATH = `${dir}:${originalPath}`;
|
||||
try {
|
||||
fn();
|
||||
} finally {
|
||||
process.env.PATH = originalPath;
|
||||
}
|
||||
}
|
||||
|
||||
test("detectKeyboardLayout reads the X11 Layout line", () => {
|
||||
withFakeLocalectl(
|
||||
` System Locale: LANG=de_DE.UTF-8
|
||||
VC Keymap: de-latin1
|
||||
X11 Layout: de
|
||||
X11 Model: pc105`,
|
||||
() => {
|
||||
assert.strictEqual(detectKeyboardLayout(), "de");
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
test("detectKeyboardLayout falls back to 'us' when localectl has no X11 Layout line", () => {
|
||||
withFakeLocalectl(` System Locale: LANG=en_US.UTF-8\n VC Keymap: us`, () => {
|
||||
assert.strictEqual(detectKeyboardLayout(), "us");
|
||||
});
|
||||
});
|
||||
|
||||
test("detectKeyboardLayout falls back to 'us' when localectl is missing entirely", () => {
|
||||
const originalPath = process.env.PATH;
|
||||
process.env.PATH = "/nonexistent";
|
||||
try {
|
||||
assert.strictEqual(detectKeyboardLayout(), "us");
|
||||
} finally {
|
||||
process.env.PATH = originalPath;
|
||||
}
|
||||
});
|
||||
|
||||
test("detectLang reads $LANG", () => {
|
||||
const original = process.env.LANG;
|
||||
process.env.LANG = "de_DE.UTF-8";
|
||||
try {
|
||||
assert.strictEqual(detectLang(), "de_DE.UTF-8");
|
||||
} finally {
|
||||
if (original === undefined) delete process.env.LANG;
|
||||
else process.env.LANG = original;
|
||||
}
|
||||
});
|
||||
|
||||
test("detectLang returns null when $LANG is unset", () => {
|
||||
const original = process.env.LANG;
|
||||
delete process.env.LANG;
|
||||
try {
|
||||
assert.strictEqual(detectLang(), null);
|
||||
} finally {
|
||||
if (original !== undefined) process.env.LANG = original;
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user