@@ -1026,4 +1026,63 @@ TEST_SUITE("xassist"){
1026
1026
std::remove (" ollama_model.txt" );
1027
1027
}
1028
1028
1029
- }
1029
+ }
1030
+
1031
+
1032
+ TEST_SUITE (" file" ) {
1033
+ TEST_CASE (" Write" ) {
1034
+ xcpp::writefile wf;
1035
+ std::string line = " %%file testfile.txt" ;
1036
+ std::string cell = " Hello, World!" ;
1037
+
1038
+ wf (line, cell);
1039
+
1040
+ std::ifstream infile (" testfile.txt" );
1041
+ std::string content;
1042
+ std::getline (infile, content);
1043
+
1044
+ REQUIRE (content == " Hello, World!" );
1045
+ infile.close ();
1046
+ }
1047
+ TEST_CASE (" Overwrite" ) {
1048
+ xcpp::writefile wf;
1049
+ std::string line = " %%file testfile.txt" ;
1050
+ std::string cell = " Hello, World!" ;
1051
+
1052
+ wf (line, cell);
1053
+
1054
+ std::string overwrite_cell = " Overwrite test" ;
1055
+
1056
+ wf (line, overwrite_cell);
1057
+
1058
+ std::ifstream infile (" testfile.txt" );
1059
+ std::string content;
1060
+ std::getline (infile, content);
1061
+
1062
+ REQUIRE (content == overwrite_cell);
1063
+ infile.close ();
1064
+ }
1065
+ TEST_CASE (" Append" ) {
1066
+ xcpp::writefile wf;
1067
+ std::string line = " %%file testfile.txt" ;
1068
+ std::string cell = " Hello, World!" ;
1069
+
1070
+ wf (line, cell);
1071
+
1072
+ std::string append_line = " %%file -a testfile.txt" ;
1073
+ std::string append_cell = " Hello, again!" ;
1074
+
1075
+ wf (append_line, append_cell);
1076
+
1077
+ std::ifstream infile (" testfile.txt" );
1078
+ std::vector<std::string> lines;
1079
+ std::string content;
1080
+ while (std::getline (infile, content)) {
1081
+ lines.push_back (content);
1082
+ }
1083
+
1084
+ REQUIRE (lines[0 ] == " Hello, World!" );
1085
+ REQUIRE (lines[1 ] == " Hello, again!" );
1086
+ infile.close ();
1087
+ }
1088
+ }
0 commit comments