19
19
#include " ../src/xparser.hpp"
20
20
#include " ../src/xsystem.hpp"
21
21
#include " ../src/xmagics/os.hpp"
22
+ #include " ../src/xmagics/xassist.hpp"
22
23
#include " ../src/xinspect.hpp"
23
24
24
25
@@ -886,4 +887,79 @@ TEST_SUITE("xinspect"){
886
887
cmp.child_value = " nonexistentMethod" ;
887
888
REQUIRE (cmp (node) == false );
888
889
}
890
+ }
891
+
892
+ TEST_SUITE (" xassist" ){
893
+
894
+ TEST_CASE (" model_not_found" ){
895
+ xcpp::xassist assist;
896
+ std::string line = " %%xassist testModel" ;
897
+ std::string cell = " test input" ;
898
+
899
+ StreamRedirectRAII redirect (std::cerr);
900
+
901
+ assist (line, cell);
902
+
903
+ REQUIRE (redirect.getCaptured () == " Model not found.\n " );
904
+
905
+ }
906
+
907
+ TEST_CASE (" key_not_found" ){
908
+ xcpp::xassist assist;
909
+ std::string line = " %%xassist openai" ;
910
+ std::string cell = " test input" ;
911
+
912
+ StreamRedirectRAII redirect (std::cerr);
913
+
914
+ assist (line, cell);
915
+
916
+ REQUIRE (redirect.getCaptured () == " Failed to open file for reading API key for model openai\n API key for model openai is not available.\n " );
917
+ }
918
+
919
+ TEST_CASE (" gemini" ){
920
+ xcpp::xassist assist;
921
+ std::string line = " %%xassist gemini --save-key" ;
922
+ std::string cell = " 1234" ;
923
+
924
+ assist (line, cell);
925
+
926
+ std::ifstream infile (" gemini_api_key.txt" );
927
+ std::string content;
928
+ std::getline (infile, content);
929
+
930
+ REQUIRE (content == " 1234" );
931
+ infile.close ();
932
+
933
+ StreamRedirectRAII redirect (std::cerr);
934
+
935
+ assist (" %%xassist gemini" , " hello" );
936
+
937
+ REQUIRE (!redirect.getCaptured ().empty ());
938
+
939
+ std::remove (" gemini_api_key.txt" );
940
+ }
941
+
942
+ TEST_CASE (" openai" ){
943
+ xcpp::xassist assist;
944
+ std::string line = " %%xassist openai --save-key" ;
945
+ std::string cell = " 1234" ;
946
+
947
+ assist (line, cell);
948
+
949
+ std::ifstream infile (" openai_api_key.txt" );
950
+ std::string content;
951
+ std::getline (infile, content);
952
+
953
+ REQUIRE (content == " 1234" );
954
+ infile.close ();
955
+
956
+ StreamRedirectRAII redirect (std::cerr);
957
+
958
+ assist (" %%xassist openai" , " hello" );
959
+
960
+ REQUIRE (!redirect.getCaptured ().empty ());
961
+
962
+ std::remove (" openai_api_key.txt" );
963
+ }
964
+
889
965
}
0 commit comments