Don't show the '#' before tags in the UI

This commit is contained in:
Vyn 2024-04-21 09:43:56 +02:00
parent e18691d72c
commit 6ca786a4f6
3 changed files with 34 additions and 16 deletions

1
build-tests.sh Normal file
View file

@ -0,0 +1 @@
cmake -DCMAKE_BUILD_TYPE=Debug -S . -B ./build -G Ninja && cd build && ninja && ./tests

View file

@ -53,12 +53,12 @@ Tags TodoMdFormat::extractTagsFromMetadata(std::string metadata)
{ {
Tags tags; Tags tags;
std::regex regex("(#[a-zA-Z0-1]+)"); std::regex regex("(#([a-zA-Z0-1]+))");
std::smatch matches; std::smatch matches;
while (std::regex_search(metadata, matches, regex)) { while (std::regex_search(metadata, matches, regex)) {
if (!vectorUtils::contains(tags, matches[0].str())) { if (!vectorUtils::contains(tags, matches[2].str())) {
tags.push_back(matches[0]); tags.push_back(matches[2]);
} }
metadata = matches.suffix(); metadata = matches.suffix();
} }
@ -128,7 +128,7 @@ std::string TodoMdFormat::TaskToString(const TaskItem &task)
if (task.getTags().size() > 0) { if (task.getTags().size() > 0) {
str += " --"; str += " --";
for (const std::string &tag : task.getTags()) { for (const std::string &tag : task.getTags()) {
str += " " + tag; str += " #" + tag;
} }
} }
if (task.getStartTime() != "" && task.getEndTime() != "") { if (task.getStartTime() != "" && task.getEndTime() != "") {

View file

@ -11,17 +11,34 @@
#include "core/TodoMd.h" #include "core/TodoMd.h"
#include <catch2/catch_test_macros.hpp> #include <catch2/catch_test_macros.hpp>
TEST_CASE("TODO make tests", "[todo]") TEST_CASE("Creating task from string")
{ {
mirai::Mirai mirai; SECTION("Task with all properties")
{
auto task = mirai::TodoMdFormat::StringToTask( auto task = mirai::TodoMdFormat::StringToTask(
"- [X] 08:00-10:00 > This is a test -- #mirai", "2024-04-19" "- [X] 08:00-10:00 > This is a test -- #mirai", "2024-04-19"
); );
REQUIRE(task.date == "2024-04-19"); REQUIRE(task.date == "2024-04-19");
REQUIRE(task.tags.size() == 1); REQUIRE(task.tags.size() == 1);
REQUIRE(task.tags[0] == "#mirai"); REQUIRE(task.tags[0] == "mirai");
REQUIRE(task.text == "This is a test"); REQUIRE(task.text == "This is a test");
REQUIRE(task.state == mirai::DONE); REQUIRE(task.state == mirai::DONE);
REQUIRE(task.startTime == "08:00"); REQUIRE(task.startTime == "08:00");
REQUIRE(task.endTime == "10: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");
}
} }