2018-06-22 16:35:24 +00:00
|
|
|
const tap = require('tap')
|
2018-07-10 17:51:32 +00:00
|
|
|
const calcWidth = require('../lib/calc-text-width.js').Verdana11
|
2018-06-22 16:35:24 +00:00
|
|
|
|
2018-07-18 06:11:11 +00:00
|
|
|
tap.test('basic functions', t => {
|
2018-07-11 05:36:30 +00:00
|
|
|
t.ok(typeof calcWidth === 'function', 'export calcWidth function')
|
2018-07-18 06:11:11 +00:00
|
|
|
t.ok(Number.isFinite(calcWidth('')), 'result is a number')
|
|
|
|
t.ok(calcWidth('') === 0, 'return 0 for empty string')
|
|
|
|
t.end()
|
|
|
|
})
|
|
|
|
|
|
|
|
tap.test('calc width for "npm"', t => {
|
2018-07-11 05:36:30 +00:00
|
|
|
t.is(calcWidth('npm'), 24.9, 'result is correct value')
|
2018-06-22 16:35:24 +00:00
|
|
|
t.end()
|
|
|
|
})
|
2018-07-18 05:59:40 +00:00
|
|
|
|
2018-07-18 06:11:11 +00:00
|
|
|
tap.test('calc width for unicode', t => {
|
2018-07-19 05:00:57 +00:00
|
|
|
t.is(calcWidth('壹佰贰拾叁'), 56, 'result is correct value')
|
2018-07-18 06:11:11 +00:00
|
|
|
t.end()
|
|
|
|
})
|
|
|
|
|
2018-07-18 05:59:40 +00:00
|
|
|
tap.test('exception handling', t => {
|
|
|
|
t.throws(() => calcWidth(0), TypeError, 'throw if feed with non-string input')
|
|
|
|
t.end()
|
|
|
|
})
|