Skip to content

Commit

Permalink
chore: respond to test comments
Browse files Browse the repository at this point in the history
  • Loading branch information
sofisl committed Oct 9, 2024
1 parent 1f1d33c commit 4ca95c3
Showing 1 changed file with 111 additions and 13 deletions.
124 changes: 111 additions & 13 deletions tests/feature_resolution_editions.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,36 @@ tape.test("feature resolution inheritance file to message", function(test) {
test.end();
});

tape.test("feature resolution inheritance file to nested message", function(test) {
tape.test("feature resolution inheritance message to field", function(test) {
var rootEditionsOverriden = protobuf.parse(`edition = "2023";
option features.json_format = LEGACY_BEST_EFFORT;
option features.(abc).d_e = deeply_nested_false;
message Message {
option features.json_format = LEGACY_BEST_EFFORT;
option features.(abc).d_e = deeply_nested_false;
string string_val = 1;
string string_repeated = 2 [features.enum_type = CLOSED];
}`).root.resolveAll();

// Should flip enum_type from default setting, inherit from Message,
// and keep everything else
test.same(rootEditionsOverriden.lookup("Message").fields.stringRepeated._features, {
enum_type: 'CLOSED',
field_presence: 'EXPLICIT',
json_format: 'LEGACY_BEST_EFFORT',
message_encoding: 'LENGTH_PREFIXED',
repeated_field_encoding: 'PACKED',
utf8_validation: 'VERIFY',
'(abc)': { d_e: 'deeply_nested_false' }
})

test.end();
});

tape.test("feature resolution inheritance message to nested message", function(test) {
var rootEditionsOverriden = protobuf.parse(`edition = "2023";
message Message {
option features.json_format = LEGACY_BEST_EFFORT;
option features.(abc).d_e = deeply_nested_false;
string string_val = 1;
string string_repeated = 2 [features.enum_type = CLOSED];
Expand Down Expand Up @@ -180,21 +204,20 @@ tape.test("feature resolution inheritance file to enums and enum values", functi
test.end();
});

tape.test("feature resolution inheritance file to oneofs", function(test) {
tape.test("feature resolution inheritance message to oneofs", function(test) {

var rootEditionsOverriden = protobuf.parse(`
edition = "2023";
option features.json_format = LEGACY_BEST_EFFORT;
option features.(abc).d_e = deeply_nested_false;
message Message {
option features.json_format = LEGACY_BEST_EFFORT;
oneof SomeOneOf {
option features.json_format = ALLOW;
int32 a = 13;
string b = 14;
}
}`).root.resolveAll();

// console.log(rootEditionsOverriden.lookup("SomeOneOf")._features)
test.same(rootEditionsOverriden.lookup("SomeOneOf")._features, {
enum_type: 'OPEN',
field_presence: 'EXPLICIT',
Expand All @@ -208,20 +231,96 @@ tape.test("feature resolution inheritance file to oneofs", function(test) {
test.end();
});

tape.test("feature resolution inheritance oneofs to field", function(test) {
var rootEditionsOverriden = protobuf.parse(`
edition = "2023";
option features.(abc).d_e = deeply_nested_false;
message Message {
option features.json_format = LEGACY_BEST_EFFORT;
oneof SomeOneOf {
option features.json_format = ALLOW;
int32 a = 13;
string b = 14;
}
}`).root.resolveAll();

test.same(rootEditionsOverriden.lookup("SomeOneOf").fieldsArray.find(x => x.name === 'b')._features, {
enum_type: 'OPEN',
field_presence: 'EXPLICIT',
json_format: 'LEGACY_BEST_EFFORT',
message_encoding: 'LENGTH_PREFIXED',
repeated_field_encoding: 'PACKED',
utf8_validation: 'VERIFY',
'(abc)': { d_e: 'deeply_nested_false' }
})

test.end();
});

tape.test("feature resolution inheritance file to extensions", function(test) {

var rootEditionsOverriden = protobuf.parse(`
edition = "2023";
option features.json_format = LEGACY_BEST_EFFORT;
option features.(abc).d_e = deeply_nested_false;
extend Message {
int32 bar = 10 [features.utf8_validation = NONE];
}
message Message {}`).root.resolveAll();

test.same(rootEditionsOverriden.lookup(".bar")._features, {
enum_type: 'OPEN',
field_presence: 'EXPLICIT',
json_format: 'LEGACY_BEST_EFFORT',
message_encoding: 'LENGTH_PREFIXED',
repeated_field_encoding: 'PACKED',
utf8_validation: 'NONE',
'(abc)': { d_e: 'deeply_nested_false' }
})

test.end();
});

tape.test("feature resolution inheritance message to extensions", function(test) {

var rootEditionsOverriden = protobuf.parse(`
edition = "2023";
option features.json_format = LEGACY_BEST_EFFORT;
option features.(abc).d_e = deeply_nested_false;
extend Message {
int32 bar = 10 [features.utf8_validation = NONE];
}
message Message {}`).root.resolveAll();

test.same(rootEditionsOverriden.lookup(".bar")._features, {
enum_type: 'OPEN',
field_presence: 'EXPLICIT',
json_format: 'LEGACY_BEST_EFFORT',
message_encoding: 'LENGTH_PREFIXED',
repeated_field_encoding: 'PACKED',
utf8_validation: 'NONE',
'(abc)': { d_e: 'deeply_nested_false' }
})

test.end();
});

tape.test("feature resolution inheritance message to enum", function(test) {

var rootEditionsOverriden = protobuf.parse(`edition = "2023";
option features.json_format = LEGACY_BEST_EFFORT;
option features.(abc).d_e = deeply_nested_false;
message Message {
extensions 10 to 100;
extend Message {
int32 bar = 10 [features.utf8_validation = NONE];
option features.utf8_validation = NONE;
enum SomeEnum {
ONE = 1;
TWO = 2;
}
}`).root.resolveAll();

test.same(rootEditionsOverriden.lookup("Message").lookup(".Message.bar")._features, {
test.same(rootEditionsOverriden.lookup("Message").lookup("SomeEnum")._features, {
enum_type: 'OPEN',
field_presence: 'EXPLICIT',
json_format: 'LEGACY_BEST_EFFORT',
Expand All @@ -234,7 +333,7 @@ tape.test("feature resolution inheritance file to extensions", function(test) {
test.end();
});

tape.test("feature resolution inheritance file to top-level enum", function(test) {
tape.test("feature resolution inheritance message to enum", function(test) {

var rootEditionsOverriden = protobuf.parse(`edition = "2023";
option features.json_format = LEGACY_BEST_EFFORT;
Expand All @@ -245,7 +344,6 @@ tape.test("feature resolution inheritance file to top-level enum", function(test
TWO = 2;
}`).root.resolveAll();

console.log(rootEditionsOverriden.lookup("SomeEnum")._features)
test.same(rootEditionsOverriden.lookup("SomeEnum")._features, {
enum_type: 'OPEN',
field_presence: 'EXPLICIT',
Expand All @@ -259,7 +357,7 @@ tape.test("feature resolution inheritance file to top-level enum", function(test
test.end();
});

tape.test("feature resolution inheritance file to service and method", function(test) {
tape.test("feature resolution inheritance file to service and service to method", function(test) {
var rootEditionsOverriden = protobuf.parse(`edition = "2023";
option features.json_format = LEGACY_BEST_EFFORT;
option features.(abc).d_e = deeply_nested_false;
Expand Down

0 comments on commit 4ca95c3

Please sign in to comment.