1 | (function (root, factory) {
|
2 | 'use strict';
|
3 | if (typeof define === 'function' && define.amd) {
|
4 | define(['power-assert-formatter', 'assert'], factory);
|
5 | } else if (typeof exports === 'object') {
|
6 | factory(require('..'), require('assert'));
|
7 | } else {
|
8 | factory(root.powerAssertFormatter, root.assert);
|
9 | }
|
10 | }(this, function (
|
11 | formatter,
|
12 | assert
|
13 | ) {
|
14 | var stringWidth = formatter.stringWidth();
|
15 |
|
16 | suite('string width', function () {
|
17 | [
|
18 | ['abcde', 5],
|
19 | ['あいうえお', 10],
|
20 | ['アイウエオ', 5]
|
21 | ].forEach(function(col, idx) {
|
22 | var input = col[0], expected = col[1];
|
23 | test(idx + ': ' + input, function () {
|
24 | assert.equal(stringWidth(input), expected);
|
25 | });
|
26 | });
|
27 |
|
28 | suite('unicode normalization', function () {
|
29 | test('composition', function () {
|
30 | var str = 'が';
|
31 | assert.equal(str.length, 1);
|
32 | assert.equal(stringWidth(str), 2);
|
33 | });
|
34 | test('decomposition', function () {
|
35 | var str = 'か\u3099';
|
36 | assert.equal(str.length, 2);
|
37 | assert.equal(stringWidth(str), 4);
|
38 | });
|
39 | });
|
40 |
|
41 | test('surrogate pair', function () {
|
42 | var strWithSurrogatePair = "𠮷野家で𩸽";
|
43 | assert.equal(strWithSurrogatePair.length, 7);
|
44 | assert.equal(stringWidth(strWithSurrogatePair), 10);
|
45 | });
|
46 | });
|
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 | });
|
65 | }));
|