-
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.
Add preOffsetTypeNode and postOffsetTypeNode (#197)
- Loading branch information
1 parent
6307b3a
commit 8eaf605
Showing
11 changed files
with
163 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,5 @@ | ||
--- | ||
"@metaplex-foundation/kinobi": minor | ||
--- | ||
|
||
Add preOffsetTypeNode and postOffsetTypeNode |
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,20 @@ | ||
import { TypeNode } from './TypeNode'; | ||
|
||
export interface PostOffsetTypeNode<TType extends TypeNode = TypeNode> { | ||
readonly kind: 'postOffsetTypeNode'; | ||
|
||
// Children. | ||
readonly type: TType; | ||
|
||
// Data. | ||
readonly offset: number; | ||
readonly strategy?: 'relative' | 'absolute' | 'padded' | 'preOffset'; | ||
} | ||
|
||
export function postOffsetTypeNode<TType extends TypeNode>( | ||
type: TType, | ||
offset: number, | ||
strategy?: PostOffsetTypeNode['strategy'] | ||
): PostOffsetTypeNode<TType> { | ||
return { kind: 'postOffsetTypeNode', type, offset, strategy }; | ||
} |
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,20 @@ | ||
import { TypeNode } from './TypeNode'; | ||
|
||
export interface PreOffsetTypeNode<TType extends TypeNode = TypeNode> { | ||
readonly kind: 'preOffsetTypeNode'; | ||
|
||
// Children. | ||
readonly type: TType; | ||
|
||
// Data. | ||
readonly offset: number; | ||
readonly strategy?: 'relative' | 'absolute' | 'padded'; | ||
} | ||
|
||
export function preOffsetTypeNode<TType extends TypeNode>( | ||
type: TType, | ||
offset: number, | ||
strategy?: PreOffsetTypeNode['strategy'] | ||
): PreOffsetTypeNode<TType> { | ||
return { kind: 'preOffsetTypeNode', type, offset, strategy }; | ||
} |
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,32 @@ | ||
import test from 'ava'; | ||
import { postOffsetTypeNode, stringTypeNode } from '../../../../src'; | ||
import { | ||
deleteNodesVisitorMacro, | ||
getDebugStringVisitorMacro, | ||
identityVisitorMacro, | ||
mergeVisitorMacro, | ||
} from '../_setup'; | ||
|
||
const node = postOffsetTypeNode(stringTypeNode(), 42); | ||
|
||
test(mergeVisitorMacro, node, 2); | ||
test(identityVisitorMacro, node); | ||
test(deleteNodesVisitorMacro, node, '[stringTypeNode]', null); | ||
test(deleteNodesVisitorMacro, node, '[postOffsetTypeNode]', null); | ||
test( | ||
getDebugStringVisitorMacro, | ||
node, | ||
` | ||
postOffsetTypeNode [42.relative] | ||
| stringTypeNode [utf8]` | ||
); | ||
|
||
// Different strategy. | ||
test( | ||
'getDebugStringVisitor: different strategy', | ||
getDebugStringVisitorMacro, | ||
postOffsetTypeNode(stringTypeNode(), 42, 'absolute'), | ||
` | ||
postOffsetTypeNode [42.absolute] | ||
| stringTypeNode [utf8]` | ||
); |
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,32 @@ | ||
import test from 'ava'; | ||
import { preOffsetTypeNode, stringTypeNode } from '../../../../src'; | ||
import { | ||
deleteNodesVisitorMacro, | ||
getDebugStringVisitorMacro, | ||
identityVisitorMacro, | ||
mergeVisitorMacro, | ||
} from '../_setup'; | ||
|
||
const node = preOffsetTypeNode(stringTypeNode(), 42); | ||
|
||
test(mergeVisitorMacro, node, 2); | ||
test(identityVisitorMacro, node); | ||
test(deleteNodesVisitorMacro, node, '[stringTypeNode]', null); | ||
test(deleteNodesVisitorMacro, node, '[preOffsetTypeNode]', null); | ||
test( | ||
getDebugStringVisitorMacro, | ||
node, | ||
` | ||
preOffsetTypeNode [42.relative] | ||
| stringTypeNode [utf8]` | ||
); | ||
|
||
// Different strategy. | ||
test( | ||
'getDebugStringVisitor: different strategy', | ||
getDebugStringVisitorMacro, | ||
preOffsetTypeNode(stringTypeNode(), 42, 'absolute'), | ||
` | ||
preOffsetTypeNode [42.absolute] | ||
| stringTypeNode [utf8]` | ||
); |