From e89eec05a36a84e0e891c6e9d4f528f9e7c231e6 Mon Sep 17 00:00:00 2001 From: JavierMonton Date: Fri, 9 Oct 2026 22:22:10 +0200 Subject: [PATCH] Cover Scala 3 core gaps: formats specs, Seq, empty struct, summoner --- .../conversions/SqlTypeConversionSpec.scala | 19 ++++++++ .../bigdatatypes/formats/FormatsSpec.scala | 47 +++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 core/src/test/scala_3/org/datatools/bigdatatypes/formats/FormatsSpec.scala diff --git a/core/src/test/scala_3/org/datatools/bigdatatypes/conversions/SqlTypeConversionSpec.scala b/core/src/test/scala_3/org/datatools/bigdatatypes/conversions/SqlTypeConversionSpec.scala index 0df636a9..ce6cc2dd 100644 --- a/core/src/test/scala_3/org/datatools/bigdatatypes/conversions/SqlTypeConversionSpec.scala +++ b/core/src/test/scala_3/org/datatools/bigdatatypes/conversions/SqlTypeConversionSpec.scala @@ -138,4 +138,23 @@ class SqlTypeConversionSpec extends UnitSpec { sqlType shouldBe extendedTypes } + "Seq type" should "be converted into Repeated type" in { + val sqlType: SqlType = SqlTypeConversion[Seq[Int]].getType + sqlType shouldBe SqlInt(Repeated) + } + + "Empty case class" should "be converted into an empty SqlStruct" in { + val sqlType: SqlType = SqlTypeConversion[EmptyRow].getType + sqlType shouldBe SqlStruct(List.empty[(String, SqlType)]) + } + + "SqlInstanceConversion summoner" should "return the given instance" in { + given SqlInstanceConversion[String] with { + def getType(value: String): SqlType = SqlString(Required) + } + SqlInstanceConversion[String].getType("anything") shouldBe SqlString(Required) + } + } + +case class EmptyRow() diff --git a/core/src/test/scala_3/org/datatools/bigdatatypes/formats/FormatsSpec.scala b/core/src/test/scala_3/org/datatools/bigdatatypes/formats/FormatsSpec.scala new file mode 100644 index 00000000..fc1ecb0c --- /dev/null +++ b/core/src/test/scala_3/org/datatools/bigdatatypes/formats/FormatsSpec.scala @@ -0,0 +1,47 @@ +package org.datatools.bigdatatypes.formats + +import org.datatools.bigdatatypes.UnitSpec +import org.datatools.bigdatatypes.basictypes.SqlType._ +import org.datatools.bigdatatypes.basictypes.SqlTypeMode._ + +class FormatsSpec extends UnitSpec { + + behavior of "FormatsSpec" + + "Default Formats" should "leave keys unchanged" in { + DefaultFormats.transformKey("myValue", SqlString()) shouldBe "myValue" + DefaultFormats.transformKey("myValue", SqlInt()) shouldBe "myValue" + } + + "Default Formats" should "use BigDecimal precision 10 scale 0" in { + DefaultFormats.bigDecimal shouldBe DefaultFormats.BigDecimalPrecision(10, 0) + } + + "Base Formats" should "leave keys unchanged by default" in { + val formats = new Formats {} + formats.transformKey("myValue", SqlString()) shouldBe "myValue" + } + + "Snakify Formats" should "convert camelCase to snake_case" in { + SnakifyFormats.transformKey("myValue", SqlString()) shouldBe "my_value" + } + + "Snakify Formats" should "handle acronyms" in { + SnakifyFormats.transformKey("myURLValue", SqlString()) shouldBe "my_url_value" + } + + "KeyTypeExample Formats" should "prefix booleans with is_" in { + KeyTypeExampleFormats.transformKey("active", SqlBool()) shouldBe "is_active" + } + + "KeyTypeExample Formats" should "suffix dates and timestamps with _at" in { + KeyTypeExampleFormats.transformKey("birth", SqlDate()) shouldBe "birth_at" + KeyTypeExampleFormats.transformKey("created", SqlTimestamp()) shouldBe "created_at" + } + + "KeyTypeExample Formats" should "leave other types unchanged" in { + KeyTypeExampleFormats.transformKey("name", SqlString()) shouldBe "name" + KeyTypeExampleFormats.transformKey("count", SqlInt()) shouldBe "count" + } + +}