Skip to content
Open
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
14 changes: 12 additions & 2 deletions packages/widgets/src/display/Code.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// @termuijs/widgets — Tests for Code widget
// ─────────────────────────────────────────────────────

import { describe, it, expect } from 'vitest';
import { Screen } from '@termuijs/core';
import { describe, it, expect, vi } from 'vitest';
import { Screen, caps } from '@termuijs/core';
import { Code } from './Code.js';

describe('Code', () => {
Expand Down Expand Up @@ -73,4 +73,14 @@ describe('Code', () => {
expect(screen.back[0][3].char).toBe('t');
expect(screen.back[0][4].char).toBe('╮'); // topRight corner (width-1 index)
});

it('uses ASCII pipe for gutter separator when caps.unicode is false', () => {
vi.spyOn(caps, 'unicode', 'get').mockReturnValue(false);
const code = new Code('hello');
code.updateRect({ x: 0, y: 0, width: 12, height: 4 });
const screen = new Screen(12, 4);
code.render(screen);
// Gutter separator should be '|' in ASCII mode, not '\u2502'
expect(screen.back[1][2].char).toBe('|');
});
Comment on lines +77 to +85

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

rg -n -C 4 'unicode\s*:' packages/core/src/terminal/env-caps.ts
rg -n -C 3 "spyOn\(caps, 'unicode', 'get'\)" packages/widgets/src/display/Code.test.ts

Repository: Karanjot786/TermUI

Length of output: 982


🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

printf '--- env-caps.ts ---\n'
sed -n '1,120p' packages/core/src/terminal/env-caps.ts
printf '\n--- Code.test.ts relevant section ---\n'
sed -n '1,130p' packages/widgets/src/display/Code.test.ts
printf '\n--- descriptor probe (repository code not executed) ---\n'
node <<'JS'
const obj = { unicode: true };
const descriptor = Object.getOwnPropertyDescriptor(obj, 'unicode') || Object.getPrototypeOf(obj).unicode || {};
try {
  Object.getOwnPropertyDescriptor(obj, 'unicode');
} catch (e) {
  console.log('descriptorError', e && e.message);
}
console.log(JSON.stringify(descriptor, null, 2));
JS

Repository: Karanjot786/TermUI

Length of output: 247


🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

printf '%s\n' '--- env-caps.ts ---'
sed -n '1,120p' packages/core/src/terminal/env-caps.ts
printf '%s\n' ''
printf '%s\n' '--- Code.test.ts relevant section ---'
sed -n '1,130p' packages/widgets/src/display/Code.test.ts
printf '%s\n' ''
printf '%s\n' '--- descriptor probe ---'
node <<'JS'
const obj = { unicode: true };
const descriptor = Object.getOwnPropertyDescriptor(obj, 'unicode');
console.log(JSON.stringify(descriptor, null, 2));
JS

Repository: Karanjot786/TermUI

Length of output: 7173


Fix the caps.unicode mock used for the ASCII-gutter test.

caps.unicode is a writable data property, not a static getter, so the vi.spyOn(caps, 'unicode', 'get') overload does not correctly replace the value Vitest expects for this accessor signature. Use a scoped Object.defineProperty override instead and restore the original value in finally.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/widgets/src/display/Code.test.ts` around lines 77 - 85, Update the
ASCII-gutter test to override the writable caps.unicode property with a scoped
Object.defineProperty call, preserving its original descriptor or value and
restoring it in a finally block around the test logic; remove the vi.spyOn
getter usage while keeping the existing Code rendering assertion unchanged.

Source: Learnings

});
2 changes: 1 addition & 1 deletion packages/widgets/src/display/Code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export class Code extends Widget {
screen.writeString(x, y, lineNum, { dim: true });
x += lineNumWidth;

screen.setCell(x, y, { char: '│', dim: true });
screen.setCell(x, y, { char: caps.unicode ? '│' : '|', dim: true });

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Make the existing gutter test capability-independent.

This branch correctly renders | when caps.unicode is false. However, packages/widgets/src/display/Code.test.ts, Line 27 still requires . The test suite fails when TERM=dumb or NO_UNICODE disables Unicode support.

Update that assertion to accept the selected separator, or force Unicode explicitly for that test.

Suggested test adjustment
-        expect(screen.back[1][2].char).toBe('\u2502');
+        expect(screen.back[1][2].char).toBe(caps.unicode ? '\u2502' : '|');
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/widgets/src/display/Code.ts` at line 52, Update the gutter assertion
in Code.test.ts to match the separator selected by the display capability,
accepting either the Unicode or ASCII character, or explicitly enable Unicode
within that test before asserting. Keep the existing Code rendering behavior
unchanged.

x++;

screen.setCell(x, y, { char: ' ' });
Expand Down
Loading