-
Notifications
You must be signed in to change notification settings - Fork 18
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
1 parent
5d943e6
commit 1eb39c8
Showing
4 changed files
with
65 additions
and
32 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
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,54 @@ | ||
import test from 'ava'; | ||
import { | ||
fixedSizeTypeNode, | ||
isNestedTypeNode, | ||
numberTypeNode, | ||
publicKeyTypeNode, | ||
resolveNestedTypeNode, | ||
sizePrefixTypeNode, | ||
stringTypeNode, | ||
transformNestedTypeNode, | ||
} from '../../../src'; | ||
|
||
test('it resolved nested type nodes', (t) => { | ||
const node = sizePrefixTypeNode( | ||
fixedSizeTypeNode(stringTypeNode(), 32), | ||
numberTypeNode('u8') | ||
); | ||
t.deepEqual(resolveNestedTypeNode(node), stringTypeNode()); | ||
}); | ||
|
||
test('it returns the same instance when resolving nested types nodes', (t) => { | ||
const node = numberTypeNode('u8'); | ||
t.is(resolveNestedTypeNode(node), node); | ||
}); | ||
|
||
test('it transforms nested type nodes', (t) => { | ||
const node = sizePrefixTypeNode( | ||
fixedSizeTypeNode(stringTypeNode(), 32), | ||
numberTypeNode('u8') | ||
); | ||
const transformedNode = transformNestedTypeNode(node, () => | ||
publicKeyTypeNode() | ||
); | ||
t.deepEqual( | ||
transformedNode, | ||
sizePrefixTypeNode( | ||
fixedSizeTypeNode(publicKeyTypeNode(), 32), | ||
numberTypeNode('u8') | ||
) | ||
); | ||
}); | ||
|
||
test('it checks if a node is a nested type', (t) => { | ||
const flatNode = numberTypeNode('u64'); | ||
t.true(isNestedTypeNode(flatNode, 'numberTypeNode')); | ||
t.false(isNestedTypeNode(flatNode, 'stringTypeNode')); | ||
|
||
const nestedNode = sizePrefixTypeNode( | ||
fixedSizeTypeNode(numberTypeNode('u64'), 32), | ||
numberTypeNode('u8') | ||
); | ||
t.true(isNestedTypeNode(nestedNode, 'numberTypeNode')); | ||
t.false(isNestedTypeNode(nestedNode, 'stringTypeNode')); | ||
}); |
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 was deleted.
Oops, something went wrong.