-
Notifications
You must be signed in to change notification settings - Fork 349
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add unrecognizedEnumName and unrecognizedEnumValue options (#946)
- Loading branch information
Showing
9 changed files
with
181 additions
and
35 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
23 changes: 23 additions & 0 deletions
23
integration/enums-with-unrecognized-name-value/default-value-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,23 @@ | ||
import { stateEnumFromJSON, stateEnumToJSON, stateEnumToNumber, StateEnum } from "./test"; | ||
|
||
describe("enums-with-unrecognized-name-value", () => { | ||
describe("stateEnumFromJSON", () => { | ||
it("returns correct default state", () => { | ||
expect(stateEnumFromJSON("non-existent")).toBe(StateEnum.UNKNOWN_STATE); | ||
}); | ||
}); | ||
|
||
describe("stateEnumToJSON", () => { | ||
it("returns correct default state", () => { | ||
// @ts-expect-error Argument of type '1' is not assignable to parameter of type 'StateEnum'. | ||
expect(stateEnumToJSON(1)).toBe("UNKNOWN_STATE"); | ||
}); | ||
}); | ||
|
||
describe("stateEnumToNumber", () => { | ||
it("returns correct default state", () => { | ||
// @ts-expect-error Argument of type '1' is not assignable to parameter of type 'StateEnum'. | ||
expect(stateEnumToNumber(1)).toBe(0); | ||
}); | ||
}); | ||
}); |
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 @@ | ||
unrecognizedEnumName=UNKNOWN,unrecognizedEnumValue=0,stringEnums=true |
Binary file not shown.
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,7 @@ | ||
syntax = "proto3"; | ||
|
||
enum StateEnum { | ||
UNKNOWN_STATE = 0; | ||
ON = 2; | ||
OFF = 3; | ||
} |
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,51 @@ | ||
/* eslint-disable */ | ||
|
||
export const protobufPackage = ""; | ||
|
||
export enum StateEnum { | ||
UNKNOWN_STATE = "UNKNOWN_STATE", | ||
ON = "ON", | ||
OFF = "OFF", | ||
} | ||
|
||
export function stateEnumFromJSON(object: any): StateEnum { | ||
switch (object) { | ||
case 0: | ||
case "UNKNOWN_STATE": | ||
return StateEnum.UNKNOWN_STATE; | ||
case 2: | ||
case "ON": | ||
return StateEnum.ON; | ||
case 3: | ||
case "OFF": | ||
return StateEnum.OFF; | ||
default: | ||
return StateEnum.UNKNOWN_STATE; | ||
} | ||
} | ||
|
||
export function stateEnumToJSON(object: StateEnum): string { | ||
switch (object) { | ||
case StateEnum.UNKNOWN_STATE: | ||
return "UNKNOWN_STATE"; | ||
case StateEnum.ON: | ||
return "ON"; | ||
case StateEnum.OFF: | ||
return "OFF"; | ||
default: | ||
return "UNKNOWN_STATE"; | ||
} | ||
} | ||
|
||
export function stateEnumToNumber(object: StateEnum): number { | ||
switch (object) { | ||
case StateEnum.UNKNOWN_STATE: | ||
return 0; | ||
case StateEnum.ON: | ||
return 2; | ||
case StateEnum.OFF: | ||
return 3; | ||
default: | ||
return 0; | ||
} | ||
} |
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