diff --git a/avrohugger-core/src/main/scala/Generator.scala b/avrohugger-core/src/main/scala/Generator.scala index b8f7a195..a45bafc2 100644 --- a/avrohugger-core/src/main/scala/Generator.scala +++ b/avrohugger-core/src/main/scala/Generator.scala @@ -2,21 +2,21 @@ package avrohugger import avrohugger.format.abstractions.SourceFormat import avrohugger.format._ -import avrohugger.generators.{FileGenerator, StringGenerator} -import avrohugger.input.parsers.{FileInputParser, StringInputParser} +import avrohugger.generators.{ FileGenerator, StringGenerator } +import avrohugger.input.parsers.{ FileInputParser, StringInputParser } import avrohugger.matchers.TypeMatcher import avrohugger.types.AvroScalaTypes -import avrohugger.stores.{ClassStore, SchemaStore} -import org.apache.avro.{Protocol, Schema} +import avrohugger.stores.{ ClassStore, SchemaStore } +import org.apache.avro.{ Protocol, Schema } import java.io.File // Unable to overload this class' methods because outDir uses a default value case class Generator(format: SourceFormat, - avroScalaCustomTypes: Option[AvroScalaTypes] = None, - avroScalaCustomNamespace: Map[String, String] = Map.empty, - restrictedFieldNumber: Boolean = false, - classLoader: ClassLoader = Thread.currentThread.getContextClassLoader, - targetScalaPartialVersion: String = avrohugger.internal.ScalaVersion.version) { + avroScalaCustomTypes: Option[AvroScalaTypes] = None, + avroScalaCustomNamespace: Map[String, String] = Map.empty, + restrictedFieldNumber: Boolean = false, + classLoader: ClassLoader = Thread.currentThread.getContextClassLoader, + targetScalaPartialVersion: String = avrohugger.internal.ScalaVersion.version) { val avroScalaTypes = avroScalaCustomTypes.getOrElse(format.defaultTypes) val defaultOutputDir = "target/generated-sources" @@ -25,20 +25,22 @@ case class Generator(format: SourceFormat, lazy val schemaParser = new Schema.Parser val classStore = new ClassStore val schemaStore = new SchemaStore + val fileGenerator = new FileGenerator + val stringGenerator = new StringGenerator val typeMatcher = new TypeMatcher(avroScalaTypes, avroScalaCustomNamespace) //////////////// methods for writing definitions out to file ///////////////// def schemaToFile( schema: Schema, outDir: String = defaultOutputDir): Unit = { - FileGenerator.schemaToFile( + fileGenerator.schemaToFile( schema, outDir, format, classStore, schemaStore, typeMatcher, restrictedFieldNumber, targetScalaPartialVersion) } def protocolToFile( protocol: Protocol, outDir: String = defaultOutputDir): Unit = { - FileGenerator.protocolToFile( + fileGenerator.protocolToFile( protocol, outDir, format, @@ -52,7 +54,7 @@ case class Generator(format: SourceFormat, def stringToFile( schemaStr: String, outDir: String = defaultOutputDir): Unit = { - FileGenerator.stringToFile( + fileGenerator.stringToFile( schemaStr, outDir, format, @@ -67,7 +69,7 @@ case class Generator(format: SourceFormat, def fileToFile( inFile: File, outDir: String = defaultOutputDir): Unit = { - FileGenerator.fileToFile( + fileGenerator.fileToFile( inFile, outDir, format, @@ -82,17 +84,17 @@ case class Generator(format: SourceFormat, //////// methods for writing to a list of definitions in String format /////// def schemaToStrings(schema: Schema): List[String] = { - StringGenerator.schemaToStrings( + stringGenerator.schemaToStrings( schema, format, classStore, schemaStore, typeMatcher, restrictedFieldNumber, targetScalaPartialVersion) } def protocolToStrings(protocol: Protocol): List[String] = { - StringGenerator.protocolToStrings( + stringGenerator.protocolToStrings( protocol, format, classStore, schemaStore, typeMatcher, restrictedFieldNumber, targetScalaPartialVersion) } def stringToStrings(schemaStr: String): List[String] = { - StringGenerator.stringToStrings( + stringGenerator.stringToStrings( schemaStr, format, classStore, @@ -104,7 +106,7 @@ case class Generator(format: SourceFormat, } def fileToStrings(inFile: File): List[String] = { - StringGenerator.fileToStrings( + stringGenerator.fileToStrings( inFile, format, classStore, diff --git a/avrohugger-core/src/main/scala/format/abstractions/Importer.scala b/avrohugger-core/src/main/scala/format/abstractions/Importer.scala index 71392370..92fa2bbc 100644 --- a/avrohugger-core/src/main/scala/format/abstractions/Importer.scala +++ b/avrohugger-core/src/main/scala/format/abstractions/Importer.scala @@ -44,38 +44,38 @@ trait Importer { // gets enum schemas which may be dependencies def getEnumSchemas( topLevelSchemas: List[Schema], - alreadyImported: List[Schema] = List.empty[Schema]): List[Schema] = { - def nextSchemas(s: Schema, us: List[Schema]) = getRecordSchemas(List(s), us) + alreadyImported: Set[Schema] = Set.empty[Schema]): List[Schema] = { + def nextSchemas(s: Schema, us: Set[Schema]) = getRecordSchemas(List(s), us) + topLevelSchemas .flatMap(schema => { schema.getType match { case RECORD => - val fieldSchemasWithChildSchemas = getFieldSchemas(schema).toSeq - .filter(s => alreadyImported.contains(s)) - .flatMap(s => nextSchemas(s, alreadyImported :+ s)) + val fieldSchemasWithChildSchemas = getFieldSchemas(schema).toSet + .intersect(alreadyImported) + .flatMap(s => nextSchemas(s, alreadyImported + s)) Seq(schema) ++ fieldSchemasWithChildSchemas case ENUM => Seq(schema) case UNION => schema.getTypes().asScala - .find(s => s.getType != NULL).toSeq - .filter(s => alreadyImported.contains(s)) - .flatMap(s => nextSchemas(schema, alreadyImported :+ s)) + .find(s => s.getType != NULL).toSet + .intersect(alreadyImported) + .flatMap(s => nextSchemas(schema, alreadyImported + s)) case MAP => - Seq(schema.getValueType) - .filter(s => alreadyImported.contains(s)) - .flatMap(s => nextSchemas(schema, alreadyImported :+ s)) + Set(schema.getValueType) + .intersect(alreadyImported) + .flatMap(s => nextSchemas(schema, alreadyImported + s)) case ARRAY => - Seq(schema.getElementType) - .filter(s => alreadyImported.contains(s)) - .flatMap(s => nextSchemas(schema, alreadyImported :+ s)) + Set(schema.getElementType) + .intersect(alreadyImported) + .flatMap(s => nextSchemas(schema, alreadyImported + s)) case _ => Seq.empty[Schema] } }) .filter(schema => schema.getType == ENUM) .distinct - .toList } def getFixedSchemas(topLevelSchemas: List[Schema]): List[Schema] = @@ -88,8 +88,7 @@ trait Importer { }) .filter(_.getType == FIXED) .distinct - .toList - + def getFieldSchemas(schema: Schema): List[Schema] = { schema.getFields().asScala.toList.map(field => field.schema) } @@ -126,8 +125,8 @@ trait Importer { def requiresImportDef(schema: Schema): Boolean = { (isRecord(schema) || isEnum(schema) || isFixed(schema)) && - checkNamespace(schema).isDefined && - checkNamespace(schema) != namespace + checkNamespace(schema).isDefined && + checkNamespace(schema) != namespace } recordSchemas @@ -135,38 +134,39 @@ trait Importer { .groupBy(schema => checkNamespace(schema).getOrElse(schema.getNamespace)) .toList .map(group => group match { - case(packageName, fields) => asImportDef(packageName, fields) + case (packageName, fields) => asImportDef(packageName, fields) }) } // gets record schemas which may be dependencies def getRecordSchemas( topLevelSchemas: List[Schema], - alreadyImported: List[Schema] = List.empty[Schema]): List[Schema] = { - def nextSchemas(s: Schema, us: List[Schema]) = getRecordSchemas(List(s), us) + alreadyImported: Set[Schema] = Set.empty[Schema]): List[Schema] = { + def nextSchemas(s: Schema, us: Set[Schema]) = getRecordSchemas(List(s), us) + topLevelSchemas .flatMap(schema => { schema.getType match { case RECORD => - val fieldSchemasWithChildSchemas = getFieldSchemas(schema).toSeq - .filter(s => alreadyImported.contains(s)) - .flatMap(s => nextSchemas(s, alreadyImported :+ s)) + val fieldSchemasWithChildSchemas = getFieldSchemas(schema).toSet + .intersect(alreadyImported) + .flatMap(s => nextSchemas(s, alreadyImported + s)) Seq(schema) ++ fieldSchemasWithChildSchemas case ENUM => Seq(schema) case UNION => schema.getTypes().asScala - .find(s => s.getType != NULL).toSeq - .filter(s => alreadyImported.contains(s)) - .flatMap(s => nextSchemas(schema, alreadyImported :+ s)) + .find(s => s.getType != NULL).toSet + .intersect(alreadyImported) + .flatMap(s => nextSchemas(schema, alreadyImported + s)) case MAP => - Seq(schema.getValueType) - .filter(s => alreadyImported.contains(s)) - .flatMap(s => nextSchemas(schema, alreadyImported :+ s)) + Set(schema.getValueType) + .intersect(alreadyImported) + .flatMap(s => nextSchemas(schema, alreadyImported + s)) case ARRAY => - Seq(schema.getElementType) - .filter(s => alreadyImported.contains(s)) - .flatMap(s => nextSchemas(schema, alreadyImported :+ s)) + Set(schema.getElementType) + .intersect(alreadyImported) + .flatMap(s => nextSchemas(schema, alreadyImported + s)) case _ => Seq.empty[Schema] } @@ -177,23 +177,23 @@ trait Importer { } def getTopLevelSchemas( - schemaOrProtocol: Either[Schema, Protocol], + schemaOrProtocol: Either[Schema, Protocol], schemaStore: SchemaStore, typeMatcher: TypeMatcher): List[Schema] = { schemaOrProtocol match { case Left(schema) => - schema::(NestedSchemaExtractor.getNestedSchemas(schema, schemaStore, typeMatcher)) + schema :: (NestedSchemaExtractor.getNestedSchemas(schema, schemaStore, typeMatcher)) case Right(protocol) => protocol.getTypes().asScala.toList.flatMap(schema => { - schema::(NestedSchemaExtractor.getNestedSchemas(schema, schemaStore, typeMatcher)) + schema :: (NestedSchemaExtractor.getNestedSchemas(schema, schemaStore, typeMatcher)) }) } } - def isFixed(schema: Schema): Boolean = ( schema.getType == FIXED ) + def isFixed(schema: Schema): Boolean = (schema.getType == FIXED) - def isEnum(schema: Schema): Boolean = ( schema.getType == ENUM ) + def isEnum(schema: Schema): Boolean = (schema.getType == ENUM) - def isRecord(schema: Schema): Boolean = ( schema.getType == RECORD ) + def isRecord(schema: Schema): Boolean = (schema.getType == RECORD) } diff --git a/avrohugger-core/src/main/scala/format/abstractions/SourceFormat.scala b/avrohugger-core/src/main/scala/format/abstractions/SourceFormat.scala index 54ebf5f8..5cfd3618 100644 --- a/avrohugger-core/src/main/scala/format/abstractions/SourceFormat.scala +++ b/avrohugger-core/src/main/scala/format/abstractions/SourceFormat.scala @@ -4,18 +4,18 @@ package abstractions import avrohugger.matchers.TypeMatcher import avrohugger.models.CompilationUnit -import avrohugger.stores.{ClassStore, SchemaStore} +import avrohugger.stores.{ ClassStore, SchemaStore } import avrohugger.types._ -import org.apache.avro.Schema.Type.{ENUM, FIXED, RECORD} -import org.apache.avro.{Protocol, Schema} +import org.apache.avro.Schema.Type.{ ENUM, FIXED, RECORD } +import org.apache.avro.{ Protocol, Schema } import treehugger.forest._ import definitions._ -import java.io.{FileNotFoundException, IOException} -import java.nio.file.{Files, Path, Paths, StandardOpenOption} +import java.io.{ FileNotFoundException, IOException } +import java.nio.file.{ Files, Path, Paths, StandardOpenOption } import scala.jdk.CollectionConverters._ -/** Parent to all ouput formats +/** Parent to all output formats * * _ABSTRACT MEMBERS_: to be implemented by a subclass * asCompilationUnits @@ -51,7 +51,7 @@ trait SourceFormat { typeMatcher: TypeMatcher, restrictedFields: Boolean, targetScalaPartialVersion: String): List[CompilationUnit] - + def compile( classStore: ClassStore, namespace: Option[String], @@ -61,7 +61,7 @@ trait SourceFormat { typeMatcher: TypeMatcher, restrictedFields: Boolean, targetScalaPartialVersion: String): Unit - + val defaultTypes: AvroScalaTypes def getName( @@ -81,13 +81,14 @@ trait SourceFormat { schemaOrProtocol: Either[Schema, Protocol], typeMatcher: TypeMatcher): String = { val enumType = typeMatcher.avroScalaTypes.`enum` + def enumExt: String = enumType match { case JavaEnum => ".java" case ScalaCaseObjectEnum => ".scala" case ScalaEnumeration => ".scala" case EnumAsScalaString => sys.error("Only RECORD and ENUM can be top-level definitions") } - + schemaOrProtocol match { case Left(schema) => schema.getType match { case RECORD => ".scala" @@ -97,7 +98,7 @@ trait SourceFormat { } case Right(protocol) => ".scala" } - + } def getFilePath( @@ -105,28 +106,26 @@ trait SourceFormat { schemaOrProtocol: Either[Schema, Protocol], maybeOutDir: Option[String], typeMatcher: TypeMatcher): Option[Path] = { - maybeOutDir match { - case Some(outDir) => { - val folderPath: Path = Paths.get { - if (namespace.isDefined) { - s"$outDir/${namespace.get.toString.replace('.', '/')}" - } - else outDir + maybeOutDir.map { outDir => + val folderPath: Path = Paths.get { + if (namespace.isDefined) { + s"$outDir/${namespace.get.replace('.', '/')}" } - val ext = fileExt(schemaOrProtocol, typeMatcher) - val fileName = getName(schemaOrProtocol, typeMatcher) + ext - if (!Files.exists(folderPath)) Files.createDirectories(folderPath) - Some(Paths.get(s"$folderPath/$fileName")) + else outDir } - case None => None + val ext = fileExt(schemaOrProtocol, typeMatcher) + val fileName = getName(schemaOrProtocol, typeMatcher) + ext + if (!Files.exists(folderPath)) Files.createDirectories(folderPath) + Paths.get(s"$folderPath/$fileName") } - } def getLocalSubtypes(protocol: Protocol): List[Schema] = { val protocolNS = protocol.getNamespace val types = protocol.getTypes().asScala.toList + def isTopLevelNamespace(schema: Schema) = schema.getNamespace == protocolNS + types.filter(isTopLevelNamespace) } @@ -186,11 +185,10 @@ trait SourceFormat { val classSymbol = RootClass.newClass(typeName) classStore.accept(schema, classSymbol) } + schemaOrProtocol match { case Left(schema) => registerSchema(schema) - case Right(protocol) => protocol.getTypes().asScala.foreach(schema => { - registerSchema(schema) - }) + case Right(protocol) => protocol.getTypes().asScala.foreach(registerSchema) } } @@ -202,18 +200,18 @@ trait SourceFormat { case _ => sys.error("Only RECORD, ENUM or FIXED can be top-level definitions") } } - + // From: https://github.com/apache/avro/blob/33d495840c896b693b7f37b5ec786ac1acacd3b4/lang/java/avro/src/main/java/org/apache/avro/specific/SpecificData.java#L70 val RESERVED_WORDS: Set[String] = Set("abstract", "assert", "boolean", "break", "byte", "case", "catch", - "char", "class", "const", "continue", "default", "do", "double", - "else", "enum", "extends", "false", "final", "finally", "float", - "for", "goto", "if", "implements", "import", "instanceof", "int", - "interface", "long", "native", "new", "null", "package", "private", - "protected", "public", "return", "short", "static", "strictfp", - "super", "switch", "synchronized", "this", "throw", "throws", - "transient", "true", "try", "void", "volatile", "while", - /* classnames use internally by the avro code generator */ - "Builder") + "char", "class", "const", "continue", "default", "do", "double", + "else", "enum", "extends", "false", "final", "finally", "float", + "for", "goto", "if", "implements", "import", "instanceof", "int", + "interface", "long", "native", "new", "null", "package", "private", + "protected", "public", "return", "short", "static", "strictfp", + "super", "switch", "synchronized", "this", "throw", "throws", + "transient", "true", "try", "void", "volatile", "while", + /* classnames use internally by the avro code generator */ + "Builder") def writeToFile(compilationUnit: CompilationUnit): Unit = { val path = compilationUnit.maybeFilePath match { diff --git a/avrohugger-core/src/main/scala/generators/FileGenerator.scala b/avrohugger-core/src/main/scala/generators/FileGenerator.scala index fa7eca59..53431c44 100644 --- a/avrohugger-core/src/main/scala/generators/FileGenerator.scala +++ b/avrohugger-core/src/main/scala/generators/FileGenerator.scala @@ -2,20 +2,16 @@ package avrohugger package generators import avrohugger.format.abstractions.SourceFormat -import avrohugger.input.DependencyInspector -import avrohugger.input.NestedSchemaExtractor -// import avrohugger.input.reflectivecompilation.schemagen._ -import avrohugger.input.parsers.{ FileInputParser, StringInputParser} +import avrohugger.input.{ DependencyInspector, NestedSchemaExtractor } +import avrohugger.input.parsers.{ FileInputParser, StringInputParser } import avrohugger.matchers.TypeMatcher import avrohugger.stores.{ ClassStore, SchemaStore } - -import java.io.{File, FileNotFoundException, IOException} - import org.apache.avro.{ Protocol, Schema } -import org.apache.avro.Schema.Type.ENUM + +import java.io.File // Unable to overload this class' methods because outDir uses a default value -private[avrohugger] object FileGenerator { +private[avrohugger] class FileGenerator { def schemaToFile( schema: Schema, @@ -61,16 +57,12 @@ private[avrohugger] object FileGenerator { restrictedFields: Boolean, targetScalaPartialVersion: String): Unit = { val schemaOrProtocols = stringParser.getSchemaOrProtocols(str, schemaStore) - schemaOrProtocols.foreach(schemaOrProtocol => { - schemaOrProtocol match { - case Left(schema) => { - schemaToFile(schema, outDir, format, classStore, schemaStore, typeMatcher, restrictedFields, targetScalaPartialVersion) - } - case Right(protocol) => { - protocolToFile(protocol, outDir, format, classStore, schemaStore, typeMatcher, restrictedFields, targetScalaPartialVersion) - } - } - }) + schemaOrProtocols.foreach { + case Left(schema) => + schemaToFile(schema, outDir, format, classStore, schemaStore, typeMatcher, restrictedFields, targetScalaPartialVersion) + case Right(protocol) => + protocolToFile(protocol, outDir, format, classStore, schemaStore, typeMatcher, restrictedFields, targetScalaPartialVersion) + } } def fileToFile( @@ -86,14 +78,12 @@ private[avrohugger] object FileGenerator { targetScalaPartialVersion: String): Unit = { val schemaOrProtocols: List[Either[Schema, Protocol]] = fileParser.getSchemaOrProtocols(inFile, format, classStore, classLoader) - schemaOrProtocols.foreach(schemaOrProtocol => schemaOrProtocol match { - case Left(schema) => { + schemaOrProtocols.foreach { + case Left(schema) => schemaToFile(schema, outDir, format, classStore, schemaStore, typeMatcher, restrictedFields, targetScalaPartialVersion) - } - case Right(protocol) => { + case Right(protocol) => protocolToFile(protocol, outDir, format, classStore, schemaStore, typeMatcher, restrictedFields, targetScalaPartialVersion) - } - }) + } } } diff --git a/avrohugger-core/src/main/scala/generators/StringGenerator.scala b/avrohugger-core/src/main/scala/generators/StringGenerator.scala index 3aa41e8b..797cfd6c 100644 --- a/avrohugger-core/src/main/scala/generators/StringGenerator.scala +++ b/avrohugger-core/src/main/scala/generators/StringGenerator.scala @@ -4,18 +4,16 @@ package generators import avrohugger.format.abstractions.SourceFormat import avrohugger.input.DependencyInspector import avrohugger.input.NestedSchemaExtractor -// import avrohugger.input.reflectivecompilation.schemagen._ -import avrohugger.input.parsers.{ FileInputParser, StringInputParser} +import avrohugger.input.parsers.{ FileInputParser, StringInputParser } import avrohugger.matchers.TypeMatcher import avrohugger.stores.{ ClassStore, SchemaStore } -import java.io.{File, FileNotFoundException, IOException} +import java.io.{ File, FileNotFoundException, IOException } import org.apache.avro.{ Protocol, Schema } -import org.apache.avro.Schema.Type.ENUM // Unable to overload this class' methods because outDir uses a default value -private[avrohugger] object StringGenerator { +private[avrohugger] class StringGenerator { def schemaToStrings( schema: Schema, @@ -31,9 +29,7 @@ private[avrohugger] object StringGenerator { //reversed to process nested classes first val compilationUnits = topLevels.reverse.distinct.flatMap(schema => { // pass in the top-level schema's namespace if the nested schema has none - val maybeNS = DependencyInspector.getReferredNamespace(schema) orElse { - maybeNamespace - } + val maybeNS = DependencyInspector.getReferredNamespace(schema).orElse(maybeNamespace) format.asCompilationUnits( classStore, maybeNS, @@ -78,16 +74,12 @@ private[avrohugger] object StringGenerator { restrictedFields: Boolean, targetScalaPartialVersion: String): List[String] = { val schemaOrProtocols = stringParser.getSchemaOrProtocols(str, schemaStore) - val codeStrings = schemaOrProtocols.flatMap(schemaOrProtocol => { - schemaOrProtocol match { - case Left(schema) => { - schemaToStrings(schema, format, classStore, schemaStore, typeMatcher, restrictedFields, targetScalaPartialVersion) - } - case Right(protocol) => { - protocolToStrings(protocol, format, classStore, schemaStore, typeMatcher, restrictedFields, targetScalaPartialVersion) - } - } - }).distinct + val codeStrings = schemaOrProtocols.flatMap { + case Left(schema) => + schemaToStrings(schema, format, classStore, schemaStore, typeMatcher, restrictedFields, targetScalaPartialVersion) + case Right(protocol) => + protocolToStrings(protocol, format, classStore, schemaStore, typeMatcher, restrictedFields, targetScalaPartialVersion) + }.distinct // reset the schema store after processing the whole submission schemaStore.schemas.clear() codeStrings @@ -104,16 +96,13 @@ private[avrohugger] object StringGenerator { restrictedFields: Boolean, targetScalaPartialVersion: String): List[String] = { try { - val schemaOrProtocols: List[Either[Schema, Protocol]] = - fileParser.getSchemaOrProtocols(inFile, format, classStore, classLoader) - schemaOrProtocols.flatMap(schemaOrProtocol => schemaOrProtocol match { - case Left(schema) => { + val schemaOrProtocols: List[Either[Schema, Protocol]] = fileParser.getSchemaOrProtocols(inFile, format, classStore, classLoader) + schemaOrProtocols.flatMap { + case Left(schema) => schemaToStrings(schema, format, classStore, schemaStore, typeMatcher, restrictedFields, targetScalaPartialVersion) - } - case Right(protocol) => { + case Right(protocol) => protocolToStrings(protocol, format, classStore, schemaStore, typeMatcher, restrictedFields, targetScalaPartialVersion) - } - }) + } } catch { case ex: FileNotFoundException => sys.error("File not found:" + ex) @@ -123,13 +112,14 @@ private[avrohugger] object StringGenerator { def removeExtraWarning(codeStr: String): String = { - if (codeStr.startsWith("""/** MACHINE-GENERATED FROM AVRO SCHEMA. DO NOT EDIT DIRECTLY */ - |/** - | * Autogenerated by Avro - | * - | * DO NOT EDIT DIRECTLY - | */ - |""".stripMargin)) + if (codeStr.startsWith( + """/** MACHINE-GENERATED FROM AVRO SCHEMA. DO NOT EDIT DIRECTLY */ + |/** + | * Autogenerated by Avro + | * + | * DO NOT EDIT DIRECTLY + | */ + |""".stripMargin)) codeStr.replace("/** MACHINE-GENERATED FROM AVRO SCHEMA. DO NOT EDIT DIRECTLY */\n", "") else codeStr } diff --git a/avrohugger-core/src/test/scala/avrohugger/SeqSpec.scala b/avrohugger-core/src/test/scala/avrohugger/SeqSpec.scala index a8817522..38f3ff66 100644 --- a/avrohugger-core/src/test/scala/avrohugger/SeqSpec.scala +++ b/avrohugger-core/src/test/scala/avrohugger/SeqSpec.scala @@ -6,6 +6,7 @@ import avrohugger.types._ import org.specs2.Specification import org.specs2.matcher.MatchResult import org.specs2.specification.core.SpecStructure +import util.Util.LineEndingAmbiguousMatcherString trait SeqSpec { self: Specification => @@ -43,7 +44,7 @@ trait SeqSpec { val expectedDep1 = util.Util.readFile(expectedOutput(formatType, outputArrayType)).dropRight(1) - dep1 === expectedDep1 + dep1 ===/ expectedDep1 } @@ -60,7 +61,7 @@ trait SeqSpec { val expectedDep1 = util.Util.readFile(expectedOutput(formatType, outputArrayType)).dropRight(1) - dep1 === expectedDep1 + dep1 ===/ expectedDep1 } } diff --git a/avrohugger-core/src/test/scala/specific/SpecificCommentsSpec.scala b/avrohugger-core/src/test/scala/specific/SpecificCommentsSpec.scala index f1735ccf..801cd039 100644 --- a/avrohugger-core/src/test/scala/specific/SpecificCommentsSpec.scala +++ b/avrohugger-core/src/test/scala/specific/SpecificCommentsSpec.scala @@ -2,6 +2,7 @@ package avrohugger import avrohugger.format.SpecificRecord import org.specs2._ +import util.Util.LineEndingAmbiguousMatcherString class SpecificCommentsSpec extends Specification { @@ -16,48 +17,48 @@ class SpecificCommentsSpec extends Specification { def e1 = { val infile = new java.io.File("avrohugger-core/src/test/avro/comments1.avdl") - val gen = new Generator(SpecificRecord) + val gen = Generator(SpecificRecord) val outDir = gen.defaultOutputDir + "/specific/" gen.fileToFile(infile, outDir) val sourceRecord = scala.io.Source.fromFile(s"$outDir/com/example/NoSpaces1.scala").mkString - sourceRecord ==== util.Util.readFile("avrohugger-core/src/test/expected/comments/specific/NoSpaces1.scala") + sourceRecord ===/ util.Util.readFile("avrohugger-core/src/test/expected/comments/specific/NoSpaces1.scala") } def e2 = { val infile = new java.io.File("avrohugger-core/src/test/avro/comments2.avdl") - val gen = new Generator(SpecificRecord) + val gen = Generator(SpecificRecord) val outDir = gen.defaultOutputDir + "/specific/" gen.fileToFile(infile, outDir) val sourceRecord = scala.io.Source.fromFile(s"$outDir/com/example/NoSpaces2.scala").mkString - sourceRecord ==== util.Util.readFile("avrohugger-core/src/test/expected/comments/specific/NoSpaces2.scala") + sourceRecord ===/ util.Util.readFile("avrohugger-core/src/test/expected/comments/specific/NoSpaces2.scala") } def e3 = { val infile = new java.io.File("avrohugger-core/src/test/avro/comments3.avdl") - val gen = new Generator(SpecificRecord) + val gen = Generator(SpecificRecord) val outDir = gen.defaultOutputDir + "/specific/" gen.fileToFile(infile, outDir) val sourceRecord = scala.io.Source.fromFile(s"$outDir/com/example/NoSpaces3.scala").mkString - sourceRecord ==== util.Util.readFile("avrohugger-core/src/test/expected/comments/specific/NoSpaces3.scala") + sourceRecord ===/ util.Util.readFile("avrohugger-core/src/test/expected/comments/specific/NoSpaces3.scala") } def e4 = { val infile = new java.io.File("avrohugger-core/src/test/avro/comments4.avdl") val myAvroScalaCustomTypes = SpecificRecord.defaultTypes.copy(protocol = types.ScalaADT) - val gen = new Generator(format = SpecificRecord, avroScalaCustomTypes = Some(myAvroScalaCustomTypes)) + val gen = Generator(format = SpecificRecord, avroScalaCustomTypes = Some(myAvroScalaCustomTypes)) val outDir = gen.defaultOutputDir + "/specific/" gen.fileToFile(infile, outDir) val sourceRecord = scala.io.Source.fromFile(s"$outDir/com/example/Example4.scala").mkString - sourceRecord ==== util.Util.readFile("avrohugger-core/src/test/expected/comments/specific/Example4.scala") + sourceRecord ===/ util.Util.readFile("avrohugger-core/src/test/expected/comments/specific/Example4.scala") } def e5 = { val infile = new java.io.File("avrohugger-core/src/test/avro/comments5.avdl") - val gen = new Generator(SpecificRecord) + val gen = Generator(SpecificRecord) val outDir = gen.defaultOutputDir + "/specific/" gen.fileToFile(infile, outDir) val sourceRecord = scala.io.Source.fromFile(s"$outDir/com/example/Example5.scala").mkString - sourceRecord ==== util.Util.readFile("avrohugger-core/src/test/expected/comments/specific/Example5.scala") + sourceRecord ===/ util.Util.readFile("avrohugger-core/src/test/expected/comments/specific/Example5.scala") } } diff --git a/avrohugger-core/src/test/scala/specific/SpecificCustomEnumSpec.scala b/avrohugger-core/src/test/scala/specific/SpecificCustomEnumSpec.scala index bbb6ad9c..be122e01 100644 --- a/avrohugger-core/src/test/scala/specific/SpecificCustomEnumSpec.scala +++ b/avrohugger-core/src/test/scala/specific/SpecificCustomEnumSpec.scala @@ -3,6 +3,7 @@ package avrohugger import avrohugger.format.SpecificRecord import avrohugger.types._ import org.specs2._ +import util.Util.LineEndingAmbiguousMatcherString class SpecificCustomEnumSpec extends Specification { @@ -16,7 +17,7 @@ class SpecificCustomEnumSpec extends Specification { def e1 = { val infile = new java.io.File("avrohugger-core/src/test/avro/import.avdl") - val gen = new Generator( + val gen = Generator( SpecificRecord, Some(SpecificRecord.defaultTypes.copy(`enum` = JavaEnum, protocol = ScalaADT)), Map( @@ -30,17 +31,17 @@ class SpecificCustomEnumSpec extends Specification { val expectedDep2 = util.Util.readFile("avrohugger-core/src/test/expected/specific/other/ns/java/ExternalDependency.scala") val expectedDep3 = util.Util.readFile("avrohugger-core/src/test/expected/specific/other/ns/java/Suit.java") - adt === expectedADT - dep1a === expectedDep1a - dep1 === expectedDep1 - dep2 === expectedDep2 - dep3 === expectedDep3 + adt ===/ expectedADT + dep1a ===/ expectedDep1a + dep1 ===/ expectedDep1 + dep2 ===/ expectedDep2 + dep3 ===/ expectedDep3 } def e2 = { val infile = new java.io.File("avrohugger-core/src/test/avro/import.avdl") - val gen = new Generator( + val gen = Generator( SpecificRecord, Some(SpecificRecord.defaultTypes.copy(`enum` = JavaEnum, protocol = ScalaADT)), Map( @@ -61,18 +62,18 @@ class SpecificCustomEnumSpec extends Specification { val expectedDep2 = util.Util.readFile("avrohugger-core/src/test/expected/specific/other/ns/java/ExternalDependency.scala") val expectedDep3 = util.Util.readFile("avrohugger-core/src/test/expected/specific/other/ns/java/Suit.java") - adt === expectedADT - dep1a === expectedDep1a - dep1 === expectedDep1 - dep2 === expectedDep2 - dep3 === expectedDep3 + adt ===/ expectedADT + dep1a ===/ expectedDep1a + dep1 ===/ expectedDep1 + dep2 ===/ expectedDep2 + dep3 ===/ expectedDep3 } def e5 = { val infile = new java.io.File("avrohugger-core/src/test/avro/import.avdl") - val gen = new Generator( + val gen = Generator( SpecificRecord, Some(SpecificRecord.defaultTypes.copy(`enum` = EnumAsScalaString, protocol = ScalaADT)), Map( @@ -84,15 +85,15 @@ class SpecificCustomEnumSpec extends Specification { val expectedDep1 = util.Util.readFile("avrohugger-core/src/test/expected/specific/example/idl/string/Defaults.scala") val expectedDep2 = util.Util.readFile("avrohugger-core/src/test/expected/specific/other/ns/string/ExternalDependency.scala") - adt === expectedADT - dep1 === expectedDep1 - dep2 === expectedDep2 + adt ===/ expectedADT + dep1 ===/ expectedDep1 + dep2 ===/ expectedDep2 } def e6 = { val infile = new java.io.File("avrohugger-core/src/test/avro/import.avdl") - val gen = new Generator( + val gen = Generator( SpecificRecord, Some(SpecificRecord.defaultTypes.copy(`enum` = EnumAsScalaString, protocol = ScalaADT)), Map( @@ -109,9 +110,9 @@ class SpecificCustomEnumSpec extends Specification { val expectedDep1 = util.Util.readFile("avrohugger-core/src/test/expected/specific/example/idl/string/Defaults.scala") val expectedDep2 = util.Util.readFile("avrohugger-core/src/test/expected/specific/other/ns/string/ExternalDependency.scala") - adt === expectedADT - dep1 === expectedDep1 - dep2 === expectedDep2 + adt ===/ expectedADT + dep1 ===/ expectedDep1 + dep2 ===/ expectedDep2 } } diff --git a/avrohugger-core/src/test/scala/specific/SpecificDefaultValueFullnameSpec.scala b/avrohugger-core/src/test/scala/specific/SpecificDefaultValueFullnameSpec.scala index f9481c54..f9682b9b 100644 --- a/avrohugger-core/src/test/scala/specific/SpecificDefaultValueFullnameSpec.scala +++ b/avrohugger-core/src/test/scala/specific/SpecificDefaultValueFullnameSpec.scala @@ -3,16 +3,17 @@ package specific import avrohugger._ import avrohugger.format.SpecificRecord import org.specs2._ +import util.Util.LineEndingAmbiguousMatcherString class SpecificDefaultValueFullnameSpec extends mutable.Specification { "a Generator" should { "use the fully qualified name if field name equals type name" in { val infile = new java.io.File("avrohugger-core/src/test/avro/field_type_equals_field_name.avsc") - val gen = new Generator(SpecificRecord) + val gen = Generator(SpecificRecord) val outDir = gen.defaultOutputDir + "/specific/" gen.fileToFile(infile, outDir) val sourceRecord = scala.io.Source.fromFile(s"$outDir/example/Room.scala").mkString - sourceRecord ==== util.Util.readFile("avrohugger-core/src/test/expected/specific/example/Room.scala") + sourceRecord ===/ util.Util.readFile("avrohugger-core/src/test/expected/specific/example/Room.scala") } } } diff --git a/avrohugger-core/src/test/scala/specific/SpecificFileToFileSpec.scala b/avrohugger-core/src/test/scala/specific/SpecificFileToFileSpec.scala index ad24ee93..95c2b6df 100644 --- a/avrohugger-core/src/test/scala/specific/SpecificFileToFileSpec.scala +++ b/avrohugger-core/src/test/scala/specific/SpecificFileToFileSpec.scala @@ -7,7 +7,7 @@ import avrohugger.format.SpecificRecord import avrohugger.types._ import org.specs2._ import org.specs2.execute.Result -import util.Util.containExpectedContentIn +import util.Util.LineEndingAmbiguousMatcherString import java.io.File import scala.util.Try @@ -59,64 +59,64 @@ class SpecificFileToFileSpec extends Specification { // tests specific to fileToX def eA = { val infile = new java.io.File("avrohugger-core/src/test/avro/twitter.avro") - val gen = new Generator(SpecificRecord) + val gen = Generator(SpecificRecord) val outDir = gen.defaultOutputDir + "/specific/" gen.fileToFile(infile, outDir) val source = util.Util.readFile("target/generated-sources/specific/com/miguno/avro/twitter_schema.scala") - source === util.Util.readFile("avrohugger-core/src/test/expected/specific/com/miguno/avro/twitter_schema.scala") + source ===/ util.Util.readFile("avrohugger-core/src/test/expected/specific/com/miguno/avro/twitter_schema.scala") } // tests specific to fileToFile def e0 = { val infile = new java.io.File("avrohugger-core/src/test/avro/import.avdl") - val gen = new Generator(SpecificRecord) + val gen = Generator(SpecificRecord) val outDir = gen.defaultOutputDir + "/specific/" gen.fileToFile(infile, outDir) - (new File(s"target/generated-sources/specific/example/idl/ExternalDependency.scala")).exists === false + new File(s"target/generated-sources/specific/example/idl/ExternalDependency.scala").exists === false } // tests common to fileToX and stringToX def e1 = { val infile = new java.io.File("avrohugger-core/src/test/avro/mail.avpr") - val gen = new Generator(SpecificRecord) + val gen = Generator(SpecificRecord) val outDir = gen.defaultOutputDir + "/specific/" gen.fileToFile(infile, outDir) val sourceTrait = util.Util.readFile(s"$outDir/example/proto/Mail.scala") val sourceRecord = util.Util.readFile(s"$outDir/example/proto/Message.scala") - sourceTrait === util.Util.readFile("avrohugger-core/src/test/expected/specific/example/proto/Mail.scala") - sourceRecord === util.Util.readFile("avrohugger-core/src/test/expected/specific/example/proto/Message.scala") + sourceTrait ===/ util.Util.readFile("avrohugger-core/src/test/expected/specific/example/proto/Mail.scala") + sourceRecord ===/ util.Util.readFile("avrohugger-core/src/test/expected/specific/example/proto/Message.scala") } def e2 = { val infile = new java.io.File("avrohugger-core/src/test/avro/user.avsc") - val gen = new Generator(SpecificRecord) + val gen = Generator(SpecificRecord) val outDir = gen.defaultOutputDir + "/specific/" gen.fileToFile(infile, outDir) val source = util.Util.readFile("target/generated-sources/specific/example/User.scala") - source === util.Util.readFile("avrohugger-core/src/test/expected/specific/example/User.scala") + source ===/ util.Util.readFile("avrohugger-core/src/test/expected/specific/example/User.scala") } def e3 = { val infile = new java.io.File("avrohugger-core/src/test/avro/AvroTypeProviderTestNoNamespace.avsc") - val gen = new Generator(SpecificRecord) + val gen = Generator(SpecificRecord) val outDir = gen.defaultOutputDir + "/specific/" gen.fileToFile(infile, outDir) val source = util.Util.readFile("target/generated-sources/specific/AvroTypeProviderTestNoNamespace.scala") - source === util.Util.readFile("avrohugger-core/src/test/expected/specific/AvroTypeProviderTestNoNamespace.scala") + source ===/ util.Util.readFile("avrohugger-core/src/test/expected/specific/AvroTypeProviderTestNoNamespace.scala") } def e4 = { val infile = new java.io.File("avrohugger-core/src/test/avro/nested.avsc") - val gen = new Generator(SpecificRecord) + val gen = Generator(SpecificRecord) val outDir = gen.defaultOutputDir + "/specific/" gen.fileToFile(infile, outDir) @@ -124,118 +124,118 @@ class SpecificFileToFileSpec extends Specification { val source1 = util.Util.readFile("target/generated-sources/specific/example/Level1.scala") val source2 = util.Util.readFile("target/generated-sources/specific/example/Level2.scala") - source0 === util.Util.readFile("avrohugger-core/src/test/expected/specific/example/Level0.scala") - source1 === util.Util.readFile("avrohugger-core/src/test/expected/specific/example/Level1.scala") - source2 === util.Util.readFile("avrohugger-core/src/test/expected/specific/example/Level2.scala") + source0 ===/ util.Util.readFile("avrohugger-core/src/test/expected/specific/example/Level0.scala") + source1 ===/ util.Util.readFile("avrohugger-core/src/test/expected/specific/example/Level1.scala") + source2 ===/ util.Util.readFile("avrohugger-core/src/test/expected/specific/example/Level2.scala") } def e5 = { val infile = new java.io.File("avrohugger-core/src/test/avro/nested.avdl") val myAvroScalaCustomTypes = SpecificRecord.defaultTypes.copy(protocol = types.ScalaADT) - val gen = new Generator(format = SpecificRecord, avroScalaCustomTypes = Some(myAvroScalaCustomTypes)) + val gen = Generator(format = SpecificRecord, avroScalaCustomTypes = Some(myAvroScalaCustomTypes)) val outDir = gen.defaultOutputDir + "/specific/" gen.fileToFile(infile, outDir) val source = util.Util.readFile("target/generated-sources/specific/example/idl/NestedProtocol.scala") - source === util.Util.readFile("avrohugger-core/src/test/expected/specific/example/idl/NestedProtocol.scala") + source ===/ util.Util.readFile("avrohugger-core/src/test/expected/specific/example/idl/NestedProtocol.scala") } def e6 = { val infile = new java.io.File("avrohugger-core/src/test/avro/recursive.avdl") - val gen = new Generator(SpecificRecord) + val gen = Generator(SpecificRecord) val outDir = gen.defaultOutputDir + "/specific/" gen.fileToFile(infile, outDir) val source = util.Util.readFile("target/generated-sources/specific/example/idl/Recursive.scala") - source === util.Util.readFile("avrohugger-core/src/test/expected/specific/example/idl/Recursive.scala") + source ===/ util.Util.readFile("avrohugger-core/src/test/expected/specific/example/idl/Recursive.scala") } def e7 = { val infile = new java.io.File("avrohugger-core/src/test/avro/enums.avsc") - val gen = new Generator(SpecificRecord) + val gen = Generator(SpecificRecord) val outDir = gen.defaultOutputDir + "/specific/" gen.fileToFile(infile, outDir) val source = util.Util.readFile("target/generated-sources/specific/example/Suit.java") - source === util.Util.readFile("avrohugger-core/src/test/expected/specific/example/Suit.java") + source ===/ util.Util.readFile("avrohugger-core/src/test/expected/specific/example/Suit.java") } def e8 = { val infile = new java.io.File("avrohugger-core/src/test/avro/enums.avpr") - val gen = new Generator(SpecificRecord) + val gen = Generator(SpecificRecord) val outDir = gen.defaultOutputDir + "/specific/" gen.fileToFile(infile, outDir) val sourceEnum = util.Util.readFile("target/generated-sources/specific/example/proto/Suit.java") val sourceRecord = util.Util.readFile("target/generated-sources/specific/example/proto/Card.scala") - sourceEnum === util.Util.readFile("avrohugger-core/src/test/expected/specific/example/proto/Suit.java") - sourceRecord === util.Util.readFile("avrohugger-core/src/test/expected/specific/example/proto/Card.scala") + sourceEnum ===/ util.Util.readFile("avrohugger-core/src/test/expected/specific/example/proto/Suit.java") + sourceRecord ===/ util.Util.readFile("avrohugger-core/src/test/expected/specific/example/proto/Card.scala") } def e9 = { val infile = new java.io.File("avrohugger-core/src/test/avro/enums.avdl") - val gen = new Generator(SpecificRecord) + val gen = Generator(SpecificRecord) val outDir = gen.defaultOutputDir + "/specific/" gen.fileToFile(infile, outDir) val sourceEnum = util.Util.readFile("target/generated-sources/specific/example/idl/Suit.java") val sourceRecord = util.Util.readFile("target/generated-sources/specific/example/idl/Card.scala") - sourceEnum === util.Util.readFile("avrohugger-core/src/test/expected/specific/example/idl/Suit.java") - sourceRecord === util.Util.readFile("avrohugger-core/src/test/expected/specific/example/idl/Card.scala") + sourceEnum ===/ util.Util.readFile("avrohugger-core/src/test/expected/specific/example/idl/Suit.java") + sourceRecord ===/ util.Util.readFile("avrohugger-core/src/test/expected/specific/example/idl/Card.scala") } def e10 = { val infile = new java.io.File("avrohugger-core/src/test/avro/enums_nested.avsc") - val gen = new Generator(SpecificRecord) + val gen = Generator(SpecificRecord) val outDir = gen.defaultOutputDir + "/specific/" gen.fileToFile(infile, outDir) val sourceEnum = util.Util.readFile("target/generated-sources/specific/example/Direction.java") val sourceRecord = util.Util.readFile("target/generated-sources/specific/example/Compass.scala") - sourceEnum === util.Util.readFile("avrohugger-core/src/test/expected/specific/example/Direction.java") - sourceRecord === util.Util.readFile("avrohugger-core/src/test/expected/specific/example/Compass.scala") + sourceEnum ===/ util.Util.readFile("avrohugger-core/src/test/expected/specific/example/Direction.java") + sourceRecord ===/ util.Util.readFile("avrohugger-core/src/test/expected/specific/example/Compass.scala") } def e11 = { val infile = new java.io.File("avrohugger-core/src/test/avro/bytes.avsc") - val gen = new Generator(SpecificRecord) + val gen = Generator(SpecificRecord) val outDir = gen.defaultOutputDir + "/specific/" gen.fileToFile(infile, outDir) val source = util.Util.readFile("target/generated-sources/specific/example/BinarySc.scala") - source === util.Util.readFile("avrohugger-core/src/test/expected/specific/example/BinarySc.scala") + source ===/ util.Util.readFile("avrohugger-core/src/test/expected/specific/example/BinarySc.scala") } def e12 = { val infile = new java.io.File("avrohugger-core/src/test/avro/bytes.avpr") - val gen = new Generator(SpecificRecord) + val gen = Generator(SpecificRecord) val outDir = gen.defaultOutputDir + "/specific/" gen.fileToFile(infile, outDir) val source = util.Util.readFile("target/generated-sources/specific/example/proto/BinaryPr.scala") - source === util.Util.readFile("avrohugger-core/src/test/expected/specific/example/proto/BinaryPr.scala") + source ===/ util.Util.readFile("avrohugger-core/src/test/expected/specific/example/proto/BinaryPr.scala") } def e13 = { val infile = new java.io.File("avrohugger-core/src/test/avro/bytes.avdl") - val gen = new Generator(SpecificRecord) + val gen = Generator(SpecificRecord) val outDir = gen.defaultOutputDir + "/specific/" gen.fileToFile(infile, outDir) val source = util.Util.readFile("target/generated-sources/specific/example/idl/BinaryIdl.scala") - source === util.Util.readFile("avrohugger-core/src/test/expected/specific/example/idl/BinaryIdl.scala") + source ===/ util.Util.readFile("avrohugger-core/src/test/expected/specific/example/idl/BinaryIdl.scala") } def e14 = { val importing = new java.io.File("avrohugger-core/src/test/avro/import.avdl") - val gen = new Generator(SpecificRecord) + val gen = Generator(SpecificRecord) val outDir = gen.defaultOutputDir + "/specific/" gen.fileToFile(importing, outDir) @@ -245,52 +245,52 @@ class SpecificFileToFileSpec extends Specification { val sourceDep2 = util.Util.readFile("target/generated-sources/specific/other/ns/ExternalDependency.scala") val sourceDep3 = util.Util.readFile("target/generated-sources/specific/other/ns/Suit.java") - sourceADT === util.Util.readFile("avrohugger-core/src/test/expected/specific/example/idl/ImportProtocol.scala") - sourceDep1 === util.Util.readFile("avrohugger-core/src/test/expected/specific/example/idl/Defaults.scala") - sourceEnum === util.Util.readFile("avrohugger-core/src/test/expected/specific/example/idl/DefaultEnum.java") - sourceDep2 === util.Util.readFile("avrohugger-core/src/test/expected/specific/other/ns/ExternalDependency.scala") - sourceDep3 === util.Util.readFile("avrohugger-core/src/test/expected/specific/other/ns/Suit.java") + sourceADT ===/ util.Util.readFile("avrohugger-core/src/test/expected/specific/example/idl/ImportProtocol.scala") + sourceDep1 ===/ util.Util.readFile("avrohugger-core/src/test/expected/specific/example/idl/Defaults.scala") + sourceEnum ===/ util.Util.readFile("avrohugger-core/src/test/expected/specific/example/idl/DefaultEnum.java") + sourceDep2 ===/ util.Util.readFile("avrohugger-core/src/test/expected/specific/other/ns/ExternalDependency.scala") + sourceDep3 ===/ util.Util.readFile("avrohugger-core/src/test/expected/specific/other/ns/Suit.java") } def e15 = { val infile = new java.io.File("avrohugger-core/src/test/avro/AvroTypeProviderTestEmptyRecord.avdl") val myAvroScalaCustomTypes = SpecificRecord.defaultTypes.copy(protocol = types.ScalaADT) - val gen = new Generator(format = SpecificRecord, avroScalaCustomTypes = Some(myAvroScalaCustomTypes)) + val gen = Generator(format = SpecificRecord, avroScalaCustomTypes = Some(myAvroScalaCustomTypes)) val outDir = gen.defaultOutputDir + "/specific/" gen.fileToFile(infile, outDir) val source = util.Util.readFile("target/generated-sources/specific/test/Calculator.scala") - source === util.Util.readFile("avrohugger-core/src/test/expected/specific/test/Calculator.scala") + source ===/ util.Util.readFile("avrohugger-core/src/test/expected/specific/test/Calculator.scala") } def e16 = { val infile = new java.io.File("avrohugger-core/src/test/avro/defaults.avdl") - val gen = new Generator(SpecificRecord) + val gen = Generator(SpecificRecord) val outDir = gen.defaultOutputDir + "/specific/" gen.fileToFile(infile, outDir) val sourceRecord = util.Util.readFile("target/generated-sources/specific/example/idl/Defaults.scala") val sourceEnum = util.Util.readFile("target/generated-sources/specific/example/idl/DefaultEnum.java") - sourceRecord === util.Util.readFile("avrohugger-core/src/test/expected/specific/example/idl/Defaults.scala") - sourceEnum === util.Util.readFile("avrohugger-core/src/test/expected/specific/example/idl/DefaultEnum.java") + sourceRecord ===/ util.Util.readFile("avrohugger-core/src/test/expected/specific/example/idl/Defaults.scala") + sourceEnum ===/ util.Util.readFile("avrohugger-core/src/test/expected/specific/example/idl/DefaultEnum.java") } def e18 = { val infile = new java.io.File("avrohugger-core/src/test/avro/unions_with_coproduct.avdl") - val gen = new Generator(SpecificRecord) + val gen = Generator(SpecificRecord) val outDir = gen.defaultOutputDir + "/specific/" gen.fileToFile(infile, outDir) val source = util.Util.readFile("target/generated-sources/specific/example/idl/WithShapelessCoproduct.scala") - source === util.Util.readFile("avrohugger-core/src/test/expected/specific/example/idl/WithShapelessCoproduct.scala") + source ===/ util.Util.readFile("avrohugger-core/src/test/expected/specific/example/idl/WithShapelessCoproduct.scala") } def e19 = { val inOrderSchema = new java.io.File("avrohugger-core/src/test/avro/unions_with_coproduct.avsc") - val gen = new Generator(format = SpecificRecord) + val gen = Generator(format = SpecificRecord) val outDir = gen.defaultOutputDir + "/specific/" gen.fileToFile(inOrderSchema, outDir) @@ -298,7 +298,7 @@ class SpecificFileToFileSpec extends Specification { val sources = classes.map(className => util.Util.readFile(s"avrohugger-core/src/test/expected/specific/com/example/avrohugger/unions_with_coproduct_avsc/$className.scala")) Result.foreach(classes.zip(sources)) { case (className, expect) => - util.Util.readFile(s"target/generated-sources/specific/com/example/avrohugger/unions_with_coproduct_avsc/$className.scala") === expect + util.Util.readFile(s"target/generated-sources/specific/com/example/avrohugger/unions_with_coproduct_avsc/$className.scala") ===/ expect } } @@ -317,21 +317,21 @@ class SpecificFileToFileSpec extends Specification { "UnionOfNullWithMoreThanTwoNonNullTypes" )) ( className => { - val generatedFile = s"target/generated-sources/specific/$unionType/com/example/avrohugger/unions_with_coproduct_avsc2/$className.scala" - val expectationFile = s"avrohugger-core/src/test/expected/specific/$unionType/com/example/avrohugger/unions_with_coproduct_avsc2/$className.scala" - generatedFile must containExpectedContentIn(expectationFile) + val generatedFile = util.Util.readFile(s"target/generated-sources/specific/$unionType/com/example/avrohugger/unions_with_coproduct_avsc2/$className.scala") + val expectationFile = util.Util.readFile(s"avrohugger-core/src/test/expected/specific/$unionType/com/example/avrohugger/unions_with_coproduct_avsc2/$className.scala") + generatedFile ===/ expectationFile }) }) def e21 = { val infile = new java.io.File("avrohugger-core/src/test/avro/AvroTypeProviderTestProtocol.avdl") - val gen = new Generator(format = SpecificRecord) + val gen = Generator(format = SpecificRecord) val outDir = gen.defaultOutputDir + "/specific/" gen.fileToFile(infile, outDir) val source = util.Util.readFile("target/generated-sources/specific/test/Joystick.scala") - source === util.Util.readFile("avrohugger-core/src/test/expected/specific/test/Joystick.scala") + source ===/ util.Util.readFile("avrohugger-core/src/test/expected/specific/test/Joystick.scala") } def e22 = { @@ -366,65 +366,65 @@ class SpecificFileToFileSpec extends Specification { def e24 = { val infile = new java.io.File("avrohugger-core/src/test/avro/logical.avsc") - val gen = new Generator(SpecificRecord) + val gen = Generator(SpecificRecord) val outDir = gen.defaultOutputDir + "/specific/" gen.fileToFile(infile, outDir) val source1 = util.Util.readFile("target/generated-sources/specific/example/logical/LogicalSc.scala") val source2 = util.Util.readFile("target/generated-sources/specific/example/logical/fxType.scala") - source1 === util.Util.readFile("avrohugger-core/src/test/expected/specific/example/logical/LogicalSc.scala") and - source2 === util.Util.readFile("avrohugger-core/src/test/expected/specific/example/logical/fxType.scala") + source1 ===/ util.Util.readFile("avrohugger-core/src/test/expected/specific/example/logical/LogicalSc.scala") and + source2 ===/ util.Util.readFile("avrohugger-core/src/test/expected/specific/example/logical/fxType.scala") } def e25 = { val infile = new java.io.File("avrohugger-core/src/test/avro/logical.avpr") - val gen = new Generator(SpecificRecord) + val gen = Generator(SpecificRecord) val outDir = gen.defaultOutputDir + "/specific/" gen.fileToFile(infile, outDir) val source = util.Util.readFile("target/generated-sources/specific/example/logical/proto/Logical.scala") - source === util.Util.readFile("avrohugger-core/src/test/expected/specific/example/logical/proto/Logical.scala") + source ===/ util.Util.readFile("avrohugger-core/src/test/expected/specific/example/logical/proto/Logical.scala") } // def e26 = { // val infile = new java.io.File("avrohugger-core/src/test/avro/logical.avdl") - // val gen = new Generator(SpecificRecord) + // val gen = Generator(SpecificRecord) // val outDir = gen.defaultOutputDir + "/specific/" // gen.fileToFile(infile, outDir) // val source = util.Util.readFile("target/generated-sources/specific/example/idl/LogicalIdl.scala") - // source === util.Util.readFile("avrohugger-core/src/test/expected/specific/example/idl/LogicalIdl.scala") + // source ===/ util.Util.readFile("avrohugger-core/src/test/expected/specific/example/idl/LogicalIdl.scala") // } def e27 = { val infile = new java.io.File("avrohugger-core/src/test/avro/logicalsql.avsc") val avroScalaCustomTypes = SpecificRecord.defaultTypes.copy(date = JavaSqlDate, timestampMillis = JavaSqlTimestamp, timeMillis = JavaSqlTime) - val gen = new Generator(SpecificRecord, avroScalaCustomTypes = Some(avroScalaCustomTypes)) + val gen = Generator(SpecificRecord, avroScalaCustomTypes = Some(avroScalaCustomTypes)) val outDir = gen.defaultOutputDir + "/specific/" gen.fileToFile(infile, outDir) val source = util.Util.readFile("target/generated-sources/specific/example/logical/LogicalSql.scala") - source === util.Util.readFile("avrohugger-core/src/test/expected/specific/example/logical/LogicalSql.scala") + source ===/ util.Util.readFile("avrohugger-core/src/test/expected/specific/example/logical/LogicalSql.scala") } def e28 = { val infile = new java.io.File("avrohugger-core/src/test/avro/special_names.avdl") - val gen = new Generator(SpecificRecord) + val gen = Generator(SpecificRecord) val outDir = gen.defaultOutputDir + "/specific/" gen.fileToFile(infile, outDir) val source = util.Util.readFile("target/generated-sources/specific/example/idl/Names.scala") - source === util.Util.readFile("avrohugger-core/src/test/expected/specific/example/idl/Names.scala") + source ===/ util.Util.readFile("avrohugger-core/src/test/expected/specific/example/idl/Names.scala") } def e29 = { val infile = new java.io.File("avrohugger-core/src/test/avro/mail.avpr") - val gen = new Generator(SpecificRecord, + val gen = Generator(SpecificRecord, avroScalaCustomNamespace = Map("example.*" -> "example.protocol")) val outDir = gen.defaultOutputDir + "/specific" gen.fileToFile(infile, outDir) @@ -432,13 +432,13 @@ class SpecificFileToFileSpec extends Specification { val sourceTrait = util.Util.readFile(s"$outDir/example/protocol/Mail.scala") val sourceRecord = util.Util.readFile(s"$outDir/example/protocol/Message.scala") - sourceTrait === util.Util.readFile("avrohugger-core/src/test/expected/specific/example/protocol/Mail.scala") - sourceRecord === util.Util.readFile("avrohugger-core/src/test/expected/specific/example/protocol/Message.scala") + sourceTrait ===/ util.Util.readFile("avrohugger-core/src/test/expected/specific/example/protocol/Mail.scala") + sourceRecord ===/ util.Util.readFile("avrohugger-core/src/test/expected/specific/example/protocol/Message.scala") } def e30 = { val infile = new java.io.File("avrohugger-core/src/test/avro/fixed_two.avsc") - val gen = new Generator(SpecificRecord) + val gen = Generator(SpecificRecord) val outDir = gen.defaultOutputDir + "/specific/" gen.fileToFile(infile, outDir) @@ -446,20 +446,20 @@ class SpecificFileToFileSpec extends Specification { val source2 = util.Util.readFile("target/generated-sources/specific/fixedtwo/one/fixed.scala") val source3 = util.Util.readFile("target/generated-sources/specific/fixedtwo/two/fixed.scala") - source1 === util.Util.readFile("avrohugger-core/src/test/expected/specific/example/fixedtwo/FixedTwo.scala") and - source2 === util.Util.readFile("avrohugger-core/src/test/expected/specific/example/fixedtwo/one/fixed.scala") and - source3 === util.Util.readFile("avrohugger-core/src/test/expected/specific/example/fixedtwo/two/fixed.scala") + source1 ===/ util.Util.readFile("avrohugger-core/src/test/expected/specific/example/fixedtwo/FixedTwo.scala") and + source2 ===/ util.Util.readFile("avrohugger-core/src/test/expected/specific/example/fixedtwo/one/fixed.scala") and + source3 ===/ util.Util.readFile("avrohugger-core/src/test/expected/specific/example/fixedtwo/two/fixed.scala") } def e31 = { val infile = new java.io.File("avrohugger-core/src/test/avro/date_time_related_fields.avsc") val avroScalaCustomTypes = SpecificRecord.defaultTypes.copy(date = UnderlyingPrimitive, timestampMillis = UnderlyingPrimitive, timestampMicros = UnderlyingPrimitive, localTimestampMicros = UnderlyingPrimitive, localTimestampMillis = UnderlyingPrimitive, timeMillis = UnderlyingPrimitive, timeMicros = UnderlyingPrimitive) - val gen = new Generator(SpecificRecord, avroScalaCustomTypes = Some(avroScalaCustomTypes)) + val gen = Generator(SpecificRecord, avroScalaCustomTypes = Some(avroScalaCustomTypes)) val outDir = gen.defaultOutputDir + "/specific/" gen.fileToFile(infile, outDir) val source = util.Util.readFile("target/generated-sources/specific/example/datetimerelatedfields/DateTimeRelatedFields.scala") - source === util.Util.readFile("avrohugger-core/src/test/expected/specific/example/datetimerelatedfields/DateTimeRelatedFields.scala") + source ===/ util.Util.readFile("avrohugger-core/src/test/expected/specific/example/datetimerelatedfields/DateTimeRelatedFields.scala") } } diff --git a/avrohugger-core/src/test/scala/specific/SpecificFileToStringsSpec.scala b/avrohugger-core/src/test/scala/specific/SpecificFileToStringsSpec.scala index e403e9f4..1dffb148 100644 --- a/avrohugger-core/src/test/scala/specific/SpecificFileToStringsSpec.scala +++ b/avrohugger-core/src/test/scala/specific/SpecificFileToStringsSpec.scala @@ -5,6 +5,7 @@ package specific import avrohugger.Generator import avrohugger.format.SpecificRecord import org.specs2._ +import util.Util.LineEndingAmbiguousMatcherString class SpecificFileToStringsSpec extends Specification { @@ -39,137 +40,137 @@ class SpecificFileToStringsSpec extends Specification { // tests specific to fileToX def eA = { val infile = new java.io.File("avrohugger-core/src/test/avro/twitter.avro") - val gen = new Generator(SpecificRecord) + val gen = Generator(SpecificRecord) val List(source) = gen.fileToStrings(infile) val expected = util.Util.readFile("avrohugger-core/src/test/expected/specific/com/miguno/avro/twitter_schema.scala") - source === expected + source ===/ expected } // tests common to fileToX and stringToX def e1 = { val infile = new java.io.File("avrohugger-core/src/test/avro/mail.avpr") - val gen = new Generator(SpecificRecord) + val gen = Generator(SpecificRecord) val List(sourceTrait, sourceRecord) = gen.fileToStrings(infile) val expectedTrait = util.Util.readFile("avrohugger-core/src/test/expected/specific/example/proto/Mail.scala") val expectedRecord = util.Util.readFile("avrohugger-core/src/test/expected/specific/example/proto/Message.scala") - sourceTrait === expectedTrait - sourceRecord === expectedRecord + sourceTrait ===/ expectedTrait + sourceRecord ===/ expectedRecord } def e2 = { val infile = new java.io.File("avrohugger-core/src/test/avro/user.avsc") - val gen = new Generator(SpecificRecord) + val gen = Generator(SpecificRecord) val List(source) = gen.fileToStrings(infile) val expected = util.Util.readFile("avrohugger-core/src/test/expected/specific/example/User.scala") - source === expected + source ===/ expected } def e3 = { val infile = new java.io.File("avrohugger-core/src/test/avro/AvroTypeProviderTestNoNamespace.avsc") - val gen = new Generator(SpecificRecord) + val gen = Generator(SpecificRecord) val List(source) = gen.fileToStrings(infile) val expected = util.Util.readFile("avrohugger-core/src/test/expected/specific/AvroTypeProviderTestNoNamespace.scala") - source === expected + source ===/ expected } def e4 = { val infile = new java.io.File("avrohugger-core/src/test/avro/nested.avsc") - val gen = new Generator(SpecificRecord) + val gen = Generator(SpecificRecord) val List(source2, source1, source0) = gen.fileToStrings(infile) val expected0 = util.Util.readFile("avrohugger-core/src/test/expected/specific/example/Level0.scala") val expected1 = util.Util.readFile("avrohugger-core/src/test/expected/specific/example/Level1.scala") val expected2 = util.Util.readFile("avrohugger-core/src/test/expected/specific/example/Level2.scala") - source0 === expected0 - source1 === expected1 - source2 === expected2 + source0 ===/ expected0 + source1 ===/ expected1 + source2 ===/ expected2 } def e5 = { val infile = new java.io.File("avrohugger-core/src/test/avro/nested.avdl") val myAvroScalaCustomTypes = SpecificRecord.defaultTypes.copy(protocol = types.ScalaADT) - val gen = new Generator(format = SpecificRecord, avroScalaCustomTypes = Some(myAvroScalaCustomTypes)) + val gen = Generator(format = SpecificRecord, avroScalaCustomTypes = Some(myAvroScalaCustomTypes)) val List(source) = gen.fileToStrings(infile) val expected = util.Util.readFile("avrohugger-core/src/test/expected/specific/example/idl/NestedProtocol.scala") - source === expected + source ===/ expected } def e6 = { val infile = new java.io.File("avrohugger-core/src/test/avro/recursive.avdl") - val gen = new Generator(SpecificRecord) + val gen = Generator(SpecificRecord) val List(source) = gen.fileToStrings(infile) val expected = util.Util.readFile("avrohugger-core/src/test/expected/specific/example/idl/Recursive.scala") - source === expected + source ===/ expected } def e7 = { val infile = new java.io.File("avrohugger-core/src/test/avro/enums.avsc") - val gen = new Generator(SpecificRecord) + val gen = Generator(SpecificRecord) val List(source) = gen.fileToStrings(infile) val expected = util.Util.readFile("avrohugger-core/src/test/expected/specific/example/Suit.java") - source === expected + source ===/ expected } def e8 = { val infile = new java.io.File("avrohugger-core/src/test/avro/enums.avpr") - val gen = new Generator(SpecificRecord) + val gen = Generator(SpecificRecord) val List(sourceRecord, sourceEnum) = gen.fileToStrings(infile) val expectedEnum = util.Util.readFile("avrohugger-core/src/test/expected/specific/example/proto/Suit.java") val expectedRecord = util.Util.readFile("avrohugger-core/src/test/expected/specific/example/proto/Card.scala") - sourceEnum === expectedEnum - sourceRecord === expectedRecord + sourceEnum ===/ expectedEnum + sourceRecord ===/ expectedRecord } def e9 = { val infile = new java.io.File("avrohugger-core/src/test/avro/enums.avdl") - val gen = new Generator(SpecificRecord) + val gen = Generator(SpecificRecord) val List(sourceRecord, sourceEnum) = gen.fileToStrings(infile) val expectedEnum = util.Util.readFile("avrohugger-core/src/test/expected/specific/example/idl/Suit.java") val expectedRecord = util.Util.readFile("avrohugger-core/src/test/expected/specific/example/idl/Card.scala") - sourceEnum === expectedEnum - sourceRecord === expectedRecord + sourceEnum ===/ expectedEnum + sourceRecord ===/ expectedRecord } def e10 = { val infile = new java.io.File("avrohugger-core/src/test/avro/enums_nested.avsc") - val gen = new Generator(SpecificRecord) + val gen = Generator(SpecificRecord) val List(sourceEnum, sourceRecord) = gen.fileToStrings(infile) val expectedEnum = util.Util.readFile("avrohugger-core/src/test/expected/specific/example/Direction.java") val expectedRecord = util.Util.readFile("avrohugger-core/src/test/expected/specific/example/Compass.scala") - sourceEnum === expectedEnum - sourceRecord === expectedRecord + sourceEnum ===/ expectedEnum + sourceRecord ===/ expectedRecord } def e11 = { val infile = new java.io.File("avrohugger-core/src/test/avro/bytes.avsc") - val gen = new Generator(SpecificRecord) + val gen = Generator(SpecificRecord) val List(source) = gen.fileToStrings(infile) val expected = util.Util.readFile("avrohugger-core/src/test/expected/specific/example/BinarySc.scala") - source === expected + source ===/ expected } def e12 = { val infile = new java.io.File("avrohugger-core/src/test/avro/bytes.avpr") - val gen = new Generator(SpecificRecord) + val gen = Generator(SpecificRecord) val List(source) = gen.fileToStrings(infile) val expected = util.Util.readFile("avrohugger-core/src/test/expected/specific/example/proto/BinaryPr.scala") - source === expected + source ===/ expected } def e13 = { val infile = new java.io.File("avrohugger-core/src/test/avro/bytes.avdl") - val gen = new Generator(SpecificRecord) + val gen = Generator(SpecificRecord) val List(source) = gen.fileToStrings(infile) val expected = util.Util.readFile("avrohugger-core/src/test/expected/specific/example/idl/BinaryIdl.scala") - source === expected + source ===/ expected } def e14 = { val infile = new java.io.File("avrohugger-core/src/test/avro/import.avdl") - val gen = new Generator(SpecificRecord) + val gen = Generator(SpecificRecord) val List(dep3, dep2, dep1, enm, adt) = gen.fileToStrings(infile) val expectedADT = util.Util.readFile("avrohugger-core/src/test/expected/specific/example/idl/ImportProtocol.scala") @@ -178,32 +179,32 @@ class SpecificFileToStringsSpec extends Specification { val expectedDep2 = util.Util.readFile("avrohugger-core/src/test/expected/specific/other/ns/ExternalDependency.scala") val expectedDep3 = util.Util.readFile("avrohugger-core/src/test/expected/specific/other/ns/Suit.java") - adt === expectedADT - dep1 === expectedDep1 - enm === expectedEnum - dep2 === expectedDep2 - dep3 === expectedDep3 + adt ===/ expectedADT + dep1 ===/ expectedDep1 + enm ===/ expectedEnum + dep2 ===/ expectedDep2 + dep3 ===/ expectedDep3 } def e15 = { val infile = new java.io.File("avrohugger-core/src/test/avro/AvroTypeProviderTestEmptyRecord.avdl") val myAvroScalaCustomTypes = SpecificRecord.defaultTypes.copy(protocol = types.ScalaADT) - val gen = new Generator(format = SpecificRecord, avroScalaCustomTypes = Some(myAvroScalaCustomTypes)) + val gen = Generator(format = SpecificRecord, avroScalaCustomTypes = Some(myAvroScalaCustomTypes)) val List(source) = gen.fileToStrings(infile) val expected = util.Util.readFile("avrohugger-core/src/test/expected/specific/test/Calculator.scala") - source === expected + source ===/ expected } def e16 = { val infile = new java.io.File("avrohugger-core/src/test/avro/defaults.avdl") - val gen = new Generator(SpecificRecord) + val gen = Generator(SpecificRecord) val List(sourceRecord, sourceEnum) = gen.fileToStrings(infile) val expectedRecord = util.Util.readFile("avrohugger-core/src/test/expected/specific/example/idl/Defaults.scala") val expectedEnum = util.Util.readFile("avrohugger-core/src/test/expected/specific/example/idl/DefaultEnum.java") - sourceRecord === expectedRecord - sourceEnum === expectedEnum + sourceRecord ===/ expectedRecord + sourceEnum ===/ expectedEnum } @@ -213,19 +214,19 @@ class SpecificFileToStringsSpec extends Specification { def e21 = { val infile = new java.io.File("avrohugger-core/src/test/avro/AvroTypeProviderTestProtocol.avdl") - val gen = new Generator(format = SpecificRecord) + val gen = Generator(format = SpecificRecord) val outDir = gen.defaultOutputDir + "/specific/" val List(source) = gen.fileToStrings(infile) - source === util.Util.readFile("avrohugger-core/src/test/expected/specific/test/Joystick.scala") + source ===/ util.Util.readFile("avrohugger-core/src/test/expected/specific/test/Joystick.scala") } // def e22 = { // val infile = new java.io.File("avrohugger-core/src/test/avro/logical.avdl") - // val gen = new Generator(SpecificRecord) + // val gen = Generator(SpecificRecord) // val List(source) = gen.fileToStrings(infile) // val expected = util.Util.readFile("avrohugger-core/src/test/expected/specific/example/idl/LogicalIdl.scala") - // source === expected + // source ===/ expected // } } diff --git a/avrohugger-core/src/test/scala/specific/SpecificManyFieldsSpec.scala b/avrohugger-core/src/test/scala/specific/SpecificManyFieldsSpec.scala index 706f807e..7a4f83d4 100644 --- a/avrohugger-core/src/test/scala/specific/SpecificManyFieldsSpec.scala +++ b/avrohugger-core/src/test/scala/specific/SpecificManyFieldsSpec.scala @@ -15,9 +15,9 @@ class SpecificManyFieldsSpec extends Specification { val avdlPath = "avrohugger-core/src/test/avro/ManyFields.avdl" val avscPath = "avrohugger-core/src/test/avro/ManyFields.avsc" - val genNonRestricted = new Generator(SpecificRecord, restrictedFieldNumber = false) + val genNonRestricted = Generator(SpecificRecord, restrictedFieldNumber = false) val outDirNonRestricted = genNonRestricted.defaultOutputDir + "/specific/non-restricted" - val genRestricted = new Generator(SpecificRecord, restrictedFieldNumber = true) + val genRestricted = Generator(SpecificRecord, restrictedFieldNumber = true) val outDirRestricted = genRestricted.defaultOutputDir + "/specific/restricted" def is = s2""" diff --git a/avrohugger-core/src/test/scala/specific/SpecificSameRecordNameSpec.scala b/avrohugger-core/src/test/scala/specific/SpecificSameRecordNameSpec.scala index de0304f0..31732674 100644 --- a/avrohugger-core/src/test/scala/specific/SpecificSameRecordNameSpec.scala +++ b/avrohugger-core/src/test/scala/specific/SpecificSameRecordNameSpec.scala @@ -3,16 +3,17 @@ package specific import avrohugger._ import avrohugger.format.SpecificRecord import org.specs2._ +import util.Util.LineEndingAmbiguousMatcherString class SpecificSameRecordNameSpec extends mutable.Specification { "a Generator" should { "use the fully qualified name of the records" in { val infile = new java.io.File("avrohugger-core/src/test/avro/SameRecordNameDifferentNamespace.avsc") - val gen = new Generator(SpecificRecord) + val gen = Generator(SpecificRecord) val outDir = gen.defaultOutputDir + "/specific/" gen.fileToFile(infile, outDir) val sourceRecord = scala.io.Source.fromFile(s"$outDir/com/countries/Country.scala").mkString - sourceRecord ==== util.Util.readFile("avrohugger-core/src/test/expected/specific/com/countries/Country.scala") + sourceRecord ===/ util.Util.readFile("avrohugger-core/src/test/expected/specific/com/countries/Country.scala") } } } diff --git a/avrohugger-core/src/test/scala/specific/SpecificStringToFileSpec.scala b/avrohugger-core/src/test/scala/specific/SpecificStringToFileSpec.scala index 997f63d5..acbfd477 100644 --- a/avrohugger-core/src/test/scala/specific/SpecificStringToFileSpec.scala +++ b/avrohugger-core/src/test/scala/specific/SpecificStringToFileSpec.scala @@ -6,6 +6,7 @@ import avrohugger._ import avrohugger.format.SpecificRecord import org.apache.avro.Schema import org.specs2._ +import util.Util.LineEndingAmbiguousMatcherString import java.io.File import scala.io.Source @@ -44,40 +45,40 @@ class SpecificStringToFileSpec extends Specification { // tests common to fileToX and stringToX def e1 = { val inputString = util.Util.readFile("avrohugger-core/src/test/avro/mail.avpr") - val gen = new Generator(SpecificRecord) + val gen = Generator(SpecificRecord) val outDir = gen.defaultOutputDir + "/specific/" gen.stringToFile(inputString, outDir) val sourceTrait = util.Util.readFile(s"$outDir/example/proto/Mail.scala") val sourceRecord = util.Util.readFile(s"$outDir/example/proto/Message.scala") - sourceTrait === util.Util.readFile("avrohugger-core/src/test/expected/specific/example/proto/Mail.scala") - sourceRecord === util.Util.readFile("avrohugger-core/src/test/expected/specific/example/proto/Message.scala") + sourceTrait ===/ util.Util.readFile("avrohugger-core/src/test/expected/specific/example/proto/Mail.scala") + sourceRecord ===/ util.Util.readFile("avrohugger-core/src/test/expected/specific/example/proto/Message.scala") } def e2 = { val inputString = util.Util.readFile("avrohugger-core/src/test/avro/user.avsc") - val gen = new Generator(SpecificRecord) + val gen = Generator(SpecificRecord) val outDir = gen.defaultOutputDir + "/specific/" gen.stringToFile(inputString, outDir) val source = util.Util.readFile("target/generated-sources/specific/example/User.scala") - source === util.Util.readFile("avrohugger-core/src/test/expected/specific/example/User.scala") + source ===/ util.Util.readFile("avrohugger-core/src/test/expected/specific/example/User.scala") } def e3 = { val inputString = util.Util.readFile("avrohugger-core/src/test/avro/AvroTypeProviderTestNoNamespace.avsc") - val gen = new Generator(SpecificRecord) + val gen = Generator(SpecificRecord) val outDir = gen.defaultOutputDir + "/specific/" gen.stringToFile(inputString, outDir) val source = util.Util.readFile("target/generated-sources/specific/AvroTypeProviderTestNoNamespace.scala") - source === util.Util.readFile("avrohugger-core/src/test/expected/specific/AvroTypeProviderTestNoNamespace.scala") + source ===/ util.Util.readFile("avrohugger-core/src/test/expected/specific/AvroTypeProviderTestNoNamespace.scala") } def e4 = { val inputString = util.Util.readFile("avrohugger-core/src/test/avro/nested.avsc") - val gen = new Generator(SpecificRecord) + val gen = Generator(SpecificRecord) val outDir = gen.defaultOutputDir + "/specific/" gen.stringToFile(inputString, outDir) @@ -85,121 +86,121 @@ class SpecificStringToFileSpec extends Specification { val source1 = util.Util.readFile("target/generated-sources/specific/example/Level1.scala") val source2 = util.Util.readFile("target/generated-sources/specific/example/Level2.scala") - source0 === util.Util.readFile("avrohugger-core/src/test/expected/specific/example/Level0.scala") - source1 === util.Util.readFile("avrohugger-core/src/test/expected/specific/example/Level1.scala") - source2 === util.Util.readFile("avrohugger-core/src/test/expected/specific/example/Level2.scala") + source0 ===/ util.Util.readFile("avrohugger-core/src/test/expected/specific/example/Level0.scala") + source1 ===/ util.Util.readFile("avrohugger-core/src/test/expected/specific/example/Level1.scala") + source2 ===/ util.Util.readFile("avrohugger-core/src/test/expected/specific/example/Level2.scala") } def e5 = { val inputString = util.Util.readFile("avrohugger-core/src/test/avro/nested.avdl") val myAvroScalaCustomTypes = SpecificRecord.defaultTypes.copy(protocol = types.ScalaADT) - val gen = new Generator(format = SpecificRecord, avroScalaCustomTypes = Some(myAvroScalaCustomTypes)) + val gen = Generator(format = SpecificRecord, avroScalaCustomTypes = Some(myAvroScalaCustomTypes)) val outDir = gen.defaultOutputDir + "/specific/" gen.stringToFile(inputString, outDir) val source = util.Util.readFile("target/generated-sources/specific/example/idl/NestedProtocol.scala") - source === util.Util.readFile("avrohugger-core/src/test/expected/specific/example/idl/NestedProtocol.scala") + source ===/ util.Util.readFile("avrohugger-core/src/test/expected/specific/example/idl/NestedProtocol.scala") } def e6 = { val inputString = util.Util.readFile("avrohugger-core/src/test/avro/recursive.avdl") val myAvroScalaCustomTypes = SpecificRecord.defaultTypes.copy(protocol = types.ScalaADT) - val gen = new Generator(format = SpecificRecord, avroScalaCustomTypes = Some(myAvroScalaCustomTypes)) + val gen = Generator(format = SpecificRecord, avroScalaCustomTypes = Some(myAvroScalaCustomTypes)) val outDir = gen.defaultOutputDir + "/specific/" gen.stringToFile(inputString, outDir) val source = util.Util.readFile("target/generated-sources/specific/example/idl/Recursive.scala") - source === util.Util.readFile("avrohugger-core/src/test/expected/specific/example/idl/Recursive.scala") + source ===/ util.Util.readFile("avrohugger-core/src/test/expected/specific/example/idl/Recursive.scala") } def e7 = { val inputString = util.Util.readFile("avrohugger-core/src/test/avro/enums.avsc") - val gen = new Generator(SpecificRecord) + val gen = Generator(SpecificRecord) val outDir = gen.defaultOutputDir + "/specific/" gen.stringToFile(inputString, outDir) val source = util.Util.readFile("target/generated-sources/specific/example/Suit.java") - source === util.Util.readFile("avrohugger-core/src/test/expected/specific/example/Suit.java") + source ===/ util.Util.readFile("avrohugger-core/src/test/expected/specific/example/Suit.java") } def e8 = { val inputString = util.Util.readFile("avrohugger-core/src/test/avro/enums.avpr") - val gen = new Generator(SpecificRecord) + val gen = Generator(SpecificRecord) val outDir = gen.defaultOutputDir + "/specific/" gen.stringToFile(inputString, outDir) val sourceEnum = util.Util.readFile("target/generated-sources/specific/example/proto/Suit.java") val sourceRecord = util.Util.readFile("target/generated-sources/specific/example/proto/Card.scala") - sourceEnum === util.Util.readFile("avrohugger-core/src/test/expected/specific/example/proto/Suit.java") - sourceRecord === util.Util.readFile("avrohugger-core/src/test/expected/specific/example/proto/Card.scala") + sourceEnum ===/ util.Util.readFile("avrohugger-core/src/test/expected/specific/example/proto/Suit.java") + sourceRecord ===/ util.Util.readFile("avrohugger-core/src/test/expected/specific/example/proto/Card.scala") } def e9 = { val inputString = util.Util.readFile("avrohugger-core/src/test/avro/enums.avdl") - val gen = new Generator(SpecificRecord) + val gen = Generator(SpecificRecord) val outDir = gen.defaultOutputDir + "/specific/" gen.stringToFile(inputString, outDir) val sourceEnum = util.Util.readFile("target/generated-sources/specific/example/idl/Suit.java") val sourceRecord = util.Util.readFile("target/generated-sources/specific/example/idl/Card.scala") - sourceEnum === util.Util.readFile("avrohugger-core/src/test/expected/specific/example/idl/Suit.java") - sourceRecord === util.Util.readFile("avrohugger-core/src/test/expected/specific/example/idl/Card.scala") + sourceEnum ===/ util.Util.readFile("avrohugger-core/src/test/expected/specific/example/idl/Suit.java") + sourceRecord ===/ util.Util.readFile("avrohugger-core/src/test/expected/specific/example/idl/Card.scala") } def e10 = { val inputString = util.Util.readFile("avrohugger-core/src/test/avro/enums_nested.avsc") - val gen = new Generator(SpecificRecord) + val gen = Generator(SpecificRecord) val outDir = gen.defaultOutputDir + "/specific/" gen.stringToFile(inputString, outDir) val sourceEnum = util.Util.readFile("target/generated-sources/specific/example/Direction.java") val sourceRecord = util.Util.readFile("target/generated-sources/specific/example/Compass.scala") - sourceEnum === util.Util.readFile("avrohugger-core/src/test/expected/specific/example/Direction.java") - sourceRecord === util.Util.readFile("avrohugger-core/src/test/expected/specific/example/Compass.scala") + sourceEnum ===/ util.Util.readFile("avrohugger-core/src/test/expected/specific/example/Direction.java") + sourceRecord ===/ util.Util.readFile("avrohugger-core/src/test/expected/specific/example/Compass.scala") } def e11 = { val inputString = util.Util.readFile("avrohugger-core/src/test/avro/bytes.avsc") - val gen = new Generator(SpecificRecord) + val gen = Generator(SpecificRecord) val outDir = gen.defaultOutputDir + "/specific/" gen.stringToFile(inputString, outDir) val source = util.Util.readFile("target/generated-sources/specific/example/BinarySc.scala") - source === util.Util.readFile("avrohugger-core/src/test/expected/specific/example/BinarySc.scala") + source ===/ util.Util.readFile("avrohugger-core/src/test/expected/specific/example/BinarySc.scala") } def e12 = { val inputString = util.Util.readFile("avrohugger-core/src/test/avro/bytes.avpr") - val gen = new Generator(SpecificRecord) + val gen = Generator(SpecificRecord) val outDir = gen.defaultOutputDir + "/specific/" gen.stringToFile(inputString, outDir) val source = util.Util.readFile("target/generated-sources/specific/example/proto/BinaryPr.scala") - source === util.Util.readFile("avrohugger-core/src/test/expected/specific/example/proto/BinaryPr.scala") + source ===/ util.Util.readFile("avrohugger-core/src/test/expected/specific/example/proto/BinaryPr.scala") } def e13 = { val inputString = util.Util.readFile("avrohugger-core/src/test/avro/bytes.avdl") - val gen = new Generator(SpecificRecord) + val gen = Generator(SpecificRecord) val outDir = gen.defaultOutputDir + "/specific/" gen.stringToFile(inputString, outDir) val source = util.Util.readFile("target/generated-sources/specific/example/idl/BinaryIdl.scala") - source === util.Util.readFile("avrohugger-core/src/test/expected/specific/example/idl/BinaryIdl.scala") + source ===/ util.Util.readFile("avrohugger-core/src/test/expected/specific/example/idl/BinaryIdl.scala") } def e14 = { val inputString = util.Util.readFile("avrohugger-core/src/test/avro/import.avdl") - val gen = new Generator(SpecificRecord) + val gen = Generator(SpecificRecord) val outDir = gen.defaultOutputDir + "/specific/" gen.stringToFile(inputString, outDir) must throwA(new java.lang.RuntimeException("Imports not supported in String IDLs, only avdl files.")) } @@ -207,26 +208,26 @@ class SpecificStringToFileSpec extends Specification { def e15 = { val inputString = util.Util.readFile("avrohugger-core/src/test/avro/AvroTypeProviderTestEmptyRecord.avdl") val myAvroScalaCustomTypes = SpecificRecord.defaultTypes.copy(protocol = types.ScalaADT) - val gen = new Generator(format = SpecificRecord, avroScalaCustomTypes = Some(myAvroScalaCustomTypes)) + val gen = Generator(format = SpecificRecord, avroScalaCustomTypes = Some(myAvroScalaCustomTypes)) val outDir = gen.defaultOutputDir + "/specific/" gen.stringToFile(inputString, outDir) val source = util.Util.readFile("target/generated-sources/specific/test/Calculator.scala") - source === util.Util.readFile("avrohugger-core/src/test/expected/specific/test/Calculator.scala") + source ===/ util.Util.readFile("avrohugger-core/src/test/expected/specific/test/Calculator.scala") } def e16 = { val inputString = util.Util.readFile("avrohugger-core/src/test/avro/defaults.avdl") - val gen = new Generator(SpecificRecord) + val gen = Generator(SpecificRecord) val outDir = gen.defaultOutputDir + "/specific/" gen.stringToFile(inputString, outDir) val sourceRecord = util.Util.readFile("target/generated-sources/specific/example/idl/Defaults.scala") val sourceEnum = util.Util.readFile("target/generated-sources/specific/example/idl/DefaultEnum.java") - sourceRecord === util.Util.readFile("avrohugger-core/src/test/expected/specific/example/idl/Defaults.scala") - sourceEnum === util.Util.readFile("avrohugger-core/src/test/expected/specific/example/idl/DefaultEnum.java") + sourceRecord ===/ util.Util.readFile("avrohugger-core/src/test/expected/specific/example/idl/Defaults.scala") + sourceEnum ===/ util.Util.readFile("avrohugger-core/src/test/expected/specific/example/idl/DefaultEnum.java") } @@ -235,24 +236,24 @@ class SpecificStringToFileSpec extends Specification { def e21 = { val inputString = util.Util.readFile("avrohugger-core/src/test/avro/AvroTypeProviderTestProtocol.avdl") - val gen = new Generator(format = SpecificRecord) + val gen = Generator(format = SpecificRecord) val outDir = gen.defaultOutputDir + "/specific/" gen.stringToFile(inputString, outDir) val source = util.Util.readFile("target/generated-sources/specific/test/Joystick.scala") - source === util.Util.readFile("avrohugger-core/src/test/expected/specific/test/Joystick.scala") + source ===/ util.Util.readFile("avrohugger-core/src/test/expected/specific/test/Joystick.scala") } // def e22 = { // val inputString = util.Util.readFile("avrohugger-core/src/test/avro/logical.avdl") - // val gen = new Generator(SpecificRecord) + // val gen = Generator(SpecificRecord) // val outDir = gen.defaultOutputDir + "/specific/" // gen.stringToFile(inputString, outDir) // val source = util.Util.readFile("target/generated-sources/specific/example/idl/LogicalIdl.scala") - // source === util.Util.readFile("avrohugger-core/src/test/expected/specific/example/idl/LogicalIdl.scala") + // source ===/ util.Util.readFile("avrohugger-core/src/test/expected/specific/example/idl/LogicalIdl.scala") // } diff --git a/avrohugger-core/src/test/scala/specific/SpecificStringToStringsSpec.scala b/avrohugger-core/src/test/scala/specific/SpecificStringToStringsSpec.scala index 2bcacaa3..cd4272a4 100644 --- a/avrohugger-core/src/test/scala/specific/SpecificStringToStringsSpec.scala +++ b/avrohugger-core/src/test/scala/specific/SpecificStringToStringsSpec.scala @@ -5,6 +5,7 @@ package specific import avrohugger.Generator import avrohugger.format.SpecificRecord import org.specs2._ +import util.Util.LineEndingAmbiguousMatcherString class SpecificStringToStringsSpec extends Specification { @@ -36,156 +37,156 @@ class SpecificStringToStringsSpec extends Specification { // tests common to fileToX and stringToX def e1 = { val inputString = util.Util.readFile("avrohugger-core/src/test/avro/mail.avpr") - val gen = new Generator(SpecificRecord) + val gen = Generator(SpecificRecord) val List(sourceTrait, sourceRecord) = gen.stringToStrings(inputString) val expectedTrait = util.Util.readFile("avrohugger-core/src/test/expected/specific/example/proto/Mail.scala") val expectedRecord = util.Util.readFile("avrohugger-core/src/test/expected/specific/example/proto/Message.scala") - sourceTrait === expectedTrait - sourceRecord === expectedRecord + sourceTrait ===/ expectedTrait + sourceRecord ===/ expectedRecord } def e2 = { val inputString = util.Util.readFile("avrohugger-core/src/test/avro/user.avsc") - val gen = new Generator(SpecificRecord) + val gen = Generator(SpecificRecord) val List(source) = gen.stringToStrings(inputString) val expected = util.Util.readFile("avrohugger-core/src/test/expected/specific/example/User.scala") - source === expected + source ===/ expected } def e3 = { val inputString = util.Util.readFile("avrohugger-core/src/test/avro/AvroTypeProviderTestNoNamespace.avsc") - val gen = new Generator(SpecificRecord) + val gen = Generator(SpecificRecord) val List(source) = gen.stringToStrings(inputString) val expected = util.Util.readFile("avrohugger-core/src/test/expected/specific/AvroTypeProviderTestNoNamespace.scala") - source === expected + source ===/ expected } def e4 = { val inputString = util.Util.readFile("avrohugger-core/src/test/avro/nested.avsc") - val gen = new Generator(SpecificRecord) + val gen = Generator(SpecificRecord) val List(source2, source1, source0) = gen.stringToStrings(inputString) val expected0 = util.Util.readFile("avrohugger-core/src/test/expected/specific/example/Level0.scala") val expected1 = util.Util.readFile("avrohugger-core/src/test/expected/specific/example/Level1.scala") val expected2 = util.Util.readFile("avrohugger-core/src/test/expected/specific/example/Level2.scala") - source0 === expected0 - source1 === expected1 - source2 === expected2 + source0 ===/ expected0 + source1 ===/ expected1 + source2 ===/ expected2 } def e5 = { val inputString = util.Util.readFile("avrohugger-core/src/test/avro/nested.avdl") val myAvroScalaCustomTypes = SpecificRecord.defaultTypes.copy(protocol = types.ScalaADT) - val gen = new Generator(format = SpecificRecord, avroScalaCustomTypes = Some(myAvroScalaCustomTypes)) + val gen = Generator(format = SpecificRecord, avroScalaCustomTypes = Some(myAvroScalaCustomTypes)) val List(source) = gen.stringToStrings(inputString) val expected = util.Util.readFile("avrohugger-core/src/test/expected/specific/example/idl/NestedProtocol.scala") - source === expected + source ===/ expected } def e6 = { val inputString = util.Util.readFile("avrohugger-core/src/test/avro/recursive.avdl") - val gen = new Generator(SpecificRecord) + val gen = Generator(SpecificRecord) val List(source) = gen.stringToStrings(inputString) val expected = util.Util.readFile("avrohugger-core/src/test/expected/specific/example/idl/Recursive.scala") - source === expected + source ===/ expected } def e7 = { val inputString = util.Util.readFile("avrohugger-core/src/test/avro/enums.avsc") - val gen = new Generator(SpecificRecord) + val gen = Generator(SpecificRecord) val List(source) = gen.stringToStrings(inputString) val expected = util.Util.readFile("avrohugger-core/src/test/expected/specific/example/Suit.java") - source === expected + source ===/ expected } def e8 = { val inputString = util.Util.readFile("avrohugger-core/src/test/avro/enums.avpr") - val gen = new Generator(SpecificRecord) + val gen = Generator(SpecificRecord) val List(sourceRecord, sourceEnum) = gen.stringToStrings(inputString) val expectedEnum = util.Util.readFile("avrohugger-core/src/test/expected/specific/example/proto/Suit.java") val expectedRecord = util.Util.readFile("avrohugger-core/src/test/expected/specific/example/proto/Card.scala") - sourceEnum === expectedEnum - sourceRecord === expectedRecord + sourceEnum ===/ expectedEnum + sourceRecord ===/ expectedRecord } def e9 = { val inputString = util.Util.readFile("avrohugger-core/src/test/avro/enums.avdl") - val gen = new Generator(SpecificRecord) + val gen = Generator(SpecificRecord) val List(sourceRecord, sourceEnum) = gen.stringToStrings(inputString) val expectedEnum = util.Util.readFile("avrohugger-core/src/test/expected/specific/example/idl/Suit.java") val expectedRecord = util.Util.readFile("avrohugger-core/src/test/expected/specific/example/idl/Card.scala") - sourceEnum === expectedEnum - sourceRecord === expectedRecord + sourceEnum ===/ expectedEnum + sourceRecord ===/ expectedRecord } def e10 = { val inputString = util.Util.readFile("avrohugger-core/src/test/avro/enums_nested.avsc") - val gen = new Generator(SpecificRecord) + val gen = Generator(SpecificRecord) val List(sourceEnum, sourceRecord) = gen.stringToStrings(inputString) val expectedEnum = util.Util.readFile("avrohugger-core/src/test/expected/specific/example/Direction.java") val expectedRecord = util.Util.readFile("avrohugger-core/src/test/expected/specific/example/Compass.scala") - sourceEnum === expectedEnum - sourceRecord === expectedRecord + sourceEnum ===/ expectedEnum + sourceRecord ===/ expectedRecord } def e11 = { val inputString = util.Util.readFile("avrohugger-core/src/test/avro/bytes.avsc") - val gen = new Generator(SpecificRecord) + val gen = Generator(SpecificRecord) val List(source) = gen.stringToStrings(inputString) val expected = util.Util.readFile("avrohugger-core/src/test/expected/specific/example/BinarySc.scala") - source === expected + source ===/ expected } def e12 = { val inputString = util.Util.readFile("avrohugger-core/src/test/avro/bytes.avpr") - val gen = new Generator(SpecificRecord) + val gen = Generator(SpecificRecord) val List(source) = gen.stringToStrings(inputString) val expected = util.Util.readFile("avrohugger-core/src/test/expected/specific/example/proto/BinaryPr.scala") - source === expected + source ===/ expected } def e13 = { val inputString = util.Util.readFile("avrohugger-core/src/test/avro/bytes.avdl") - val gen = new Generator(SpecificRecord) + val gen = Generator(SpecificRecord) val List(source) = gen.stringToStrings(inputString) val expected = util.Util.readFile("avrohugger-core/src/test/expected/specific/example/idl/BinaryIdl.scala") - source === expected + source ===/ expected } def e14 = { val inputString = util.Util.readFile("avrohugger-core/src/test/avro/import.avdl") - val gen = new Generator(SpecificRecord) + val gen = Generator(SpecificRecord) gen.stringToStrings(inputString) must throwA(new java.lang.RuntimeException("Imports not supported in String IDLs, only avdl files.")) } def e15 = { val inputString = util.Util.readFile("avrohugger-core/src/test/avro/AvroTypeProviderTestEmptyRecord.avdl") val myAvroScalaCustomTypes = SpecificRecord.defaultTypes.copy(protocol = types.ScalaADT) - val gen = new Generator(format = SpecificRecord, avroScalaCustomTypes = Some(myAvroScalaCustomTypes)) + val gen = Generator(format = SpecificRecord, avroScalaCustomTypes = Some(myAvroScalaCustomTypes)) val List(source) = gen.stringToStrings(inputString) val expected = util.Util.readFile("avrohugger-core/src/test/expected/specific/test/Calculator.scala") - source === expected + source ===/ expected } def e16 = { val inputString = util.Util.readFile("avrohugger-core/src/test/avro/defaults.avdl") - val gen = new Generator(SpecificRecord) + val gen = Generator(SpecificRecord) val List(sourceRecord, sourceEnum) = gen.stringToStrings(inputString) val expectedRecord = util.Util.readFile("avrohugger-core/src/test/expected/specific/example/idl/Defaults.scala") val expectedEnum = util.Util.readFile("avrohugger-core/src/test/expected/specific/example/idl/DefaultEnum.java") - sourceRecord === expectedRecord - sourceEnum === expectedEnum + sourceRecord ===/ expectedRecord + sourceEnum ===/ expectedEnum } @@ -195,11 +196,11 @@ class SpecificStringToStringsSpec extends Specification { def e21 = { val inputString = util.Util.readFile("avrohugger-core/src/test/avro/AvroTypeProviderTestProtocol.avdl") - val gen = new Generator(format = SpecificRecord) + val gen = Generator(format = SpecificRecord) val List(source) = gen.stringToStrings(inputString) - source === util.Util.readFile("avrohugger-core/src/test/expected/specific/test/Joystick.scala") + source ===/ util.Util.readFile("avrohugger-core/src/test/expected/specific/test/Joystick.scala") } } diff --git a/avrohugger-core/src/test/scala/standard/StandardCommentsSpec.scala b/avrohugger-core/src/test/scala/standard/StandardCommentsSpec.scala index 9f039778..165b3d3d 100644 --- a/avrohugger-core/src/test/scala/standard/StandardCommentsSpec.scala +++ b/avrohugger-core/src/test/scala/standard/StandardCommentsSpec.scala @@ -2,6 +2,7 @@ package avrohugger import avrohugger.format.Standard import org.specs2._ +import util.Util.LineEndingAmbiguousMatcherString class StandardCommentsSpec extends Specification { @@ -16,48 +17,48 @@ class StandardCommentsSpec extends Specification { def e1 = { val infile = new java.io.File("avrohugger-core/src/test/avro/comments1.avdl") - val gen = new Generator(Standard) + val gen = Generator(Standard) val outDir = gen.defaultOutputDir + "/standard/" gen.fileToFile(infile, outDir) val sourceRecord = scala.io.Source.fromFile(s"$outDir/com/example/NoSpaces1.scala").mkString - sourceRecord ==== util.Util.readFile("avrohugger-core/src/test/expected/comments/standard/NoSpaces1.scala") + sourceRecord ===/ util.Util.readFile("avrohugger-core/src/test/expected/comments/standard/NoSpaces1.scala") } def e2 = { val infile = new java.io.File("avrohugger-core/src/test/avro/comments2.avdl") - val gen = new Generator(Standard) + val gen = Generator(Standard) val outDir = gen.defaultOutputDir + "/standard/" gen.fileToFile(infile, outDir) val sourceRecord = scala.io.Source.fromFile(s"$outDir/com/example/NoSpaces2.scala").mkString - sourceRecord ==== util.Util.readFile("avrohugger-core/src/test/expected/comments/standard/NoSpaces2.scala") + sourceRecord ===/ util.Util.readFile("avrohugger-core/src/test/expected/comments/standard/NoSpaces2.scala") } def e3 = { val infile = new java.io.File("avrohugger-core/src/test/avro/comments3.avdl") - val gen = new Generator(Standard) + val gen = Generator(Standard) val outDir = gen.defaultOutputDir + "/standard/" gen.fileToFile(infile, outDir) val sourceRecord = scala.io.Source.fromFile(s"$outDir/com/example/NoSpaces3.scala").mkString - sourceRecord ==== util.Util.readFile("avrohugger-core/src/test/expected/comments/standard/NoSpaces3.scala") + sourceRecord ===/ util.Util.readFile("avrohugger-core/src/test/expected/comments/standard/NoSpaces3.scala") } def e4 = { val infile = new java.io.File("avrohugger-core/src/test/avro/comments4.avdl") val myAvroScalaCustomTypes = Standard.defaultTypes.copy(protocol = types.ScalaADT) - val gen = new Generator(format = Standard, avroScalaCustomTypes = Some(myAvroScalaCustomTypes)) + val gen = Generator(format = Standard, avroScalaCustomTypes = Some(myAvroScalaCustomTypes)) val outDir = gen.defaultOutputDir + "/standard/" gen.fileToFile(infile, outDir) val sourceRecord = scala.io.Source.fromFile(s"$outDir/com/example/Example4.scala").mkString - sourceRecord ==== util.Util.readFile("avrohugger-core/src/test/expected/comments/standard/Example4.scala") + sourceRecord ===/ util.Util.readFile("avrohugger-core/src/test/expected/comments/standard/Example4.scala") } def e5 = { val infile = new java.io.File("avrohugger-core/src/test/avro/comments5.avdl") - val gen = new Generator(format = Standard) + val gen = Generator(format = Standard) val outDir = gen.defaultOutputDir + "/standard/" gen.fileToFile(infile, outDir) val sourceRecord = scala.io.Source.fromFile(s"$outDir/com/example/Example5.scala").mkString - sourceRecord ==== util.Util.readFile("avrohugger-core/src/test/expected/comments/standard/Example5.scala") + sourceRecord ===/ util.Util.readFile("avrohugger-core/src/test/expected/comments/standard/Example5.scala") } } diff --git a/avrohugger-core/src/test/scala/standard/StandardCustomEnumSpec.scala b/avrohugger-core/src/test/scala/standard/StandardCustomEnumSpec.scala index 5b08f9ad..2ca54912 100644 --- a/avrohugger-core/src/test/scala/standard/StandardCustomEnumSpec.scala +++ b/avrohugger-core/src/test/scala/standard/StandardCustomEnumSpec.scala @@ -3,6 +3,7 @@ package avrohugger import avrohugger.format.Standard import avrohugger.types._ import org.specs2._ +import util.Util.LineEndingAmbiguousMatcherString class StandardCustomEnumSpec extends Specification { @@ -19,7 +20,7 @@ class StandardCustomEnumSpec extends Specification { def e1 = { val infile = new java.io.File("avrohugger-core/src/test/avro/import.avdl") - val gen = new Generator( + val gen = Generator( Standard, Some(Standard.defaultTypes.copy(`enum` = JavaEnum, protocol = ScalaADT)), Map( @@ -33,17 +34,17 @@ class StandardCustomEnumSpec extends Specification { val expectedDep2 = util.Util.readFile("avrohugger-core/src/test/expected/standard/other/ns/java/ExternalDependency.scala") val expectedDep3 = util.Util.readFile("avrohugger-core/src/test/expected/standard/other/ns/java/Suit.java") - adt === expectedADT - dep1a === expectedDep1a - dep1 === expectedDep1 - dep2 === expectedDep2 - dep3 === expectedDep3 + adt ===/ expectedADT + dep1a ===/ expectedDep1a + dep1 ===/ expectedDep1 + dep2 ===/ expectedDep2 + dep3 ===/ expectedDep3 } def e2 = { val infile = new java.io.File("avrohugger-core/src/test/avro/import.avdl") - val gen = new Generator( + val gen = Generator( Standard, Some(Standard.defaultTypes.copy(`enum` = JavaEnum, protocol = ScalaADT)), Map( @@ -64,16 +65,16 @@ class StandardCustomEnumSpec extends Specification { val expectedDep2 = util.Util.readFile("avrohugger-core/src/test/expected/standard/other/ns/java/ExternalDependency.scala") val expectedDep3 = util.Util.readFile("avrohugger-core/src/test/expected/standard/other/ns/java/Suit.java") - adt === expectedADT - dep1a === expectedDep1a - dep1 === expectedDep1 - dep2 === expectedDep2 - dep3 === expectedDep3 + adt ===/ expectedADT + dep1a ===/ expectedDep1a + dep1 ===/ expectedDep1 + dep2 ===/ expectedDep2 + dep3 ===/ expectedDep3 } def e3 = { val infile = new java.io.File("avrohugger-core/src/test/avro/import.avdl") - val gen = new Generator( + val gen = Generator( Standard, Some(Standard.defaultTypes.copy(`enum` = ScalaCaseObjectEnum, protocol = ScalaADT)), Map( @@ -86,16 +87,16 @@ class StandardCustomEnumSpec extends Specification { val expectedDep2 = util.Util.readFile("avrohugger-core/src/test/expected/standard/other/ns/case/ExternalDependency.scala") val expectedDep3 = util.Util.readFile("avrohugger-core/src/test/expected/standard/other/ns/case/Suit.scala") - adt === expectedADT - dep1 === expectedDep1 - dep2 === expectedDep2 - dep3 === expectedDep3 + adt ===/ expectedADT + dep1 ===/ expectedDep1 + dep2 ===/ expectedDep2 + dep3 ===/ expectedDep3 } def e4 = { val infile = new java.io.File("avrohugger-core/src/test/avro/import.avdl") - val gen = new Generator( + val gen = Generator( Standard, Some(Standard.defaultTypes.copy(`enum` = ScalaCaseObjectEnum, protocol = ScalaADT)), Map( @@ -114,16 +115,16 @@ class StandardCustomEnumSpec extends Specification { val expectedDep2 = util.Util.readFile("avrohugger-core/src/test/expected/standard/other/ns/case/ExternalDependency.scala") val expectedDep3 = util.Util.readFile("avrohugger-core/src/test/expected/standard/other/ns/case/Suit.scala") - adt === expectedADT - dep1 === expectedDep1 - dep2 === expectedDep2 - dep3 === expectedDep3 + adt ===/ expectedADT + dep1 ===/ expectedDep1 + dep2 ===/ expectedDep2 + dep3 ===/ expectedDep3 } def e5 = { val infile = new java.io.File("avrohugger-core/src/test/avro/import.avdl") - val gen = new Generator( + val gen = Generator( Standard, Some(Standard.defaultTypes.copy(`enum` = EnumAsScalaString, protocol = ScalaADT)), Map( @@ -135,15 +136,15 @@ class StandardCustomEnumSpec extends Specification { val expectedDep1 = util.Util.readFile("avrohugger-core/src/test/expected/standard/example/idl/string/Defaults.scala") val expectedDep2 = util.Util.readFile("avrohugger-core/src/test/expected/standard/other/ns/string/ExternalDependency.scala") - adt === expectedADT - dep1 === expectedDep1 - dep2 === expectedDep2 + adt ===/ expectedADT + dep1 ===/ expectedDep1 + dep2 ===/ expectedDep2 } def e6 = { val infile = new java.io.File("avrohugger-core/src/test/avro/import.avdl") - val gen = new Generator( + val gen = Generator( Standard, Some(Standard.defaultTypes.copy(`enum` = EnumAsScalaString, protocol = ScalaADT)), Map( @@ -160,9 +161,9 @@ class StandardCustomEnumSpec extends Specification { val expectedDep1 = util.Util.readFile("avrohugger-core/src/test/expected/standard/example/idl/string/Defaults.scala") val expectedDep2 = util.Util.readFile("avrohugger-core/src/test/expected/standard/other/ns/string/ExternalDependency.scala") - adt === expectedADT - dep1 === expectedDep1 - dep2 === expectedDep2 + adt ===/ expectedADT + dep1 ===/ expectedDep1 + dep2 ===/ expectedDep2 } } diff --git a/avrohugger-core/src/test/scala/standard/StandardFileToFileSpec.scala b/avrohugger-core/src/test/scala/standard/StandardFileToFileSpec.scala index 44eb3932..d356a02c 100644 --- a/avrohugger-core/src/test/scala/standard/StandardFileToFileSpec.scala +++ b/avrohugger-core/src/test/scala/standard/StandardFileToFileSpec.scala @@ -7,13 +7,14 @@ import avrohugger._ import avrohugger.format.Standard import avrohugger.types._ import org.specs2._ -import util.Util.checkFileExist +import util.Util.{ LineEndingAmbiguousMatcherString, checkFileExist } import scala.util.Try class StandardFileToFileSpec extends Specification { - def is = s2""" + def is = + s2""" Standard Generator fileToFile method should correctly generate a simple case class definition from AVRO $eA @@ -76,30 +77,30 @@ class StandardFileToFileSpec extends Specification { // tests standard to fileToX def eA = { val infile = new java.io.File("avrohugger-core/src/test/avro/twitter.avro") - val gen = new Generator(Standard) + val gen = Generator(Standard) val outDir = gen.defaultOutputDir + "/standard/" gen.fileToFile(infile, outDir) val source = util.Util.readFile("target/generated-sources/standard/com/miguno/avro/twitter_schema.scala") - source === util.Util.readFile("avrohugger-core/src/test/expected/standard/com/miguno/avro/twitter_schema.scala") + source ===/ util.Util.readFile("avrohugger-core/src/test/expected/standard/com/miguno/avro/twitter_schema.scala") } def eB = { val infile = new java.io.File("avrohugger-core/src/test/avro/relative.avsc") - val gen = new Generator(Standard, Some(Standard.defaultTypes.copy(record = ScalaCaseClassWithSchema))) + val gen = Generator(Standard, Some(Standard.defaultTypes.copy(record = ScalaCaseClassWithSchema))) val outDir = gen.defaultOutputDir + "/standard/" gen.fileToFile(infile, outDir) val source = util.Util.readFile("target/generated-sources/standard/example/Relative.scala") - source === util.Util.readFile("avrohugger-core/src/test/expected/standard/example/Relative.scala") + source ===/ util.Util.readFile("avrohugger-core/src/test/expected/standard/example/Relative.scala") } // tests standard to fileToFile def e0 = { val infile = new java.io.File("avrohugger-core/src/test/avro/import.avdl") - val gen = new Generator(Standard) + val gen = Generator(Standard) val outDir = gen.defaultOutputDir + "/standard/" gen.fileToFile(infile, outDir) @@ -109,40 +110,40 @@ class StandardFileToFileSpec extends Specification { // tests common to fileToX and stringToX def e1 = { val infile = new java.io.File("avrohugger-core/src/test/avro/mail.avpr") - val gen = new Generator(Standard) + val gen = Generator(Standard) val outDir = gen.defaultOutputDir + "/standard/" gen.fileToFile(infile, outDir) val source = util.Util.readFile(s"$outDir/example/proto/Message.scala") - source === util.Util.readFile("avrohugger-core/src/test/expected/standard/example/proto/Message.scala") + source ===/ util.Util.readFile("avrohugger-core/src/test/expected/standard/example/proto/Message.scala") } def e2 = { val infile = new java.io.File("avrohugger-core/src/test/avro/user.avsc") - val gen = new Generator(Standard) + val gen = Generator(Standard) val outDir = gen.defaultOutputDir + "/standard/" gen.fileToFile(infile, outDir) val source = util.Util.readFile("target/generated-sources/standard/example/User.scala") - source === util.Util.readFile("avrohugger-core/src/test/expected/standard/example/User.scala") + source ===/ util.Util.readFile("avrohugger-core/src/test/expected/standard/example/User.scala") } def e3 = { val infile = new java.io.File("avrohugger-core/src/test/avro/AvroTypeProviderTestNoNamespace.avsc") - val gen = new Generator(Standard) + val gen = Generator(Standard) val outDir = gen.defaultOutputDir + "/standard/" gen.fileToFile(infile, outDir) val source = util.Util.readFile("target/generated-sources/standard/AvroTypeProviderTestNoNamespace.scala") - source === util.Util.readFile("avrohugger-core/src/test/expected/standard/AvroTypeProviderTestNoNamespace.scala") + source ===/ util.Util.readFile("avrohugger-core/src/test/expected/standard/AvroTypeProviderTestNoNamespace.scala") } def e4 = { val infile = new java.io.File("avrohugger-core/src/test/avro/nested.avsc") - val gen = new Generator(Standard) + val gen = Generator(Standard) val outDir = gen.defaultOutputDir + "/standard/" gen.fileToFile(infile, outDir) @@ -150,118 +151,118 @@ class StandardFileToFileSpec extends Specification { val source1 = util.Util.readFile("target/generated-sources/standard/example/Level1.scala") val source2 = util.Util.readFile("target/generated-sources/standard/example/Level2.scala") - source0 === util.Util.readFile("avrohugger-core/src/test/expected/standard/example/Level0.scala") - source1 === util.Util.readFile("avrohugger-core/src/test/expected/standard/example/Level1.scala") - source2 === util.Util.readFile("avrohugger-core/src/test/expected/standard/example/Level2.scala") + source0 ===/ util.Util.readFile("avrohugger-core/src/test/expected/standard/example/Level0.scala") + source1 ===/ util.Util.readFile("avrohugger-core/src/test/expected/standard/example/Level1.scala") + source2 ===/ util.Util.readFile("avrohugger-core/src/test/expected/standard/example/Level2.scala") } def e5 = { val infile = new java.io.File("avrohugger-core/src/test/avro/nested.avdl") val myAvroScalaCustomTypes = Standard.defaultTypes.copy(protocol = types.ScalaADT) - val gen = new Generator(format = Standard, avroScalaCustomTypes = Some(myAvroScalaCustomTypes)) + val gen = Generator(format = Standard, avroScalaCustomTypes = Some(myAvroScalaCustomTypes)) val outDir = gen.defaultOutputDir + "/standard/" gen.fileToFile(infile, outDir) val source = util.Util.readFile("target/generated-sources/standard/example/idl/NestedProtocol.scala") - source === util.Util.readFile("avrohugger-core/src/test/expected/standard/example/idl/NestedProtocol.scala") + source ===/ util.Util.readFile("avrohugger-core/src/test/expected/standard/example/idl/NestedProtocol.scala") } def e6 = { val infile = new java.io.File("avrohugger-core/src/test/avro/recursive.avdl") - val gen = new Generator(Standard) + val gen = Generator(Standard) val outDir = gen.defaultOutputDir + "/standard/" gen.fileToFile(infile, outDir) val source = util.Util.readFile("target/generated-sources/standard/example/idl/Recursive.scala") - source === util.Util.readFile("avrohugger-core/src/test/expected/standard/example/idl/Recursive.scala") + source ===/ util.Util.readFile("avrohugger-core/src/test/expected/standard/example/idl/Recursive.scala") } def e7 = { val infile = new java.io.File("avrohugger-core/src/test/avro/enums.avsc") - val gen = new Generator(Standard) + val gen = Generator(Standard) val outDir = gen.defaultOutputDir + "/standard/" gen.fileToFile(infile, outDir) val source = util.Util.readFile("target/generated-sources/standard/example/Suit.scala") - source === util.Util.readFile("avrohugger-core/src/test/expected/standard/example/Suit.scala") + source ===/ util.Util.readFile("avrohugger-core/src/test/expected/standard/example/Suit.scala") } def e8 = { val infile = new java.io.File("avrohugger-core/src/test/avro/enums.avpr") val myAvroScalaCustomTypes = Standard.defaultTypes.copy(protocol = types.ScalaADT) - val gen = new Generator(format = Standard, avroScalaCustomTypes = Some(myAvroScalaCustomTypes)) + val gen = Generator(format = Standard, avroScalaCustomTypes = Some(myAvroScalaCustomTypes)) val outDir = gen.defaultOutputDir + "/standard/" gen.fileToFile(infile, outDir) val source = util.Util.readFile("target/generated-sources/standard/example/proto/EnumProtocol.scala") - source === util.Util.readFile("avrohugger-core/src/test/expected/standard/example/proto/EnumProtocol.scala") + source ===/ util.Util.readFile("avrohugger-core/src/test/expected/standard/example/proto/EnumProtocol.scala") } def e9 = { val infile = new java.io.File("avrohugger-core/src/test/avro/enums.avdl") val myAvroScalaCustomTypes = Standard.defaultTypes.copy(protocol = types.ScalaADT) - val gen = new Generator(format = Standard, avroScalaCustomTypes = Some(myAvroScalaCustomTypes)) + val gen = Generator(format = Standard, avroScalaCustomTypes = Some(myAvroScalaCustomTypes)) val outDir = gen.defaultOutputDir + "/standard/" gen.fileToFile(infile, outDir) val source = util.Util.readFile("target/generated-sources/standard/example/idl/EnumProtocol.scala") - source === util.Util.readFile("avrohugger-core/src/test/expected/standard/example/idl/EnumProtocol.scala") + source ===/ util.Util.readFile("avrohugger-core/src/test/expected/standard/example/idl/EnumProtocol.scala") } def e10 = { val infile = new java.io.File("avrohugger-core/src/test/avro/enums_nested.avsc") - val gen = new Generator(Standard) + val gen = Generator(Standard) val outDir = gen.defaultOutputDir + "/standard/" gen.fileToFile(infile, outDir) val sourceEnum = util.Util.readFile("target/generated-sources/standard/example/Direction.scala") val sourceRecord = util.Util.readFile("target/generated-sources/standard/example/Compass.scala") - sourceEnum === util.Util.readFile("avrohugger-core/src/test/expected/standard/example/Direction.scala") - sourceRecord === util.Util.readFile("avrohugger-core/src/test/expected/standard/example/Compass.scala") + sourceEnum ===/ util.Util.readFile("avrohugger-core/src/test/expected/standard/example/Direction.scala") + sourceRecord ===/ util.Util.readFile("avrohugger-core/src/test/expected/standard/example/Compass.scala") } def e11 = { val infile = new java.io.File("avrohugger-core/src/test/avro/bytes.avsc") - val gen = new Generator(Standard) + val gen = Generator(Standard) val outDir = gen.defaultOutputDir + "/standard/" gen.fileToFile(infile, outDir) val source = util.Util.readFile("target/generated-sources/standard/example/BinarySc.scala") - source === util.Util.readFile("avrohugger-core/src/test/expected/standard/example/BinarySc.scala") + source ===/ util.Util.readFile("avrohugger-core/src/test/expected/standard/example/BinarySc.scala") } def e12 = { val infile = new java.io.File("avrohugger-core/src/test/avro/bytes.avpr") - val gen = new Generator(Standard) + val gen = Generator(Standard) val outDir = gen.defaultOutputDir + "/standard/" gen.fileToFile(infile, outDir) val source = util.Util.readFile("target/generated-sources/standard/example/proto/BinaryPr.scala") - source === util.Util.readFile("avrohugger-core/src/test/expected/standard/example/proto/BinaryPr.scala") + source ===/ util.Util.readFile("avrohugger-core/src/test/expected/standard/example/proto/BinaryPr.scala") } def e13 = { val infile = new java.io.File("avrohugger-core/src/test/avro/bytes.avdl") - val gen = new Generator(Standard) + val gen = Generator(Standard) val outDir = gen.defaultOutputDir + "/standard/" gen.fileToFile(infile, outDir) val source = util.Util.readFile("target/generated-sources/standard/example/idl/BinaryIdl.scala") - source === util.Util.readFile("avrohugger-core/src/test/expected/standard/example/idl/BinaryIdl.scala") + source ===/ util.Util.readFile("avrohugger-core/src/test/expected/standard/example/idl/BinaryIdl.scala") } def e14 = { val importing = new java.io.File("avrohugger-core/src/test/avro/import.avdl") - val gen = new Generator(Standard) + val gen = Generator(Standard) val outDir = gen.defaultOutputDir + "/standard/" gen.fileToFile(importing, outDir) @@ -270,151 +271,151 @@ class StandardFileToFileSpec extends Specification { val sourceDep2 = util.Util.readFile("target/generated-sources/standard/other/ns/ExternalDependency.scala") val sourceDep3 = util.Util.readFile("target/generated-sources/standard/other/ns/Suit.scala") - sourceADT === util.Util.readFile("avrohugger-core/src/test/expected/standard/example/idl/ImportProtocol.scala") - sourceDep1 === util.Util.readFile("avrohugger-core/src/test/expected/standard/example/idl/Defaults.scala") - sourceDep2 === util.Util.readFile("avrohugger-core/src/test/expected/standard/other/ns/ExternalDependency.scala") - sourceDep3 === util.Util.readFile("avrohugger-core/src/test/expected/standard/other/ns/Suit.scala") + sourceADT ===/ util.Util.readFile("avrohugger-core/src/test/expected/standard/example/idl/ImportProtocol.scala") + sourceDep1 ===/ util.Util.readFile("avrohugger-core/src/test/expected/standard/example/idl/Defaults.scala") + sourceDep2 ===/ util.Util.readFile("avrohugger-core/src/test/expected/standard/other/ns/ExternalDependency.scala") + sourceDep3 ===/ util.Util.readFile("avrohugger-core/src/test/expected/standard/other/ns/Suit.scala") } def e15 = { val infile = new java.io.File("avrohugger-core/src/test/avro/AvroTypeProviderTestEmptyRecord.avdl") val myAvroScalaCustomTypes = Standard.defaultTypes.copy(protocol = types.ScalaADT) - val gen = new Generator(format = Standard, avroScalaCustomTypes = Some(myAvroScalaCustomTypes)) + val gen = Generator(format = Standard, avroScalaCustomTypes = Some(myAvroScalaCustomTypes)) val outDir = gen.defaultOutputDir + "/standard/" gen.fileToFile(infile, outDir) val source = util.Util.readFile("target/generated-sources/standard/test/Calculator.scala") - source === util.Util.readFile("avrohugger-core/src/test/expected/standard/test/Calculator.scala") + source ===/ util.Util.readFile("avrohugger-core/src/test/expected/standard/test/Calculator.scala") } def e16 = { val infile = new java.io.File("avrohugger-core/src/test/avro/defaults.avdl") val myAvroScalaCustomTypes = Standard.defaultTypes.copy(protocol = types.ScalaADT) - val gen = new Generator(format = Standard, avroScalaCustomTypes = Some(myAvroScalaCustomTypes)) + val gen = Generator(format = Standard, avroScalaCustomTypes = Some(myAvroScalaCustomTypes)) val outDir = gen.defaultOutputDir + "/standard/" gen.fileToFile(infile, outDir) val adt = util.Util.readFile("target/generated-sources/standard/example/idl/Defaults.scala") - adt === util.Util.readFile("avrohugger-core/src/test/expected/standard/example/idl/Defaults.scala") + adt ===/ util.Util.readFile("avrohugger-core/src/test/expected/standard/example/idl/Defaults.scala") } def e17 = { val infile = new java.io.File("avrohugger-core/src/test/avro/unions_without_coproduct.avdl") - val gen = new Generator(Standard) + val gen = Generator(Standard) val outDir = gen.defaultOutputDir + "/standard/" gen.fileToFile(infile, outDir) val adt = util.Util.readFile("target/generated-sources/standard/example/idl/WithoutShapelessCoproduct.scala") - adt === util.Util.readFile("avrohugger-core/src/test/expected/standard/example/idl/WithoutShapelessCoproduct.scala") + adt ===/ util.Util.readFile("avrohugger-core/src/test/expected/standard/example/idl/WithoutShapelessCoproduct.scala") } def e18 = { val infile = new java.io.File("avrohugger-core/src/test/avro/unions_with_coproduct.avdl") - val gen = new Generator(Standard) + val gen = Generator(Standard) val outDir = gen.defaultOutputDir + "/standard/" gen.fileToFile(infile, outDir) val adt = util.Util.readFile("target/generated-sources/standard/example/idl/WithShapelessCoproduct.scala") - adt === util.Util.readFile("avrohugger-core/src/test/expected/standard/example/idl/WithShapelessCoproduct.scala") + adt ===/ util.Util.readFile("avrohugger-core/src/test/expected/standard/example/idl/WithShapelessCoproduct.scala") } def e19 = { val infile = new java.io.File("avrohugger-core/src/test/avro/all_unions_as_optional_coproduct.avdl") val avroScalaCustomTypes = Standard.defaultTypes.copy(union = OptionalShapelessCoproduct) - val gen = new Generator(Standard, avroScalaCustomTypes = Some(avroScalaCustomTypes)) + val gen = Generator(Standard, avroScalaCustomTypes = Some(avroScalaCustomTypes)) val outDir = gen.defaultOutputDir + "/standard/" gen.fileToFile(infile, outDir) val adt = util.Util.readFile("target/generated-sources/standard/example/idl/AllUnionsWithOptionalShapelessCoproduct.scala") - adt === util.Util.readFile("avrohugger-core/src/test/expected/standard/example/idl/AllUnionsWithOptionalShapelessCoproduct.scala") + adt ===/ util.Util.readFile("avrohugger-core/src/test/expected/standard/example/idl/AllUnionsWithOptionalShapelessCoproduct.scala") } def e20 = { val infile = new java.io.File("avrohugger-core/src/test/avro/all_unions_as_option_coproduct.avdl") val avroScalaCustomTypes = Standard.defaultTypes.copy(union = OptionShapelessCoproduct) - val gen = new Generator(Standard, avroScalaCustomTypes = Some(avroScalaCustomTypes)) + val gen = Generator(Standard, avroScalaCustomTypes = Some(avroScalaCustomTypes)) val outDir = gen.defaultOutputDir + "/standard/" gen.fileToFile(infile, outDir) val adt = util.Util.readFile("target/generated-sources/standard/example/idl/AllUnionsWithOptionShapelessCoproduct.scala") - adt === util.Util.readFile("avrohugger-core/src/test/expected/standard/example/idl/AllUnionsWithOptionShapelessCoproduct.scala") + adt ===/ util.Util.readFile("avrohugger-core/src/test/expected/standard/example/idl/AllUnionsWithOptionShapelessCoproduct.scala") } def e21 = { val infile = new java.io.File("avrohugger-core/src/test/avro/all_unions_as_scala3_union_type.avdl") val avroScalaCustomTypes = Standard.defaultTypes.copy(union = OptionScala3UnionType) - val gen = new Generator(Standard, avroScalaCustomTypes = Some(avroScalaCustomTypes)) + val gen = Generator(Standard, avroScalaCustomTypes = Some(avroScalaCustomTypes)) val outDir = gen.defaultOutputDir + "/standard/" gen.fileToFile(infile, outDir) val adt = util.Util.readFile("target/generated-sources/standard/example/idl/AllUnionsWithScala3UnionType.scala") - adt === util.Util.readFile("avrohugger-core/src/test/expected/standard/example/idl/AllUnionsWithScala3UnionType.scala") + adt ===/ util.Util.readFile("avrohugger-core/src/test/expected/standard/example/idl/AllUnionsWithScala3UnionType.scala") } def e22 = { val infile = new java.io.File("avrohugger-core/src/test/avro/unions_option_either_default_param_values.avdl") - val gen = new Generator(Standard) + val gen = Generator(Standard) val outDir = gen.defaultOutputDir + "/standard/" gen.fileToFile(infile, outDir) val adt = util.Util.readFile("target/generated-sources/standard/example/idl/UnionsOptionEitherDefaultParamsValues.scala") - adt === util.Util.readFile("avrohugger-core/src/test/expected/standard/example/idl/UnionsOptionEitherDefaultParamsValues.scala") + adt ===/ util.Util.readFile("avrohugger-core/src/test/expected/standard/example/idl/UnionsOptionEitherDefaultParamsValues.scala") } def e23 = { val infile = new java.io.File("avrohugger-core/src/test/avro/unions_option_default_param_values.avdl") val avroScalaCustomTypes = Standard.defaultTypes.copy(union = OptionShapelessCoproduct) - val gen = new Generator(Standard, avroScalaCustomTypes = Some(avroScalaCustomTypes)) + val gen = Generator(Standard, avroScalaCustomTypes = Some(avroScalaCustomTypes)) val outDir = gen.defaultOutputDir + "/standard/" gen.fileToFile(infile, outDir) val adt = util.Util.readFile("target/generated-sources/standard/example/idl/UnionsOptionDefaultParamsValues.scala") - adt === util.Util.readFile("avrohugger-core/src/test/expected/standard/example/idl/UnionsOptionDefaultParamsValues.scala") + adt ===/ util.Util.readFile("avrohugger-core/src/test/expected/standard/example/idl/UnionsOptionDefaultParamsValues.scala") } def e24 = { val infile = new java.io.File("avrohugger-core/src/test/avro/unions_optional_default_param_values.avdl") val avroScalaCustomTypes = Standard.defaultTypes.copy(union = OptionalShapelessCoproduct) - val gen = new Generator(Standard, avroScalaCustomTypes = Some(avroScalaCustomTypes)) + val gen = Generator(Standard, avroScalaCustomTypes = Some(avroScalaCustomTypes)) val outDir = gen.defaultOutputDir + "/standard/" gen.fileToFile(infile, outDir) val adt = util.Util.readFile("target/generated-sources/standard/example/idl/UnionsOptionalDefaultParamsValues.scala") - adt === util.Util.readFile("avrohugger-core/src/test/expected/standard/example/idl/UnionsOptionalDefaultParamsValues.scala") + adt ===/ util.Util.readFile("avrohugger-core/src/test/expected/standard/example/idl/UnionsOptionalDefaultParamsValues.scala") } def e25 = { val infile = new java.io.File("avrohugger-core/src/test/avro/unions_option_scala3_union_types.avdl") val avroScalaCustomTypes = Standard.defaultTypes.copy(union = OptionScala3UnionType) - val gen = new Generator(Standard, avroScalaCustomTypes = Some(avroScalaCustomTypes)) + val gen = Generator(Standard, avroScalaCustomTypes = Some(avroScalaCustomTypes)) val outDir = gen.defaultOutputDir + "/standard/" gen.fileToFile(infile, outDir) val adt = util.Util.readFile("target/generated-sources/standard/example/idl/UnionsOptionScala3UnionTypes.scala") - adt === util.Util.readFile("avrohugger-core/src/test/expected/standard/example/idl/UnionsOptionScala3UnionTypes.scala") + adt ===/ util.Util.readFile("avrohugger-core/src/test/expected/standard/example/idl/UnionsOptionScala3UnionTypes.scala") } def e26 = { val infile = new java.io.File("avrohugger-core/src/test/avro/AvroTypeProviderTestProtocol.avdl") - val gen = new Generator(format = Standard) + val gen = Generator(format = Standard) val outDir = gen.defaultOutputDir + "/standard/" gen.fileToFile(infile, outDir) val source = util.Util.readFile("target/generated-sources/standard/test/Joystick.scala") - source === util.Util.readFile("avrohugger-core/src/test/expected/standard/test/Joystick.scala") + source ===/ util.Util.readFile("avrohugger-core/src/test/expected/standard/test/Joystick.scala") } def e27 = { @@ -449,148 +450,148 @@ class StandardFileToFileSpec extends Specification { def e29 = { val infile = new java.io.File("avrohugger-core/src/test/avro/logical.avsc") - val gen = new Generator(Standard) + val gen = Generator(Standard) val outDir = gen.defaultOutputDir + "/standard/" gen.fileToFile(infile, outDir) val source = util.Util.readFile("target/generated-sources/standard/example/logical/LogicalSc.scala") - source === util.Util.readFile("avrohugger-core/src/test/expected/standard/example/logical/LogicalSc.scala") + source ===/ util.Util.readFile("avrohugger-core/src/test/expected/standard/example/logical/LogicalSc.scala") } def e30 = { val infile = new java.io.File("avrohugger-core/src/test/avro/logical.avpr") - val gen = new Generator(Standard) + val gen = Generator(Standard) val outDir = gen.defaultOutputDir + "/standard/" gen.fileToFile(infile, outDir) val source = util.Util.readFile("target/generated-sources/standard/example/logical/proto/Logical.scala") - source === util.Util.readFile("avrohugger-core/src/test/expected/standard/example/logical/proto/Logical.scala") + source ===/ util.Util.readFile("avrohugger-core/src/test/expected/standard/example/logical/proto/Logical.scala") } // def e31 = { // val infile = new java.io.File("avrohugger-core/src/test/avro/logical.avdl") - // val gen = new Generator(Standard) + // val gen = Generator(Standard) // val outDir = gen.defaultOutputDir + "/standard/" // gen.fileToFile(infile, outDir) // val source = util.Util.readFile("target/generated-sources/standard/example/idl/LogicalIdl.scala") - // source === util.Util.readFile("avrohugger-core/src/test/expected/standard/example/idl/LogicalIdl.scala") + // source ===/ util.Util.readFile("avrohugger-core/src/test/expected/standard/example/idl/LogicalIdl.scala") // } def e32 = { val infile = new java.io.File("avrohugger-core/src/test/avro/logicalsql.avsc") val avroScalaCustomTypes = Standard.defaultTypes.copy(date = JavaSqlDate, timestampMillis = JavaSqlTimestamp, timeMillis = JavaSqlTime) - val gen = new Generator(Standard, avroScalaCustomTypes = Some(avroScalaCustomTypes)) + val gen = Generator(Standard, avroScalaCustomTypes = Some(avroScalaCustomTypes)) val outDir = gen.defaultOutputDir + "/standard/" gen.fileToFile(infile, outDir) val source = util.Util.readFile("target/generated-sources/standard/example/logical/LogicalSql.scala") - source === util.Util.readFile("avrohugger-core/src/test/expected/standard/example/logical/LogicalSql.scala") + source ===/ util.Util.readFile("avrohugger-core/src/test/expected/standard/example/logical/LogicalSql.scala") } def e33 = { val infile = new java.io.File("avrohugger-core/src/test/avro/logical.avsc") val myAvroScalaCustomTypes = Standard.defaultTypes.copy(decimal = ScalaBigDecimalWithPrecision(None)) - val gen = new Generator(Standard, avroScalaCustomTypes = Some(myAvroScalaCustomTypes)) + val gen = Generator(Standard, avroScalaCustomTypes = Some(myAvroScalaCustomTypes)) val outDir = gen.defaultOutputDir + "/standard-tagged/" gen.fileToFile(infile, outDir) val source = util.Util.readFile("target/generated-sources/standard-tagged/example/logical/LogicalSc.scala") - source === util.Util.readFile("avrohugger-core/src/test/expected/standard-tagged/example/logical/LogicalSc.scala") + source ===/ util.Util.readFile("avrohugger-core/src/test/expected/standard-tagged/example/logical/LogicalSc.scala") } def e34 = { val infile = new java.io.File("avrohugger-core/src/test/avro/logical.avpr") val myAvroScalaCustomTypes = Standard.defaultTypes.copy(decimal = ScalaBigDecimalWithPrecision(None)) - val gen = new Generator(Standard, avroScalaCustomTypes = Some(myAvroScalaCustomTypes)) + val gen = Generator(Standard, avroScalaCustomTypes = Some(myAvroScalaCustomTypes)) val outDir = gen.defaultOutputDir + "/standard-tagged/" gen.fileToFile(infile, outDir) val source = util.Util.readFile("target/generated-sources/standard-tagged/example/logical/proto/Logical.scala") - source === util.Util.readFile("avrohugger-core/src/test/expected/standard-tagged/example/logical/proto/Logical.scala") + source ===/ util.Util.readFile("avrohugger-core/src/test/expected/standard-tagged/example/logical/proto/Logical.scala") } // def e35 = { // val infile = new java.io.File("avrohugger-core/src/test/avro/logical.avdl") // val myAvroScalaCustomTypes = Standard.defaultTypes.copy(decimal = ScalaBigDecimalWithPrecision(None)) - // val gen = new Generator(Standard, avroScalaCustomTypes = Some(myAvroScalaCustomTypes)) + // val gen = Generator(Standard, avroScalaCustomTypes = Some(myAvroScalaCustomTypes)) // val outDir = gen.defaultOutputDir + "/standard-tagged/" // gen.fileToFile(infile, outDir) // val source = util.Util.readFile("target/generated-sources/standard-tagged/example/idl/LogicalIdl.scala") - // source === util.Util.readFile("avrohugger-core/src/test/expected/standard-tagged/example/idl/LogicalIdl.scala") + // source ===/ util.Util.readFile("avrohugger-core/src/test/expected/standard-tagged/example/idl/LogicalIdl.scala") // } def e36 = { val infile = new java.io.File("avrohugger-core/src/test/avro/logicalsql.avsc") val avroScalaCustomTypes = Standard.defaultTypes.copy(date = JavaSqlDate, timestampMillis = JavaSqlTimestamp, decimal = ScalaBigDecimalWithPrecision(None), timeMillis = JavaSqlTime) - val gen = new Generator(Standard, avroScalaCustomTypes = Some(avroScalaCustomTypes)) + val gen = Generator(Standard, avroScalaCustomTypes = Some(avroScalaCustomTypes)) val outDir = gen.defaultOutputDir + "/standard-tagged/" gen.fileToFile(infile, outDir) val source = util.Util.readFile("target/generated-sources/standard-tagged/example/logical/LogicalSql.scala") - source === util.Util.readFile("avrohugger-core/src/test/expected/standard-tagged/example/logical/LogicalSql.scala") + source ===/ util.Util.readFile("avrohugger-core/src/test/expected/standard-tagged/example/logical/LogicalSql.scala") } def e37 = { val infile = new java.io.File("avrohugger-core/src/test/avro/logical_optional.avdl") val myAvroScalaCustomTypes = Standard.defaultTypes.copy(decimal = ScalaBigDecimalWithPrecision(None)) - val gen = new Generator(Standard, avroScalaCustomTypes = Some(myAvroScalaCustomTypes)) + val gen = Generator(Standard, avroScalaCustomTypes = Some(myAvroScalaCustomTypes)) val outDir = gen.defaultOutputDir + "/standard-tagged/" gen.fileToFile(infile, outDir) val source = util.Util.readFile("target/generated-sources/standard-tagged/example/idl/LogicalOptionalIdl.scala") - source === util.Util.readFile("avrohugger-core/src/test/expected/standard-tagged/example/idl/LogicalOptionalIdl.scala") + source ===/ util.Util.readFile("avrohugger-core/src/test/expected/standard-tagged/example/idl/LogicalOptionalIdl.scala") } def e38 = { val infile = new java.io.File("avrohugger-core/src/test/avro/logical_either.avdl") val myAvroScalaCustomTypes = Standard.defaultTypes.copy(decimal = ScalaBigDecimalWithPrecision(None)) - val gen = new Generator(Standard, avroScalaCustomTypes = Some(myAvroScalaCustomTypes)) + val gen = Generator(Standard, avroScalaCustomTypes = Some(myAvroScalaCustomTypes)) val outDir = gen.defaultOutputDir + "/standard-tagged/" gen.fileToFile(infile, outDir) val source = util.Util.readFile("target/generated-sources/standard-tagged/example/idl/LogicalEitherIdl.scala") - source === util.Util.readFile("avrohugger-core/src/test/expected/standard-tagged/example/idl/LogicalEitherIdl.scala") + source ===/ util.Util.readFile("avrohugger-core/src/test/expected/standard-tagged/example/idl/LogicalEitherIdl.scala") } def e39 = { val infile = new java.io.File("avrohugger-core/src/test/avro/logical_coproduct.avdl") val myAvroScalaCustomTypes = Standard.defaultTypes.copy(decimal = ScalaBigDecimalWithPrecision(None)) - val gen = new Generator(Standard, avroScalaCustomTypes = Some(myAvroScalaCustomTypes)) + val gen = Generator(Standard, avroScalaCustomTypes = Some(myAvroScalaCustomTypes)) val outDir = gen.defaultOutputDir + "/standard-tagged/" gen.fileToFile(infile, outDir) val source = util.Util.readFile("target/generated-sources/standard-tagged/example/idl/LogicalCoproductIdl.scala") - source === util.Util.readFile("avrohugger-core/src/test/expected/standard-tagged/example/idl/LogicalCoproductIdl.scala") + source ===/ util.Util.readFile("avrohugger-core/src/test/expected/standard-tagged/example/idl/LogicalCoproductIdl.scala") } def e40 = { val infile = new java.io.File("avrohugger-core/src/test/avro/special_names.avdl") - val gen = new Generator(Standard) + val gen = Generator(Standard) val outDir = gen.defaultOutputDir + "/standard/" gen.fileToFile(infile, outDir) val source = util.Util.readFile("target/generated-sources/standard/example/idl/Names.scala") - source === util.Util.readFile("avrohugger-core/src/test/expected/standard/example/idl/Names.scala") + source ===/ util.Util.readFile("avrohugger-core/src/test/expected/standard/example/idl/Names.scala") } def e41 = { val infile = new File("avrohugger-core/src/test/avro/fixed.avsc") - val gen = new Generator(Standard) + val gen = Generator(Standard) val outDir = gen.defaultOutputDir + "/standard/" gen.fileToFile(infile, outDir) @@ -599,77 +600,57 @@ class StandardFileToFileSpec extends Specification { def e42 = { val infile = new File("avrohugger-core/src/test/avro/fixed_bytes_simple.avsc") - val gen = new Generator(Standard) + val gen = Generator(Standard) val outDir = gen.defaultOutputDir + "/standard/" gen.fileToFile(infile, outDir) - val expected = util.Util.readFile("avrohugger-core/src/test/expected/standard/example/shasimple/Sha256.scala") + val expected = util.Util.readFile("avrohugger-core/src/test/expected/standard/example/shasimple/Sha256.scala") val generated = util.Util.readFile("target/generated-sources/standard/example/shasimple/Sha256.scala") - expected === generated + expected ===/ generated } def e43 = { val infile = new File("avrohugger-core/src/test/avro/fixed_bytes_record.avsc") - val gen = new Generator(Standard) + val gen = Generator(Standard) val outDir = gen.defaultOutputDir + "/standard/" gen.fileToFile(infile, outDir) - val expected = List( - util.Util.readFile("avrohugger-core/src/test/expected/standard/example/sharecord/Sha256.scala"), - util.Util.readFile("avrohugger-core/src/test/expected/standard/example/sharecord/HashRecord.scala") - ) - - val generated = List( - util.Util.readFile("target/generated-sources/standard/example/sharecord/Sha256.scala"), - util.Util.readFile("target/generated-sources/standard/example/sharecord/HashRecord.scala") - ) - - expected must containAllOf(generated) + util.Util.readFile("avrohugger-core/src/test/expected/standard/example/sharecord/Sha256.scala") ===/ util.Util.readFile("target/generated-sources/standard/example/sharecord/Sha256.scala") + util.Util.readFile("avrohugger-core/src/test/expected/standard/example/sharecord/HashRecord.scala") ===/ util.Util.readFile("target/generated-sources/standard/example/sharecord/HashRecord.scala") } def e44 = { val infile = new File("avrohugger-core/src/test/avro/fixed_bytes_nested.avsc") - val gen = new Generator(Standard) + val gen = Generator(Standard) val outDir = gen.defaultOutputDir + "/standard/" gen.fileToFile(infile, outDir) - val expected = List( - util.Util.readFile("avrohugger-core/src/test/expected/standard/example/shanested/foo/HashRecord.scala"), - util.Util.readFile("avrohugger-core/src/test/expected/standard/example/shanested/Prop.scala"), - util.Util.readFile("avrohugger-core/src/test/expected/standard/example/shanested/Sha256.scala") - ) - - val generated = List( - util.Util.readFile("target/generated-sources/standard/example/shanested/foo/HashRecord.scala"), - util.Util.readFile("target/generated-sources/standard/example/shanested/Prop.scala"), - util.Util.readFile("target/generated-sources/standard/example/shanested/Sha256.scala") - ) - - expected must containAllOf(generated) + util.Util.readFile("avrohugger-core/src/test/expected/standard/example/shanested/foo/HashRecord.scala") ===/ util.Util.readFile("target/generated-sources/standard/example/shanested/foo/HashRecord.scala") + util.Util.readFile("avrohugger-core/src/test/expected/standard/example/shanested/Prop.scala") ===/ util.Util.readFile("target/generated-sources/standard/example/shanested/Prop.scala") + util.Util.readFile("avrohugger-core/src/test/expected/standard/example/shanested/Sha256.scala") ===/ util.Util.readFile("target/generated-sources/standard/example/shanested/Sha256.scala") } def e45 = { val infile = new File("avrohugger-core/src/test/avro/outer.avdl") val customNs = Map("a.b.c" -> "aa.bb.cc") - val gen = new Generator(Standard, avroScalaCustomNamespace = customNs) + val gen = Generator(Standard, avroScalaCustomNamespace = customNs) val outDir = gen.defaultOutputDir + "/standard/" gen.fileToFile(infile, outDir) val source = util.Util.readFile("target/generated-sources/standard/aa/bb/cc/Test.scala") - - source === util.Util.readFile("avrohugger-core/src/test/expected/standard/aa/bb/cc/Test.scala") + source ===/ util.Util.readFile("avrohugger-core/src/test/expected/standard/aa/bb/cc/Test.scala") } def e46 = { val infile = new java.io.File("avrohugger-core/src/test/avro/date_time_related_fields.avsc") val avroScalaCustomTypes = Standard.defaultTypes.copy(date = UnderlyingPrimitive, timestampMillis = UnderlyingPrimitive, timestampMicros = UnderlyingPrimitive, localTimestampMicros = UnderlyingPrimitive, localTimestampMillis = UnderlyingPrimitive, timeMillis = UnderlyingPrimitive, timeMicros = UnderlyingPrimitive) - val gen = new Generator(Standard, avroScalaCustomTypes = Some(avroScalaCustomTypes)) + val gen = Generator(Standard, avroScalaCustomTypes = Some(avroScalaCustomTypes)) val outDir = gen.defaultOutputDir + "/standard/" gen.fileToFile(infile, outDir) val source = util.Util.readFile("target/generated-sources/standard/example/datetimerelatedfields/DateTimeRelatedFields.scala") - source === util.Util.readFile("avrohugger-core/src/test/expected/standard/example/datetimerelatedfields/DateTimeRelatedFields.scala") + source ===/ util.Util.readFile("avrohugger-core/src/test/expected/standard/example/datetimerelatedfields/DateTimeRelatedFields.scala") } } \ No newline at end of file diff --git a/avrohugger-core/src/test/scala/standard/StandardFileToStringsSpec.scala b/avrohugger-core/src/test/scala/standard/StandardFileToStringsSpec.scala index aa9b8457..90edc58a 100644 --- a/avrohugger-core/src/test/scala/standard/StandardFileToStringsSpec.scala +++ b/avrohugger-core/src/test/scala/standard/StandardFileToStringsSpec.scala @@ -6,6 +6,7 @@ import avrohugger.Generator import avrohugger.format.Standard import avrohugger.types._ import org.specs2._ +import util.Util.LineEndingAmbiguousMatcherString class StandardFileToStringsSpec extends Specification { @@ -46,141 +47,141 @@ class StandardFileToStringsSpec extends Specification { // tests specific to fileToX def eA = { val infile = new java.io.File("avrohugger-core/src/test/avro/twitter.avro") - val gen = new Generator(Standard) + val gen = Generator(Standard) val List(source) = gen.fileToStrings(infile) val expected = util.Util.readFile("avrohugger-core/src/test/expected/standard/com/miguno/avro/twitter_schema.scala") - source === expected + source ===/ expected } def eB = { val infile = new java.io.File("avrohugger-core/src/test/avro/relative.avsc") - val gen = new Generator(Standard, Some(Standard.defaultTypes.copy(record = ScalaCaseClassWithSchema))) + val gen = Generator(Standard, Some(Standard.defaultTypes.copy(record = ScalaCaseClassWithSchema))) val List(source) = gen.fileToStrings(infile) val expected = util.Util.readFile("avrohugger-core/src/test/expected/standard/example/Relative.scala") - source === expected + source ===/ expected } // tests common to fileToX and stringToX def e1 = { val infile = new java.io.File("avrohugger-core/src/test/avro/mail.avpr") - val gen = new Generator(Standard) + val gen = Generator(Standard) val List(source) = gen.fileToStrings(infile) val expected = util.Util.readFile("avrohugger-core/src/test/expected/standard/example/proto/Message.scala") - source === expected + source ===/ expected } def e2 = { val infile = new java.io.File("avrohugger-core/src/test/avro/user.avsc") - val gen = new Generator(Standard) + val gen = Generator(Standard) val List(source) = gen.fileToStrings(infile) val expected = util.Util.readFile("avrohugger-core/src/test/expected/standard/example/User.scala") - source === expected + source ===/ expected } def e3 = { val infile = new java.io.File("avrohugger-core/src/test/avro/AvroTypeProviderTestNoNamespace.avsc") - val gen = new Generator(Standard) + val gen = Generator(Standard) val List(source) = gen.fileToStrings(infile) val expected = util.Util.readFile("avrohugger-core/src/test/expected/standard/AvroTypeProviderTestNoNamespace.scala") - source === expected + source ===/ expected } def e4 = { val infile = new java.io.File("avrohugger-core/src/test/avro/nested.avsc") - val gen = new Generator(Standard) + val gen = Generator(Standard) val List(source2, source1, source0) = gen.fileToStrings(infile) val expected0 = util.Util.readFile("avrohugger-core/src/test/expected/standard/example/Level0.scala") val expected1 = util.Util.readFile("avrohugger-core/src/test/expected/standard/example/Level1.scala") val expected2 = util.Util.readFile("avrohugger-core/src/test/expected/standard/example/Level2.scala") - source0 === expected0 - source1 === expected1 - source2 === expected2 + source0 ===/ expected0 + source1 ===/ expected1 + source2 ===/ expected2 } def e5 = { val infile = new java.io.File("avrohugger-core/src/test/avro/nested.avdl") val myAvroScalaCustomTypes = Standard.defaultTypes.copy(protocol = types.ScalaADT) - val gen = new Generator(format = Standard, avroScalaCustomTypes = Some(myAvroScalaCustomTypes)) + val gen = Generator(format = Standard, avroScalaCustomTypes = Some(myAvroScalaCustomTypes)) val List(source) = gen.fileToStrings(infile) val expected = util.Util.readFile("avrohugger-core/src/test/expected/standard/example/idl/NestedProtocol.scala") - source === expected + source ===/ expected } def e6 = { val infile = new java.io.File("avrohugger-core/src/test/avro/recursive.avdl") - val gen = new Generator(Standard) + val gen = Generator(Standard) val List(source) = gen.fileToStrings(infile) val expected = util.Util.readFile("avrohugger-core/src/test/expected/standard/example/idl/Recursive.scala") - source === expected + source ===/ expected } def e7 = { val infile = new java.io.File("avrohugger-core/src/test/avro/enums.avsc") - val gen = new Generator(Standard) + val gen = Generator(Standard) val List(source) = gen.fileToStrings(infile) val expected = util.Util.readFile("avrohugger-core/src/test/expected/standard/example/Suit.scala") - source === expected + source ===/ expected } def e8 = { val infile = new java.io.File("avrohugger-core/src/test/avro/enums.avpr") val myAvroScalaCustomTypes = Standard.defaultTypes.copy(protocol = types.ScalaADT) - val gen = new Generator(format = Standard, avroScalaCustomTypes = Some(myAvroScalaCustomTypes)) + val gen = Generator(format = Standard, avroScalaCustomTypes = Some(myAvroScalaCustomTypes)) val List(source) = gen.fileToStrings(infile) val expected = util.Util.readFile("avrohugger-core/src/test/expected/standard/example/proto/EnumProtocol.scala") - source === expected + source ===/ expected } def e9 = { val infile = new java.io.File("avrohugger-core/src/test/avro/enums.avdl") val myAvroScalaCustomTypes = Standard.defaultTypes.copy(protocol = types.ScalaADT) - val gen = new Generator(format = Standard, avroScalaCustomTypes = Some(myAvroScalaCustomTypes)) + val gen = Generator(format = Standard, avroScalaCustomTypes = Some(myAvroScalaCustomTypes)) val List(source) = gen.fileToStrings(infile) val expected = util.Util.readFile("avrohugger-core/src/test/expected/standard/example/idl/EnumProtocol.scala") - source === expected + source ===/ expected } def e10 = { val infile = new java.io.File("avrohugger-core/src/test/avro/enums_nested.avsc") - val gen = new Generator(Standard) + val gen = Generator(Standard) val List(sourceEnum, sourceRecord) = gen.fileToStrings(infile) val expectedEnum = util.Util.readFile("avrohugger-core/src/test/expected/standard/example/Direction.scala") val expectedRecord = util.Util.readFile("avrohugger-core/src/test/expected/standard/example/Compass.scala") - sourceEnum === expectedEnum - sourceRecord === expectedRecord + sourceEnum ===/ expectedEnum + sourceRecord ===/ expectedRecord } def e11 = { val infile = new java.io.File("avrohugger-core/src/test/avro/bytes.avsc") - val gen = new Generator(Standard) + val gen = Generator(Standard) val List(source) = gen.fileToStrings(infile) val expected = util.Util.readFile("avrohugger-core/src/test/expected/standard/example/BinarySc.scala") - source === expected + source ===/ expected } def e12 = { val infile = new java.io.File("avrohugger-core/src/test/avro/bytes.avpr") - val gen = new Generator(Standard) + val gen = Generator(Standard) val List(source) = gen.fileToStrings(infile) val expected = util.Util.readFile("avrohugger-core/src/test/expected/standard/example/proto/BinaryPr.scala") - source === expected + source ===/ expected } def e13 = { val infile = new java.io.File("avrohugger-core/src/test/avro/bytes.avdl") - val gen = new Generator(Standard) + val gen = Generator(Standard) val List(source) = gen.fileToStrings(infile) val expected = util.Util.readFile("avrohugger-core/src/test/expected/standard/example/idl/BinaryIdl.scala") - source === expected + source ===/ expected } def e14 = { val infile = new java.io.File("avrohugger-core/src/test/avro/import.avdl") - val gen = new Generator(Standard) + val gen = Generator(Standard) val List(dep3, dep2, dep1, adt) = gen.fileToStrings(infile) val expectedADT = util.Util.readFile("avrohugger-core/src/test/expected/standard/example/idl/ImportProtocol.scala") @@ -188,93 +189,93 @@ class StandardFileToStringsSpec extends Specification { val expectedDep2 = util.Util.readFile("avrohugger-core/src/test/expected/standard/other/ns/ExternalDependency.scala") val expectedDep3 = util.Util.readFile("avrohugger-core/src/test/expected/standard/other/ns/Suit.scala") - adt === expectedADT - dep1 === expectedDep1 - dep2 === expectedDep2 - dep3 === expectedDep3 + adt ===/ expectedADT + dep1 ===/ expectedDep1 + dep2 ===/ expectedDep2 + dep3 ===/ expectedDep3 } def e15 = { val infile = new java.io.File("avrohugger-core/src/test/avro/AvroTypeProviderTestEmptyRecord.avdl") val myAvroScalaCustomTypes = Standard.defaultTypes.copy(protocol = types.ScalaADT) - val gen = new Generator(format = Standard, avroScalaCustomTypes = Some(myAvroScalaCustomTypes)) + val gen = Generator(format = Standard, avroScalaCustomTypes = Some(myAvroScalaCustomTypes)) val List(source) = gen.fileToStrings(infile) val expected = util.Util.readFile("avrohugger-core/src/test/expected/standard/test/Calculator.scala") - source === expected + source ===/ expected } def e16 = { val infile = new java.io.File("avrohugger-core/src/test/avro/defaults.avdl") val myAvroScalaCustomTypes = Standard.defaultTypes.copy(protocol = types.ScalaADT) - val gen = new Generator(format = Standard, avroScalaCustomTypes = Some(myAvroScalaCustomTypes)) + val gen = Generator(format = Standard, avroScalaCustomTypes = Some(myAvroScalaCustomTypes)) val List(source) = gen.fileToStrings(infile) val expected = util.Util.readFile("avrohugger-core/src/test/expected/standard/example/idl/Defaults.scala") - source === expected + source ===/ expected } def e21 = { val infile = new java.io.File("avrohugger-core/src/test/avro/AvroTypeProviderTestProtocol.avdl") - val gen = new Generator(format = Standard) + val gen = Generator(format = Standard) val outDir = gen.defaultOutputDir + "/standard/" val List(source) = gen.fileToStrings(infile) - source === util.Util.readFile("avrohugger-core/src/test/expected/standard/test/Joystick.scala") + source ===/ util.Util.readFile("avrohugger-core/src/test/expected/standard/test/Joystick.scala") } // def e22 = { // val infile = new java.io.File("avrohugger-core/src/test/avro/logical.avdl") - // val gen = new Generator(Standard) + // val gen = Generator(Standard) // val List(source) = gen.fileToStrings(infile) // val expected = util.Util.readFile("avrohugger-core/src/test/expected/standard/example/idl/LogicalIdl.scala") - // source === expected + // source ===/ expected // } // def e23 = { // val infile = new java.io.File("avrohugger-core/src/test/avro/logical.avdl") // val myAvroScalaCustomTypes = Standard.defaultTypes.copy(decimal = ScalaBigDecimalWithPrecision(None)) - // val gen = new Generator(Standard, avroScalaCustomTypes = Some(myAvroScalaCustomTypes)) + // val gen = Generator(Standard, avroScalaCustomTypes = Some(myAvroScalaCustomTypes)) // val List(source) = gen.fileToStrings(infile) // val expected = util.Util.readFile("avrohugger-core/src/test/expected/standard-tagged/example/idl/LogicalIdl.scala") - // source === expected + // source ===/ expected // } def e24 = { val infile = new java.io.File("avrohugger-core/src/test/avro/logical_optional.avdl") val myAvroScalaCustomTypes = Standard.defaultTypes.copy(decimal = ScalaBigDecimalWithPrecision(None)) - val gen = new Generator(Standard, avroScalaCustomTypes = Some(myAvroScalaCustomTypes)) + val gen = Generator(Standard, avroScalaCustomTypes = Some(myAvroScalaCustomTypes)) val List(source) = gen.fileToStrings(infile) val expected = util.Util.readFile("avrohugger-core/src/test/expected/standard-tagged/example/idl/LogicalOptionalIdl.scala") - source === expected + source ===/ expected } def e25 = { val infile = new java.io.File("avrohugger-core/src/test/avro/logical_either.avdl") val myAvroScalaCustomTypes = Standard.defaultTypes.copy(decimal = ScalaBigDecimalWithPrecision(None)) - val gen = new Generator(Standard, avroScalaCustomTypes = Some(myAvroScalaCustomTypes)) + val gen = Generator(Standard, avroScalaCustomTypes = Some(myAvroScalaCustomTypes)) val List(source) = gen.fileToStrings(infile) val expected = util.Util.readFile("avrohugger-core/src/test/expected/standard-tagged/example/idl/LogicalEitherIdl.scala") - source === expected + source ===/ expected } def e26 = { val infile = new java.io.File("avrohugger-core/src/test/avro/logical_coproduct.avdl") val myAvroScalaCustomTypes = Standard.defaultTypes.copy(decimal = ScalaBigDecimalWithPrecision(None)) - val gen = new Generator(Standard, avroScalaCustomTypes = Some(myAvroScalaCustomTypes)) + val gen = Generator(Standard, avroScalaCustomTypes = Some(myAvroScalaCustomTypes)) val List(source) = gen.fileToStrings(infile) val expected = util.Util.readFile("avrohugger-core/src/test/expected/standard-tagged/example/idl/LogicalCoproductIdl.scala") - source === expected + source ===/ expected } def e27 = { val infile = new java.io.File("avrohugger-core/src/test/avro/top_level_union.avsc") - val gen = new Generator(Standard) + val gen = Generator(Standard) val List(source1, source0) = gen.fileToStrings(infile) val expected0 = util.Util.readFile("avrohugger-core/src/test/expected/standard/example/Dum.scala") val expected1 = util.Util.readFile("avrohugger-core/src/test/expected/standard/example/Dee.scala") - source0 === expected0 - source1 === expected1 + source0 ===/ expected0 + source1 ===/ expected1 } } diff --git a/avrohugger-core/src/test/scala/standard/StandardManyFieldsSpec.scala b/avrohugger-core/src/test/scala/standard/StandardManyFieldsSpec.scala index 0b0c9faf..16af146c 100644 --- a/avrohugger-core/src/test/scala/standard/StandardManyFieldsSpec.scala +++ b/avrohugger-core/src/test/scala/standard/StandardManyFieldsSpec.scala @@ -15,9 +15,9 @@ class StandardManyFieldsSpec extends Specification { val avdlPath = "avrohugger-core/src/test/avro/ManyFields.avdl" val avscPath = "avrohugger-core/src/test/avro/ManyFields.avsc" - val genNonRestricted = new Generator(Standard, restrictedFieldNumber = false) + val genNonRestricted = Generator(Standard, restrictedFieldNumber = false) val outDirNonRestricted = genNonRestricted.defaultOutputDir + "/standard/non-restricted" - val genRestricted = new Generator(Standard, restrictedFieldNumber = true) + val genRestricted = Generator(Standard, restrictedFieldNumber = true) val outDirRestricted = genRestricted.defaultOutputDir + "/standard/restricted" def is = s2""" diff --git a/avrohugger-core/src/test/scala/standard/StandardStringToFileSpec.scala b/avrohugger-core/src/test/scala/standard/StandardStringToFileSpec.scala index 2cb3c54b..167bb720 100644 --- a/avrohugger-core/src/test/scala/standard/StandardStringToFileSpec.scala +++ b/avrohugger-core/src/test/scala/standard/StandardStringToFileSpec.scala @@ -6,6 +6,7 @@ import avrohugger._ import avrohugger.format.Standard import avrohugger.types._ import org.specs2._ +import util.Util._ class StandardStringToFileSpec extends Specification { @@ -45,52 +46,52 @@ class StandardStringToFileSpec extends Specification { def eB = { val inputString = util.Util.readFile("avrohugger-core/src/test/avro/relative.avsc") - val gen = new Generator(Standard, Some(Standard.defaultTypes.copy(record = ScalaCaseClassWithSchema))) + val gen = Generator(Standard, Some(Standard.defaultTypes.copy(record = ScalaCaseClassWithSchema))) val outDir = gen.defaultOutputDir + "/standard/" gen.stringToFile(inputString, outDir) val source = util.Util.readFile(s"$outDir/example/Relative.scala") - source === util.Util.readFile("avrohugger-core/src/test/expected/standard/example/Relative.scala") + source ===/ util.Util.readFile("avrohugger-core/src/test/expected/standard/example/Relative.scala") } // tests common to fileToX and stringToX def e1 = { val inputString = util.Util.readFile("avrohugger-core/src/test/avro/mail.avpr") - val gen = new Generator(Standard) + val gen = Generator(Standard) val outDir = gen.defaultOutputDir + "/standard/" gen.stringToFile(inputString, outDir) val source = util.Util.readFile(s"$outDir/example/proto/Message.scala") - source === util.Util.readFile("avrohugger-core/src/test/expected/standard/example/proto/Message.scala") + source ===/ util.Util.readFile("avrohugger-core/src/test/expected/standard/example/proto/Message.scala") } def e2 = { val inputString = util.Util.readFile("avrohugger-core/src/test/avro/user.avsc") - val gen = new Generator(Standard) + val gen = Generator(Standard) val outDir = gen.defaultOutputDir + "/standard/" gen.stringToFile(inputString, outDir) val source = util.Util.readFile("target/generated-sources/standard/example/User.scala") - source === util.Util.readFile("avrohugger-core/src/test/expected/standard/example/User.scala") + source ===/ util.Util.readFile("avrohugger-core/src/test/expected/standard/example/User.scala") } def e3 = { val inputString = util.Util.readFile("avrohugger-core/src/test/avro/AvroTypeProviderTestNoNamespace.avsc") - val gen = new Generator(Standard) + val gen = Generator(Standard) val outDir = gen.defaultOutputDir + "/standard/" gen.stringToFile(inputString, outDir) val source = util.Util.readFile("target/generated-sources/standard/AvroTypeProviderTestNoNamespace.scala") - source === util.Util.readFile("avrohugger-core/src/test/expected/standard/AvroTypeProviderTestNoNamespace.scala") + source ===/ util.Util.readFile("avrohugger-core/src/test/expected/standard/AvroTypeProviderTestNoNamespace.scala") } def e4 = { val inputString = util.Util.readFile("avrohugger-core/src/test/avro/nested.avsc") - val gen = new Generator(Standard) + val gen = Generator(Standard) val outDir = gen.defaultOutputDir + "/standard/" gen.stringToFile(inputString, outDir) @@ -98,118 +99,118 @@ class StandardStringToFileSpec extends Specification { val source1 = util.Util.readFile("target/generated-sources/standard/example/Level1.scala") val source2 = util.Util.readFile("target/generated-sources/standard/example/Level2.scala") - source0 === util.Util.readFile("avrohugger-core/src/test/expected/standard/example/Level0.scala") - source1 === util.Util.readFile("avrohugger-core/src/test/expected/standard/example/Level1.scala") - source2 === util.Util.readFile("avrohugger-core/src/test/expected/standard/example/Level2.scala") + source0 ===/ util.Util.readFile("avrohugger-core/src/test/expected/standard/example/Level0.scala") + source1 ===/ util.Util.readFile("avrohugger-core/src/test/expected/standard/example/Level1.scala") + source2 ===/ util.Util.readFile("avrohugger-core/src/test/expected/standard/example/Level2.scala") } def e5 = { val inputString = util.Util.readFile("avrohugger-core/src/test/avro/nested.avdl") val myAvroScalaCustomTypes = Standard.defaultTypes.copy(protocol = types.ScalaADT) - val gen = new Generator(format = Standard, avroScalaCustomTypes = Some(myAvroScalaCustomTypes)) + val gen = Generator(format = Standard, avroScalaCustomTypes = Some(myAvroScalaCustomTypes)) val outDir = gen.defaultOutputDir + "/standard/" gen.stringToFile(inputString, outDir) val source = util.Util.readFile("target/generated-sources/standard/example/idl/NestedProtocol.scala") - source === util.Util.readFile("avrohugger-core/src/test/expected/standard/example/idl/NestedProtocol.scala") + source ===/ util.Util.readFile("avrohugger-core/src/test/expected/standard/example/idl/NestedProtocol.scala") } def e6 = { val inputString = util.Util.readFile("avrohugger-core/src/test/avro/recursive.avdl") - val gen = new Generator(Standard) + val gen = Generator(Standard) val outDir = gen.defaultOutputDir + "/standard/" gen.stringToFile(inputString, outDir) val source = util.Util.readFile("target/generated-sources/standard/example/idl/Recursive.scala") - source === util.Util.readFile("avrohugger-core/src/test/expected/standard/example/idl/Recursive.scala") + source ===/ util.Util.readFile("avrohugger-core/src/test/expected/standard/example/idl/Recursive.scala") } def e7 = { val inputString = util.Util.readFile("avrohugger-core/src/test/avro/enums.avsc") - val gen = new Generator(Standard) + val gen = Generator(Standard) val outDir = gen.defaultOutputDir + "/standard/" gen.stringToFile(inputString, outDir) val source = util.Util.readFile("target/generated-sources/standard/example/Suit.scala") - source === util.Util.readFile("avrohugger-core/src/test/expected/standard/example/Suit.scala") + source ===/ util.Util.readFile("avrohugger-core/src/test/expected/standard/example/Suit.scala") } def e8 = { val inputString = util.Util.readFile("avrohugger-core/src/test/avro/enums.avpr") val myAvroScalaCustomTypes = Standard.defaultTypes.copy(protocol = types.ScalaADT) - val gen = new Generator(format = Standard, avroScalaCustomTypes = Some(myAvroScalaCustomTypes)) + val gen = Generator(format = Standard, avroScalaCustomTypes = Some(myAvroScalaCustomTypes)) val outDir = gen.defaultOutputDir + "/standard/" gen.stringToFile(inputString, outDir) val source = util.Util.readFile("target/generated-sources/standard/example/proto/EnumProtocol.scala") - source === util.Util.readFile("avrohugger-core/src/test/expected/standard/example/proto/EnumProtocol.scala") + source ===/ util.Util.readFile("avrohugger-core/src/test/expected/standard/example/proto/EnumProtocol.scala") } def e9 = { val inputString = util.Util.readFile("avrohugger-core/src/test/avro/enums.avdl") val myAvroScalaCustomTypes = Standard.defaultTypes.copy(protocol = types.ScalaADT) - val gen = new Generator(format = Standard, avroScalaCustomTypes = Some(myAvroScalaCustomTypes)) + val gen = Generator(format = Standard, avroScalaCustomTypes = Some(myAvroScalaCustomTypes)) val outDir = gen.defaultOutputDir + "/standard/" gen.stringToFile(inputString, outDir) val source = util.Util.readFile("target/generated-sources/standard/example/idl/EnumProtocol.scala") - source === util.Util.readFile("avrohugger-core/src/test/expected/standard/example/idl/EnumProtocol.scala") + source ===/ util.Util.readFile("avrohugger-core/src/test/expected/standard/example/idl/EnumProtocol.scala") } def e10 = { val inputString = util.Util.readFile("avrohugger-core/src/test/avro/enums_nested.avsc") - val gen = new Generator(Standard) + val gen = Generator(Standard) val outDir = gen.defaultOutputDir + "/standard/" gen.stringToFile(inputString, outDir) val sourceEnum = util.Util.readFile("target/generated-sources/standard/example/Direction.scala") val sourceRecord = util.Util.readFile("target/generated-sources/standard/example/Compass.scala") - sourceEnum === util.Util.readFile("avrohugger-core/src/test/expected/standard/example/Direction.scala") - sourceRecord === util.Util.readFile("avrohugger-core/src/test/expected/standard/example/Compass.scala") + sourceEnum ===/ util.Util.readFile("avrohugger-core/src/test/expected/standard/example/Direction.scala") + sourceRecord ===/ util.Util.readFile("avrohugger-core/src/test/expected/standard/example/Compass.scala") } def e11 = { val inputString = util.Util.readFile("avrohugger-core/src/test/avro/bytes.avsc") - val gen = new Generator(Standard) + val gen = Generator(Standard) val outDir = gen.defaultOutputDir + "/standard/" gen.stringToFile(inputString, outDir) val source = util.Util.readFile("target/generated-sources/standard/example/BinarySc.scala") - source === util.Util.readFile("avrohugger-core/src/test/expected/standard/example/BinarySc.scala") + source ===/ util.Util.readFile("avrohugger-core/src/test/expected/standard/example/BinarySc.scala") } def e12 = { val inputString = util.Util.readFile("avrohugger-core/src/test/avro/bytes.avpr") - val gen = new Generator(Standard) + val gen = Generator(Standard) val outDir = gen.defaultOutputDir + "/standard/" gen.stringToFile(inputString, outDir) val source = util.Util.readFile("target/generated-sources/standard/example/proto/BinaryPr.scala") - source === util.Util.readFile("avrohugger-core/src/test/expected/standard/example/proto/BinaryPr.scala") + source ===/ util.Util.readFile("avrohugger-core/src/test/expected/standard/example/proto/BinaryPr.scala") } def e13 = { val inputString = util.Util.readFile("avrohugger-core/src/test/avro/bytes.avdl") - val gen = new Generator(Standard) + val gen = Generator(Standard) val outDir = gen.defaultOutputDir + "/standard/" gen.stringToFile(inputString, outDir) val source = util.Util.readFile("target/generated-sources/standard/example/idl/BinaryIdl.scala") - source === util.Util.readFile("avrohugger-core/src/test/expected/standard/example/idl/BinaryIdl.scala") + source ===/ util.Util.readFile("avrohugger-core/src/test/expected/standard/example/idl/BinaryIdl.scala") } def e14 = { val inputString = util.Util.readFile("avrohugger-core/src/test/avro/import.avdl") - val gen = new Generator(Standard) + val gen = Generator(Standard) val outDir = gen.defaultOutputDir + "/standard/" gen.stringToFile(inputString, outDir) must throwA(new java.lang.RuntimeException("Imports not supported in String IDLs, only avdl files.")) } @@ -217,118 +218,118 @@ class StandardStringToFileSpec extends Specification { def e15 = { val inputString = util.Util.readFile("avrohugger-core/src/test/avro/AvroTypeProviderTestEmptyRecord.avdl") val myAvroScalaCustomTypes = Standard.defaultTypes.copy(protocol = types.ScalaADT) - val gen = new Generator(format = Standard, avroScalaCustomTypes = Some(myAvroScalaCustomTypes)) + val gen = Generator(format = Standard, avroScalaCustomTypes = Some(myAvroScalaCustomTypes)) val outDir = gen.defaultOutputDir + "/standard/" gen.stringToFile(inputString, outDir) val source = util.Util.readFile("target/generated-sources/standard/test/Calculator.scala") - source === util.Util.readFile("avrohugger-core/src/test/expected/standard/test/Calculator.scala") + source ===/ util.Util.readFile("avrohugger-core/src/test/expected/standard/test/Calculator.scala") } def e16 = { val inputString = util.Util.readFile("avrohugger-core/src/test/avro/defaults.avdl") val myAvroScalaCustomTypes = Standard.defaultTypes.copy(protocol = types.ScalaADT) - val gen = new Generator(format = Standard, avroScalaCustomTypes = Some(myAvroScalaCustomTypes)) + val gen = Generator(format = Standard, avroScalaCustomTypes = Some(myAvroScalaCustomTypes)) val outDir = gen.defaultOutputDir + "/standard/" gen.stringToFile(inputString, outDir) val adt = util.Util.readFile("target/generated-sources/standard/example/idl/Defaults.scala") - adt === util.Util.readFile("avrohugger-core/src/test/expected/standard/example/idl/Defaults.scala") + adt ===/ util.Util.readFile("avrohugger-core/src/test/expected/standard/example/idl/Defaults.scala") } def e17 = { val inputString = util.Util.readFile("avrohugger-core/src/test/avro/fixed_sc.avsc") - val gen = new Generator(Standard) + val gen = Generator(Standard) val outDir = gen.defaultOutputDir + "/standard/" gen.stringToFile(inputString, outDir) val source1 = util.Util.readFile("target/generated-sources/standard/example/FixedSc.scala") val source2 = util.Util.readFile("target/generated-sources/standard/example/my_fixed.scala") - source1 === util.Util.readFile("avrohugger-core/src/test/expected/standard/example/FixedSc.scala") - source2 === util.Util.readFile("avrohugger-core/src/test/expected/standard/example/my_fixed.scala") + source1 ===/ util.Util.readFile("avrohugger-core/src/test/expected/standard/example/FixedSc.scala") + source2 ===/ util.Util.readFile("avrohugger-core/src/test/expected/standard/example/my_fixed.scala") } // def e18 = { // val inputString = util.Util.readFile("avrohugger-core/src/test/avro/fixed.avdl") - // val gen = new Generator(Standard) + // val gen = Generator(Standard) // val outDir = gen.defaultOutputDir + "/standard/" // gen.stringToFile(inputString, outDir) // val source = util.Util.readFile("target/generated-sources/standard/example/idl/FixedIdl.scala") - // source === util.Util.readFile("avrohugger-core/src/test/expected/standard/example/idl/FixedIdl.scala") + // source ===/ util.Util.readFile("avrohugger-core/src/test/expected/standard/example/idl/FixedIdl.scala") // } def e21 = { val inputString = util.Util.readFile("avrohugger-core/src/test/avro/AvroTypeProviderTestProtocol.avdl") - val gen = new Generator(format = Standard) + val gen = Generator(format = Standard) val outDir = gen.defaultOutputDir + "/standard/" gen.stringToFile(inputString, outDir) val source = util.Util.readFile("target/generated-sources/standard/test/Joystick.scala") - source === util.Util.readFile("avrohugger-core/src/test/expected/standard/test/Joystick.scala") + source ===/ util.Util.readFile("avrohugger-core/src/test/expected/standard/test/Joystick.scala") } // def e22 = { // val inputString = util.Util.readFile("avrohugger-core/src/test/avro/logical.avdl") - // val gen = new Generator(Standard) + // val gen = Generator(Standard) // val outDir = gen.defaultOutputDir + "/standard/" // gen.stringToFile(inputString, outDir) // val source = util.Util.readFile("target/generated-sources/standard/example/idl/LogicalIdl.scala") - // source === util.Util.readFile("avrohugger-core/src/test/expected/standard/example/idl/LogicalIdl.scala") + // source ===/ util.Util.readFile("avrohugger-core/src/test/expected/standard/example/idl/LogicalIdl.scala") // } // def e23 = { // val inputString = util.Util.readFile("avrohugger-core/src/test/avro/logical.avdl") // val myAvroScalaCustomTypes = Standard.defaultTypes.copy(decimal = ScalaBigDecimalWithPrecision(None)) - // val gen = new Generator(Standard, avroScalaCustomTypes = Some(myAvroScalaCustomTypes)) + // val gen = Generator(Standard, avroScalaCustomTypes = Some(myAvroScalaCustomTypes)) // val outDir = gen.defaultOutputDir + "/standard-tagged/" // gen.stringToFile(inputString, outDir) // val source = util.Util.readFile("target/generated-sources/standard-tagged/example/idl/LogicalIdl.scala") - // source === util.Util.readFile("avrohugger-core/src/test/expected/standard-tagged/example/idl/LogicalIdl.scala") + // source ===/ util.Util.readFile("avrohugger-core/src/test/expected/standard-tagged/example/idl/LogicalIdl.scala") // } def e24 = { val inputString = util.Util.readFile("avrohugger-core/src/test/avro/logical_optional.avdl") val myAvroScalaCustomTypes = Standard.defaultTypes.copy(decimal = ScalaBigDecimalWithPrecision(None)) - val gen = new Generator(Standard, avroScalaCustomTypes = Some(myAvroScalaCustomTypes)) + val gen = Generator(Standard, avroScalaCustomTypes = Some(myAvroScalaCustomTypes)) val outDir = gen.defaultOutputDir + "/standard-tagged/" gen.stringToFile(inputString, outDir) val source = util.Util.readFile("target/generated-sources/standard-tagged/example/idl/LogicalOptionalIdl.scala") - source === util.Util.readFile("avrohugger-core/src/test/expected/standard-tagged/example/idl/LogicalOptionalIdl.scala") + source ===/ util.Util.readFile("avrohugger-core/src/test/expected/standard-tagged/example/idl/LogicalOptionalIdl.scala") } def e25 = { val inputString = util.Util.readFile("avrohugger-core/src/test/avro/logical_either.avdl") val myAvroScalaCustomTypes = Standard.defaultTypes.copy(decimal = ScalaBigDecimalWithPrecision(None)) - val gen = new Generator(Standard, avroScalaCustomTypes = Some(myAvroScalaCustomTypes)) + val gen = Generator(Standard, avroScalaCustomTypes = Some(myAvroScalaCustomTypes)) val outDir = gen.defaultOutputDir + "/standard-tagged/" gen.stringToFile(inputString, outDir) val source = util.Util.readFile("target/generated-sources/standard-tagged/example/idl/LogicalEitherIdl.scala") - source === util.Util.readFile("avrohugger-core/src/test/expected/standard-tagged/example/idl/LogicalEitherIdl.scala") + source ===/ util.Util.readFile("avrohugger-core/src/test/expected/standard-tagged/example/idl/LogicalEitherIdl.scala") } def e26 = { val inputString = util.Util.readFile("avrohugger-core/src/test/avro/logical_coproduct.avdl") val myAvroScalaCustomTypes = Standard.defaultTypes.copy(decimal = ScalaBigDecimalWithPrecision(None)) - val gen = new Generator(Standard, avroScalaCustomTypes = Some(myAvroScalaCustomTypes)) + val gen = Generator(Standard, avroScalaCustomTypes = Some(myAvroScalaCustomTypes)) val outDir = gen.defaultOutputDir + "/standard-tagged/" gen.stringToFile(inputString, outDir) val source = util.Util.readFile("target/generated-sources/standard-tagged/example/idl/LogicalCoproductIdl.scala") - source === util.Util.readFile("avrohugger-core/src/test/expected/standard-tagged/example/idl/LogicalCoproductIdl.scala") + source ===/ util.Util.readFile("avrohugger-core/src/test/expected/standard-tagged/example/idl/LogicalCoproductIdl.scala") } } diff --git a/avrohugger-core/src/test/scala/standard/StandardStringToStringsSpec.scala b/avrohugger-core/src/test/scala/standard/StandardStringToStringsSpec.scala index 4b8f84b9..92b2699e 100644 --- a/avrohugger-core/src/test/scala/standard/StandardStringToStringsSpec.scala +++ b/avrohugger-core/src/test/scala/standard/StandardStringToStringsSpec.scala @@ -6,6 +6,7 @@ import avrohugger.Generator import avrohugger.format.Standard import avrohugger.types._ import org.specs2._ +import util.Util.LineEndingAmbiguousMatcherString class StandardStringToStringsSpec extends Specification { @@ -44,205 +45,205 @@ class StandardStringToStringsSpec extends Specification { def eB = { val inputString = util.Util.readFile("avrohugger-core/src/test/avro/relative.avsc") - val gen = new Generator(Standard, Some(Standard.defaultTypes.copy(record = ScalaCaseClassWithSchema))) + val gen = Generator(Standard, Some(Standard.defaultTypes.copy(record = ScalaCaseClassWithSchema))) val List(source) = gen.stringToStrings(inputString) val expected = util.Util.readFile("avrohugger-core/src/test/expected/standard/example/Relative.scala") - source === expected + source ===/ expected } // tests common to fileToX and stringToX def e1 = { val inputString = util.Util.readFile("avrohugger-core/src/test/avro/mail.avpr") - val gen = new Generator(Standard) + val gen = Generator(Standard) val List(source) = gen.stringToStrings(inputString) val expected = util.Util.readFile("avrohugger-core/src/test/expected/standard/example/proto/Message.scala") - source === expected + source ===/ expected } def e2 = { val inputString = util.Util.readFile("avrohugger-core/src/test/avro/user.avsc") - val gen = new Generator(Standard) + val gen = Generator(Standard) val List(source) = gen.stringToStrings(inputString) val expected = util.Util.readFile("avrohugger-core/src/test/expected/standard/example/User.scala") - source === expected + source ===/ expected } def e3 = { val inputString = util.Util.readFile("avrohugger-core/src/test/avro/AvroTypeProviderTestNoNamespace.avsc") - val gen = new Generator(Standard) + val gen = Generator(Standard) val List(source) = gen.stringToStrings(inputString) val expected = util.Util.readFile("avrohugger-core/src/test/expected/standard/AvroTypeProviderTestNoNamespace.scala") - source === expected + source ===/ expected } def e4 = { val inputString = util.Util.readFile("avrohugger-core/src/test/avro/nested.avsc") - val gen = new Generator(Standard) + val gen = Generator(Standard) val List(source2, source1, source0) = gen.stringToStrings(inputString) val expected0 = util.Util.readFile("avrohugger-core/src/test/expected/standard/example/Level0.scala") val expected1 = util.Util.readFile("avrohugger-core/src/test/expected/standard/example/Level1.scala") val expected2 = util.Util.readFile("avrohugger-core/src/test/expected/standard/example/Level2.scala") - source0 === expected0 - source1 === expected1 - source2 === expected2 + source0 ===/ expected0 + source1 ===/ expected1 + source2 ===/ expected2 } def e5 = { val inputString = util.Util.readFile("avrohugger-core/src/test/avro/nested.avdl") val myAvroScalaCustomTypes = Standard.defaultTypes.copy(protocol = types.ScalaADT) - val gen = new Generator(format = Standard, avroScalaCustomTypes = Some(myAvroScalaCustomTypes)) + val gen = Generator(format = Standard, avroScalaCustomTypes = Some(myAvroScalaCustomTypes)) val List(source) = gen.stringToStrings(inputString) val expected = util.Util.readFile("avrohugger-core/src/test/expected/standard/example/idl/NestedProtocol.scala") - source === expected + source ===/ expected } def e6 = { val inputString = util.Util.readFile("avrohugger-core/src/test/avro/recursive.avdl") - val gen = new Generator(Standard) + val gen = Generator(Standard) val List(source) = gen.stringToStrings(inputString) val expected = util.Util.readFile("avrohugger-core/src/test/expected/standard/example/idl/Recursive.scala") - source === expected + source ===/ expected } def e7 = { val inputString = util.Util.readFile("avrohugger-core/src/test/avro/enums.avsc") - val gen = new Generator(Standard) + val gen = Generator(Standard) val List(source) = gen.stringToStrings(inputString) val expected = util.Util.readFile("avrohugger-core/src/test/expected/standard/example/Suit.scala") - source === expected + source ===/ expected } def e8 = { val inputString = util.Util.readFile("avrohugger-core/src/test/avro/enums.avpr") val myAvroScalaCustomTypes = Standard.defaultTypes.copy(protocol = types.ScalaADT) - val gen = new Generator(format = Standard, avroScalaCustomTypes = Some(myAvroScalaCustomTypes)) + val gen = Generator(format = Standard, avroScalaCustomTypes = Some(myAvroScalaCustomTypes)) val List(source) = gen.stringToStrings(inputString) val expected = util.Util.readFile("avrohugger-core/src/test/expected/standard/example/proto/EnumProtocol.scala") - source === expected + source ===/ expected } def e9 = { val inputString = util.Util.readFile("avrohugger-core/src/test/avro/enums.avdl") val myAvroScalaCustomTypes = Standard.defaultTypes.copy(protocol = types.ScalaADT) - val gen = new Generator(format = Standard, avroScalaCustomTypes = Some(myAvroScalaCustomTypes)) + val gen = Generator(format = Standard, avroScalaCustomTypes = Some(myAvroScalaCustomTypes)) val List(source) = gen.stringToStrings(inputString) val expected = util.Util.readFile("avrohugger-core/src/test/expected/standard/example/idl/EnumProtocol.scala") - source === expected + source ===/ expected } def e10 = { val inputString = util.Util.readFile("avrohugger-core/src/test/avro/enums_nested.avsc") - val gen = new Generator(Standard) + val gen = Generator(Standard) val List(sourceEnum, sourceRecord) = gen.stringToStrings(inputString) val expectedEnum = util.Util.readFile("avrohugger-core/src/test/expected/standard/example/Direction.scala") val expectedRecord = util.Util.readFile("avrohugger-core/src/test/expected/standard/example/Compass.scala") - sourceEnum === expectedEnum - sourceRecord === expectedRecord + sourceEnum ===/ expectedEnum + sourceRecord ===/ expectedRecord } def e11 = { val inputString = util.Util.readFile("avrohugger-core/src/test/avro/bytes.avsc") - val gen = new Generator(Standard) + val gen = Generator(Standard) val List(source) = gen.stringToStrings(inputString) val expected = util.Util.readFile("avrohugger-core/src/test/expected/standard/example/BinarySc.scala") - source === expected + source ===/ expected } def e12 = { val inputString = util.Util.readFile("avrohugger-core/src/test/avro/bytes.avpr") - val gen = new Generator(Standard) + val gen = Generator(Standard) val List(source) = gen.stringToStrings(inputString) val expected = util.Util.readFile("avrohugger-core/src/test/expected/standard/example/proto/BinaryPr.scala") - source === expected + source ===/ expected } def e13 = { val inputString = util.Util.readFile("avrohugger-core/src/test/avro/bytes.avdl") - val gen = new Generator(Standard) + val gen = Generator(Standard) val List(source) = gen.stringToStrings(inputString) val expected = util.Util.readFile("avrohugger-core/src/test/expected/standard/example/idl/BinaryIdl.scala") - source === expected + source ===/ expected } def e14 = { val inputString = util.Util.readFile("avrohugger-core/src/test/avro/import.avdl") - val gen = new Generator(Standard) + val gen = Generator(Standard) gen.stringToStrings(inputString) must throwA(new java.lang.RuntimeException("Imports not supported in String IDLs, only avdl files.")) } def e15 = { val inputString = util.Util.readFile("avrohugger-core/src/test/avro/AvroTypeProviderTestEmptyRecord.avdl") val myAvroScalaCustomTypes = Standard.defaultTypes.copy(protocol = types.ScalaADT) - val gen = new Generator(format = Standard, avroScalaCustomTypes = Some(myAvroScalaCustomTypes)) + val gen = Generator(format = Standard, avroScalaCustomTypes = Some(myAvroScalaCustomTypes)) val List(source) = gen.stringToStrings(inputString) val expected = util.Util.readFile("avrohugger-core/src/test/expected/standard/test/Calculator.scala") - source === expected + source ===/ expected } def e16 = { val inputString = util.Util.readFile("avrohugger-core/src/test/avro/defaults.avdl") val myAvroScalaCustomTypes = Standard.defaultTypes.copy(protocol = types.ScalaADT) - val gen = new Generator(format = Standard, avroScalaCustomTypes = Some(myAvroScalaCustomTypes)) + val gen = Generator(format = Standard, avroScalaCustomTypes = Some(myAvroScalaCustomTypes)) val List(source) = gen.stringToStrings(inputString) val expected = util.Util.readFile("avrohugger-core/src/test/expected/standard/example/idl/Defaults.scala") - source === expected + source ===/ expected } def e21 = { val inputString = util.Util.readFile("avrohugger-core/src/test/avro/AvroTypeProviderTestProtocol.avdl") - val gen = new Generator(format = Standard) + val gen = Generator(format = Standard) val List(source) = gen.stringToStrings(inputString) - source === util.Util.readFile("avrohugger-core/src/test/expected/standard/test/Joystick.scala") + source ===/ util.Util.readFile("avrohugger-core/src/test/expected/standard/test/Joystick.scala") } // def e22 = { // val inputString = util.Util.readFile("avrohugger-core/src/test/avro/logical.avdl") - // val gen = new Generator(Standard) + // val gen = Generator(Standard) // val List(source) = gen.stringToStrings(inputString) // val expected = util.Util.readFile("avrohugger-core/src/test/expected/standard/example/idl/LogicalIdl.scala") - // source === expected + // source ===/ expected // } // def e23 = { // val inputString = util.Util.readFile("avrohugger-core/src/test/avro/logical.avdl") // val myAvroScalaCustomTypes = Standard.defaultTypes.copy(decimal = ScalaBigDecimalWithPrecision(None)) - // val gen = new Generator(Standard, avroScalaCustomTypes = Some(myAvroScalaCustomTypes)) + // val gen = Generator(Standard, avroScalaCustomTypes = Some(myAvroScalaCustomTypes)) // val List(source) = gen.stringToStrings(inputString) // val expected = util.Util.readFile("avrohugger-core/src/test/expected/standard-tagged/example/idl/LogicalIdl.scala") - // source === expected + // source ===/ expected // } def e24 = { val inputString = util.Util.readFile("avrohugger-core/src/test/avro/logical_optional.avdl") val myAvroScalaCustomTypes = Standard.defaultTypes.copy(decimal = ScalaBigDecimalWithPrecision(None)) - val gen = new Generator(Standard, avroScalaCustomTypes = Some(myAvroScalaCustomTypes)) + val gen = Generator(Standard, avroScalaCustomTypes = Some(myAvroScalaCustomTypes)) val List(source) = gen.stringToStrings(inputString) val expected = util.Util.readFile("avrohugger-core/src/test/expected/standard-tagged/example/idl/LogicalOptionalIdl.scala") - source === expected + source ===/ expected } def e25 = { val inputString = util.Util.readFile("avrohugger-core/src/test/avro/logical_either.avdl") val myAvroScalaCustomTypes = Standard.defaultTypes.copy(decimal = ScalaBigDecimalWithPrecision(None)) - val gen = new Generator(Standard, avroScalaCustomTypes = Some(myAvroScalaCustomTypes)) + val gen = Generator(Standard, avroScalaCustomTypes = Some(myAvroScalaCustomTypes)) val List(source) = gen.stringToStrings(inputString) val expected = util.Util.readFile("avrohugger-core/src/test/expected/standard-tagged/example/idl/LogicalEitherIdl.scala") - source === expected + source ===/ expected } def e26 = { val inputString = util.Util.readFile("avrohugger-core/src/test/avro/logical_coproduct.avdl") val myAvroScalaCustomTypes = Standard.defaultTypes.copy(decimal = ScalaBigDecimalWithPrecision(None)) - val gen = new Generator(Standard, avroScalaCustomTypes = Some(myAvroScalaCustomTypes)) + val gen = Generator(Standard, avroScalaCustomTypes = Some(myAvroScalaCustomTypes)) val List(source) = gen.stringToStrings(inputString) val expected = util.Util.readFile("avrohugger-core/src/test/expected/standard-tagged/example/idl/LogicalCoproductIdl.scala") - source === expected + source ===/ expected } } diff --git a/avrohugger-core/src/test/scala/util/Util.scala b/avrohugger-core/src/test/scala/util/Util.scala index 8663458d..8f627f6d 100644 --- a/avrohugger-core/src/test/scala/util/Util.scala +++ b/avrohugger-core/src/test/scala/util/Util.scala @@ -1,13 +1,16 @@ package util -import org.specs2.matcher.{Expectable, MatchResult, Matcher} +import org.specs2.matcher.Matchers.typedEqualExpectation +import org.specs2.matcher.{ Expectable, ExpectationsCreation, MatchResult, Matcher } object Util { def readFile(fileName: String, maxTries: Int = 3): String = { def readFile0(count: Int): String = { try { // if file is empty, try again, it should be there - val contents: String = scala.io.Source.fromFile(fileName).mkString + val source = scala.io.Source.fromFile(fileName) + val contents: String = source.mkString + source.close() if (contents.isEmpty && (count < maxTries)) readFile0(count + 1) else contents } catch { // if file is not found, try again, it should be there @@ -28,10 +31,18 @@ object Util { case e: Throwable => false } - def containExpectedContentIn(expectPath: String): Matcher[String] = new Matcher[String] { - override def apply[S <: String](t: Expectable[S]): MatchResult[S] = { - val generatedPath = t.value - result(readFile(generatedPath) == readFile(expectPath), s"$generatedPath === $expectPath", s"\ndiff -ruBbE $expectPath $generatedPath", t) + class LineEndingAmbiguousMatcher(left: String) extends Matcher[String] { + def apply[S <: String](right: Expectable[S]): MatchResult[S] = { + val leftAsList = if (left.contains("\r\n")) left.split("\r\n") else left.split("\n") + val rightValue: String = right.value + val rightAsList = if (rightValue.contains("\r\n")) rightValue.split("\r\n") else rightValue.split("\n") + + val res = leftAsList === rightAsList + result(res.isSuccess, res.message, res.message, right) } } + + implicit class LineEndingAmbiguousMatcherString(s: String) extends ExpectationsCreation{ + def ===/(other: String): MatchResult[String] = createExpectable(s).applyMatcher(new LineEndingAmbiguousMatcher(other)) + } } \ No newline at end of file diff --git a/avrohugger-tools/src/test/scala/MainSpec.scala b/avrohugger-tools/src/test/scala/MainSpec.scala index 6c24f76b..c9e008af 100644 --- a/avrohugger-tools/src/test/scala/MainSpec.scala +++ b/avrohugger-tools/src/test/scala/MainSpec.scala @@ -1,6 +1,6 @@ -import java.io.{ByteArrayOutputStream, PrintStream} +import java.io.{ ByteArrayOutputStream, PrintStream } -import avrohugger.tool.{Directory, Runner} +import avrohugger.tool.{ Directory, Runner } import org.specs2._ import scala.jdk.CollectionConverters._ @@ -9,12 +9,11 @@ import scala.jdk.CollectionConverters._ class MainSpec extends mutable.Specification { "tool descriptions fit in 80 characters" in { val r: Runner = new Runner(null, null, null) - val descResults = r.toolsMap.values().asScala.map(t => { - if (r.maxLen + 2 + t.getShortDescription().length() > 80) true - else false - }) + val descResults = r.toolsMap.values().asScala.exists { t => + r.maxLen + 2 + t.getShortDescription().length() > 80 + } //make sure there is no tool that didn't pass the desc. length test - descResults.exists(x => x == true) === false + descResults === false } "successful runs yield zero exit code" in { diff --git a/avrohugger-tools/src/test/scala/SpecificGeneratorToolSpec.scala b/avrohugger-tools/src/test/scala/SpecificGeneratorToolSpec.scala index 9a9770e2..ab8abdbb 100644 --- a/avrohugger-tools/src/test/scala/SpecificGeneratorToolSpec.scala +++ b/avrohugger-tools/src/test/scala/SpecificGeneratorToolSpec.scala @@ -1,9 +1,9 @@ import avrohugger.format.SpecificRecord -import avrohugger.tool.{Main, Directory, GeneratorTool} -import org.apache.avro.tool.Tool - +import avrohugger.tool.{ Directory, GeneratorTool } import org.specs2._ +import Util.LineEndingAmbiguousMatcherString + import scala.jdk.CollectionConverters._ import scala.util.Try @@ -26,8 +26,8 @@ class SpecificGeneratorToolSpec extends mutable.Specification { Directory.TEST_INPUT_DIR + "mail.avpr", Directory.TEST_OUTPUT_SPECIFIC_BASE_DIR )) - Util.readFile(Directory.TEST_OUTPUT_SPECIFIC_MAIL) === Util.readFile(Directory.TEST_EXPECTED_SPECIFIC_MAIL) - Util.readFile(Directory.TEST_OUTPUT_SPECIFIC_MESSAGE) === Util.readFile(Directory.TEST_EXPECTED_SPECIFIC_MESSAGE) + Util.readFile(Directory.TEST_OUTPUT_SPECIFIC_MAIL) ===/ Util.readFile(Directory.TEST_EXPECTED_SPECIFIC_MAIL) + Util.readFile(Directory.TEST_OUTPUT_SPECIFIC_MESSAGE) ===/ Util.readFile(Directory.TEST_EXPECTED_SPECIFIC_MESSAGE) } "match the expected single datafile file" in { @@ -35,7 +35,7 @@ class SpecificGeneratorToolSpec extends mutable.Specification { Directory.TEST_INPUT_DIR + "twitter.avro", Directory.TEST_OUTPUT_SPECIFIC_BASE_DIR )) - Util.readFile(Directory.TEST_OUTPUT_SPECIFIC_TWITTER) === Util.readFile(Directory.TEST_EXPECTED_SPECIFIC_TWITTER) + Util.readFile(Directory.TEST_OUTPUT_SPECIFIC_TWITTER) ===/ Util.readFile(Directory.TEST_EXPECTED_SPECIFIC_TWITTER) } "match the expected single schema file" in { @@ -43,7 +43,7 @@ class SpecificGeneratorToolSpec extends mutable.Specification { Directory.TEST_INPUT_DIR + "mascot.avsc", Directory.TEST_OUTPUT_SPECIFIC_BASE_DIR )) - Util.readFile(Directory.TEST_OUTPUT_SPECIFIC_MASCOT) === Util.readFile(Directory.TEST_EXPECTED_SPECIFIC_MASCOT) + Util.readFile(Directory.TEST_OUTPUT_SPECIFIC_MASCOT) ===/ Util.readFile(Directory.TEST_EXPECTED_SPECIFIC_MASCOT) } "match the expected dependent files" in { @@ -58,8 +58,8 @@ class SpecificGeneratorToolSpec extends mutable.Specification { else if (avrohugger.internal.ScalaVersion.version == "3.3") Directory.TEST_EXPECTED_SPECIFIC_PLAYER_3 else Directory.TEST_EXPECTED_SPECIFIC_PLAYER - Util.readFile(Directory.TEST_OUTPUT_SPECIFIC_NICKNAME) === Util.readFile(Directory.TEST_EXPECTED_SPECIFIC_NICKNAME) - Util.readFile(Directory.TEST_OUTPUT_SPECIFIC_PLAYER) === Util.readFile(testPlayerFile) + Util.readFile(Directory.TEST_OUTPUT_SPECIFIC_NICKNAME) ===/ Util.readFile(Directory.TEST_EXPECTED_SPECIFIC_NICKNAME) + Util.readFile(Directory.TEST_OUTPUT_SPECIFIC_PLAYER) ===/ Util.readFile(testPlayerFile) } "match the expected file and directory" in { @@ -75,8 +75,8 @@ class SpecificGeneratorToolSpec extends mutable.Specification { else Directory.TEST_EXPECTED_SPECIFIC_WRESTLER } - Util.readFile(Directory.TEST_OUTPUT_SPECIFIC_MASCOT) === Util.readFile(Directory.TEST_EXPECTED_SPECIFIC_MASCOT) - Util.readFile(Directory.TEST_OUTPUT_SPECIFIC_WRESTLER) === Util.readFile(testWrestlerFile) + Util.readFile(Directory.TEST_OUTPUT_SPECIFIC_MASCOT) ===/ Util.readFile(Directory.TEST_EXPECTED_SPECIFIC_MASCOT) + Util.readFile(Directory.TEST_OUTPUT_SPECIFIC_WRESTLER) ===/ Util.readFile(testWrestlerFile) } } \ No newline at end of file diff --git a/avrohugger-tools/src/test/scala/StandardGeneratorToolSpec.scala b/avrohugger-tools/src/test/scala/StandardGeneratorToolSpec.scala index e76cf1be..8d94ff23 100644 --- a/avrohugger-tools/src/test/scala/StandardGeneratorToolSpec.scala +++ b/avrohugger-tools/src/test/scala/StandardGeneratorToolSpec.scala @@ -1,79 +1,78 @@ import avrohugger.format.Standard - -import avrohugger.tool.{Main, Directory, GeneratorTool} -import org.apache.avro.tool.Tool - +import avrohugger.tool.{ Directory, GeneratorTool } import org.specs2._ +import Util.LineEndingAmbiguousMatcherString + import scala.jdk.CollectionConverters._ import scala.util.Try /** - * Verifies that the GeneratorTool generates Scala source properly - */ + * Verifies that the GeneratorTool generates Scala source properly + */ class StandardGeneratorToolSpec extends mutable.Specification { // Runs the actual generator tool with the given input args - private def doCompile(args: List[String]) = { + private def doCompile(args: List[String]) = { val tool = new GeneratorTool(Standard) - Try{ + Try { tool.run(null, null, null, args.asJava) } } - + "match the expected single protocol file" in { - doCompile(List[String] ("protocol", + doCompile(List[String]("protocol", Directory.TEST_INPUT_DIR + "/mail.avpr", Directory.TEST_OUTPUT_BASE_DIR )) - Util.readFile(Directory.TEST_OUTPUT_MESSAGE) === Util.readFile(Directory.TEST_EXPECTED_MESSAGE) + Util.readFile(Directory.TEST_OUTPUT_MESSAGE) ===/ Util.readFile(Directory.TEST_EXPECTED_MESSAGE) } - + "match the expected single datafile file" in { - doCompile(List[String] ("datafile", + doCompile(List[String]("datafile", Directory.TEST_INPUT_DIR + "/twitter.avro", Directory.TEST_OUTPUT_BASE_DIR )) - Util.readFile(Directory.TEST_OUTPUT_TWITTER) === Util.readFile(Directory.TEST_EXPECTED_TWITTER) + Util.readFile(Directory.TEST_OUTPUT_TWITTER) ===/ Util.readFile(Directory.TEST_EXPECTED_TWITTER) } - + "match the expected single schema file" in { - doCompile(List[String] ("schema", + doCompile(List[String]("schema", Directory.TEST_INPUT_DIR + "/handle.avsc", Directory.TEST_OUTPUT_BASE_DIR )) - Util.readFile(Directory.TEST_OUTPUT_HANDLE) === Util.readFile(Directory.TEST_EXPECTED_HANDLE) + Util.readFile(Directory.TEST_OUTPUT_HANDLE) ===/ Util.readFile(Directory.TEST_EXPECTED_HANDLE) } - + "match the expected dependent files" in { doCompile(List[String]("schema", Directory.TEST_INPUT_DIR + "/handle.avsc", Directory.TEST_INPUT_DIR + "/pilot.avsc", Directory.TEST_OUTPUT_BASE_DIR )) - Util.readFile(Directory.TEST_OUTPUT_HANDLE) === Util.readFile(Directory.TEST_EXPECTED_HANDLE) - Util.readFile(Directory.TEST_OUTPUT_PILOT) === Util.readFile(Directory.TEST_EXPECTED_PILOT) + Util.readFile(Directory.TEST_OUTPUT_HANDLE) ===/ Util.readFile(Directory.TEST_EXPECTED_HANDLE) + Util.readFile(Directory.TEST_OUTPUT_PILOT) ===/ Util.readFile(Directory.TEST_EXPECTED_PILOT) } - + "match the expected file and directory" in { doCompile(List[String]("schema", Directory.TEST_INPUT_DIR + "/mascot.avsc", Directory.TEST_INPUT_DIR, Directory.TEST_OUTPUT_BASE_DIR )) - Util.readFile(Directory.TEST_OUTPUT_MASCOT) === Util.readFile(Directory.TEST_EXPECTED_MASCOT) - Util.readFile(Directory.TEST_OUTPUT_WRESTLER) === Util.readFile(Directory.TEST_EXPECTED_WRESTLER) + Util.readFile(Directory.TEST_OUTPUT_MASCOT) ===/ Util.readFile(Directory.TEST_EXPECTED_MASCOT) + Util.readFile(Directory.TEST_OUTPUT_WRESTLER) ===/ Util.readFile(Directory.TEST_EXPECTED_WRESTLER) } -/* currently -string makes no difference, all case classes use String - "match the expected using the -string option" in { - doCompile(List[String]("-string", "schema", - Directory.TEST_INPUT_DIR + "/nickname.avsc", - Directory.TEST_INPUT_DIR + "/player.avsc", - Directory.TEST_INPUT_DIR + "/twitter_schema.avro", - Directory.TEST_OUTPUT_STRING_BASE_DIR - )) - Util.readFile(Directory.TEST_OUTPUT_STRING_PLAYER) === Util.readFile(Directory.TEST_EXPECTED_STRING_PLAYER) - } -*/ + /* currently -string makes no difference, all case classes use String + "match the expected using the -string option" in { + doCompile(List[String]("-string", "schema", + Directory.TEST_INPUT_DIR + "/nickname.avsc", + Directory.TEST_INPUT_DIR + "/player.avsc", + Directory.TEST_INPUT_DIR + "/twitter_schema.avro", + Directory.TEST_OUTPUT_STRING_BASE_DIR + )) + Util.readFile(Directory.TEST_OUTPUT_STRING_PLAYER) ===/ Util.readFile(Directory.TEST_EXPECTED_STRING_PLAYER) + } + */ } \ No newline at end of file diff --git a/avrohugger-tools/src/test/scala/Util.scala b/avrohugger-tools/src/test/scala/Util.scala index 5ea9f5b3..f39d5a85 100644 --- a/avrohugger-tools/src/test/scala/Util.scala +++ b/avrohugger-tools/src/test/scala/Util.scala @@ -1,15 +1,15 @@ -import java.io.BufferedReader -import java.io.File -import java.io.FileReader -import java.io.IOException +import org.specs2.matcher.{ Expectable, ExpectationsCreation, MatchResult, Matcher } +import org.specs2.matcher.Matchers.typedEqualExpectation object Util { def readFile(fileName: String, maxTries: Int = 3): String = { def readFile0(count: Int): String = { try { // if file is empty, try again, it should be there - val contents: String = scala.io.Source.fromFile(fileName).mkString + val source = scala.io.Source.fromFile(fileName) + val contents: String = source.mkString + source.close() if (contents.isEmpty && (count < maxTries)) readFile0(count + 1) else contents } catch { // if file is not found, try again, it should be there @@ -20,6 +20,20 @@ object Util { } readFile0(0) } - + + class LineEndingAmbiguousMatcher(left: String) extends Matcher[String] { + def apply[S <: String](right: Expectable[S]): MatchResult[S] = { + val leftAsList = if (left.contains("\r\n")) left.split("\r\n") else left.split("\n") + val rightValue: String = right.value + val rightAsList = if (rightValue.contains("\r\n")) rightValue.split("\r\n") else rightValue.split("\n") + + val res = leftAsList === rightAsList + result(res.isSuccess, res.message, res.message, right) + } + } + + implicit class LineEndingAmbiguousMatcherString(s: String) extends ExpectationsCreation{ + def ===/(other: String): MatchResult[String] = createExpectable(s).applyMatcher(new LineEndingAmbiguousMatcher(other)) + } } \ No newline at end of file