bengbengbalabalabeng commented on code in PR #982:
URL: https://github.com/apache/fesod/pull/982#discussion_r3711091503


##########
fesod-sheet/src/test/java/org/apache/fesod/sheet/FesodSheetTest.java:
##########
@@ -253,6 +255,31 @@ void testReadSheet_withAllParams_shouldReturnBuilder() {
         Assertions.assertNotNull(builder);
     }
 
+    @Test
+    void testReadCsv_withColumnIndexes_shouldFilterColumns() throws Exception {
+
+        String csvContent = "1,Alice,30,Female\n2,Bob,25,Male";
+        File csvFile = tempDir.resolve("test_columns.csv").toFile();
+        FileUtils.writeStringToFile(csvFile, csvContent, 
StandardCharsets.UTF_8);
+
+        List<Integer> targetColumns = Arrays.asList(0, 2);
+
+        List<Map<Integer, String>> readResults = FesodSheet.read(csvFile)
+                .csv()
+                .includeColumnIndexes(targetColumns)
+                .sheet(0)
+                .doReadSync();
+
+        Assertions.assertNotNull(readResults);
+        Assertions.assertEquals(2, readResults.size());
+
+        Map<Integer, String> row1 = readResults.get(0);
+        Assertions.assertEquals(2, row1.size(), "Should only contain the 2 
filtered columns");
+        Assertions.assertEquals("1", row1.get(0));
+        Assertions.assertEquals("30", row1.get(2));
+        Assertions.assertNull(row1.get(1), "Column index 1 (Name) should be 
omitted");

Review Comment:
   Current test assertion:
   
   ```java
   Map<Integer, String> row1 = readResults.get(0);
   Assertions.assertEquals(2, row1.size(), "Should only contain the 2 filtered 
columns");
   Assertions.assertEquals("1", row1.get(0));
   Assertions.assertEquals("30", row1.get(2)); // Wrong behavior
   Assertions.assertNull(row1.get(1), "Column index 1 (Name) should be 
omitted"); // Wrong behavior
   ```
   
   Expected behavior (follower #942):
   
   ```java
   Map<Integer, String> row1 = readResults.get(0);
   Assertions.assertEquals(2, row1.size(), "Should only contain the 2 filtered 
columns");
   Assertions.assertEquals("1", row1.get(0));
   Assertions.assertEquals("30", row1.get(1));
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to