-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add typegen support for string slice (#1468)
- Loading branch information
1 parent
5ac9673
commit 5e544e1
Showing
6 changed files
with
75 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 @@ | ||
--- | ||
"@fuel-ts/abi-typegen": minor | ||
--- | ||
|
||
add string slice support in typegen |
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,23 @@ | ||
import type { IType } from '../../types/interfaces/IType'; | ||
|
||
import { AType } from './AType'; | ||
|
||
export class StrSliceType extends AType implements IType { | ||
public static swayType = 'str'; | ||
|
||
public name = 'strSlice'; | ||
|
||
static MATCH_REGEX: RegExp = /^str$/m; | ||
|
||
static isSuitableFor(params: { type: string }) { | ||
return StrSliceType.MATCH_REGEX.test(params.type); | ||
} | ||
|
||
public parseComponentsAttributes(_params: { types: IType[] }) { | ||
this.attributes = { | ||
inputLabel: 'StrSlice', | ||
outputLabel: 'StrSlice', | ||
}; | ||
return this.attributes; | ||
} | ||
} |
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,33 @@ | ||
import { BoolType } from './BoolType'; | ||
import { StdStringType } from './StdStringType'; | ||
import { StrSliceType } from './StrSliceType'; | ||
import { StrType } from './StrType'; | ||
|
||
describe('StrSlicesType.ts', () => { | ||
test('should properly parse type attributes', () => { | ||
const strSlices = new StrSliceType({ | ||
rawAbiType: { | ||
components: null, | ||
typeParameters: null, | ||
typeId: 1, | ||
type: StrSliceType.swayType, | ||
}, | ||
}); | ||
|
||
strSlices.parseComponentsAttributes({ types: [] }); | ||
|
||
const suitableForStrSlices = StrSliceType.isSuitableFor({ type: StrSliceType.swayType }); | ||
const suitableForU16 = StrSliceType.isSuitableFor({ type: BoolType.swayType }); | ||
const suitableForStr = StrSliceType.isSuitableFor({ type: StrType.swayType }); | ||
const suitableForStdString = StrSliceType.isSuitableFor({ type: StdStringType.swayType }); | ||
|
||
expect(suitableForStrSlices).toEqual(true); | ||
expect(suitableForU16).toEqual(false); | ||
expect(suitableForStr).toEqual(false); | ||
expect(suitableForStdString).toEqual(false); | ||
|
||
expect(strSlices.attributes.inputLabel).toEqual('StrSlice'); | ||
expect(strSlices.attributes.outputLabel).toEqual('StrSlice'); | ||
expect(strSlices.requiredFuelsMembersImports).toStrictEqual([]); | ||
}); | ||
}); |
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