Skip to content

Commit

Permalink
Made .proto and parsed test file names consistent (#133)
Browse files Browse the repository at this point in the history
* Renamed proto files

* Renamed parsed files

* Updated unit tests

* Updated generated files
  • Loading branch information
krizalys authored and SandroGrzicic committed Aug 16, 2017
1 parent cd0b8be commit 31632d9
Show file tree
Hide file tree
Showing 47 changed files with 40 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Generated by ScalaBuff, the Scala Protocol Buffers compiler. DO NOT EDIT!
// source: multi_one.proto
// source: MultiOne.proto

package resources.generated

Expand Down
14 changes: 11 additions & 3 deletions scalabuff-compiler/src/test/resources/generated/MultiTwo.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Generated by ScalaBuff, the Scala Protocol Buffers compiler. DO NOT EDIT!
// source: multi_two.proto
// source: MultiTwo.proto

package resources.generated

Expand Down Expand Up @@ -33,7 +33,11 @@ final case class MultiMessageTwo (
def writeTo(output: com.google.protobuf.CodedOutputStream) {
output.writeInt32(1, requiredField)
if (optionalField.isDefined) output.writeFloat(2, optionalField.get)
for (_v <- repeatedField) output.writeString(3, _v)
var index_repeatedField = 0
while (index_repeatedField < repeatedField.length) {
output.writeString(3, repeatedField(index_repeatedField))
index_repeatedField += 1
}
if (`type`.isDefined) output.writeInt32(4, `type`.get)
if (int32Default.isDefined) output.writeInt32(5, int32Default.get)
if (stringDefault.isDefined) output.writeString(6, stringDefault.get)
Expand All @@ -44,7 +48,11 @@ final case class MultiMessageTwo (
var __size = 0
__size += computeInt32Size(1, requiredField)
if (optionalField.isDefined) __size += computeFloatSize(2, optionalField.get)
for (_v <- repeatedField) __size += computeStringSize(3, _v)
var index_repeatedField = 0
while (index_repeatedField < repeatedField.length) {
__size += computeStringSize(3, repeatedField(index_repeatedField))
index_repeatedField += 1
}
if (`type`.isDefined) __size += computeInt32Size(4, `type`.get)
if (int32Default.isDefined) __size += computeInt32Size(5, int32Default.get)
if (stringDefault.isDefined) __size += computeStringSize(6, stringDefault.get)
Expand Down
14 changes: 11 additions & 3 deletions scalabuff-compiler/src/test/resources/generated/Simple.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Generated by ScalaBuff, the Scala Protocol Buffers compiler. DO NOT EDIT!
// source: simple.proto
// source: Simple.proto

package resources.generated

Expand Down Expand Up @@ -42,7 +42,11 @@ final case class SimpleTest (
def writeTo(output: com.google.protobuf.CodedOutputStream) {
output.writeInt32(1, requiredField)
if (optionalField.isDefined) output.writeFloat(2, optionalField.get)
for (_v <- repeatedField) output.writeString(3, _v)
var index_repeatedField = 0
while (index_repeatedField < repeatedField.length) {
output.writeString(3, repeatedField(index_repeatedField))
index_repeatedField += 1
}
if (`type`.isDefined) output.writeInt32(4, `type`.get)
if (int32Default.isDefined) output.writeInt32(5, int32Default.get)
if (int32Negative.isDefined) output.writeInt32(6, int32Negative.get)
Expand All @@ -56,7 +60,11 @@ final case class SimpleTest (
var __size = 0
__size += computeInt32Size(1, requiredField)
if (optionalField.isDefined) __size += computeFloatSize(2, optionalField.get)
for (_v <- repeatedField) __size += computeStringSize(3, _v)
var index_repeatedField = 0
while (index_repeatedField < repeatedField.length) {
__size += computeStringSize(3, repeatedField(index_repeatedField))
index_repeatedField += 1
}
if (`type`.isDefined) __size += computeInt32Size(4, `type`.get)
if (int32Default.isDefined) __size += computeInt32Size(5, int32Default.get)
if (int32Negative.isDefined) __size += computeInt32Size(6, int32Negative.get)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Generated by ScalaBuff, the Scala Protocol Buffers compiler. DO NOT EDIT!
// source: package_name.proto
// source: PackageName.proto

package resources.generated.nested

Expand Down
2 changes: 1 addition & 1 deletion scalabuff-compiler/src/test/tests/ParserTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class ParserTest extends FunSuite with Matchers {
* make sure the Parser output equals the corresponding output file in the parsedDir directory.
*/
for (file <- protoDir.listFiles(protoFileFilter)) {
val fileName = file.getName.stripSuffix(".proto").camelCase
val fileName = file.getName.stripSuffix(".proto")
test(fileName) {
val output = io.Source.fromFile(new File(parsedDir + fileName + parsedExtension))
var parsed: String = null
Expand Down
30 changes: 15 additions & 15 deletions scalabuff-compiler/src/test/tests/ScalaBuffTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ class ScalaBuffTest extends FunSuite with Matchers {
val resourcesGeneratedDir = "resources" + / + "generated" + /
val generatedDir = outputDir + resourcesGeneratedDir

val testProto = "simple"
val testProto = "Simple"
val testProtoParsed = io.Source.fromFile(new File(parsedDir + testProto + parsedExtension), "UTF-8").mkString
val testProtoGenerated = io.Source.fromFile(new File(generatedDir + testProto.capitalize + ".scala"), "UTF-8").mkString

val testProtoMulti = "multi_one"
val testProtoMulti = "MultiOne"

val testProtoPacked = "packed"
val testProtoPacked = "Packed"

test("apply: simple .proto file") {
val settings = ScalaBuff.Settings(generateJsonMethod = true)
Expand Down Expand Up @@ -62,7 +62,7 @@ class ScalaBuffTest extends FunSuite with Matchers {
ScalaBuff.run(Array("--generate_json_method", simpleProto))
outputStream.toString("utf-8") should be('empty)
}
val outputFile = new File(resourcesGeneratedDir + testProto.camelCase + ".scala")
val outputFile = new File(resourcesGeneratedDir + testProto + ".scala")
outputFile should be('exists)
outputFile.deleteOnExit()
val outputFileSource = io.Source.fromFile(outputFile, "UTF-8")
Expand All @@ -84,15 +84,15 @@ class ScalaBuffTest extends FunSuite with Matchers {
output(0) should startWith("Parameters: ")
output(1) should startWith("Paths: ")
}
val outputFile = new File(outputDir + / + resourcesGeneratedDir + testProto.camelCase + ".scala")
val outputFile = new File(outputDir + / + resourcesGeneratedDir + testProto + ".scala")
outputFile should be('exists)
val outputFileSource = io.Source.fromFile(outputFile, "UTF-8")
outputFileSource.mkString should equal(testProtoGenerated)
outputFileSource.close()
}

test("run: input directory only") {
val protoFiles = Seq("multi_one", "multi_two")
val protoFiles = Seq("MultiOne", "MultiTwo")

val outputStream = new ByteArrayOutputStream()
Console.withOut(new PrintStream(outputStream)) {
Expand All @@ -101,10 +101,10 @@ class ScalaBuffTest extends FunSuite with Matchers {
}

for (proto <- protoFiles) {
val outputFile = new File(outputDir + / + resourcesGeneratedDir + proto.camelCase + ".scala")
val outputFile = new File(outputDir + / + resourcesGeneratedDir + proto + ".scala")
outputFile should be('exists)
val outputFileSource = io.Source.fromFile(outputFile, "UTF-8")
val exampleProtoGenerated = io.Source.fromFile(new File(generatedDir + proto.camelCase + ".scala"), "UTF-8").mkString
val exampleProtoGenerated = io.Source.fromFile(new File(generatedDir + proto + ".scala"), "UTF-8").mkString
outputFileSource.mkString should equal(exampleProtoGenerated)
outputFileSource.close()
}
Expand All @@ -114,25 +114,25 @@ class ScalaBuffTest extends FunSuite with Matchers {
val outputStream = new ByteArrayOutputStream()
Console.withOut(new PrintStream(outputStream)) {
ScalaBuff.run(Array("--scala_out=" + outputDir,
"--proto_path=" + parsedDir, // no proto files here, but we want to make sure multi_one.proto is found
"--proto_path=" + parsedDir, // no proto files here, but we want to make sure MultiOne.proto is found
"--proto_path=" + multiProtoDir,
"--verbose",
testProtoMulti + ".proto"))
outputStream.toString("utf-8").split("\n").size should be(1)
}

val outputFile = new File(outputDir + / + resourcesGeneratedDir + testProtoMulti.camelCase + ".scala")
val outputFile = new File(outputDir + / + resourcesGeneratedDir + testProtoMulti + ".scala")
outputFile should be('exists)
val outputFileSource = io.Source.fromFile(outputFile, "UTF-8")
val exampleProtoGenerated = io.Source.fromFile(new File(generatedDir + testProtoMulti.camelCase + ".scala"), "UTF-8").mkString
val exampleProtoGenerated = io.Source.fromFile(new File(generatedDir + testProtoMulti + ".scala"), "UTF-8").mkString
outputFileSource.mkString should equal(exampleProtoGenerated)
outputFileSource.close()
}

test("run: import across packages") {
def compile(filename: String, subFolder: Option[String]) {
val protoFile = filename + ".proto"
val scalaFile = filename.camelCase + ".scala"
val scalaFile = filename + ".scala"
val outputStream = new ByteArrayOutputStream()
Console.withOut(new PrintStream(outputStream)) {
ScalaBuff.run(Array("--scala_out=" + outputDir,
Expand All @@ -153,9 +153,9 @@ class ScalaBuffTest extends FunSuite with Matchers {
outputFileSource.close()
}

compile("package_name", Some("nested"))
compile("import_packages", None)
compile("import_use_fullname", None)
compile("PackageName", Some("nested"))
compile("ImportPackages", None)
compile("ImportUseFullname", None)
}

test("run: unknown option") {
Expand Down

0 comments on commit 31632d9

Please sign in to comment.