-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
133 additions
and
1 deletion.
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
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
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
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
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
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
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,9 @@ | ||
// Vitest Snapshot v1 | ||
|
||
exports[`DataView > serialize > supports DataView 1`] = `"new DataView(new Uint8Array([0,0,42,0,0,0,0,0,0,0,0,0,0,0,0,0]).buffer,0,16)"`; | ||
|
||
exports[`DataView > serializeAsync > supports DataView 1`] = `"Promise.resolve(new DataView(new Uint8Array([0,0,42,0,0,0,0,0,0,0,0,0,0,0,0,0]).buffer,0,16))"`; | ||
|
||
exports[`DataView > toJSON > supports DataView 1`] = `"{\\"t\\":{\\"t\\":29,\\"i\\":0,\\"l\\":16,\\"f\\":{\\"t\\":28,\\"i\\":1,\\"s\\":[0,0,42,0,0,0,0,0,0,0,0,0,0,0,0,0]},\\"b\\":0},\\"r\\":0,\\"i\\":false,\\"f\\":16383,\\"m\\":[]}"`; | ||
|
||
exports[`DataView > toJSONAsync > supports DataView 1`] = `"{\\"t\\":{\\"t\\":18,\\"i\\":0,\\"f\\":{\\"t\\":29,\\"i\\":1,\\"l\\":16,\\"f\\":{\\"t\\":28,\\"i\\":2,\\"s\\":[0,0,42,0,0,0,0,0,0,0,0,0,0,0,0,0]},\\"b\\":0}},\\"r\\":0,\\"i\\":false,\\"f\\":16383,\\"m\\":[]}"`; |
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,60 @@ | ||
import { describe, it, expect } from 'vitest'; | ||
import { | ||
deserialize, | ||
fromJSON, | ||
serialize, | ||
serializeAsync, | ||
toJSONAsync, | ||
toJSON, | ||
} from '../src'; | ||
|
||
describe('DataView', () => { | ||
describe('serialize', () => { | ||
it('supports DataView', () => { | ||
const buffer = new ArrayBuffer(16); | ||
const example = new DataView(buffer, 0); | ||
example.setInt16(1, 42); | ||
const result = serialize(example); | ||
expect(result).toMatchSnapshot(); | ||
const back = deserialize<DataView>(result); | ||
expect(back).toBeInstanceOf(DataView); | ||
expect(back.getInt16(1)).toBe(example.getInt16(1)); | ||
}); | ||
}); | ||
describe('serializeAsync', () => { | ||
it('supports DataView', async () => { | ||
const buffer = new ArrayBuffer(16); | ||
const example = new DataView(buffer, 0); | ||
example.setInt16(1, 42); | ||
const result = await serializeAsync(Promise.resolve(example)); | ||
expect(result).toMatchSnapshot(); | ||
const back = await deserialize<Promise<DataView>>(result); | ||
expect(back).toBeInstanceOf(DataView); | ||
expect(back.getInt16(1)).toBe(example.getInt16(1)); | ||
}); | ||
}); | ||
describe('toJSON', () => { | ||
it('supports DataView', () => { | ||
const buffer = new ArrayBuffer(16); | ||
const example = new DataView(buffer, 0); | ||
example.setInt16(1, 42); | ||
const result = toJSON(example); | ||
expect(JSON.stringify(result)).toMatchSnapshot(); | ||
const back = fromJSON<DataView>(result); | ||
expect(back).toBeInstanceOf(DataView); | ||
expect(back.getInt16(1)).toBe(example.getInt16(1)); | ||
}); | ||
}); | ||
describe('toJSONAsync', () => { | ||
it('supports DataView', async () => { | ||
const buffer = new ArrayBuffer(16); | ||
const example = new DataView(buffer, 0); | ||
example.setInt16(1, 42); | ||
const result = await toJSONAsync(Promise.resolve(example)); | ||
expect(JSON.stringify(result)).toMatchSnapshot(); | ||
const back = await fromJSON<Promise<DataView>>(result); | ||
expect(back).toBeInstanceOf(DataView); | ||
expect(back.getInt16(1)).toBe(example.getInt16(1)); | ||
}); | ||
}); | ||
}); |