1
0
mirror of https://github.com/benjlevesque/short-sha.git synced 2026-03-09 13:54:52 +01:00

short-sha

This commit is contained in:
Benjamin LEVESQUE
2020-03-09 21:40:47 +01:00
parent 6e8dcce3fd
commit 9f96a4f558
13 changed files with 29878 additions and 6881 deletions

39
__tests__/shorten.test.ts Normal file
View File

@@ -0,0 +1,39 @@
import {shorten} from '../src/shorten'
test('normal case', () => {
expect(shorten('6e8dcce3fd71cfe9aca3e18c82255dd1e4052aa1', 7)).toBe('6e8dcce')
})
test('already short', () => {
expect(shorten('6e8dcce', 7)).toBe('6e8dcce')
})
test('too short', () => {
expect(() => shorten('6e8dcc', 7)).toThrowError('input is too short')
})
test('undefined', () => {
expect(() => shorten(undefined as any, 7)).toThrowError('sha must be defined')
})
test('null', () => {
expect(() => shorten(null as any, 7)).toThrowError('sha must be defined')
})
test('invalid length', () => {
expect(() =>
shorten('6e8dcce3fd71cfe9aca3e18c82255dd1e4052aa1', 'x' as any)
).toThrowError('length is invalid')
})
test('negative length', () => {
expect(() =>
shorten('6e8dcce3fd71cfe9aca3e18c82255dd1e4052aa1', -1)
).toThrowError('length is invalid')
})
test('zero length', () => {
expect(() =>
shorten('6e8dcce3fd71cfe9aca3e18c82255dd1e4052aa1', 0)
).toThrowError('length is invalid')
})