-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
37 lines (32 loc) · 1.54 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import assert from 'node:assert/strict'
import test from 'node:test'
import {longestStreak} from './index.js'
test('longestStreak(value, substring)', function () {
// @ts-expect-error Incorrect `value`.
assert.equal(longestStreak(true, 't'), 1, 'should coerce to string')
assert.throws(
function () {
// @ts-expect-error Incorrect `substring`.
longestStreak('', 0)
},
/Expected substring/,
'should throw when substring is invalid (non-string)'
)
assert.equal(longestStreak('', 'f'), 0, 'should work (1)')
assert.equal(longestStreak('foo', 'o'), 2, 'should work (2)')
assert.equal(longestStreak('fo foo fo', 'o'), 2, 'should work (3)')
assert.equal(longestStreak('fo foo foo', 'o'), 2, 'should work (4)')
assert.equal(longestStreak('fo fooo fo', 'o'), 3, 'should work (5)')
assert.equal(longestStreak('fo fooo foo', 'o'), 3, 'should work (6)')
assert.equal(longestStreak('ooo', 'o'), 3, 'should work (7)')
assert.equal(longestStreak('fo fooo fooooo', 'o'), 5, 'should work (8)')
assert.equal(longestStreak('fo fooooo fooo', 'o'), 5, 'should work (9)')
assert.equal(longestStreak('fo fooooo fooooo', 'o'), 5, 'should work (10)')
assert.equal(longestStreak("'`'", '`'), 1, 'should match on one')
assert.equal(longestStreak('👨👩👧👦👨👩👧👦', '👨👩👧👦'), 2, 'should match complex emoji (1)')
assert.equal(
longestStreak('👨👩👧👦a👨👩👧👦', '👨👩👧👦'),
1,
'should match complex emoji (2)'
)
})