Skip to content

Commit 2f768b4

Browse files
committed
test: strengthen assertions after review
- Use deepEqual for shape verification on first two measureText tests - Add value assertions to cache test before identity check - Add 256-color ANSI escape sequence test - Add lines.length assertions in multiline text-width tests - Remove redundant single-character test and restating comments
1 parent 127344c commit 2f768b4

2 files changed

Lines changed: 12 additions & 15 deletions

File tree

test/measure-text.tsx

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,11 @@ import test from 'ava';
22
import measureText from '../src/measure-text.js';
33

44
test('measure single word', t => {
5-
const result = measureText('constructor');
6-
t.is(result.width, 11);
7-
t.is(result.height, 1);
5+
t.deepEqual(measureText('constructor'), {width: 11, height: 1});
86
});
97

108
test('measure empty string', t => {
11-
const result = measureText('');
12-
t.is(result.width, 0);
13-
t.is(result.height, 0);
14-
});
15-
16-
test('measure single character', t => {
17-
const result = measureText('x');
18-
t.is(result.width, 1);
19-
t.is(result.height, 1);
9+
t.deepEqual(measureText(''), {width: 0, height: 0});
2010
});
2111

2212
test('measure multiline text', t => {
@@ -45,19 +35,25 @@ test('measure text with only newlines', t => {
4535

4636
test('returns cached result on repeated calls', t => {
4737
const first = measureText('cached-test');
38+
t.is(first.width, 11);
39+
t.is(first.height, 1);
4840
const second = measureText('cached-test');
4941
t.is(first, second);
5042
});
5143

5244
test('measure text with ANSI escape sequences', t => {
53-
// ANSI codes should not count toward width
5445
const result = measureText('\u001B[31mred\u001B[0m');
5546
t.is(result.width, 3);
5647
t.is(result.height, 1);
5748
});
5849

50+
test('measure text with 256-color ANSI', t => {
51+
const result = measureText('\u001B[38;5;196mred\u001B[0m');
52+
t.is(result.width, 3);
53+
t.is(result.height, 1);
54+
});
55+
5956
test('measure text with wide characters', t => {
60-
// CJK characters are 2 columns wide
6157
const result = measureText('你好');
6258
t.is(result.width, 4);
6359
t.is(result.height, 1);

test/text-width.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ test('wide characters do not add extra space inside fixed-width Box', t => {
2323
);
2424

2525
const lines = output.split('\n');
26-
// Both lines should have the pipe directly after the 2-column box
26+
t.is(lines.length, 2);
2727
t.is(lines[0], '🍔|');
2828
t.is(lines[1], '⏳|');
2929
});
@@ -60,6 +60,7 @@ test('mixed ASCII and wide characters align correctly', t => {
6060
);
6161

6262
const lines = output.split('\n');
63+
t.is(lines.length, 2);
6364
t.is(lines[0], 'ab🍔cd|');
6465
t.is(lines[1], 'abcdef|');
6566
});

0 commit comments

Comments
 (0)