Skip to content

Commit 20ee139

Browse files
committed
feat(power-assert-formatter): treat ambiguous east asian character as fullwidth (= 2)
1 parent 7e8c932 commit 20ee139

File tree

3 files changed

+48
-1
lines changed

3 files changed

+48
-1
lines changed

lib/default-options.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ module.exports = function defaultOptions () {
77
anonymous: 'Object',
88
circular: '#@Circular#',
99
lineSeparator: '\n',
10-
ambiguousEastAsianCharWidth: 1,
10+
ambiguousEastAsianCharWidth: 2,
1111
renderers: [
1212
'./built-in/file',
1313
'./built-in/assertion',

test/power_assert_formatter_test.js

+29
Original file line numberDiff line numberDiff line change
@@ -844,7 +844,36 @@ suite('power-assert-formatter', function () {
844844
' false ',
845845
' '
846846
]);
847+
});
848+
847849

850+
test('Ambiguous EastAsianWidth', function () {
851+
var suffix1 = '…',
852+
suffix2 = '☆';
853+
assertPowerAssertContextFormatting(function () {
854+
eval(weave('assert("※ただしイケメンに限る" + suffix1 === "○ただしイケメンに限る" + suffix2);'));
855+
}, [
856+
' # /path/to/some_test.js:1',
857+
' ',
858+
' assert("※ただしイケメンに限る" + suffix1 === "○ただしイケメンに限る" + suffix2)',
859+
' | | | | | ',
860+
' | | | | "☆" ',
861+
' | "…" false "○ただしイケメンに限る☆"',
862+
' "※ただしイケメンに限る…" ',
863+
' ',
864+
' --- [string] "○ただしイケメンに限る" + suffix2',
865+
' +++ [string] "※ただしイケメンに限る" + suffix1',
866+
' @@ -1,5 +1,5 @@',
867+
' -○',
868+
' +※',
869+
' ただしイ',
870+
' @@ -8,5 +8,5 @@',
871+
' ンに限る',
872+
' -☆',
873+
' +…',
874+
' ',
875+
' '
876+
]);
848877
});
849878

850879

test/string_width_test.js

+18
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,22 @@
4444
assert.equal(stringWidth(strWithSurrogatePair), 10);
4545
});
4646
});
47+
48+
suite('ambiguous EastAsianWidth', function () {
49+
setup(function () {
50+
this.strWithAmbiguousEastAsian = '※ただしイケメンに限る';
51+
});
52+
test('when set to 1', function () {
53+
var widthOf = formatter.stringWidth({
54+
ambiguousEastAsianCharWidth: 1
55+
});
56+
assert.equal(widthOf(this.strWithAmbiguousEastAsian), 21);
57+
});
58+
test('when set to 2', function () {
59+
var widthOf = formatter.stringWidth({
60+
ambiguousEastAsianCharWidth: 2
61+
});
62+
assert.equal(widthOf(this.strWithAmbiguousEastAsian), 22);
63+
});
64+
});
4765
}));

0 commit comments

Comments
 (0)