@@ -50,3 +50,57 @@ def fake_update_todo(index: int, task: str | None, category: str | None) -> None
5050 assert captured ["task" ] == "New"
5151 # and treats the remainder as the category
5252 assert captured ["category" ] == "text"
53+
54+
55+ def test_add_task_parses_quoted_category (monkeypatch ) -> None :
56+ """`task add "<task>" "<category>"` stores the supplied category (gh-46)."""
57+ from trushell .commands .tasks import add_task
58+
59+ captured : dict [str , Any ] = {}
60+
61+ def fake_insert_todo (todo : Any ) -> None :
62+ captured ["task" ] = todo .task
63+ captured ["category" ] = todo .category
64+
65+ monkeypatch .setattr ("trushell.commands.tasks.insert_todo" , fake_insert_todo )
66+
67+ add_task ('"Buy milk" "Shopping"' )
68+
69+ assert captured ["task" ] == "Buy milk"
70+ assert captured ["category" ] == "Shopping"
71+
72+
73+ def test_add_task_defaults_category_when_omitted (monkeypatch ) -> None :
74+ """A quoted task with no category falls back to the "General" category."""
75+ from trushell .commands .tasks import add_task
76+
77+ captured : dict [str , Any ] = {}
78+
79+ def fake_insert_todo (todo : Any ) -> None :
80+ captured ["task" ] = todo .task
81+ captured ["category" ] = todo .category
82+
83+ monkeypatch .setattr ("trushell.commands.tasks.insert_todo" , fake_insert_todo )
84+
85+ add_task ('"Pay rent"' )
86+
87+ assert captured ["task" ] == "Pay rent"
88+ assert captured ["category" ] == "General"
89+
90+
91+ def test_add_task_unquoted_remains_backwards_compatible (monkeypatch ) -> None :
92+ """Unquoted input keeps the whole remainder as the task text (back-compat)."""
93+ from trushell .commands .tasks import add_task
94+
95+ captured : dict [str , Any ] = {}
96+
97+ def fake_insert_todo (todo : Any ) -> None :
98+ captured ["task" ] = todo .task
99+ captured ["category" ] = todo .category
100+
101+ monkeypatch .setattr ("trushell.commands.tasks.insert_todo" , fake_insert_todo )
102+
103+ add_task ("buy groceries" )
104+
105+ assert captured ["task" ] == "buy groceries"
106+ assert captured ["category" ] == "General"
0 commit comments