-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: refactor uint8arrayTool to replace buffer shim
- Loading branch information
1 parent
7e5b048
commit e8ae8e4
Showing
2 changed files
with
31 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { Uint8arrayTool } from "../binary"; | ||
|
||
describe("Uint8arrayTool ", () => { | ||
it("should be able to convert to hex", () => { | ||
const bytes = new Uint8Array([0, 1, 2, 3, 4, 5]); | ||
const hex = Uint8arrayTool.toHex(bytes); | ||
expect(hex).toBe("000102030405"); | ||
}); | ||
|
||
it("should be able to ensure Uint8Array", () => { | ||
const bytes = new Uint8Array([0, 1, 2, 3, 4, 5]); | ||
const b64 = "AAECAwQF"; | ||
const arr = [0, 1, 2, 3, 4, 5]; | ||
expect(Uint8arrayTool.ensureUint8Array(bytes)).toBe(bytes); | ||
expect(Uint8arrayTool.ensureUint8Array(b64)).toEqual(bytes); | ||
expect(Uint8arrayTool.ensureUint8Array(arr)).toEqual(bytes); | ||
}); | ||
|
||
it("should be able to compare bytes", () => { | ||
const a = new Uint8Array([0, 1, 2, 3, 4, 5]); | ||
const b = new Uint8Array([0, 1, 2, 3, 4, 5]); | ||
const c = new Uint8Array([0, 1, 2, 3, 4, 6]); | ||
const d = new Uint8Array([0, 1, 2, 3, 4]); | ||
expect(Uint8arrayTool.bytesEqual(a, b)).toBe(true); | ||
expect(Uint8arrayTool.bytesEqual(a, c)).toBe(false); | ||
expect(Uint8arrayTool.bytesEqual(a, d)).toBe(false); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters