-
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
748d8ea
commit 0463a43
Showing
7 changed files
with
106 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@metaplex-foundation/kinobi": minor | ||
--- | ||
|
||
Add ZeroableOptionTypeNode |
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,25 @@ | ||
import { ConstantValueNode } from '../valueNodes'; | ||
import { TypeNode } from './TypeNode'; | ||
|
||
export interface ZeroableOptionTypeNode< | ||
TItem extends TypeNode = TypeNode, | ||
TZeroValue extends ConstantValueNode | undefined = | ||
| ConstantValueNode | ||
| undefined, | ||
> { | ||
readonly kind: 'zeroableOptionTypeNode'; | ||
|
||
// Children. | ||
readonly item: TItem; | ||
readonly zeroValue?: TZeroValue; | ||
} | ||
|
||
export function zeroableOptionTypeNode< | ||
TItem extends TypeNode, | ||
TZeroValue extends ConstantValueNode | undefined, | ||
>( | ||
item: TItem, | ||
zeroValue?: TZeroValue | ||
): ZeroableOptionTypeNode<TItem, TZeroValue> { | ||
return { kind: 'zeroableOptionTypeNode', item, zeroValue }; | ||
} |
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
48 changes: 48 additions & 0 deletions
48
test/visitors/nodes/typeNodes/ZeroableOptionTypeNode.test.ts
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,48 @@ | ||
import test from 'ava'; | ||
import { | ||
constantValueNodeFromBytes, | ||
publicKeyTypeNode, | ||
zeroableOptionTypeNode, | ||
} from '../../../../src'; | ||
import { | ||
deleteNodesVisitorMacro, | ||
getDebugStringVisitorMacro, | ||
identityVisitorMacro, | ||
mergeVisitorMacro, | ||
} from '../_setup'; | ||
|
||
const node = zeroableOptionTypeNode( | ||
publicKeyTypeNode(), | ||
constantValueNodeFromBytes('base16', 'ff'.repeat(32)) | ||
); | ||
|
||
test(mergeVisitorMacro, node, 5); | ||
test(identityVisitorMacro, node); | ||
test(deleteNodesVisitorMacro, node, '[zeroableOptionTypeNode]', null); | ||
test(deleteNodesVisitorMacro, node, '[publicKeyTypeNode]', null); | ||
test( | ||
deleteNodesVisitorMacro, | ||
node, | ||
'[constantValueNode]', | ||
zeroableOptionTypeNode(publicKeyTypeNode()) | ||
); | ||
test( | ||
getDebugStringVisitorMacro, | ||
node, | ||
` | ||
zeroableOptionTypeNode | ||
| publicKeyTypeNode | ||
| constantValueNode | ||
| | bytesTypeNode | ||
| | bytesValueNode [base16.ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff]` | ||
); | ||
|
||
// No zero value. | ||
test( | ||
'getDebugStringVisitor: different strategy', | ||
getDebugStringVisitorMacro, | ||
zeroableOptionTypeNode(publicKeyTypeNode()), | ||
` | ||
zeroableOptionTypeNode | ||
| publicKeyTypeNode` | ||
); |