2020-03-29 13:43:52 +00:00
|
|
|
import { expect } from 'chai';
|
|
|
|
|
2020-03-31 13:29:47 +00:00
|
|
|
import { leftPad, trim } from '../../src/String';
|
2020-03-29 13:43:52 +00:00
|
|
|
|
|
|
|
const TEST_SHORT = 'hello';
|
|
|
|
const TEST_LONG = 'hello world';
|
|
|
|
|
2020-06-30 13:14:30 +00:00
|
|
|
describe('left pad helper', async () => {
|
|
|
|
it('should prepend padding', async () => {
|
2020-03-29 13:43:52 +00:00
|
|
|
expect(leftPad('test')).to.equal('0000test');
|
|
|
|
});
|
|
|
|
|
2020-06-30 13:14:30 +00:00
|
|
|
it('should return long strings as-is', async () => {
|
2020-03-29 13:43:52 +00:00
|
|
|
const long = 'testing-words';
|
|
|
|
expect(leftPad(long, 8)).to.equal(long);
|
|
|
|
});
|
|
|
|
|
2020-06-30 13:14:30 +00:00
|
|
|
it('should use padding string', async () => {
|
2020-03-29 13:43:52 +00:00
|
|
|
expect(leftPad('test', 8, 'too')).to.equal('toottest', 'must repeat and truncate the padding string');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-06-30 13:14:30 +00:00
|
|
|
describe('trim helper', async () => {
|
|
|
|
it('should return strings shorter than max', async () => {
|
2020-03-29 13:43:52 +00:00
|
|
|
expect(trim('yes', 5)).to.equal('yes', 'shorter than max');
|
|
|
|
expect(trim(TEST_SHORT, 5)).to.equal(TEST_SHORT, 'equal to max');
|
|
|
|
});
|
|
|
|
|
2020-06-30 13:14:30 +00:00
|
|
|
it('should trim strings longer than max', async () => {
|
2020-03-29 13:43:52 +00:00
|
|
|
expect(trim(TEST_LONG, 3, '...')).to.equal('...');
|
|
|
|
expect(trim(TEST_LONG, 5)).to.equal('he...');
|
|
|
|
expect(trim(TEST_LONG, 8)).to.equal('hello...');
|
|
|
|
});
|
|
|
|
|
2020-06-30 13:14:30 +00:00
|
|
|
it('should not add tail when max is small', async () => {
|
2020-03-29 13:43:52 +00:00
|
|
|
expect(trim(TEST_SHORT, 2, '...')).to.equal('he');
|
|
|
|
expect(trim(TEST_LONG, 5, 'very long tail')).to.equal(TEST_SHORT);
|
|
|
|
expect(trim(TEST_SHORT, 8, 'very long tail')).to.equal(TEST_SHORT);
|
|
|
|
});
|
|
|
|
});
|