forked from scalapb/ScalaPB
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add option to block generation/access to field getters (scalapb#1140)
Add option to block generation/access to field getters
- Loading branch information
Showing
12 changed files
with
159 additions
and
49 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
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
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,15 @@ | ||
syntax = "proto3"; | ||
|
||
package scalapb.e2e; | ||
|
||
option (scalapb.options).getters = false; | ||
|
||
import "scalapb/scalapb.proto"; | ||
|
||
message NoGettersA { | ||
int32 a = 1; | ||
} | ||
|
||
message NoGetters { | ||
NoGettersA a = 1; | ||
} |
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,18 @@ | ||
syntax = "proto3"; | ||
|
||
package scalapb.e2e; | ||
|
||
option (scalapb.options) = { | ||
lenses: false | ||
getters: false | ||
}; | ||
|
||
import "scalapb/scalapb.proto"; | ||
|
||
message NoGettersOrLensesA { | ||
int32 a = 1; | ||
} | ||
|
||
message NoGettersOrLenses { | ||
NoGettersOrLensesA a = 1; | ||
} |
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,32 @@ | ||
import org.scalatest.flatspec.AnyFlatSpec | ||
import org.scalatest.matchers.must.Matchers | ||
import scalapb.e2e.no_getters._ | ||
import scalapb.e2e.no_getters_or_lenses._ | ||
import scalapb.e2e.no_lenses._ | ||
|
||
class NoGettersSpec extends AnyFlatSpec with Matchers { | ||
val noGetters = NoGetters(a = Some(NoGettersA(12))) | ||
|
||
"getters" should "not be available but lenses should function" in { | ||
noGetters.a mustBe defined | ||
assertDoesNotCompile("noGetters.getA") | ||
noGetters.update(_.a := NoGettersA(12)) | ||
} | ||
|
||
val noGettersOrLenses = NoGettersOrLenses(a = Some(NoGettersOrLensesA(12))) | ||
|
||
it should "not exist at all if lenses do not exist either" in { | ||
noGettersOrLenses.a mustBe defined | ||
|
||
assertDoesNotCompile("noGettersOrLenses.update(_.a := NoGettersOrLensesA(11))") | ||
assertDoesNotCompile("noGettersOrLenses.getA") | ||
} | ||
|
||
val noLenses = NoLenses(a = Some(NoLensesA(12)), b = 12) | ||
|
||
it should "still exist even if lenses are disabled" in { | ||
noLenses.a mustBe defined | ||
noLenses.getA.a mustBe 12 | ||
assertDoesNotCompile("noLenses.update(_.a := NoLensesA(11))") | ||
} | ||
} |
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
Oops, something went wrong.