-
-
Notifications
You must be signed in to change notification settings - Fork 286
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow disabling flat_package from file options
- Loading branch information
Showing
2 changed files
with
111 additions
and
3 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
101 changes: 101 additions & 0 deletions
101
compiler-plugin/src/test/scala/scalapb/compiler/DescriptorImplicitsSpec.scala
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,101 @@ | ||
package scalapb.compiler | ||
|
||
import org.scalatest.flatspec.AnyFlatSpec | ||
import org.scalatest.matchers.must.Matchers | ||
|
||
class DescriptorImplicitsSpec extends AnyFlatSpec with Matchers with ProtocInvocationHelper { | ||
val base = Seq( | ||
"disable_flat.proto" -> | ||
"""|syntax = "proto2"; | ||
|package disable_flat; | ||
|import "scalapb/scalapb.proto"; | ||
|option (scalapb.options) = { | ||
| flat_package: false; | ||
| scope: PACKAGE | ||
|}; | ||
|""".stripMargin, | ||
"enable_flat.proto" -> | ||
"""|syntax = "proto2"; | ||
|package enable_flat; | ||
|import "scalapb/scalapb.proto"; | ||
|option (scalapb.options) = { | ||
| flat_package: true; | ||
| scope: PACKAGE | ||
|}; | ||
|message Foo {} | ||
|""".stripMargin, | ||
"inside_disable_flat.proto" -> | ||
"""|syntax = "proto2"; | ||
|package disable_flat; | ||
|message A {}; | ||
|""".stripMargin, | ||
"inside_enable_flat.proto" -> | ||
"""|syntax = "proto2"; | ||
|package enable_flat; | ||
|message B {}; | ||
|""".stripMargin, | ||
"outside.proto" -> | ||
"""|syntax = "proto2"; | ||
|package outside; | ||
|message C {}; | ||
|""".stripMargin | ||
) | ||
|
||
"flat package" should "be overridable to false when set as generator parameter" in { | ||
val files = generateFileSet(base) | ||
val implicits = new DescriptorImplicits( | ||
GeneratorParams(flatPackage = true), | ||
files, | ||
SecondaryOutputProvider.empty | ||
) | ||
import implicits._ | ||
|
||
files | ||
.find(_.getFullName() == "inside_disable_flat.proto") | ||
.get | ||
.findMessageTypeByName("A") | ||
.scalaType | ||
.fullName must be("disable_flat.inside_disable_flat.A") | ||
files | ||
.find(_.getFullName() == "inside_enable_flat.proto") | ||
.get | ||
.findMessageTypeByName("B") | ||
.scalaType | ||
.fullName must be("enable_flat.B") | ||
files | ||
.find(_.getFullName() == "outside.proto") | ||
.get | ||
.findMessageTypeByName("C") | ||
.scalaType | ||
.fullName must be("outside.C") | ||
} | ||
|
||
"flat package" should "be overridable when not set as generator parameter" in { | ||
val files = generateFileSet(base) | ||
val implicits = new DescriptorImplicits( | ||
GeneratorParams(flatPackage = false), | ||
files, | ||
SecondaryOutputProvider.empty | ||
) | ||
import implicits._ | ||
|
||
files | ||
.find(_.getFullName() == "inside_disable_flat.proto") | ||
.get | ||
.findMessageTypeByName("A") | ||
.scalaType | ||
.fullName must be("disable_flat.inside_disable_flat.A") | ||
files | ||
.find(_.getFullName() == "inside_enable_flat.proto") | ||
.get | ||
.findMessageTypeByName("B") | ||
.scalaType | ||
.fullName must be("enable_flat.B") | ||
files | ||
.find(_.getFullName() == "outside.proto") | ||
.get | ||
.findMessageTypeByName("C") | ||
.scalaType | ||
.fullName must be("outside.outside.C") | ||
} | ||
} |