Skip to content

Commit 1af3381

Browse files
authored
Update protobuf-javascript, and add tests for oneofs (#7)
Tests that oneof values are set/retrieved properly and that oneof case values are retrieved properly.
1 parent 081a08b commit 1af3381

File tree

3 files changed

+38
-2
lines changed

3 files changed

+38
-2
lines changed

e2e/typescript_proto_usage/greeting.proto

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,15 @@ message MutuallyExclusiveThing {
4949
string mutex_string = 1;
5050
.someorg.type.Position mutex_position = 2;
5151
}
52+
53+
message NestedThing {
54+
oneof some_value {
55+
string mutex_string = 1;
56+
.someorg.type.Position mutex_position = 2;
57+
}
58+
}
59+
60+
NestedThing the_thing = 3;
5261
}
5362

5463
message Ancestor1 {

e2e/typescript_proto_usage/tests/greeting_jasmine/greeting.spec.js

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Ancestor1, GreetingRequest, TopLevelEnumExample, RepeatedThing } from "../../greeting_pb.mjs"
1+
import { Ancestor1, GreetingRequest, TopLevelEnumExample, RepeatedThing, MutuallyExclusiveThing } from "../../greeting_pb.mjs"
22
import { Position } from "../../location/location_pb.mjs"
33
//import { GreetingRequest } from "../../greeting_pb";
44

@@ -54,6 +54,33 @@ describe("lib", () => {
5454
const thing = new RepeatedThing().setChildPositionsList([a, b]);
5555
expect(thing.getChildPositionsList().map(x => x.getLatitude())).toEqual([42, 43]);
5656
});
57+
58+
it("should return correct oneof case", () => {
59+
const thing = new MutuallyExclusiveThing().setMutexString("test");
60+
expect(thing.getSomeValueCase()).toEqual(1);
61+
});
62+
63+
it("should return correct oneof case for nested message", () => {
64+
const thing = new MutuallyExclusiveThing()
65+
.setTheThing(new MutuallyExclusiveThing.NestedThing().setMutexString("test"));
66+
expect(thing.getTheThing().getSomeValueCase()).toEqual(1);
67+
});
68+
69+
it("should clear field", () => {
70+
const message = new GreetingRequest().setOrigin(new Position());
71+
expect(message.getOrigin()).not.toBeUndefined();
72+
73+
message.clearOrigin();
74+
expect(message.getOrigin()).toBeUndefined();
75+
});
76+
77+
it("should be able to check if value set", () => {
78+
const message = new GreetingRequest();
79+
expect(message.hasOrigin()).toBe(false);
80+
81+
message.setOrigin(new Position());
82+
expect(message.hasOrigin()).toBe(true);
83+
})
5784
});
5885

5986
describe("TopLevelEnumExample", () => {

ts_proto/repositories.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def rules_ts_proto_dependencies():
4545

4646
git_repository(
4747
name = "com_google_protobuf_javascript",
48-
commit = "d3ce92c081bd585dc6079609a868744b5e3033fe",
48+
commit = "885b9cdad5acc46d67f3850155d34226e2b4ee8b",
4949
remote = "https://github.com/gonzojive/protobuf-javascript.git",
5050
)
5151

0 commit comments

Comments
 (0)