-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1536 from tgrecojs/tgrecojs-marshal-readme-new-se…
…rialization-api test(marshal): added test cases for new serialization API
- Loading branch information
Showing
1 changed file
with
63 additions
and
0 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,63 @@ | ||
import { test } from './prepare-test-env-ava.js'; | ||
|
||
// eslint-disable-next-line import/order | ||
import { makeMarshal } from '../src/marshal.js'; | ||
|
||
test('toCapData', t => { | ||
const m = makeMarshal(); | ||
const o = harden({ a: 1 }); | ||
|
||
// deprecated seralization API | ||
const usingSerializeMethod = m.serialize(o); | ||
|
||
const usingToCapDataMethod = m.toCapData(o); | ||
|
||
t.deepEqual( | ||
usingSerializeMethod, | ||
usingToCapDataMethod, | ||
'should create a serialized object that is deeply equal to value produced using makeMarshal().serialize', | ||
); | ||
|
||
const oo = harden([o, o]); | ||
|
||
const ooUsingSerializeMethod = m.serialize(oo); | ||
const ooUsingToCapDataMethod = m.toCapData(oo); | ||
t.deepEqual( | ||
ooUsingSerializeMethod, | ||
ooUsingToCapDataMethod, | ||
'given a previously serialized object, should create a serialized object that is deeply equal to value produced using makeMarshal().serialize', | ||
); | ||
}); | ||
|
||
test('fromCapData', t => { | ||
const m = makeMarshal(); | ||
const o = harden({ a: 1 }); | ||
|
||
// deprecated seralization API | ||
const usingSerializeMethod = m.serialize(o); | ||
|
||
const usingToCapDataMethod = m.toCapData(o); | ||
|
||
const usingUnserializeMethod = m.unserialize(usingSerializeMethod); | ||
const usingFromCapDataMethod = m.fromCapData(usingToCapDataMethod); | ||
|
||
t.deepEqual( | ||
usingUnserializeMethod, | ||
usingFromCapDataMethod, | ||
'should return an unserialized object that is deeply equal to value unserialized using makeMarshal().unserialize', | ||
); | ||
|
||
const oo = harden([o, o]); | ||
|
||
const ooUsingSerializeMethod = m.serialize(oo); | ||
const ooUsingToCapDataMethod = m.toCapData(oo); | ||
|
||
const uoUsingUnserializeMethod = m.unserialize(ooUsingSerializeMethod); | ||
const uoUsingFromCapDataMethod = m.fromCapData(ooUsingToCapDataMethod); | ||
|
||
t.deepEqual( | ||
uoUsingUnserializeMethod, | ||
uoUsingFromCapDataMethod, | ||
'given a previously serialized object, should create a serialized object that is deeply equal to value produced using makeMarshal().serialize', | ||
); | ||
}); |