mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-26 15:15:49 +00:00
xahau-patch
This commit is contained in:
48
packages/xahau-address-codec/test/utils.test.ts
Normal file
48
packages/xahau-address-codec/test/utils.test.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
import { arrayEqual, concatArgs } from '../src/utils'
|
||||
|
||||
describe('Function: arrayEqual', () => {
|
||||
it('two sequences are equal', () => {
|
||||
expect(arrayEqual([1, 2, 3], [1, 2, 3])).toBe(true)
|
||||
})
|
||||
|
||||
it('elements must be in the same order', () => {
|
||||
expect(arrayEqual([3, 2, 1], [1, 2, 3])).toBe(false)
|
||||
})
|
||||
|
||||
it('sequences do not need to be the same type', () => {
|
||||
expect(arrayEqual(Uint8Array.from([1, 2, 3]), [1, 2, 3])).toBe(true)
|
||||
expect(
|
||||
arrayEqual(Uint8Array.from([1, 2, 3]), new Uint8Array([1, 2, 3])),
|
||||
).toBe(true)
|
||||
})
|
||||
|
||||
it('single element sequences do not need to be the same type', () => {
|
||||
expect(arrayEqual(Uint8Array.from([1]), [1])).toBe(true)
|
||||
expect(arrayEqual(Uint8Array.from([1]), new Uint8Array([1]))).toBe(true)
|
||||
})
|
||||
|
||||
it('empty sequences do not need to be the same type', () => {
|
||||
expect(arrayEqual(Uint8Array.from([]), [])).toBe(true)
|
||||
expect(arrayEqual(Uint8Array.from([]), new Uint8Array([]))).toBe(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('Function: concatArgs', () => {
|
||||
it('plain numbers are concatenated', () => {
|
||||
expect(concatArgs(10, 20, 30, 40)).toEqual([10, 20, 30, 40])
|
||||
})
|
||||
|
||||
it('a variety of values are concatenated', () => {
|
||||
expect(
|
||||
concatArgs(1, [2, 3], Uint8Array.from([4, 5]), new Uint8Array([6, 7])),
|
||||
).toEqual([1, 2, 3, 4, 5, 6, 7])
|
||||
})
|
||||
|
||||
it('a single value is returned as an array', () => {
|
||||
expect(concatArgs(Uint8Array.from([7]))).toEqual([7])
|
||||
})
|
||||
|
||||
it('no arguments returns an empty array', () => {
|
||||
expect(concatArgs()).toEqual([])
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user