Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 8 additions & 12 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions src/cli/commands/snapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,7 @@ export const snapshotCreateCommand = new Command('snapshot')
try {
// Load database
const { DatabaseClient } = await import('../../db/client.js');
const versionModule = await import('../../cli/version/comparator.js');
const K0NTEXT_VERSION = versionModule.version;
const { version: K0NTEXT_VERSION } = await import('../../cli/version/comparator.js');
const db = new DatabaseClient(projectRoot);
const manager = new SnapshotManager(db, projectRoot, K0NTEXT_VERSION);

Expand Down
2 changes: 2 additions & 0 deletions src/cli/repl/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
* Interactive shell for managing k0ntext context
*/

import fs from 'fs';

Check failure on line 7 in src/cli/repl/index.ts

View workflow job for this annotation

GitHub Actions / Test (20.x)

Duplicate identifier 'fs'.
import path from 'path';

Check failure on line 8 in src/cli/repl/index.ts

View workflow job for this annotation

GitHub Actions / Test (20.x)

Duplicate identifier 'path'.
import readline from 'readline';
import fs from 'fs';

Check failure on line 10 in src/cli/repl/index.ts

View workflow job for this annotation

GitHub Actions / Test (20.x)

Duplicate identifier 'fs'.
import path from 'path';

Check failure on line 11 in src/cli/repl/index.ts

View workflow job for this annotation

GitHub Actions / Test (20.x)

Duplicate identifier 'path'.
import { REPLSessionManager } from './core/session.js';
import { REPLCommandParser } from './core/parser.js';
import { InitWizard } from './init/wizard.js';
Expand Down
56 changes: 56 additions & 0 deletions tests/utils/encoding.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/**
* Encoding Utility Tests
*
* Tests for UTF-8 BOM handling and other encoding utilities.
*/

import { describe, it, expect } from 'vitest';
import { stripBOM, hasBOM } from '../../src/utils/encoding.js';

describe('Encoding Utilities', () => {
const BOM = '\uFEFF';
const SAMPLE_TEXT = 'Hello, world!';
const TEXT_WITH_BOM = BOM + SAMPLE_TEXT;

describe('stripBOM', () => {
it('should remove BOM from the start of a string', () => {
expect(stripBOM(TEXT_WITH_BOM)).toBe(SAMPLE_TEXT);
});

it('should return the original string if no BOM is present', () => {
expect(stripBOM(SAMPLE_TEXT)).toBe(SAMPLE_TEXT);
});

it('should handle empty strings', () => {
expect(stripBOM('')).toBe('');
});

it('should not remove BOM if it is not at the start', () => {
const textWithMidBOM = 'Hello' + BOM + 'world';
expect(stripBOM(textWithMidBOM)).toBe(textWithMidBOM);
});

it('should only remove one BOM from the start', () => {
const doubleBOM = BOM + BOM + SAMPLE_TEXT;
expect(stripBOM(doubleBOM)).toBe(BOM + SAMPLE_TEXT);
});
});

describe('hasBOM', () => {
it('should return true if BOM is present at the start', () => {
expect(hasBOM(TEXT_WITH_BOM)).toBe(true);
});

it('should return false if no BOM is present', () => {
expect(hasBOM(SAMPLE_TEXT)).toBe(false);
});

it('should return false if BOM is not at the start', () => {
expect(hasBOM('Hello' + BOM)).toBe(false);
});

it('should return false for empty string', () => {
expect(hasBOM('')).toBe(false);
});
});
});
Loading