From d8fe12927284ac845bb0cfc74d049eff65142d67 Mon Sep 17 00:00:00 2001 From: tharun571 Date: Wed, 7 Aug 2024 23:20:18 +0530 Subject: [PATCH] Add tests Rmove clang error --- src/xmagics/xassist.cpp | 19 ++++---- test/test_interpreter.cpp | 96 +++++++++++++++++++-------------------- 2 files changed, 59 insertions(+), 56 deletions(-) diff --git a/src/xmagics/xassist.cpp b/src/xmagics/xassist.cpp index 89171221..541b15b9 100644 --- a/src/xmagics/xassist.cpp +++ b/src/xmagics/xassist.cpp @@ -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); diff --git a/test/test_interpreter.cpp b/test/test_interpreter.cpp index 9a448c3b..eea3c28a 100644 --- a/test/test_interpreter.cpp +++ b/test/test_interpreter.cpp @@ -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"); + } -// } \ No newline at end of file +} \ No newline at end of file