@@ -4,6 +4,15 @@ package io.github.quafadas.scautable
44import scala .NamedTuple .*
55
66import io .github .quafadas .table .{* , given }
7+
8+
9+ /**
10+ * The cell contents of "Numbers.xlsx"
11+ *
12+ Doubles Int Longs Strings
13+ 1.10 1.00 1.00 blah
14+ 2.20 2.00 3.00 blah
15+ */
716class ExcelSuite extends munit.FunSuite :
817
918 test(" excel provider compiles and typechecks" ) {
@@ -26,7 +35,7 @@ class ExcelSuite extends munit.FunSuite:
2635 }
2736
2837 test(" Numbers" ) {
29- val csv2 = Excel .resource(" Numbers.xlsx" , " Sheet1" , TypeInferrer .FromAllRows )
38+ val csv2 = Excel .resource(" Numbers.xlsx" , " Sheet1" , " A1:D3 " , TypeInferrer .FromAllRows )
3039 csv2.toSeq.ptbln
3140 val csv = Excel .resource(" Numbers.xlsx" , " Sheet1" , " A1:C3" , TypeInferrer .FromAllRows )
3241 val seq = csv.toSeq
@@ -121,33 +130,33 @@ class ExcelSuite extends munit.FunSuite:
121130
122131 test(" excel provider with TypeInferrer.FirstRow should infer types from first row" ) {
123132 // Test FirstRow with Numbers.xlsx - should be equivalent to FirstN(1)
124- def csv = Excel .resource(" Numbers.xlsx" , " Sheet1" , " " , TypeInferrer .FirstRow )
133+ val csv = Excel .resource(" Numbers.xlsx" , " Sheet1" , " A1:D3 " , TypeInferrer .FirstRow )
125134
126135 // Verify that we can read the data and it compiles with inferred types
127- val rows = csv.toList
136+ val rows : List [( Doubles : Double , Int : Int , Longs : Int , Strings : String )] = csv.toList
128137 assertEquals(rows.size, 2 )
129138
130139 // Test access to columns with the inferred types (should be same as FirstN(1))
131- assertEquals(csv .column[" Doubles" ].toList.head, 1.1 ) // Double
132- assertEquals(csv .column[" Strings" ].toList.head, " blah" ) // String
133- assertEquals(csv .column[" Int" ].toList.head, 1 ) // Apache POI correctly identifies as Int
134- assertEquals(csv .column[" Longs" ].toList.head, 1 ) // Apache POI correctly identifies as Int
140+ assertEquals(rows .column[" Doubles" ].toList.head, 1.1 ) // Double
141+ assertEquals(rows .column[" Strings" ].toList.head, " blah" ) // String
142+ assertEquals(rows .column[" Int" ].toList.head, 1 ) // Apache POI correctly identifies as Int
143+ assertEquals(rows .column[" Longs" ].toList.head, 1 ) // Apache POI correctly identifies as Int
135144 }
136145
137146 test(" excel provider with TypeInferrer.FromAllRows should infer types from all rows" ) {
138147 // Test FromAllRows with Numbers.xlsx - should consider all data rows for type inference
139- def csv = Excel .resource(" Numbers.xlsx" , " Sheet1" , " " , TypeInferrer .FromAllRows )
148+ val csv = Excel .resource(" Numbers.xlsx" , " Sheet1" , " " , TypeInferrer .FromAllRows )
140149
141150 // Verify that we can read the data and it compiles with inferred types
142151 val rows = csv.toList
143152 assertEquals(rows.size, 2 )
144153
145154 // Test access to columns with the inferred types
146- assertEquals(csv .column[" Doubles" ].toList.head, 1.1 ) // Double
147- assertEquals(csv .column[" Strings" ].toList.head, " blah" ) // String
155+ assertEquals(rows .column[" Doubles" ].toList.head, 1.1 ) // Double
156+ assertEquals(rows .column[" Strings" ].toList.head, " blah" ) // String
148157 // Apache POI correctly identifies these as integers
149- assertEquals(csv .column[" Int" ].toList.head, 1 ) // Apache POI correctly identifies as Int
150- assertEquals(csv .column[" Longs" ].toList.head, 1 ) // Apache POI correctly identifies as Int
158+ assertEquals(rows .column[" Int" ].toList.head, 1 ) // Apache POI correctly identifies as Int
159+ assertEquals(rows .column[" Longs" ].toList.head, 1 ) // Apache POI correctly identifies as Int
151160 }
152161
153162 test(" excel provider all TypeInferrer variants now supported" ) {
@@ -163,32 +172,32 @@ class ExcelSuite extends munit.FunSuite:
163172 test(" excel provider with TypeInferrer.FirstN should infer types automatically" ) {
164173 // Test FirstN with Numbers.xlsx - based on error message, types are inferred as:
165174 // (Doubles : Double, Int : Double, Longs : Double, Strings : String)
166- def csv = Excel .resource(" Numbers.xlsx" , " Sheet1" , " " , TypeInferrer .FirstN (2 ))
175+ val csv = Excel .resource(" Numbers.xlsx" , " Sheet1" , " " , TypeInferrer .FirstN (2 ))
167176
168177 // Verify that we can read the data and it compiles with inferred types
169178 val rows = csv.toList
170179 assertEquals(rows.size, 2 )
171180
172181 // Test access to columns with the actually inferred types
173- assertEquals(csv .column[" Doubles" ].toList.head, 1.1 ) // Double
174- assertEquals(csv .column[" Strings" ].toList.head, " blah" ) // String
182+ assertEquals(rows .column[" Doubles" ].toList.head, 1.1 ) // Double
183+ assertEquals(rows .column[" Strings" ].toList.head, " blah" ) // String
175184
176185 // Apache POI correctly identifies these as integers based on cell type
177- assertEquals(csv .column[" Int" ].toList.head, 1 ) // Apache POI correctly identifies as Int
178- assertEquals(csv .column[" Longs" ].toList.head, 1 ) // Apache POI correctly identifies as Int
186+ assertEquals(rows .column[" Int" ].toList.head, 1 ) // Apache POI correctly identifies as Int
187+ assertEquals(rows .column[" Longs" ].toList.head, 1 ) // Apache POI correctly identifies as Int
179188 }
180189
181190 test(" excel provider with TypeInferrer.FirstN and preferIntToBoolean parameter" ) {
182191 // Test FirstN with custom preferIntToBoolean setting - just verify compilation and basic access
183- def csv = Excel .resource(" Numbers.xlsx" , " Sheet1" , " " , TypeInferrer .FirstN (1 , false ))
192+ val csv : ExcelIterator [( " Doubles " , " Int " , " Longs " , " Strings " ), ( Double , Int , Int , String )] = Excel .resource(" Numbers.xlsx" , " Sheet1" , " A1:D3 " , TypeInferrer .FirstN (1 , false ))
184193
185194 // Verify that we can read the data and it compiles with inferred types
186195 val rows = csv.toList
187196 assertEquals(rows.size, 2 )
188197
189198 // Basic functionality test - verify we can access data (don't assert specific types due to preferIntToBoolean differences)
190- assertEquals(csv .column[" Doubles" ].toList.head, 1.1 )
191- assertEquals(csv .column[" Strings" ].toList.head, " blah" )
199+ assertEquals(rows .column[" Doubles" ].toList.head, 1.1 )
200+ assertEquals(rows .column[" Strings" ].toList.head, " blah" )
192201 // Note: Int/Longs columns may be inferred differently with preferIntToBoolean=false
193202 }
194203
0 commit comments