Skip to content

Commit 51f2354

Browse files
committed
Add tests
1 parent 16b631a commit 51f2354

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed

test/test_interpreter.cpp

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "../src/xparser.hpp"
2020
#include "../src/xsystem.hpp"
2121
#include "../src/xmagics/os.hpp"
22+
#include "../src/xmagics/xassist.hpp"
2223
#include "../src/xinspect.hpp"
2324

2425

@@ -886,4 +887,79 @@ TEST_SUITE("xinspect"){
886887
cmp.child_value = "nonexistentMethod";
887888
REQUIRE(cmp(node) == false);
888889
}
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\nAPI 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+
889965
}

0 commit comments

Comments
 (0)