source: trip-planner-front/node_modules/wcwidth/test/index.js@ fa375fe

Last change on this file since fa375fe was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.4 KB
Line 
1"use strict"
2
3var wcwidth = require('../')
4var test = require('tape')
5
6test('handles regular strings', function(t) {
7 t.strictEqual(wcwidth('abc'), 3)
8 t.end()
9})
10
11test('handles multibyte strings', function(t) {
12 t.strictEqual(wcwidth('字的模块'), 8)
13 t.end()
14})
15
16test('handles multibyte characters mixed with regular characters', function(t) {
17 t.strictEqual(wcwidth('abc 字的模块'), 12)
18 t.end()
19})
20
21test('ignores control characters e.g. \\n', function(t) {
22 t.strictEqual(wcwidth('abc\n字的模块\ndef'), 14)
23 t.end()
24})
25
26test('ignores bad input', function(t) {
27 t.strictEqual(wcwidth(''), 0)
28 t.strictEqual(wcwidth(3), 0)
29 t.strictEqual(wcwidth({}), 0)
30 t.strictEqual(wcwidth([]), 0)
31 t.strictEqual(wcwidth(), 0)
32 t.end()
33})
34
35test('ignores nul (charcode 0)', function(t) {
36 t.strictEqual(wcwidth(String.fromCharCode(0)), 0)
37 t.end()
38})
39
40test('ignores nul mixed with chars', function(t) {
41 t.strictEqual(wcwidth('a' + String.fromCharCode(0) + '\n字的'), 5)
42 t.end()
43})
44
45test('can have custom value for nul', function(t) {
46 t.strictEqual(wcwidth.config({
47 nul: 10
48 })(String.fromCharCode(0) + 'a字的'), 15)
49 t.end()
50})
51
52test('can have custom control char value', function(t) {
53 t.strictEqual(wcwidth.config({
54 control: 1
55 })('abc\n字的模块\ndef'), 16)
56 t.end()
57})
58
59test('negative custom control chars == -1', function(t) {
60 t.strictEqual(wcwidth.config({
61 control: -1
62 })('abc\n字的模块\ndef'), -1)
63 t.end()
64})
Note: See TracBrowser for help on using the repository browser.