13
13
#include < catch2/catch.hpp>
14
14
15
15
#include < fstream>
16
+ #include < regex>
16
17
17
18
namespace fs = std::filesystem;
18
19
using namespace nx ::core;
@@ -552,4 +553,69 @@ TEST_CASE("SimplnxCore::ReadCSVFileFilter (Case 7): Valid filter execution - Str
552
553
REQUIRE (array->at (i) == v[i]);
553
554
}
554
555
}
556
+ }
557
+
558
+ TEST_CASE (" SimplnxCore::ReadCSVFileFilter (Case 8): Valid filter execution - Mixed quoted strings and integers" )
559
+ {
560
+ UnitTest::LoadPlugins ();
561
+ fs::create_directories (k_TestInput.parent_path ());
562
+
563
+ // Create CSV with single and double quoted strings and integer strings
564
+ std::ofstream file (k_TestInput);
565
+ REQUIRE (file.is_open ());
566
+ file << " SQ,DQ,Num\n " ;
567
+ std::vector<std::tuple<std::string, std::string, std::string>> rows = {{" 'Alice'" , " \" Alice\" " , " 1" }, {" 'Bob'" , " \" Bob\" " , " 2" }, {" 'Charlie'" , " \" Charlie\" " , " 3" }};
568
+ for (size_t i = 0 ; i < rows.size (); ++i)
569
+ {
570
+ file << std::get<0 >(rows[i]) << " ," << std::get<1 >(rows[i]) << " ," << std::get<2 >(rows[i]);
571
+ if (i < rows.size () - 1 )
572
+ {
573
+ file << " \n " ;
574
+ }
575
+ }
576
+ file.close ();
577
+
578
+ // Set up filter arguments
579
+ std::vector<std::string> dummy = {" 1" , " 2" , " 3" };
580
+ Arguments args = createArguments (k_TestInput.string (), 2 , ReadCSVData::HeaderMode::LINE, 1 , {' ,' }, {" SQ" , " DQ" , " Num" }, {CSVType::string, CSVType::string, CSVType::string}, {false , false , false },
581
+ {static_cast <usize>(dummy.size ())}, dummy, " New Group" );
582
+
583
+ ReadCSVFileFilter filter;
584
+ DataStructure dataStructure;
585
+ auto preflightResult = filter.preflight (dataStructure, args);
586
+ SIMPLNX_RESULT_REQUIRE_VALID (preflightResult.outputActions );
587
+
588
+ auto executeResult = filter.execute (dataStructure, args);
589
+ SIMPLNX_RESULT_REQUIRE_VALID (executeResult.result );
590
+
591
+ const std::regex re (R"( ^['"]+|['"]+$)" ); // Remove quotes and double quotes
592
+
593
+ // Verify single quoted column
594
+ const StringArray* sqArray = dataStructure.getDataAs <StringArray>(DataPath ({" New Group" , " SQ" }));
595
+ REQUIRE (sqArray != nullptr );
596
+ REQUIRE (sqArray->getSize () == rows.size ());
597
+ for (usize i = 0 ; i < sqArray->getSize (); ++i)
598
+ {
599
+ auto str = std::regex_replace (std::get<0 >(rows[i]), re, " " );
600
+ REQUIRE (sqArray->at (i) == str);
601
+ }
602
+
603
+ // Verify double quoted column
604
+ const StringArray* dqArray = dataStructure.getDataAs <StringArray>(DataPath ({" New Group" , " DQ" }));
605
+ REQUIRE (dqArray != nullptr );
606
+ REQUIRE (dqArray->getSize () == rows.size ());
607
+ for (usize i = 0 ; i < dqArray->getSize (); ++i)
608
+ {
609
+ auto str = std::regex_replace (std::get<1 >(rows[i]), re, " " );
610
+ REQUIRE (sqArray->at (i) == str);
611
+ }
612
+
613
+ // Verify integer column
614
+ const StringArray* numArray = dataStructure.getDataAs <StringArray>(DataPath ({" New Group" , " Num" }));
615
+ REQUIRE (numArray != nullptr );
616
+ REQUIRE (numArray->getSize () == rows.size ());
617
+ for (usize i = 0 ; i < numArray->getSize (); ++i)
618
+ {
619
+ REQUIRE (numArray->at (i) == std::get<2 >(rows[i]));
620
+ }
555
621
}
0 commit comments