11cb0ef41Sopenharmony_ci"use strict" 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_civar wcwidth = require('../') 41cb0ef41Sopenharmony_civar test = require('tape') 51cb0ef41Sopenharmony_ci 61cb0ef41Sopenharmony_citest('handles regular strings', function(t) { 71cb0ef41Sopenharmony_ci t.strictEqual(wcwidth('abc'), 3) 81cb0ef41Sopenharmony_ci t.end() 91cb0ef41Sopenharmony_ci}) 101cb0ef41Sopenharmony_ci 111cb0ef41Sopenharmony_citest('handles multibyte strings', function(t) { 121cb0ef41Sopenharmony_ci t.strictEqual(wcwidth('字的模块'), 8) 131cb0ef41Sopenharmony_ci t.end() 141cb0ef41Sopenharmony_ci}) 151cb0ef41Sopenharmony_ci 161cb0ef41Sopenharmony_citest('handles multibyte characters mixed with regular characters', function(t) { 171cb0ef41Sopenharmony_ci t.strictEqual(wcwidth('abc 字的模块'), 12) 181cb0ef41Sopenharmony_ci t.end() 191cb0ef41Sopenharmony_ci}) 201cb0ef41Sopenharmony_ci 211cb0ef41Sopenharmony_citest('ignores control characters e.g. \\n', function(t) { 221cb0ef41Sopenharmony_ci t.strictEqual(wcwidth('abc\n字的模块\ndef'), 14) 231cb0ef41Sopenharmony_ci t.end() 241cb0ef41Sopenharmony_ci}) 251cb0ef41Sopenharmony_ci 261cb0ef41Sopenharmony_citest('ignores bad input', function(t) { 271cb0ef41Sopenharmony_ci t.strictEqual(wcwidth(''), 0) 281cb0ef41Sopenharmony_ci t.strictEqual(wcwidth(3), 0) 291cb0ef41Sopenharmony_ci t.strictEqual(wcwidth({}), 0) 301cb0ef41Sopenharmony_ci t.strictEqual(wcwidth([]), 0) 311cb0ef41Sopenharmony_ci t.strictEqual(wcwidth(), 0) 321cb0ef41Sopenharmony_ci t.end() 331cb0ef41Sopenharmony_ci}) 341cb0ef41Sopenharmony_ci 351cb0ef41Sopenharmony_citest('ignores nul (charcode 0)', function(t) { 361cb0ef41Sopenharmony_ci t.strictEqual(wcwidth(String.fromCharCode(0)), 0) 371cb0ef41Sopenharmony_ci t.end() 381cb0ef41Sopenharmony_ci}) 391cb0ef41Sopenharmony_ci 401cb0ef41Sopenharmony_citest('ignores nul mixed with chars', function(t) { 411cb0ef41Sopenharmony_ci t.strictEqual(wcwidth('a' + String.fromCharCode(0) + '\n字的'), 5) 421cb0ef41Sopenharmony_ci t.end() 431cb0ef41Sopenharmony_ci}) 441cb0ef41Sopenharmony_ci 451cb0ef41Sopenharmony_citest('can have custom value for nul', function(t) { 461cb0ef41Sopenharmony_ci t.strictEqual(wcwidth.config({ 471cb0ef41Sopenharmony_ci nul: 10 481cb0ef41Sopenharmony_ci })(String.fromCharCode(0) + 'a字的'), 15) 491cb0ef41Sopenharmony_ci t.end() 501cb0ef41Sopenharmony_ci}) 511cb0ef41Sopenharmony_ci 521cb0ef41Sopenharmony_citest('can have custom control char value', function(t) { 531cb0ef41Sopenharmony_ci t.strictEqual(wcwidth.config({ 541cb0ef41Sopenharmony_ci control: 1 551cb0ef41Sopenharmony_ci })('abc\n字的模块\ndef'), 16) 561cb0ef41Sopenharmony_ci t.end() 571cb0ef41Sopenharmony_ci}) 581cb0ef41Sopenharmony_ci 591cb0ef41Sopenharmony_citest('negative custom control chars == -1', function(t) { 601cb0ef41Sopenharmony_ci t.strictEqual(wcwidth.config({ 611cb0ef41Sopenharmony_ci control: -1 621cb0ef41Sopenharmony_ci })('abc\n字的模块\ndef'), -1) 631cb0ef41Sopenharmony_ci t.end() 641cb0ef41Sopenharmony_ci}) 65