Skip to content

Commit d8fe129

Browse files
committed
Add tests
Rmove clang error
1 parent 1bd2df7 commit d8fe129

File tree

2 files changed

+59
-56
lines changed

2 files changed

+59
-56
lines changed

src/xmagics/xassist.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -281,16 +281,19 @@ namespace xcpp
281281
return;
282282
}
283283

284-
if (tokens[2] == "--save-key")
284+
if (tokens.size() > 2)
285285
{
286-
xcpp::APIKeyManager::saveApiKey(model, cell);
287-
return;
288-
}
286+
if (tokens[2] == "--save-key")
287+
{
288+
xcpp::APIKeyManager::saveApiKey(model, cell);
289+
return;
290+
}
289291

290-
if (tokens[2] == "--refresh")
291-
{
292-
xcpp::ChatHistory::refresh(model);
293-
return;
292+
if (tokens[2] == "--refresh")
293+
{
294+
xcpp::ChatHistory::refresh(model);
295+
return;
296+
}
294297
}
295298

296299
std::string key = xcpp::APIKeyManager::loadApiKey(model);

test/test_interpreter.cpp

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -889,77 +889,77 @@ TEST_SUITE("xinspect"){
889889
}
890890
}
891891

892-
// TEST_SUITE("xassist"){
892+
TEST_SUITE("xassist"){
893893

894-
// TEST_CASE("model_not_found"){
895-
// xcpp::xassist assist;
896-
// std::string line = "%%xassist testModel";
897-
// std::string cell = "test input";
894+
TEST_CASE("model_not_found"){
895+
xcpp::xassist assist;
896+
std::string line = "%%xassist testModel";
897+
std::string cell = "test input";
898898

899-
// StreamRedirectRAII redirect(std::cerr);
899+
StreamRedirectRAII redirect(std::cerr);
900900

901-
// assist(line, cell);
901+
assist(line, cell);
902902

903-
// REQUIRE(redirect.getCaptured() == "Model not found.\n");
903+
REQUIRE(redirect.getCaptured() == "Model not found.\n");
904904

905-
// }
905+
}
906906

907-
// TEST_CASE("gemini_save"){
908-
// xcpp::xassist assist;
909-
// std::string line = "%%xassist gemini --save-key";
910-
// std::string cell = "1234";
907+
TEST_CASE("gemini_save"){
908+
xcpp::xassist assist;
909+
std::string line = "%%xassist gemini --save-key";
910+
std::string cell = "1234";
911911

912-
// assist(line, cell);
912+
assist(line, cell);
913913

914-
// std::ifstream infile("gemini_api_key.txt");
915-
// std::string content;
916-
// std::getline(infile, content);
914+
std::ifstream infile("gemini_api_key.txt");
915+
std::string content;
916+
std::getline(infile, content);
917917

918-
// REQUIRE(content == "1234");
919-
// infile.close();
918+
REQUIRE(content == "1234");
919+
infile.close();
920920

921-
// StreamRedirectRAII redirect(std::cerr);
921+
StreamRedirectRAII redirect(std::cerr);
922922

923-
// assist("%%xassist gemini", "hello");
923+
assist("%%xassist gemini", "hello");
924924

925-
// REQUIRE(!redirect.getCaptured().empty());
925+
REQUIRE(!redirect.getCaptured().empty());
926926

927-
// std::remove("gemini_api_key.txt");
928-
// }
927+
std::remove("gemini_api_key.txt");
928+
}
929929

930-
// TEST_CASE("gemini"){
931-
// xcpp::xassist assist;
932-
// std::string line = "%%xassist gemini";
933-
// std::string cell = "hello";
930+
TEST_CASE("gemini"){
931+
xcpp::xassist assist;
932+
std::string line = "%%xassist gemini";
933+
std::string cell = "hello";
934934

935-
// StreamRedirectRAII redirect(std::cerr);
935+
StreamRedirectRAII redirect(std::cerr);
936936

937-
// assist(line, cell);
937+
assist(line, cell);
938938

939-
// REQUIRE(!redirect.getCaptured().empty());
940-
// }
939+
REQUIRE(!redirect.getCaptured().empty());
940+
}
941941

942-
// TEST_CASE("openai"){
943-
// xcpp::xassist assist;
944-
// std::string line = "%%xassist openai --save-key";
945-
// std::string cell = "1234";
942+
TEST_CASE("openai"){
943+
xcpp::xassist assist;
944+
std::string line = "%%xassist openai --save-key";
945+
std::string cell = "1234";
946946

947-
// assist(line, cell);
947+
assist(line, cell);
948948

949-
// std::ifstream infile("openai_api_key.txt");
950-
// std::string content;
951-
// std::getline(infile, content);
949+
std::ifstream infile("openai_api_key.txt");
950+
std::string content;
951+
std::getline(infile, content);
952952

953-
// REQUIRE(content == "1234");
954-
// infile.close();
953+
REQUIRE(content == "1234");
954+
infile.close();
955955

956-
// StreamRedirectRAII redirect(std::cerr);
956+
StreamRedirectRAII redirect(std::cerr);
957957

958-
// assist("%%xassist openai", "hello");
958+
assist("%%xassist openai", "hello");
959959

960-
// REQUIRE(!redirect.getCaptured().empty());
960+
REQUIRE(!redirect.getCaptured().empty());
961961

962-
// std::remove("openai_api_key.txt");
963-
// }
962+
std::remove("openai_api_key.txt");
963+
}
964964

965-
// }
965+
}

0 commit comments

Comments
 (0)