Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
Rmove clang error
  • Loading branch information
tharun571 committed Aug 7, 2024
1 parent 1bd2df7 commit d8fe129
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 56 deletions.
19 changes: 11 additions & 8 deletions src/xmagics/xassist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,16 +281,19 @@ namespace xcpp
return;
}

if (tokens[2] == "--save-key")
if (tokens.size() > 2)
{
xcpp::APIKeyManager::saveApiKey(model, cell);
return;
}
if (tokens[2] == "--save-key")
{
xcpp::APIKeyManager::saveApiKey(model, cell);
return;
}

if (tokens[2] == "--refresh")
{
xcpp::ChatHistory::refresh(model);
return;
if (tokens[2] == "--refresh")
{
xcpp::ChatHistory::refresh(model);
return;
}
}

std::string key = xcpp::APIKeyManager::loadApiKey(model);
Expand Down
96 changes: 48 additions & 48 deletions test/test_interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -889,77 +889,77 @@ TEST_SUITE("xinspect"){
}
}

// TEST_SUITE("xassist"){
TEST_SUITE("xassist"){

// TEST_CASE("model_not_found"){
// xcpp::xassist assist;
// std::string line = "%%xassist testModel";
// std::string cell = "test input";
TEST_CASE("model_not_found"){
xcpp::xassist assist;
std::string line = "%%xassist testModel";
std::string cell = "test input";

// StreamRedirectRAII redirect(std::cerr);
StreamRedirectRAII redirect(std::cerr);

// assist(line, cell);
assist(line, cell);

// REQUIRE(redirect.getCaptured() == "Model not found.\n");
REQUIRE(redirect.getCaptured() == "Model not found.\n");

// }
}

// TEST_CASE("gemini_save"){
// xcpp::xassist assist;
// std::string line = "%%xassist gemini --save-key";
// std::string cell = "1234";
TEST_CASE("gemini_save"){
xcpp::xassist assist;
std::string line = "%%xassist gemini --save-key";
std::string cell = "1234";

// assist(line, cell);
assist(line, cell);

// std::ifstream infile("gemini_api_key.txt");
// std::string content;
// std::getline(infile, content);
std::ifstream infile("gemini_api_key.txt");
std::string content;
std::getline(infile, content);

// REQUIRE(content == "1234");
// infile.close();
REQUIRE(content == "1234");
infile.close();

// StreamRedirectRAII redirect(std::cerr);
StreamRedirectRAII redirect(std::cerr);

// assist("%%xassist gemini", "hello");
assist("%%xassist gemini", "hello");

// REQUIRE(!redirect.getCaptured().empty());
REQUIRE(!redirect.getCaptured().empty());

// std::remove("gemini_api_key.txt");
// }
std::remove("gemini_api_key.txt");
}

// TEST_CASE("gemini"){
// xcpp::xassist assist;
// std::string line = "%%xassist gemini";
// std::string cell = "hello";
TEST_CASE("gemini"){
xcpp::xassist assist;
std::string line = "%%xassist gemini";
std::string cell = "hello";

// StreamRedirectRAII redirect(std::cerr);
StreamRedirectRAII redirect(std::cerr);

// assist(line, cell);
assist(line, cell);

// REQUIRE(!redirect.getCaptured().empty());
// }
REQUIRE(!redirect.getCaptured().empty());
}

// TEST_CASE("openai"){
// xcpp::xassist assist;
// std::string line = "%%xassist openai --save-key";
// std::string cell = "1234";
TEST_CASE("openai"){
xcpp::xassist assist;
std::string line = "%%xassist openai --save-key";
std::string cell = "1234";

// assist(line, cell);
assist(line, cell);

// std::ifstream infile("openai_api_key.txt");
// std::string content;
// std::getline(infile, content);
std::ifstream infile("openai_api_key.txt");
std::string content;
std::getline(infile, content);

// REQUIRE(content == "1234");
// infile.close();
REQUIRE(content == "1234");
infile.close();

// StreamRedirectRAII redirect(std::cerr);
StreamRedirectRAII redirect(std::cerr);

// assist("%%xassist openai", "hello");
assist("%%xassist openai", "hello");

// REQUIRE(!redirect.getCaptured().empty());
REQUIRE(!redirect.getCaptured().empty());

// std::remove("openai_api_key.txt");
// }
std::remove("openai_api_key.txt");
}

// }
}

0 comments on commit d8fe129

Please sign in to comment.