-
Notifications
You must be signed in to change notification settings - Fork 43
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
9e5099d
commit df44cc1
Showing
7 changed files
with
229 additions
and
19 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
63 changes: 63 additions & 0 deletions
63
packages/ast/src/encoding/proto/__snapshots__/proto.json.patch.spec.ts.snap
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 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`createProtoEnum 1`] = ` | ||
"/** AccessType permission types */ | ||
export enum NullValue { | ||
/** ACCESS_TYPE_UNSPECIFIED - AccessTypeUnspecified placeholder for empty value */ | ||
ACCESS_TYPE_UNSPECIFIED = 0, | ||
/** ACCESS_TYPE_NOBODY - AccessTypeNobody forbidden */ | ||
ACCESS_TYPE_NOBODY = 1, | ||
/** ACCESS_TYPE_ONLY_ADDRESS - AccessTypeOnlyAddress restricted to an address */ | ||
ACCESS_TYPE_ONLY_ADDRESS = 2, | ||
/** ACCESS_TYPE_EVERYBODY - AccessTypeEverybody unrestricted */ | ||
ACCESS_TYPE_EVERYBODY = 3, | ||
ACCESS_TYPE_SUPER_FUN = 4, | ||
UNRECOGNIZED = -1, | ||
}" | ||
`; | ||
|
||
exports[`createProtoEnumFromJSON 1`] = ` | ||
"export function accessTypeFromJSON(object: any): AccessType { | ||
switch (object) { | ||
case 0: | ||
case "UnspecifiedAccess": | ||
return AccessType.ACCESS_TYPE_UNSPECIFIED; | ||
case 1: | ||
case "NobodyAccess": | ||
return AccessType.ACCESS_TYPE_NOBODY; | ||
case 2: | ||
case "OnlyAddressAccess": | ||
return AccessType.ACCESS_TYPE_ONLY_ADDRESS; | ||
case 3: | ||
case "EverybodyAccess": | ||
return AccessType.ACCESS_TYPE_EVERYBODY; | ||
case 4: | ||
case "SuperFunAccessType": | ||
return AccessType.ACCESS_TYPE_SUPER_FUN; | ||
case -1: | ||
case "UNRECOGNIZED": | ||
default: | ||
return AccessType.UNRECOGNIZED; | ||
} | ||
}" | ||
`; | ||
|
||
exports[`createProtoEnumToJSON 1`] = ` | ||
"export function accessTypeToJSON(object: AccessType): string { | ||
switch (object) { | ||
case AccessType.ACCESS_TYPE_UNSPECIFIED: | ||
return "UnspecifiedAccess"; | ||
case AccessType.ACCESS_TYPE_NOBODY: | ||
return "NobodyAccess"; | ||
case AccessType.ACCESS_TYPE_ONLY_ADDRESS: | ||
return "OnlyAddressAccess"; | ||
case AccessType.ACCESS_TYPE_EVERYBODY: | ||
return "EverybodyAccess"; | ||
case AccessType.ACCESS_TYPE_SUPER_FUN: | ||
return "SuperFunAccessType"; | ||
case AccessType.UNRECOGNIZED: | ||
default: | ||
return "UNRECOGNIZED"; | ||
} | ||
}" | ||
`; |
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,82 @@ | ||
import { | ||
createProtoEnum, | ||
createProtoEnumFromJSON, | ||
createProtoEnumToJSON, | ||
} from "./enums"; | ||
import { | ||
getNestedProto, | ||
convertProtoPathToNestedJSONPath as convert, | ||
convertPackageNameToNestedJSONPath as convertPackage | ||
} from "@cosmology/utils"; | ||
import { ProtoParseContext } from "@cosmology/ast"; | ||
import { | ||
expectCode, | ||
getTestProtoStore | ||
} from "../../../test-utils"; | ||
|
||
const p = convert('cosmwasm/wasm/v1/types.proto'); | ||
const cp = convertPackage('cosmwasm.wasm.v1'); | ||
const store = getTestProtoStore({ | ||
prototypes: { | ||
patch: { | ||
'cosmwasm/wasm/v1/types.proto': [ | ||
{ op: 'replace', path: '~/AccessType/valuesOptions/ACCESS_TYPE_NOBODY/(gogoproto.enumvalue_customname)', value: 'NobodyAccess' }, | ||
{ op: 'replace', path: '@/AccessType/valuesOptions/ACCESS_TYPE_UNSPECIFIED/(gogoproto.enumvalue_customname)', value: 'UnspecifiedAccess' }, | ||
{ op: 'replace', path: p + '/AccessType/valuesOptions/ACCESS_TYPE_EVERYBODY/(gogoproto.enumvalue_customname)', value: 'EverybodyAccess' }, | ||
{ op: 'replace', path: cp + '/AccessType/valuesOptions/ACCESS_TYPE_ONLY_ADDRESS/(gogoproto.enumvalue_customname)', value: 'OnlyAddressAccess' }, | ||
{ | ||
op: "add", | ||
path: "/root/nested/cosmwasm/nested/wasm/nested/v1/nested/AccessType/values/ACCESS_TYPE_SUPER_FUN", | ||
value: 4 | ||
}, | ||
{ | ||
op: "add", | ||
path: "/root/nested/cosmwasm/nested/wasm/nested/v1/nested/AccessType/valuesOptions/ACCESS_TYPE_SUPER_FUN", | ||
value: { | ||
"(gogoproto.enumvalue_customname)": "SuperFunAccessType" | ||
} | ||
} | ||
] | ||
} | ||
}, | ||
enums: { | ||
useCustomNames: true | ||
} | ||
}); | ||
store.traverseAll(); | ||
|
||
it("createProtoEnum", async () => { | ||
const ref = store.findProto('cosmwasm/wasm/v1/types.proto'); | ||
const context = new ProtoParseContext(ref, store, store.options); | ||
expectCode( | ||
createProtoEnum( | ||
context, | ||
"NullValue", | ||
getNestedProto(ref.traversed).AccessType | ||
) | ||
); | ||
}); | ||
|
||
it("createProtoEnumFromJSON", async () => { | ||
const ref = store.findProto('cosmwasm/wasm/v1/types.proto'); | ||
const context = new ProtoParseContext(ref, store, store.options); | ||
expectCode( | ||
createProtoEnumFromJSON( | ||
context, | ||
"AccessType", | ||
getNestedProto(ref.traversed).AccessType | ||
) | ||
); | ||
}); | ||
|
||
it("createProtoEnumToJSON", async () => { | ||
const ref = store.findProto('cosmwasm/wasm/v1/types.proto'); | ||
const context = new ProtoParseContext(ref, store, store.options); | ||
expectCode( | ||
createProtoEnumToJSON( | ||
context, | ||
"AccessType", | ||
getNestedProto(ref.traversed).AccessType | ||
) | ||
); | ||
}); |
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