11"""Tests for Scala case class format (parser + generator)."""
2+
23from __future__ import annotations
34
45import sys
2324
2425# ── Parser Tests ──
2526
27+
2628def test_scala_parse_simple ():
2729 """Parser should extract case class and fields."""
2830 parser = ScalaParser ()
@@ -99,7 +101,7 @@ def test_scala_parse_multiple_classes():
99101
100102def test_scala_parse_uuid_type ():
101103 """Parser should handle UUID types."""
102- scala = ' case class Item(id: java.util.UUID, name: String)'
104+ scala = " case class Item(id: java.util.UUID, name: String)"
103105 parser = ScalaParser ()
104106 schema = parser .parse (scala )
105107 cols = {c .name : c for c in schema .tables [0 ].columns }
@@ -108,7 +110,7 @@ def test_scala_parse_uuid_type():
108110
109111def test_scala_parse_decimal_type ():
110112 """Parser should handle BigDecimal."""
111- scala = ' case class Product(id: Int, price: BigDecimal)'
113+ scala = " case class Product(id: Int, price: BigDecimal)"
112114 parser = ScalaParser ()
113115 schema = parser .parse (scala )
114116 cols = {c .name : c for c in schema .tables [0 ].columns }
@@ -117,16 +119,23 @@ def test_scala_parse_decimal_type():
117119
118120# ── Generation Tests ──
119121
122+
120123def test_scala_generate_simple ():
121124 """Generator should produce valid case class."""
122125 from schemaforge .generators .scala_generator import ScalaGenerator
123126 from schemaforge .ir import Column , ColumnType , Schema , Table
124- schema = Schema (tables = [
125- Table (name = "users" , columns = [
126- Column (name = "id" , type = ColumnType .INTEGER ),
127- Column (name = "name" , type = ColumnType .STRING , nullable = False ),
128- ])
129- ])
127+
128+ schema = Schema (
129+ tables = [
130+ Table (
131+ name = "users" ,
132+ columns = [
133+ Column (name = "id" , type = ColumnType .INTEGER ),
134+ Column (name = "name" , type = ColumnType .STRING , nullable = False ),
135+ ],
136+ )
137+ ]
138+ )
130139 gen = ScalaGenerator ()
131140 output = gen .generate (schema )
132141 assert "case class Users" in output
@@ -138,12 +147,18 @@ def test_scala_generate_nullable():
138147 """Generator should use Option[T] for nullable columns."""
139148 from schemaforge .generators .scala_generator import ScalaGenerator
140149 from schemaforge .ir import Column , ColumnType , Schema , Table
141- schema = Schema (tables = [
142- Table (name = "items" , columns = [
143- Column (name = "id" , type = ColumnType .INTEGER ),
144- Column (name = "description" , type = ColumnType .STRING , nullable = True ),
145- ])
146- ])
150+
151+ schema = Schema (
152+ tables = [
153+ Table (
154+ name = "items" ,
155+ columns = [
156+ Column (name = "id" , type = ColumnType .INTEGER ),
157+ Column (name = "description" , type = ColumnType .STRING , nullable = True ),
158+ ],
159+ )
160+ ]
161+ )
147162 gen = ScalaGenerator ()
148163 output = gen .generate (schema )
149164 assert "Option[String]" in output
@@ -154,13 +169,19 @@ def test_scala_generate_defaults():
154169 """Generator should handle default values."""
155170 from schemaforge .generators .scala_generator import ScalaGenerator
156171 from schemaforge .ir import Column , ColumnType , Schema , Table
157- schema = Schema (tables = [
158- Table (name = "config" , columns = [
159- Column (name = "id" , type = ColumnType .INTEGER ),
160- Column (name = "active" , type = ColumnType .BOOLEAN , default = True ),
161- Column (name = "name" , type = ColumnType .STRING , default = "untitled" ),
162- ])
163- ])
172+
173+ schema = Schema (
174+ tables = [
175+ Table (
176+ name = "config" ,
177+ columns = [
178+ Column (name = "id" , type = ColumnType .INTEGER ),
179+ Column (name = "active" , type = ColumnType .BOOLEAN , default = True ),
180+ Column (name = "name" , type = ColumnType .STRING , default = "untitled" ),
181+ ],
182+ )
183+ ]
184+ )
164185 gen = ScalaGenerator ()
165186 output = gen .generate (schema )
166187 assert "true" in output
@@ -169,6 +190,7 @@ def test_scala_generate_defaults():
169190
170191# ── Conversion Tests ──
171192
193+
172194def test_scala_to_sql ():
173195 """Scala case classes should convert to SQL."""
174196 sql = convert_schema (SAMPLE_SCALA , "scala" , "sql" )
0 commit comments