From 1f681c087a6d77bb6aba56bf398ee265b94cdf73 Mon Sep 17 00:00:00 2001 From: Mikolaj Jakubowski Date: Wed, 18 Dec 2024 17:39:32 +0100 Subject: [PATCH 01/10] fix tests on windows --- .../src/main/scala/Generator.scala | 36 +-- .../scala/format/abstractions/Importer.scala | 80 +++--- .../format/abstractions/SourceFormat.scala | 70 +++--- .../main/scala/generators/FileGenerator.scala | 40 ++- .../scala/generators/StringGenerator.scala | 56 ++--- .../src/test/scala/avrohugger/SeqSpec.scala | 5 +- .../scala/specific/SpecificCommentsSpec.scala | 21 +- .../specific/SpecificCustomEnumSpec.scala | 41 ++-- .../SpecificDefaultValueFullnameSpec.scala | 5 +- .../specific/SpecificFileToFileSpec.scala | 154 ++++++------ .../specific/SpecificFileToStringsSpec.scala | 99 ++++---- .../specific/SpecificManyFieldsSpec.scala | 4 +- .../specific/SpecificSameRecordNameSpec.scala | 5 +- .../specific/SpecificStringToFileSpec.scala | 85 +++---- .../SpecificStringToStringsSpec.scala | 81 ++++--- .../scala/standard/StandardCommentsSpec.scala | 21 +- .../standard/StandardCustomEnumSpec.scala | 61 ++--- .../standard/StandardFileToFileSpec.scala | 229 ++++++++---------- .../standard/StandardFileToStringsSpec.scala | 115 ++++----- .../standard/StandardManyFieldsSpec.scala | 4 +- .../standard/StandardStringToFileSpec.scala | 107 ++++---- .../StandardStringToStringsSpec.scala | 97 ++++---- .../src/test/scala/util/Util.scala | 23 +- .../src/test/scala/MainSpec.scala | 13 +- .../scala/SpecificGeneratorToolSpec.scala | 22 +- .../scala/StandardGeneratorToolSpec.scala | 67 +++-- avrohugger-tools/src/test/scala/Util.scala | 26 +- 27 files changed, 782 insertions(+), 785 deletions(-) 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 From fb08fd080aeb91d18d765ee70e77d12b6b589c5b Mon Sep 17 00:00:00 2001 From: Mikolaj Jakubowski Date: Thu, 19 Dec 2024 17:53:07 +0100 Subject: [PATCH 02/10] format --- .../custom/CustomNamespaceMatcher.scala | 42 +++----- .../src/main/scala/tool/GeneratorTool.scala | 97 +++++++++---------- 2 files changed, 58 insertions(+), 81 deletions(-) diff --git a/avrohugger-core/src/main/scala/matchers/custom/CustomNamespaceMatcher.scala b/avrohugger-core/src/main/scala/matchers/custom/CustomNamespaceMatcher.scala index 331dbd5f..15626d93 100644 --- a/avrohugger-core/src/main/scala/matchers/custom/CustomNamespaceMatcher.scala +++ b/avrohugger-core/src/main/scala/matchers/custom/CustomNamespaceMatcher.scala @@ -3,40 +3,24 @@ package matchers package custom object CustomNamespaceMatcher { - + // Custom namespaces work for simple types, but seem to fail for records // within unions, see http://apache-avro.679487.n3.nabble.com/Deserialize-with-different-schema-td4032782.html def checkCustomNamespace( maybeSchemaNamespace: Option[String], typeMatcher: TypeMatcher, - maybeDefaultNamespace: Option[String]) = { - - def queryNamespaceMap(schemaNamespace: String): Option[String] = { - val maybeCustomNamespace: Option[String] = - maybeSchemaNamespace.flatMap(schemaNamespace => { - typeMatcher.customNamespaces.get(schemaNamespace) match { - case Some(matchingNs) => Some(matchingNs) - case None => - typeMatcher.customNamespaces.filter(ns => ns._1.contains('*')).filter(wildcardedNs => - schemaNamespace.contains(wildcardedNs._1.substring(0, wildcardedNs._1.indexOf('*') - 1))) match { - case singleNs if singleNs.size == 1 => - Some(singleNs.head._2) - case multipleNs if multipleNs.size > 1 => - throw new java.lang.RuntimeException("Multiple conflicting custom namespaces supplied") - case _ => None - } - } - }) - maybeCustomNamespace match { - case Some(customNamespace) => Some(customNamespace) - case None => Some(schemaNamespace) + maybeDefaultNamespace: Option[String]): Option[String] = + maybeSchemaNamespace.flatMap { schemaNamespace => + typeMatcher.customNamespaces.get(schemaNamespace) orElse { + typeMatcher.customNamespaces.filter(ns => ns._1.contains('*')).filter(wildcardedNs => + schemaNamespace.contains(wildcardedNs._1.substring(0, wildcardedNs._1.indexOf('*') - 1))) match { + case singleNs if singleNs.size == 1 => + Some(singleNs.head._2) + case multipleNs if multipleNs.size > 1 => + throw new java.lang.RuntimeException("Multiple conflicting custom namespaces supplied") + case _ => None + } } - } - maybeDefaultNamespace match { - case Some(ns) => queryNamespaceMap(ns) - case None => None - } - - } + }.orElse(maybeDefaultNamespace) } \ No newline at end of file diff --git a/avrohugger-tools/src/main/scala/tool/GeneratorTool.scala b/avrohugger-tools/src/main/scala/tool/GeneratorTool.scala index 99efd89a..3e1ee396 100644 --- a/avrohugger-tools/src/main/scala/tool/GeneratorTool.scala +++ b/avrohugger-tools/src/main/scala/tool/GeneratorTool.scala @@ -6,60 +6,57 @@ import avrohugger.filesorter.AvscFileSorter import types.AvroScalaTypes import org.apache.avro.tool.Tool -import org.apache.avro.generic.GenericData.StringType; -import org.apache.avro.Schema; -import org.apache.avro.compiler.specific.SpecificCompiler; -import org.apache.avro.Protocol; +import org.apache.avro.generic.GenericData.StringType import java.io.File -import java.io.FilenameFilter; -import java.io.InputStream; -import java.io.PrintStream; -import java.util.ArrayList; -import java.util.Set; -import java.util.LinkedHashSet; -import java.util.List; +import java.io.FilenameFilter +import java.io.InputStream +import java.io.PrintStream +import java.util.ArrayList +import java.util.Set +import java.util.LinkedHashSet +import java.util.List import scala.jdk.CollectionConverters._ import scala.util.Try /** - * A Tool for generating Scala case classes from schemas - * Adapted from https://github.com/apache/avro/blob/branch-1.7/lang/java/tools/src/main/java/org/apache/avro/tool/SpecificCompilerTool.java - */ + * A Tool for generating Scala case classes from schemas + * Adapted from https://github.com/apache/avro/blob/branch-1.7/lang/java/tools/src/main/java/org/apache/avro/tool/SpecificCompilerTool.java + */ class GeneratorTool(sourceFormat: SourceFormat, avroScalaCustomTypes: Option[AvroScalaTypes] = None, avroScalaCustomNamespace: Map[String, String] = Map.empty) extends Tool { - val generator = new Generator(sourceFormat, avroScalaCustomTypes, avroScalaCustomNamespace) + val generator = Generator(sourceFormat, avroScalaCustomTypes, avroScalaCustomNamespace) @Override def run(in: InputStream, out: PrintStream, err: PrintStream, args: List[String]): Int = { if (args.size() < 3) { System.err - .println("Usage: [-string] (schema|protocol|datafile) input... outputdir"); + .println("Usage: [-string] (schema|protocol|datafile) input... outputdir") System.err - .println(" input - input files or directories"); + .println(" input - input files or directories") System.err - .println(" outputdir - directory to write generated scala"); - System.err.println(" -string - use java.lang.String instead of Utf8"); - 1; + .println(" outputdir - directory to write generated scala") + System.err.println(" -string - use java.lang.String instead of Utf8") + 1 } else { - var stringType: StringType = StringType.CharSequence; + var stringType: StringType = StringType.CharSequence - var arg = 0; + var arg = 0 if ("-string".equals(args.get(arg))) { - stringType = StringType.String; - arg+=1; + stringType = StringType.String + arg += 1 } - val method: String = args.get(arg); - var inputs: List[File] = new ArrayList[File](); + val method: String = args.get(arg) + val inputs: List[File] = new ArrayList[File]() for (i <- (arg + 1) until (args.size() - 1)) { Try { - inputs.add(new File(args.get(i))); + inputs.add(new File(args.get(i))) } } @@ -78,64 +75,60 @@ class GeneratorTool(sourceFormat: SourceFormat, } } else { - sys.error("Expected \"datafile\", \"schema\" or \"protocol\"."); - 1; + sys.error("Expected \"datafile\", \"schema\" or \"protocol\".") } - 0; + 0 } } @Override - def getName: String = generator.format.toolName; + def getName: String = generator.format.toolName @Override - def getShortDescription: String = generator.format.toolShortDescription; + def getShortDescription: String = generator.format.toolShortDescription /** - * For a List of files or directories, returns a File[] containing each file - * passed as well as each file with a matching extension found in the directory. - * - * @param inputs List of File objects that are files or directories - * @param filter File extension filter to match on when fetching files from a directory - * @return Unique array of files - */ + * For a List of files or directories, returns a File[] containing each file + * passed as well as each file with a matching extension found in the directory. + * + * @param inputs List of File objects that are files or directories + * @param filter File extension filter to match on when fetching files from a directory + * @return Unique array of files + */ private def determineInputs(inputs: List[File], filter: FilenameFilter): Array[File] = { - val fileSet: Set[File] = new LinkedHashSet[File](); // preserve order and uniqueness + val fileSet: Set[File] = new LinkedHashSet[File]() // preserve order and uniqueness for (file: File <- inputs.asScala) { // if directory, look at contents to see what files match extension if (file.isDirectory()) { for (f: File <- file.listFiles(filter)) { - fileSet.add(f); + fileSet.add(f) } } // otherwise, just add the file. else { - fileSet.add(file); + fileSet.add(file) } } if (fileSet.size() > 0) { - System.err.println("Input files to compile:"); + System.err.println("Input files to compile:") for (file: File <- fileSet.asScala) { - System.err.println(" " + file); + System.err.println(" " + file) } } else { - System.err.println("No input files found."); + System.err.println("No input files found.") } fileSet.asScala.toArray[File] } - val SCHEMA_FILTER: FileExtensionFilter = - new FileExtensionFilter("avsc"); - val PROTOCOL_FILTER: FileExtensionFilter = - new FileExtensionFilter("avpr"); - val DATAFILE_FILTER: FileExtensionFilter = - new FileExtensionFilter("avro"); + val SCHEMA_FILTER: FileExtensionFilter = FileExtensionFilter("avsc") + val PROTOCOL_FILTER: FileExtensionFilter = FileExtensionFilter("avpr") + val DATAFILE_FILTER: FileExtensionFilter = FileExtensionFilter("avro") case class FileExtensionFilter(extension: String) extends FilenameFilter { @Override def accept(dir: File, name: String) = { - name.endsWith(this.extension); + name.endsWith(this.extension) } } } From 73b4a39c404ba9ce3f0c2e77ceaef134260c4de5 Mon Sep 17 00:00:00 2001 From: Mikolaj Jakubowski Date: Thu, 19 Dec 2024 18:05:14 +0100 Subject: [PATCH 03/10] optimize cache lookup --- .../scala/format/abstractions/Importer.scala | 5 +- .../format/specific/SpecificImporter.scala | 57 ++++++++--------- .../format/standard/StandardImporter.scala | 62 ++++++++++--------- 3 files changed, 64 insertions(+), 60 deletions(-) diff --git a/avrohugger-core/src/main/scala/format/abstractions/Importer.scala b/avrohugger-core/src/main/scala/format/abstractions/Importer.scala index 92fa2bbc..c8cb3d7c 100644 --- a/avrohugger-core/src/main/scala/format/abstractions/Importer.scala +++ b/avrohugger-core/src/main/scala/format/abstractions/Importer.scala @@ -133,9 +133,9 @@ trait Importer { .filter(schema => requiresImportDef(schema)) .groupBy(schema => checkNamespace(schema).getOrElse(schema.getNamespace)) .toList - .map(group => group match { + .map { case (packageName, fields) => asImportDef(packageName, fields) - }) + } } // gets record schemas which may be dependencies @@ -173,7 +173,6 @@ trait Importer { }) .filter(schema => isRecord(schema)) .distinct - .toList } def getTopLevelSchemas( diff --git a/avrohugger-core/src/main/scala/format/specific/SpecificImporter.scala b/avrohugger-core/src/main/scala/format/specific/SpecificImporter.scala index 2279f239..2e1f3e08 100644 --- a/avrohugger-core/src/main/scala/format/specific/SpecificImporter.scala +++ b/avrohugger-core/src/main/scala/format/specific/SpecificImporter.scala @@ -7,7 +7,7 @@ import avrohugger.matchers.TypeMatcher import avrohugger.types._ import avrohugger.stores.SchemaStore import org.apache.avro.Schema.Type.RECORD -import org.apache.avro.{Protocol, Schema} +import org.apache.avro.{ Protocol, Schema } import treehugger.forest._ import definitions._ import treehuggerDSL._ @@ -21,7 +21,7 @@ object SpecificImporter extends Importer { currentNamespace: Option[String], schemaStore: SchemaStore, typeMatcher: TypeMatcher): List[Import] = { - + val switchAnnotSymbol = RootClass.newClass("scala.annotation.switch") val switchImport = IMPORT(switchAnnotSymbol) val topLevelSchemas = @@ -34,7 +34,7 @@ object SpecificImporter extends Importer { case OptionScala3UnionType => List() } val libraryDeps = shapelessDeps - + schemaOrProtocol match { case Left(schema) => { if (schema.getType == RECORD) switchImport :: libraryDeps ::: userDefinedDeps @@ -63,19 +63,19 @@ object SpecificImporter extends Importer { def determineShapelessCoproductImports( field: Schema.Field, schema: Schema, - potentialRecursives: List[Schema]): List[String] = schema.getType match { - case Schema.Type.UNION => + potentialRecursives: Set[String]): List[String] = schema.getType match { + case Schema.Type.UNION => coproductImportsForUnionType(schema) ++ schema.getTypes().asScala.toList.flatMap(s => determineShapelessCoproductImports(field, s, potentialRecursives)) - case Schema.Type.ARRAY => + case Schema.Type.ARRAY => determineShapelessCoproductImports(field, schema.getElementType(), potentialRecursives) - case Schema.Type.MAP => + case Schema.Type.MAP => determineShapelessCoproductImports(field, schema.getValueType(), potentialRecursives) case Schema.Type.RECORD => schema.getFields().asScala.toList.flatMap(f => { - if (potentialRecursives.map(_.getFullName).contains(schema.getFullName)) List.empty - else determineShapelessCoproductImports(field, f.schema(), potentialRecursives:+schema) + if (potentialRecursives.contains(schema.getFullName)) List.empty + else determineShapelessCoproductImports(field, f.schema(), potentialRecursives + schema.getFullName) }) case _ => List.empty[String] @@ -83,16 +83,16 @@ object SpecificImporter extends Importer { def determineShapelessTagImport( schema: Schema, - potentialRecursives: List[Schema]): List[String] = schema.getType match { - case Schema.Type.UNION => schema.getTypes().asScala.toList.flatMap(s => - determineShapelessTagImport(s, potentialRecursives)) - case Schema.Type.ARRAY => determineShapelessTagImport(schema.getElementType(), potentialRecursives) - case Schema.Type.MAP => determineShapelessTagImport(schema.getValueType(), potentialRecursives) + potentialRecursives: Set[String]): List[String] = schema.getType match { + case Schema.Type.UNION => schema.getTypes().asScala.toList.flatMap(s => + determineShapelessTagImport(s, potentialRecursives)) + case Schema.Type.ARRAY => determineShapelessTagImport(schema.getElementType(), potentialRecursives) + case Schema.Type.MAP => determineShapelessTagImport(schema.getValueType(), potentialRecursives) case Schema.Type.RECORD => schema.getFields().asScala.toList.flatMap(f => { - if (potentialRecursives.map(_.getFullName).contains(schema.getFullName)) List.empty - else determineShapelessTagImport(f.schema, potentialRecursives:+schema) - }) - case Schema.Type.BYTES => importsForBigDecimalTagged(schema) + if (potentialRecursives.contains(schema.getFullName)) List.empty + else determineShapelessTagImport(f.schema, potentialRecursives + schema.getFullName) + }) + case Schema.Type.BYTES => importsForBigDecimalTagged(schema) case _ => List.empty[String] } @@ -101,10 +101,10 @@ object SpecificImporter extends Importer { schema.getType == Schema.Type.BYTES && LogicalType.foldLogicalTypes( schema = schema, default = false) { - case Decimal(_, _) => typeMatcher.avroScalaTypes.decimal match { - case ScalaBigDecimal(_) => false - case ScalaBigDecimalWithPrecision(_) => true - } + case Decimal(_, _) => typeMatcher.avroScalaTypes.decimal match { + case ScalaBigDecimal(_) => false + case ScalaBigDecimalWithPrecision(_) => true + } } }.map(_ => List("tag.@@")).getOrElse(Nil) @@ -128,24 +128,25 @@ object SpecificImporter extends Importer { unionImports } + val shapelessImport: List[String] => List[Import] = { - case Nil => Nil - case head :: Nil => List(IMPORT(RootClass.newClass(s"shapeless.$head"))) - case list => List(IMPORT(RootClass.newClass(s"shapeless.{${list.mkString(", ")}}"))) + case Nil => Nil + case head :: Nil => List(IMPORT(RootClass.newClass(s"shapeless.$head"))) + case list => List(IMPORT(RootClass.newClass(s"shapeless.{${list.mkString(", ")}}"))) } val shapelessCopSymbols: List[String] = for { topLevelRecordSchema <- topLevelRecordSchemas field <- topLevelRecordSchema.getFields().asScala - symbol <- determineShapelessCoproductImports(field, field.schema(), List.empty[Schema]) + symbol <- determineShapelessCoproductImports(field, field.schema(), Set()) } yield symbol val shapelessTag: List[String] = for { topLevelRecordSchema <- topLevelRecordSchemas field <- topLevelRecordSchema.getFields().asScala - symbol <- determineShapelessTagImport(field.schema(), List.empty[Schema]) + symbol <- determineShapelessTagImport(field.schema(), Set()) } yield symbol - + shapelessImport(shapelessCopSymbols.distinct) ++ shapelessImport(shapelessTag.distinct) } diff --git a/avrohugger-core/src/main/scala/format/standard/StandardImporter.scala b/avrohugger-core/src/main/scala/format/standard/StandardImporter.scala index 9965df78..3540f4ab 100644 --- a/avrohugger-core/src/main/scala/format/standard/StandardImporter.scala +++ b/avrohugger-core/src/main/scala/format/standard/StandardImporter.scala @@ -6,7 +6,7 @@ import avrohugger.format.abstractions.Importer import avrohugger.matchers.TypeMatcher import avrohugger.stores.SchemaStore import avrohugger.types._ -import org.apache.avro.{Protocol, Schema} +import org.apache.avro.{ Protocol, Schema } import treehugger.forest._ import definitions._ import treehuggerDSL._ @@ -29,19 +29,19 @@ object StandardImporter extends Importer { def determineShapelessCoproductImports( field: Schema.Field, schema: Schema, - potentialRecursives: List[Schema]): List[String] = schema.getType match { - case Schema.Type.UNION => + potentialRecursives: Set[String]): List[String] = schema.getType match { + case Schema.Type.UNION => coproductImportsForUnionType(field, schema) ++ schema.getTypes().asScala.toList.flatMap(s => determineShapelessCoproductImports(field, s, potentialRecursives)) - case Schema.Type.ARRAY => + case Schema.Type.ARRAY => determineShapelessCoproductImports(field, schema.getElementType(), potentialRecursives) - case Schema.Type.MAP => + case Schema.Type.MAP => determineShapelessCoproductImports(field, schema.getValueType(), potentialRecursives) case Schema.Type.RECORD => schema.getFields().asScala.toList.flatMap(f => { - if (potentialRecursives.map(_.getFullName).contains(schema.getFullName)) List.empty - else determineShapelessCoproductImports(field, f.schema(), potentialRecursives:+schema) + if (potentialRecursives.contains(schema.getFullName)) List.empty + else determineShapelessCoproductImports(field, f.schema(), potentialRecursives + schema.getFullName) }) case _ => List.empty[String] @@ -49,16 +49,16 @@ object StandardImporter extends Importer { def determineShapelessTagImport( schema: Schema, - potentialRecursives: List[Schema]): List[String] = schema.getType match { - case Schema.Type.UNION => schema.getTypes().asScala.toList.flatMap(s => - determineShapelessTagImport(s, potentialRecursives)) - case Schema.Type.ARRAY => determineShapelessTagImport(schema.getElementType(), potentialRecursives) - case Schema.Type.MAP => determineShapelessTagImport(schema.getValueType(), potentialRecursives) + potentialRecursives: Set[String]): List[String] = schema.getType match { + case Schema.Type.UNION => schema.getTypes().asScala.toList.flatMap(s => + determineShapelessTagImport(s, potentialRecursives)) + case Schema.Type.ARRAY => determineShapelessTagImport(schema.getElementType(), potentialRecursives) + case Schema.Type.MAP => determineShapelessTagImport(schema.getValueType(), potentialRecursives) case Schema.Type.RECORD => schema.getFields().asScala.toList.flatMap(f => { - if (potentialRecursives.map(_.getFullName).contains(schema.getFullName)) List.empty - else determineShapelessTagImport(f.schema, potentialRecursives:+schema) - }) - case Schema.Type.BYTES => importsForBigDecimalTagged(schema) + if (potentialRecursives.contains(schema.getFullName)) List.empty + else determineShapelessTagImport(f.schema, potentialRecursives + schema.getFullName) + }) + case Schema.Type.BYTES => importsForBigDecimalTagged(schema) case _ => List.empty[String] } @@ -67,10 +67,10 @@ object StandardImporter extends Importer { schema.getType == Schema.Type.BYTES && LogicalType.foldLogicalTypes( schema = schema, default = false) { - case Decimal(_, _) => typeMatcher.avroScalaTypes.decimal match { - case ScalaBigDecimal(_) => false - case ScalaBigDecimalWithPrecision(_) => true - } + case Decimal(_, _) => typeMatcher.avroScalaTypes.decimal match { + case ScalaBigDecimal(_) => false + case ScalaBigDecimalWithPrecision(_) => true + } } }.map(_ => List("tag.@@")).getOrElse(Nil) @@ -83,12 +83,15 @@ object StandardImporter extends Importer { case OptionEitherShapelessCoproduct => 2 // unions of one nullable type become Option, two become Either } val unionContainsNull: Schema => Boolean = _.getType == Schema.Type.NULL + def shapelessCoproductTest(unionTypes: List[Schema], maxNonNullTypes: Int): Boolean = - (unionTypes.length > maxNonNullTypes && !unionTypes.exists(unionContainsNull)) || - (unionTypes.length > maxNonNullTypes + 1 && unionTypes.exists(unionContainsNull)) + (unionTypes.length > maxNonNullTypes && !unionTypes.exists(unionContainsNull)) || + (unionTypes.length > maxNonNullTypes + 1 && unionTypes.exists(unionContainsNull)) + def defaultValueTest(field: Schema.Field, unionTypes: List[Schema], maxNonNullTypes: Int) = - (unionTypes.length > maxNonNullTypes && !unionTypes.exists(unionContainsNull) && field.hasDefaultValue) || - (unionTypes.length > maxNonNullTypes + 1 && unionTypes.exists(unionContainsNull) && field.hasDefaultValue) + (unionTypes.length > maxNonNullTypes && !unionTypes.exists(unionContainsNull) && field.hasDefaultValue) || + (unionTypes.length > maxNonNullTypes + 1 && unionTypes.exists(unionContainsNull) && field.hasDefaultValue) + val unionTypes = unionSchema.getTypes().asScala.toList val isShapelessCoproduct: Boolean = shapelessCoproductTest(unionTypes, thresholdNonNullTypes) val hasDefaultValue: Boolean = defaultValueTest(field, unionTypes, thresholdNonNullTypes) @@ -101,22 +104,23 @@ object StandardImporter extends Importer { unionImports } + val shapelessImport: List[String] => List[Import] = { - case Nil => Nil - case head :: Nil => List(IMPORT(RootClass.newClass(s"shapeless.$head"))) - case list => List(IMPORT(RootClass.newClass(s"shapeless.{${list.mkString(", ")}}"))) + case Nil => Nil + case head :: Nil => List(IMPORT(RootClass.newClass(s"shapeless.$head"))) + case list => List(IMPORT(RootClass.newClass(s"shapeless.{${list.mkString(", ")}}"))) } val shapelessCopSymbols: List[String] = for { topLevelRecordSchema <- topLevelRecordSchemas field <- topLevelRecordSchema.getFields().asScala - symbol <- determineShapelessCoproductImports(field, field.schema(), List.empty[Schema]) + symbol <- determineShapelessCoproductImports(field, field.schema(), Set()) } yield symbol val shapelessTag: List[String] = for { topLevelRecordSchema <- topLevelRecordSchemas field <- topLevelRecordSchema.getFields().asScala - symbol <- determineShapelessTagImport(field.schema(), List.empty[Schema]) + symbol <- determineShapelessTagImport(field.schema(), Set()) } yield symbol shapelessImport(shapelessCopSymbols.distinct) ++ From 5d98bf2015b8d11ee26cae376d2d221b60a6b813 Mon Sep 17 00:00:00 2001 From: Mikolaj Jakubowski Date: Fri, 20 Dec 2024 10:21:30 +0100 Subject: [PATCH 04/10] optimize cache lookup --- .../format/specific/SpecificImporter.scala | 80 ++++++++++++------- .../scala/specific/SpecificCommentsSpec.scala | 10 +-- .../SpecificDefaultValueFullnameSpec.scala | 2 +- .../specific/SpecificSameRecordNameSpec.scala | 2 +- .../scala/standard/StandardCommentsSpec.scala | 10 +-- 5 files changed, 61 insertions(+), 43 deletions(-) diff --git a/avrohugger-core/src/main/scala/format/specific/SpecificImporter.scala b/avrohugger-core/src/main/scala/format/specific/SpecificImporter.scala index 2e1f3e08..7207cb50 100644 --- a/avrohugger-core/src/main/scala/format/specific/SpecificImporter.scala +++ b/avrohugger-core/src/main/scala/format/specific/SpecificImporter.scala @@ -12,6 +12,7 @@ import treehugger.forest._ import definitions._ import treehuggerDSL._ +import scala.annotation.tailrec import scala.jdk.CollectionConverters._ object SpecificImporter extends Importer { @@ -62,38 +63,55 @@ object SpecificImporter extends Importer { def determineShapelessCoproductImports( field: Schema.Field, - schema: Schema, - potentialRecursives: Set[String]): List[String] = schema.getType match { - case Schema.Type.UNION => - coproductImportsForUnionType(schema) ++ - schema.getTypes().asScala.toList.flatMap(s => - determineShapelessCoproductImports(field, s, potentialRecursives)) - case Schema.Type.ARRAY => - determineShapelessCoproductImports(field, schema.getElementType(), potentialRecursives) - case Schema.Type.MAP => - determineShapelessCoproductImports(field, schema.getValueType(), potentialRecursives) - case Schema.Type.RECORD => - schema.getFields().asScala.toList.flatMap(f => { - if (potentialRecursives.contains(schema.getFullName)) List.empty - else determineShapelessCoproductImports(field, f.schema(), potentialRecursives + schema.getFullName) - }) - case _ => - List.empty[String] + schema: Schema): List[String] = { + var processedSchemas: Set[String] = Set() + + def determineShapelessCoproductImportsRec( + field: Schema.Field, + schema: Schema): List[String] = { + if (processedSchemas.contains(schema.getFullName)) List.empty + else { + processedSchemas += schema.getFullName + schema.getType match { + case Schema.Type.UNION => + coproductImportsForUnionType(schema) ++ + schema.getTypes().asScala.toList.flatMap(s => determineShapelessCoproductImportsRec(field, s)) + case Schema.Type.ARRAY => + determineShapelessCoproductImportsRec(field, schema.getElementType()) + case Schema.Type.MAP => + determineShapelessCoproductImportsRec(field, schema.getValueType()) + case Schema.Type.RECORD => + schema.getFields().asScala.toList.flatMap(f => determineShapelessCoproductImportsRec(field, f.schema())) + case _ => + List.empty[String] + } + } + } + + determineShapelessCoproductImportsRec(field, schema) } def determineShapelessTagImport( - schema: Schema, - potentialRecursives: Set[String]): List[String] = schema.getType match { - case Schema.Type.UNION => schema.getTypes().asScala.toList.flatMap(s => - determineShapelessTagImport(s, potentialRecursives)) - case Schema.Type.ARRAY => determineShapelessTagImport(schema.getElementType(), potentialRecursives) - case Schema.Type.MAP => determineShapelessTagImport(schema.getValueType(), potentialRecursives) - case Schema.Type.RECORD => schema.getFields().asScala.toList.flatMap(f => { - if (potentialRecursives.contains(schema.getFullName)) List.empty - else determineShapelessTagImport(f.schema, potentialRecursives + schema.getFullName) - }) - case Schema.Type.BYTES => importsForBigDecimalTagged(schema) - case _ => List.empty[String] + schema: Schema + ): List[String] = { + var processedSchemas: Set[String] = Set() + + def determineShapelessTagImportRec(schema: Schema): List[String] = { + if (processedSchemas.contains(schema.getFullName)) List.empty + else { + processedSchemas += schema.getFullName + schema.getType match { + case Schema.Type.UNION => schema.getTypes().asScala.toList.flatMap(determineShapelessTagImportRec) + case Schema.Type.ARRAY => determineShapelessTagImportRec(schema.getElementType()) + case Schema.Type.MAP => determineShapelessTagImportRec(schema.getValueType()) + case Schema.Type.RECORD => schema.getFields().asScala.toList.flatMap(f => determineShapelessTagImportRec(f.schema)) + case Schema.Type.BYTES => importsForBigDecimalTagged(schema) + case _ => List.empty[String] + } + } + } + + determineShapelessTagImportRec(schema) } def importsForBigDecimalTagged(schemas: Schema*): List[String] = @@ -138,13 +156,13 @@ object SpecificImporter extends Importer { for { topLevelRecordSchema <- topLevelRecordSchemas field <- topLevelRecordSchema.getFields().asScala - symbol <- determineShapelessCoproductImports(field, field.schema(), Set()) + symbol <- determineShapelessCoproductImports(field, field.schema()) } yield symbol val shapelessTag: List[String] = for { topLevelRecordSchema <- topLevelRecordSchemas field <- topLevelRecordSchema.getFields().asScala - symbol <- determineShapelessTagImport(field.schema(), Set()) + symbol <- determineShapelessTagImport(field.schema()) } yield symbol shapelessImport(shapelessCopSymbols.distinct) ++ diff --git a/avrohugger-core/src/test/scala/specific/SpecificCommentsSpec.scala b/avrohugger-core/src/test/scala/specific/SpecificCommentsSpec.scala index 801cd039..1b8b195a 100644 --- a/avrohugger-core/src/test/scala/specific/SpecificCommentsSpec.scala +++ b/avrohugger-core/src/test/scala/specific/SpecificCommentsSpec.scala @@ -20,7 +20,7 @@ class SpecificCommentsSpec extends Specification { 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 + val sourceRecord = util.Util.readFile(s"$outDir/com/example/NoSpaces1.scala") sourceRecord ===/ util.Util.readFile("avrohugger-core/src/test/expected/comments/specific/NoSpaces1.scala") } @@ -29,7 +29,7 @@ class SpecificCommentsSpec extends Specification { 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 + val sourceRecord = util.Util.readFile(s"$outDir/com/example/NoSpaces2.scala") sourceRecord ===/ util.Util.readFile("avrohugger-core/src/test/expected/comments/specific/NoSpaces2.scala") } @@ -38,7 +38,7 @@ class SpecificCommentsSpec extends Specification { 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 + val sourceRecord = util.Util.readFile(s"$outDir/com/example/NoSpaces3.scala") sourceRecord ===/ util.Util.readFile("avrohugger-core/src/test/expected/comments/specific/NoSpaces3.scala") } @@ -48,7 +48,7 @@ class SpecificCommentsSpec extends Specification { 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 + val sourceRecord = util.Util.readFile(s"$outDir/com/example/Example4.scala") sourceRecord ===/ util.Util.readFile("avrohugger-core/src/test/expected/comments/specific/Example4.scala") } @@ -57,7 +57,7 @@ class SpecificCommentsSpec extends Specification { 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 + val sourceRecord = util.Util.readFile(s"$outDir/com/example/Example5.scala") sourceRecord ===/ util.Util.readFile("avrohugger-core/src/test/expected/comments/specific/Example5.scala") } diff --git a/avrohugger-core/src/test/scala/specific/SpecificDefaultValueFullnameSpec.scala b/avrohugger-core/src/test/scala/specific/SpecificDefaultValueFullnameSpec.scala index f9682b9b..dfb72931 100644 --- a/avrohugger-core/src/test/scala/specific/SpecificDefaultValueFullnameSpec.scala +++ b/avrohugger-core/src/test/scala/specific/SpecificDefaultValueFullnameSpec.scala @@ -12,7 +12,7 @@ class SpecificDefaultValueFullnameSpec extends mutable.Specification { 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 + val sourceRecord = util.Util.readFile(s"$outDir/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/SpecificSameRecordNameSpec.scala b/avrohugger-core/src/test/scala/specific/SpecificSameRecordNameSpec.scala index 31732674..98957ec8 100644 --- a/avrohugger-core/src/test/scala/specific/SpecificSameRecordNameSpec.scala +++ b/avrohugger-core/src/test/scala/specific/SpecificSameRecordNameSpec.scala @@ -12,7 +12,7 @@ class SpecificSameRecordNameSpec extends mutable.Specification { 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 + val sourceRecord = util.Util.readFile(s"$outDir/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/standard/StandardCommentsSpec.scala b/avrohugger-core/src/test/scala/standard/StandardCommentsSpec.scala index 165b3d3d..2ad8769f 100644 --- a/avrohugger-core/src/test/scala/standard/StandardCommentsSpec.scala +++ b/avrohugger-core/src/test/scala/standard/StandardCommentsSpec.scala @@ -20,7 +20,7 @@ class StandardCommentsSpec extends Specification { 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 + val sourceRecord = util.Util.readFile(s"$outDir/com/example/NoSpaces1.scala") sourceRecord ===/ util.Util.readFile("avrohugger-core/src/test/expected/comments/standard/NoSpaces1.scala") } @@ -29,7 +29,7 @@ class StandardCommentsSpec extends Specification { 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 + val sourceRecord = util.Util.readFile(s"$outDir/com/example/NoSpaces2.scala") sourceRecord ===/ util.Util.readFile("avrohugger-core/src/test/expected/comments/standard/NoSpaces2.scala") } @@ -38,7 +38,7 @@ class StandardCommentsSpec extends Specification { 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 + val sourceRecord = util.Util.readFile(s"$outDir/com/example/NoSpaces3.scala") sourceRecord ===/ util.Util.readFile("avrohugger-core/src/test/expected/comments/standard/NoSpaces3.scala") } @@ -48,7 +48,7 @@ class StandardCommentsSpec extends Specification { 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 + val sourceRecord = util.Util.readFile(s"$outDir/com/example/Example4.scala") sourceRecord ===/ util.Util.readFile("avrohugger-core/src/test/expected/comments/standard/Example4.scala") } @@ -57,7 +57,7 @@ class StandardCommentsSpec extends Specification { 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 + val sourceRecord = util.Util.readFile(s"$outDir/com/example/Example5.scala") sourceRecord ===/ util.Util.readFile("avrohugger-core/src/test/expected/comments/standard/Example5.scala") } From cd1460ee128ca978a42075410733ccfd89bd540b Mon Sep 17 00:00:00 2001 From: Mikolaj Jakubowski Date: Fri, 20 Dec 2024 10:25:28 +0100 Subject: [PATCH 05/10] fix flaky tests --- .../src/test/scala/specific/SpecificFileToFileSpec.scala | 2 +- .../src/test/scala/specific/SpecificManyFieldsSpec.scala | 2 +- .../src/test/scala/standard/StandardFileToFileSpec.scala | 2 +- .../src/test/scala/standard/StandardManyFieldsSpec.scala | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/avrohugger-core/src/test/scala/specific/SpecificFileToFileSpec.scala b/avrohugger-core/src/test/scala/specific/SpecificFileToFileSpec.scala index 95c2b6df..a833a3ba 100644 --- a/avrohugger-core/src/test/scala/specific/SpecificFileToFileSpec.scala +++ b/avrohugger-core/src/test/scala/specific/SpecificFileToFileSpec.scala @@ -14,7 +14,7 @@ import scala.util.Try class SpecificFileToFileSpec extends Specification { - def is = s2""" + def is = sequential ^ s2""" SpecificRecord Generator fileToFiles method should correctly generate a simple case class definition from AVRO $eA not generate copy of imported classes in the importing package $e0 diff --git a/avrohugger-core/src/test/scala/specific/SpecificManyFieldsSpec.scala b/avrohugger-core/src/test/scala/specific/SpecificManyFieldsSpec.scala index 7a4f83d4..c2437717 100644 --- a/avrohugger-core/src/test/scala/specific/SpecificManyFieldsSpec.scala +++ b/avrohugger-core/src/test/scala/specific/SpecificManyFieldsSpec.scala @@ -20,7 +20,7 @@ class SpecificManyFieldsSpec extends Specification { val genRestricted = Generator(SpecificRecord, restrictedFieldNumber = true) val outDirRestricted = genRestricted.defaultOutputDir + "/specific/restricted" - def is = s2""" + def is = sequential ^ s2""" A Specific Generator should generate cases classes when many fields are supported with AVDLs with AVDLs $e1 diff --git a/avrohugger-core/src/test/scala/standard/StandardFileToFileSpec.scala b/avrohugger-core/src/test/scala/standard/StandardFileToFileSpec.scala index d356a02c..ac008f7f 100644 --- a/avrohugger-core/src/test/scala/standard/StandardFileToFileSpec.scala +++ b/avrohugger-core/src/test/scala/standard/StandardFileToFileSpec.scala @@ -14,7 +14,7 @@ import scala.util.Try class StandardFileToFileSpec extends Specification { def is = - s2""" + sequential ^ s2""" Standard Generator fileToFile method should correctly generate a simple case class definition from AVRO $eA diff --git a/avrohugger-core/src/test/scala/standard/StandardManyFieldsSpec.scala b/avrohugger-core/src/test/scala/standard/StandardManyFieldsSpec.scala index 16af146c..e7f35e3c 100644 --- a/avrohugger-core/src/test/scala/standard/StandardManyFieldsSpec.scala +++ b/avrohugger-core/src/test/scala/standard/StandardManyFieldsSpec.scala @@ -20,7 +20,7 @@ class StandardManyFieldsSpec extends Specification { val genRestricted = Generator(Standard, restrictedFieldNumber = true) val outDirRestricted = genRestricted.defaultOutputDir + "/standard/restricted" - def is = s2""" + def is = sequential ^ s2""" A Standard Generator should generate cases classes when many fields are supported with AVDLs with AVDLs $e1 From 7845dccd31fa9665b076f04335ac4c304fba6bc9 Mon Sep 17 00:00:00 2001 From: Mikolaj Jakubowski Date: Fri, 20 Dec 2024 10:34:25 +0100 Subject: [PATCH 06/10] compile schema only once per file --- .../src/main/scala/Generator.scala | 16 ++++++++++++ .../main/scala/generators/FileGenerator.scala | 25 +++++++++++++++++-- .../scala/input/parsers/FileInputParser.scala | 2 +- 3 files changed, 40 insertions(+), 3 deletions(-) diff --git a/avrohugger-core/src/main/scala/Generator.scala b/avrohugger-core/src/main/scala/Generator.scala index a45bafc2..cc36a17e 100644 --- a/avrohugger-core/src/main/scala/Generator.scala +++ b/avrohugger-core/src/main/scala/Generator.scala @@ -82,6 +82,22 @@ case class Generator(format: SourceFormat, targetScalaPartialVersion) } + def filesToFile( + inFiles: List[File], + outDir: String = defaultOutputDir): Unit = { + fileGenerator.filesToFile( + inFiles, + outDir, + format, + classStore, + schemaStore, + fileParser, + typeMatcher, + classLoader, + restrictedFieldNumber, + targetScalaPartialVersion) + } + //////// methods for writing to a list of definitions in String format /////// def schemaToStrings(schema: Schema): List[String] = { stringGenerator.schemaToStrings( diff --git a/avrohugger-core/src/main/scala/generators/FileGenerator.scala b/avrohugger-core/src/main/scala/generators/FileGenerator.scala index 53431c44..963f17c9 100644 --- a/avrohugger-core/src/main/scala/generators/FileGenerator.scala +++ b/avrohugger-core/src/main/scala/generators/FileGenerator.scala @@ -56,7 +56,7 @@ private[avrohugger] class FileGenerator { typeMatcher: TypeMatcher, restrictedFields: Boolean, targetScalaPartialVersion: String): Unit = { - val schemaOrProtocols = stringParser.getSchemaOrProtocols(str, schemaStore) + val schemaOrProtocols = stringParser.getSchemaOrProtocols(str, schemaStore).distinct schemaOrProtocols.foreach { case Left(schema) => schemaToFile(schema, outDir, format, classStore, schemaStore, typeMatcher, restrictedFields, targetScalaPartialVersion) @@ -77,7 +77,7 @@ private[avrohugger] class FileGenerator { restrictedFields: Boolean, targetScalaPartialVersion: String): Unit = { val schemaOrProtocols: List[Either[Schema, Protocol]] = - fileParser.getSchemaOrProtocols(inFile, format, classStore, classLoader) + fileParser.getSchemaOrProtocols(inFile, format, classStore, classLoader).distinct schemaOrProtocols.foreach { case Left(schema) => schemaToFile(schema, outDir, format, classStore, schemaStore, typeMatcher, restrictedFields, targetScalaPartialVersion) @@ -86,4 +86,25 @@ private[avrohugger] class FileGenerator { } } + def filesToFile( + inFiles: List[File], + outDir: String, + format: SourceFormat, + classStore: ClassStore, + schemaStore: SchemaStore, + fileParser: FileInputParser, + typeMatcher: TypeMatcher, + classLoader: ClassLoader, + restrictedFields: Boolean, + targetScalaPartialVersion: String): Unit = { + inFiles.flatMap(fileParser.getSchemaOrProtocols(_, format, classStore, classLoader)) + .distinct + .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) + } + } + } diff --git a/avrohugger-core/src/main/scala/input/parsers/FileInputParser.scala b/avrohugger-core/src/main/scala/input/parsers/FileInputParser.scala index f52e9fbe..163079d7 100644 --- a/avrohugger-core/src/main/scala/input/parsers/FileInputParser.scala +++ b/avrohugger-core/src/main/scala/input/parsers/FileInputParser.scala @@ -103,7 +103,7 @@ class FileInputParser { val importedSchemaOrProtocols = importedFiles.flatMap(file => { val importParser = new Parser() // else attempts to redefine schemas getSchemaOrProtocols(file, format, classStore, classLoader, importParser) - }).toList + }) def stripImports( protocol: Protocol, importedSchemaOrProtocols: List[Either[Schema, Protocol]]) = { From ce6db2ac9e4f39d45d31f8341282c93db68f34fd Mon Sep 17 00:00:00 2001 From: Mikolaj Jakubowski Date: Fri, 20 Dec 2024 11:19:06 +0100 Subject: [PATCH 07/10] rename --- .../main/scala/generators/FileGenerator.scala | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/avrohugger-core/src/main/scala/generators/FileGenerator.scala b/avrohugger-core/src/main/scala/generators/FileGenerator.scala index 963f17c9..8af89486 100644 --- a/avrohugger-core/src/main/scala/generators/FileGenerator.scala +++ b/avrohugger-core/src/main/scala/generators/FileGenerator.scala @@ -76,17 +76,17 @@ private[avrohugger] class FileGenerator { classLoader: ClassLoader, restrictedFields: Boolean, targetScalaPartialVersion: String): Unit = { - val schemaOrProtocols: List[Either[Schema, Protocol]] = - fileParser.getSchemaOrProtocols(inFile, format, classStore, classLoader).distinct - 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) - } + fileParser.getSchemaOrProtocols(inFile, format, classStore, classLoader) + .distinct + .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 filesToFile( + def filesToFiles( inFiles: List[File], outDir: String, format: SourceFormat, From b8bbe544c6faa2ef17d95261afa134f0e428c66d Mon Sep 17 00:00:00 2001 From: Mikolaj Jakubowski Date: Fri, 20 Dec 2024 13:48:41 +0100 Subject: [PATCH 08/10] rename --- avrohugger-core/src/main/scala/Generator.scala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/avrohugger-core/src/main/scala/Generator.scala b/avrohugger-core/src/main/scala/Generator.scala index cc36a17e..403ab922 100644 --- a/avrohugger-core/src/main/scala/Generator.scala +++ b/avrohugger-core/src/main/scala/Generator.scala @@ -82,10 +82,10 @@ case class Generator(format: SourceFormat, targetScalaPartialVersion) } - def filesToFile( + def filesToFiles( inFiles: List[File], outDir: String = defaultOutputDir): Unit = { - fileGenerator.filesToFile( + fileGenerator.filesToFiles( inFiles, outDir, format, From 1b9ff46be0dc422a7a12ba66ca85337f959180e3 Mon Sep 17 00:00:00 2001 From: Mikolaj Jakubowski Date: Tue, 24 Dec 2024 11:42:25 +0100 Subject: [PATCH 09/10] review --- .../main/scala/generators/FileGenerator.scala | 30 ++++++++++++------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/avrohugger-core/src/main/scala/generators/FileGenerator.scala b/avrohugger-core/src/main/scala/generators/FileGenerator.scala index 8af89486..26b5caad 100644 --- a/avrohugger-core/src/main/scala/generators/FileGenerator.scala +++ b/avrohugger-core/src/main/scala/generators/FileGenerator.scala @@ -56,13 +56,13 @@ private[avrohugger] class FileGenerator { typeMatcher: TypeMatcher, restrictedFields: Boolean, targetScalaPartialVersion: String): Unit = { - val schemaOrProtocols = stringParser.getSchemaOrProtocols(str, schemaStore).distinct - 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) - } + distinctSchemaOrProtocol(stringParser.getSchemaOrProtocols(str, schemaStore)) + .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( @@ -76,8 +76,7 @@ private[avrohugger] class FileGenerator { classLoader: ClassLoader, restrictedFields: Boolean, targetScalaPartialVersion: String): Unit = { - fileParser.getSchemaOrProtocols(inFile, format, classStore, classLoader) - .distinct + distinctSchemaOrProtocol(fileParser.getSchemaOrProtocols(inFile, format, classStore, classLoader)) .foreach { case Left(schema) => schemaToFile(schema, outDir, format, classStore, schemaStore, typeMatcher, restrictedFields, targetScalaPartialVersion) @@ -97,8 +96,7 @@ private[avrohugger] class FileGenerator { classLoader: ClassLoader, restrictedFields: Boolean, targetScalaPartialVersion: String): Unit = { - inFiles.flatMap(fileParser.getSchemaOrProtocols(_, format, classStore, classLoader)) - .distinct + distinctSchemaOrProtocol(inFiles.flatMap(fileParser.getSchemaOrProtocols(_, format, classStore, classLoader))) .foreach { case Left(schema) => schemaToFile(schema, outDir, format, classStore, schemaStore, typeMatcher, restrictedFields, targetScalaPartialVersion) @@ -107,4 +105,14 @@ private[avrohugger] class FileGenerator { } } + private def distinctSchemaOrProtocol(schemaOrProtocols: List[Either[Schema, Protocol]]): List[Either[Schema, Protocol]] = { + schemaOrProtocols.map { + case Left(schema) => schema.getFullName -> Left(schema) + case Right(protocol) => Option(protocol.getNamespace).map(_ + ".").getOrElse("") + protocol.getName -> Right(protocol) + } + .toMap + .values + .toList + } + } From b0e0cbd122a1e233e2cd67bd7664d2fe5d8768d7 Mon Sep 17 00:00:00 2001 From: Mikolaj Jakubowski Date: Tue, 24 Dec 2024 14:13:34 +0100 Subject: [PATCH 10/10] review --- .../main/scala/generators/FileGenerator.scala | 26 ++++++++++++++----- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/avrohugger-core/src/main/scala/generators/FileGenerator.scala b/avrohugger-core/src/main/scala/generators/FileGenerator.scala index 26b5caad..60848661 100644 --- a/avrohugger-core/src/main/scala/generators/FileGenerator.scala +++ b/avrohugger-core/src/main/scala/generators/FileGenerator.scala @@ -106,13 +106,25 @@ private[avrohugger] class FileGenerator { } private def distinctSchemaOrProtocol(schemaOrProtocols: List[Either[Schema, Protocol]]): List[Either[Schema, Protocol]] = { - schemaOrProtocols.map { - case Left(schema) => schema.getFullName -> Left(schema) - case Right(protocol) => Option(protocol.getNamespace).map(_ + ".").getOrElse("") + protocol.getName -> Right(protocol) - } - .toMap - .values - .toList + var processed = Set.empty[String] + + schemaOrProtocols.flatMap { + case Left(schema) => + if (!processed.contains(schema.getFullName)) { + processed += schema.getFullName + Some(Left(schema)) + } else { + None + } + case Right(protocol) => + val fullName = Option(protocol.getNamespace).map(ns => s"$ns.${protocol.getName}").getOrElse(protocol.getName) + if (!processed.contains(fullName)) { + processed += fullName + Some(Right(protocol)) + } else { + None + } + } } }