diff --git a/build-tests.sh b/build-tests.sh new file mode 100644 index 0000000..e67b60a --- /dev/null +++ b/build-tests.sh @@ -0,0 +1 @@ +cmake -DCMAKE_BUILD_TYPE=Debug -S . -B ./build -G Ninja && cd build && ninja && ./tests diff --git a/src/core/TodoMd.cpp b/src/core/TodoMd.cpp index 173dc83..85de3f6 100644 --- a/src/core/TodoMd.cpp +++ b/src/core/TodoMd.cpp @@ -53,12 +53,12 @@ Tags TodoMdFormat::extractTagsFromMetadata(std::string metadata) { Tags tags; - std::regex regex("(#[a-zA-Z0-1]+)"); + std::regex regex("(#([a-zA-Z0-1]+))"); std::smatch matches; while (std::regex_search(metadata, matches, regex)) { - if (!vectorUtils::contains(tags, matches[0].str())) { - tags.push_back(matches[0]); + if (!vectorUtils::contains(tags, matches[2].str())) { + tags.push_back(matches[2]); } metadata = matches.suffix(); } @@ -128,7 +128,7 @@ std::string TodoMdFormat::TaskToString(const TaskItem &task) if (task.getTags().size() > 0) { str += " --"; for (const std::string &tag : task.getTags()) { - str += " " + tag; + str += " #" + tag; } } if (task.getStartTime() != "" && task.getEndTime() != "") { diff --git a/tests/test.cpp b/tests/test.cpp index f4ffe3f..04a6c8b 100644 --- a/tests/test.cpp +++ b/tests/test.cpp @@ -11,17 +11,34 @@ #include "core/TodoMd.h" #include -TEST_CASE("TODO make tests", "[todo]") +TEST_CASE("Creating task from string") { - mirai::Mirai mirai; - auto task = mirai::TodoMdFormat::StringToTask( - "- [X] 08:00-10:00 > This is a test -- #mirai", "2024-04-19" - ); - REQUIRE(task.date == "2024-04-19"); - REQUIRE(task.tags.size() == 1); - REQUIRE(task.tags[0] == "#mirai"); - REQUIRE(task.text == "This is a test"); - REQUIRE(task.state == mirai::DONE); - REQUIRE(task.startTime == "08:00"); - REQUIRE(task.endTime == "10:00"); + SECTION("Task with all properties") + { + auto task = mirai::TodoMdFormat::StringToTask( + "- [X] 08:00-10:00 > This is a test -- #mirai", "2024-04-19" + ); + REQUIRE(task.date == "2024-04-19"); + REQUIRE(task.tags.size() == 1); + REQUIRE(task.tags[0] == "mirai"); + REQUIRE(task.text == "This is a test"); + REQUIRE(task.state == mirai::DONE); + REQUIRE(task.startTime == "08:00"); + REQUIRE(task.endTime == "10:00"); + } + + SECTION("Task with all properties 2") + { + auto task = mirai::TodoMdFormat::StringToTask( + "- [ ] 09:00-17:00 > This is another test -- #mirai #feature", "2024-04-20" + ); + REQUIRE(task.date == "2024-04-20"); + REQUIRE(task.tags.size() == 2); + REQUIRE(task.tags[0] == "mirai"); + REQUIRE(task.tags[1] == "feature"); + REQUIRE(task.text == "This is another test"); + REQUIRE(task.state == mirai::TODO); + REQUIRE(task.startTime == "09:00"); + REQUIRE(task.endTime == "17:00"); + } }