-
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: Update fromPartial and fromJson to respect initializeFieldsAsUn…
…defined (#811) * feat: fromPartial do not default initialize * feat: fromJSON do not default initialize Fixes #682 * test: integration --------- Co-authored-by: ilikdoge <ilikdoge0@gmail.com>
- Loading branch information
1 parent
334bb09
commit 1615ae0
Showing
8 changed files
with
538 additions
and
70 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 @@ | ||
useOptionals=all,initializeFieldsAsUndefined=false |
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,50 @@ | ||
import { TPartial } from './test' | ||
|
||
describe('partials-test', () => { | ||
it('works with singular fields', () => { | ||
const test = { | ||
number: 2, | ||
string: 'hi', | ||
message: { | ||
field: 'hello' | ||
} | ||
}; | ||
|
||
const result = TPartial.fromPartial(test); | ||
|
||
expect(result).toEqual(test); | ||
}); | ||
|
||
it('works with repeated fields', () => { | ||
const test = { | ||
map: { | ||
a: 'b', | ||
c: 'd' | ||
}, | ||
|
||
repeatedMessage: [ | ||
{ | ||
field: 'world' | ||
}, | ||
{ | ||
field: 'hello' | ||
} | ||
], | ||
|
||
repeatedString: [ | ||
'goodbye', | ||
'world' | ||
], | ||
|
||
repeatedNumber: [ | ||
1, | ||
2, | ||
3 | ||
] | ||
}; | ||
|
||
const result = TPartial.fromPartial(test); | ||
|
||
expect(result).toEqual(test); | ||
}); | ||
}) |
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,15 @@ | ||
syntax = "proto2"; | ||
|
||
message TPartialMessage{ | ||
required string field = 1; | ||
} | ||
|
||
message TPartial{ | ||
optional int32 number = 1; | ||
optional string string = 2; | ||
map<string, string> map = 3; | ||
optional TPartialMessage message = 4; | ||
repeated TPartialMessage repeated_message = 5; | ||
repeated string repeated_string = 6; | ||
repeated int32 repeated_number = 7; | ||
} |
Oops, something went wrong.