Skip to content

Commit 64a7a65

Browse files
lholmquistTrott
authored andcommitted
test: add tests for padding util functions (#75)
* This adds tests for both the rightPad and leftPad utility function.
1 parent 479fe81 commit 64a7a65

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

test/utils-test.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
'use strict'
2+
3+
const { test } = require('tap')
4+
const utils = require('../lib/utils')
5+
6+
test('test utility functions', (t) => {
7+
t.test('test rightPad function - with padding', (tt) => {
8+
const padded = utils.rightPad('string', 10)
9+
tt.equal(padded.length, 11, 'should have extra padding')
10+
tt.equal(padded, 'string ', 'should have padding on the right')
11+
12+
tt.end()
13+
})
14+
15+
t.test('test rightPad function - withou padding', (tt) => {
16+
const padded = utils.rightPad('string', 5)
17+
tt.equal(padded.length, 6, 'should have the same length')
18+
tt.equal(padded, 'string', 'should have no padding on the right')
19+
20+
tt.end()
21+
})
22+
23+
t.test('test leftPad function - with padding', (tt) => {
24+
const padded = utils.leftPad('string', 10)
25+
tt.equal(padded.length, 11, 'should have extra padding')
26+
tt.equal(padded, ' string', 'should have padding on the left')
27+
28+
tt.end()
29+
})
30+
31+
t.test('test leftPad function - withou padding', (tt) => {
32+
const padded = utils.leftPad('string', 5)
33+
tt.equal(padded.length, 6, 'should have the same length')
34+
tt.equal(padded, 'string', 'should have no padding on the left')
35+
36+
tt.end()
37+
})
38+
39+
t.end()
40+
})

0 commit comments

Comments
 (0)