-
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.
Add deprecatedOnly option to make deprecated fields optional
- Loading branch information
1 parent
ba97f98
commit cf33875
Showing
7 changed files
with
736 additions
and
1 deletion.
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
integration/use-optionals-deprecated-only/optionals-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,56 @@ | ||
import { OptionalsTest, StateEnum } from './test' | ||
|
||
describe('useOptionals=deprecatedOnly', () => { | ||
it('has deprecated fields optional members', () => { | ||
const test: OptionalsTest = { | ||
id: 1, | ||
long: 10, | ||
|
||
repId: [1, 2], | ||
repState: [StateEnum.ON, StateEnum.OFF], | ||
repLong: [11, 12], | ||
repTruth: [true, false], | ||
repDescription: ["hello", "world"], | ||
repData: [Buffer.alloc(3).fill(0x33), Buffer.alloc(4).fill(0x34), Buffer.alloc(5).fill(0x35)], | ||
|
||
optId: 2, | ||
optLong: 13, | ||
optTruth: true, | ||
optDescription: "mumble", | ||
optData: Buffer.alloc(6).fill(0x36), | ||
|
||
translations: { | ||
"hello": "hallo", | ||
"world": "wereld", | ||
}, | ||
}; | ||
const data = OptionalsTest.encode(test).finish(); | ||
const test2 = OptionalsTest.decode(data); | ||
expect(test2).toEqual({ | ||
id: 1, | ||
state: StateEnum.UNKNOWN, | ||
long: 10, | ||
truth: false, | ||
description: "", | ||
data: new Uint8Array(0), | ||
|
||
repId: [1, 2], | ||
repState: [StateEnum.ON, StateEnum.OFF], | ||
repLong: [11, 12], | ||
repTruth: [true, false], | ||
repDescription: ["hello", "world"], | ||
repData: [Buffer.alloc(3).fill(0x33), Buffer.alloc(4).fill(0x34), Buffer.alloc(5).fill(0x35)], | ||
|
||
optId: 2, | ||
optLong: 13, | ||
optTruth: true, | ||
optDescription: "mumble", | ||
optData: Buffer.alloc(6).fill(0x36), | ||
|
||
translations: { | ||
"hello": "hallo", | ||
"world": "wereld", | ||
}, | ||
}); | ||
}); | ||
}) |
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 @@ | ||
useOptionals=deprecatedOnly |
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,34 @@ | ||
syntax = "proto3"; | ||
package optionalstest; | ||
|
||
message OptionalsTest { | ||
int32 id = 1; | ||
StateEnum state = 2 [deprecated = true]; | ||
int64 long = 3; | ||
bool truth = 4 [deprecated = true]; | ||
string description = 5 [deprecated = true]; | ||
bytes data = 6 [deprecated = true]; | ||
|
||
repeated int32 rep_id = 7; | ||
repeated StateEnum rep_state = 8 [deprecated = true]; | ||
repeated int64 rep_long = 9; | ||
repeated bool rep_truth = 10; | ||
repeated string rep_description = 11; | ||
repeated bytes rep_data = 12; | ||
|
||
optional int32 opt_id = 13; | ||
optional StateEnum opt_state = 14 [deprecated = true]; | ||
optional int64 opt_long = 15; | ||
optional bool opt_truth = 16; | ||
optional string opt_description = 17; | ||
optional bytes opt_data = 18; | ||
|
||
map<string, string> translations = 19; | ||
} | ||
|
||
enum StateEnum { | ||
option deprecated = true; | ||
UNKNOWN = 0; | ||
ON = 1; | ||
OFF = 2; | ||
} |
Oops, something went wrong.