-
-
Notifications
You must be signed in to change notification settings - Fork 285
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add an option not to wrap some values in Options when generating Scal…
…a values (#383) Add an option not to wrap some values in Options when generating Scala values Fixes #40
- Loading branch information
Showing
9 changed files
with
378 additions
and
56 deletions.
There are no files selected for viewing
160 changes: 140 additions & 20 deletions
160
compiler-plugin/src/main/java/scalapb/options/compiler/Scalapb.java
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,14 @@ | ||
syntax = "proto3"; | ||
|
||
package com.trueaccord.proto.e2e; | ||
|
||
import "scalapb/scalapb.proto"; | ||
|
||
message Tyre { | ||
int32 size = 1; | ||
} | ||
|
||
message Car { | ||
Tyre tyre1 = 1 [(scalapb.field).no_box = true]; | ||
Tyre tyre2 = 2 [(scalapb.field).no_box = 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,39 @@ | ||
import com.trueaccord.proto.e2e.NoBox | ||
import com.trueaccord.proto.e2e.no_box.Car | ||
import com.trueaccord.proto.e2e.no_box.Tyre | ||
import org.scalatest._ | ||
|
||
class NoBoxSpec extends FlatSpec with MustMatchers { | ||
val car = Car(tyre1 = Tyre(size = 10), tyre2 = Some(Tyre(size = 20))) | ||
|
||
"no_box" should "create correct methods" in { | ||
car.tyre1 must be(Tyre(size = 10)) | ||
car.tyre2 must be(Some(Tyre(size = 20))) | ||
} | ||
|
||
"fields with no_box" should "parseFrom byte array correctly" in { | ||
val serialized = car.toByteArray | ||
Car.parseFrom(serialized) must be(car) | ||
} | ||
|
||
"Scala representation of Java message with no_box field with default value" should "have that field with default value" in { | ||
val javaCar = NoBox.Car.getDefaultInstance() | ||
javaCar.hasTyre1 must be(false) | ||
|
||
val scalaCar = Car.parseFrom(javaCar.toByteArray) | ||
scalaCar.tyre1 must be(Tyre.defaultInstance) | ||
} | ||
|
||
"Java representation of Scala message with a no_box field with default value" should "not have that field" in { | ||
val scalaCar = Car(tyre1 = Tyre.defaultInstance) | ||
scalaCar.tyre1 must be(Tyre.defaultInstance) | ||
|
||
val javaCar = NoBox.Car.parseFrom(scalaCar.toByteArray) | ||
javaCar.hasTyre1 must be(false) | ||
} | ||
|
||
"Scala message with a no_box field with null value" should "throw exception when being serialized" in { | ||
val car = Car(tyre1 = null) | ||
a[NullPointerException] shouldBe thrownBy(car.toByteArray) | ||
} | ||
} |
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
Oops, something went wrong.