From 43cb92bd61c5ece9becdf5f65aef5ba3bdc4cbe8 Mon Sep 17 00:00:00 2001 From: Nolan Lawson Date: Tue, 20 Aug 2019 09:20:39 -0700 Subject: [PATCH] test: add test for measureText (#1416) --- tests/unit/test-measure-text.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 tests/unit/test-measure-text.js diff --git a/tests/unit/test-measure-text.js b/tests/unit/test-measure-text.js new file mode 100644 index 00000000..3cdc5422 --- /dev/null +++ b/tests/unit/test-measure-text.js @@ -0,0 +1,27 @@ +/* global describe, it */ + +import assert from 'assert' +import { measureText } from '../../src/routes/_utils/measureText' + +describe('test-measure-text.js', () => { + it('measures text correctly', () => { + assert.deepStrictEqual(measureText(undefined), 0) + assert.deepStrictEqual(measureText(''), 0) + assert.deepStrictEqual(measureText('foo'), 3) + assert.deepStrictEqual(measureText('\ud83c\udf4d\ud83c\udf4d'), 2) + assert.deepStrictEqual(measureText('hello world http://example.com/super/long/url/that/should/be/shortened'), 70) + assert.deepStrictEqual(measureText(' @fooooooooooooooooooooooooooooooooooooooooooooooo@example.com '), 51) + assert.deepStrictEqual(measureText(' @fooooooooooooooooooooooooooooooooooooooooooooooooooo@example.com '), 55) + assert.deepStrictEqual(measureText(' @fooooooooooooooooooooooooooooooooooooooooooooooo@exaaaaaample.com '), 51) + assert.deepStrictEqual(measureText( + 'hello world http://example.com/super/long/url/that/should/be/shortened and ' + + 'another url http://example.com/super/long/url/that/should/be/shortened/too'), + 149) + assert.deepStrictEqual(measureText( + 'hello world http://example.com/super/long/url/that/should/be/shortened and ' + + 'another url http://example.com/super/long/url/that/should/be/shortened/too and' + + 'also a handle @foooooooooooooooooooooooooooooooo@example.com @baaaar@exaaaaaaaaaaample.com and ' + + '@foooooooooooooooooooooooooo@example.com'), + 242) + }) +})