-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support most of edition 2023 presence semantics (#326)
- Loading branch information
1 parent
fcfd24c
commit f287ade
Showing
6 changed files
with
213 additions
and
1 deletion.
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
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
36 changes: 36 additions & 0 deletions
36
...kt-generation/src/main/proto/protokt/v1/testing/edition_2023_presence_file_explicit.proto
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,36 @@ | ||
/* | ||
* Copyright (c) 2024 Toast, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
edition = "2023"; | ||
|
||
package protokt.v1.testing; | ||
|
||
option features.field_presence = EXPLICIT; | ||
|
||
import "google/protobuf/empty.proto"; | ||
|
||
message TestFileExplicit { | ||
int32 foo = 1; | ||
google.protobuf.Empty bar = 2; | ||
|
||
int32 baz = 3 [features.field_presence = EXPLICIT]; | ||
google.protobuf.Empty qux = 4 [features.field_presence = EXPLICIT]; | ||
|
||
int32 corge = 5 [features.field_presence = IMPLICIT]; | ||
// not allowed: google.protobuf.Empty grault = 6 [features.field_presence = IMPLICIT]; | ||
|
||
int32 garply = 7 [features.field_presence = LEGACY_REQUIRED]; | ||
google.protobuf.Empty thud = 8 [features.field_presence = LEGACY_REQUIRED]; | ||
} |
36 changes: 36 additions & 0 deletions
36
...kt-generation/src/main/proto/protokt/v1/testing/edition_2023_presence_file_implicit.proto
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,36 @@ | ||
/* | ||
* Copyright (c) 2024 Toast, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
edition = "2023"; | ||
|
||
package protokt.v1.testing; | ||
|
||
option features.field_presence = IMPLICIT; | ||
|
||
import "google/protobuf/empty.proto"; | ||
|
||
message TestFileImplicit { | ||
int32 foo = 1; | ||
google.protobuf.Empty bar = 2; | ||
|
||
int32 baz = 3 [features.field_presence = EXPLICIT]; | ||
google.protobuf.Empty qux = 4 [features.field_presence = EXPLICIT]; | ||
|
||
int32 corge = 5 [features.field_presence = IMPLICIT]; | ||
// not allowed: google.protobuf.Empty grault = 6 [features.field_presence = IMPLICIT]; | ||
|
||
int32 garply = 7 [features.field_presence = LEGACY_REQUIRED]; | ||
google.protobuf.Empty thud = 8 [features.field_presence = LEGACY_REQUIRED]; | ||
} |
20 changes: 20 additions & 0 deletions
20
...ration/src/main/proto/protokt/v1/testing/edition_2023_presence_file_legacy_required.proto
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,20 @@ | ||
/* | ||
* Copyright (c) 2024 Toast, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
edition = "2023"; | ||
|
||
package protokt.v1.testing; | ||
|
||
// not allowed: option features.field_presence = LEGACY_REQUIRED; |
104 changes: 104 additions & 0 deletions
104
testing/protokt-generation/src/test/kotlin/protokt/v1/testing/Edition2023PresenceTest.kt
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,104 @@ | ||
/* | ||
* Copyright (c) 2024 Toast, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package protokt.v1.testing | ||
|
||
import com.google.common.truth.Truth.assertThat | ||
import org.junit.jupiter.api.Test | ||
|
||
class Edition2023PresenceTest { | ||
@Test | ||
fun `file with implicit presence and no field features has correct behavior on primitive`() { | ||
assertThat(TestFileImplicit::class.propertyIsMarkedNullable("foo")).isFalse() | ||
assertThat(TestFileImplicit {}.foo).isEqualTo(0) | ||
|
||
assertThat(TestFileImplicit::class.propertyIsMarkedNullable("corge")).isFalse() | ||
assertThat(TestFileImplicit {}.corge).isEqualTo(0) | ||
} | ||
|
||
@Test | ||
fun `file with implicit presence and no field features has correct behavior on message`() { | ||
assertThat(TestFileImplicit::class.propertyIsMarkedNullable("bar")).isTrue() | ||
assertThat(TestFileImplicit {}.bar).isNull() | ||
} | ||
|
||
@Test | ||
fun `file with implicit presence and field with explicit presence has correct behavior on primitive`() { | ||
assertThat(TestFileImplicit::class.propertyIsMarkedNullable("baz")).isTrue() | ||
assertThat(TestFileImplicit {}.baz).isNull() | ||
} | ||
|
||
@Test | ||
fun `file with implicit presence and field with explicit presence has correct behavior on message`() { | ||
assertThat(TestFileImplicit::class.propertyIsMarkedNullable("qux")).isTrue() | ||
assertThat(TestFileImplicit {}.qux).isNull() | ||
} | ||
|
||
@Test | ||
fun `file with implicit presence and field with legacy required presence has correct behavior on primitive`() { | ||
assertThat(TestFileImplicit::class.propertyIsMarkedNullable("garply")).isFalse() | ||
assertThat(TestFileImplicit {}.garply).isEqualTo(0) | ||
} | ||
|
||
@Test | ||
fun `file with implicit presence and field with legacy required for message type`() { | ||
// protokt doesn't support non-null message types | ||
assertThat(TestFileImplicit::class.propertyIsMarkedNullable("thud")).isTrue() | ||
assertThat(TestFileImplicit {}.thud).isNull() | ||
} | ||
|
||
@Test | ||
fun `file with explicit presence and no field features has correct behavior on primitive`() { | ||
assertThat(TestFileImplicit::class.propertyIsMarkedNullable("foo")).isFalse() | ||
assertThat(TestFileImplicit {}.foo).isEqualTo(0) | ||
} | ||
|
||
@Test | ||
fun `file with explicit presence and no field features has correct behavior on message`() { | ||
assertThat(TestFileImplicit::class.propertyIsMarkedNullable("bar")).isTrue() | ||
assertThat(TestFileImplicit {}.bar).isNull() | ||
} | ||
|
||
@Test | ||
fun `file with explicit presence and field with explicit presence has correct behavior on primitive`() { | ||
assertThat(TestFileImplicit::class.propertyIsMarkedNullable("baz")).isTrue() | ||
assertThat(TestFileImplicit {}.baz).isNull() | ||
} | ||
|
||
@Test | ||
fun `file with explicit presence and field with explicit presence has correct behavior on message`() { | ||
assertThat(TestFileImplicit::class.propertyIsMarkedNullable("qux")).isTrue() | ||
assertThat(TestFileImplicit {}.qux).isNull() | ||
} | ||
|
||
@Test | ||
fun `file with explicit presence and field with implicit presence has correct behavior on primitive`() { | ||
assertThat(TestFileImplicit::class.propertyIsMarkedNullable("corge")).isFalse() | ||
assertThat(TestFileImplicit {}.corge).isEqualTo(0) | ||
} | ||
|
||
@Test | ||
fun `file with explicit presence and field with legacy required presence has correct behavior on primitive`() { | ||
assertThat(TestFileImplicit::class.propertyIsMarkedNullable("garply")).isFalse() | ||
assertThat(TestFileImplicit {}.garply).isEqualTo(0) | ||
} | ||
|
||
@Test | ||
fun `file with explicit presence and field with legacy required for message type`() { | ||
// protokt doesn't support non-null message types | ||
assertThat(TestFileImplicit::class.propertyIsMarkedNullable("thud")).isTrue() | ||
assertThat(TestFileImplicit {}.thud).isNull() | ||
} | ||
} |