Skip to content

Commit 0fe10ac

Browse files
committed
Task parser tests added
1 parent 3c01816 commit 0fe10ac

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import 'package:taskwarrior/app/utils/taskfunctions/taskparser.dart';
2+
import 'package:test/test.dart';
3+
4+
void main() {
5+
group('taskParser', () {
6+
test('parses a task with multiple attributes and tags', () {
7+
const taskString =
8+
'+tag1 status:completed project:work priority:high due:2024-12-31T23:59:59Z This is a complex task';
9+
final task = taskParser(taskString);
10+
expect(task.description, 'This is a complex task');
11+
expect(task.status, 'completed');
12+
expect(task.project, 'work');
13+
expect(task.priority, 'high');
14+
expect(task.due, DateTime.parse('2024-12-31T23:59:59Z').toUtc());
15+
expect(task.wait, isNull);
16+
expect(task.until, isNull);
17+
expect(task.tags, ['tag1']);
18+
});
19+
20+
test('parses a task with long description and tags', () {
21+
const taskString = '+longtag1 +longtag2 '
22+
'This is a very long description that goes on and on, potentially including special characters and a very long string to test how the parser handles such cases';
23+
final task = taskParser(taskString);
24+
expect(task.description,
25+
'This is a very long description that goes on and on, potentially including special characters and a very long string to test how the parser handles such cases');
26+
expect(task.status, 'pending');
27+
expect(task.project, isNull);
28+
expect(task.priority, isNull);
29+
expect(task.due, isNull);
30+
expect(task.wait, isNull);
31+
expect(task.until, isNull);
32+
expect(task.tags, ['longtag1', 'longtag2']);
33+
});
34+
35+
test('parses a task with mixed attribute formats', () {
36+
const taskString =
37+
'status:completed prio:high project:work +tag1 This is a task with mixed attribute formats';
38+
final task = taskParser(taskString);
39+
expect(task.description, 'This is a task with mixed attribute formats');
40+
expect(task.status, 'completed');
41+
expect(task.project, 'work');
42+
expect(task.priority, 'high');
43+
expect(task.due, isNull);
44+
expect(task.wait, isNull);
45+
expect(task.until, isNull);
46+
expect(task.tags, ['tag1']);
47+
});
48+
49+
test('parses a task with overlapping attributes and tags', () {
50+
const taskString =
51+
'+tag1 status:completed project:work +tag2 This is a task with overlapping attributes and tags';
52+
final task = taskParser(taskString);
53+
expect(task.description,
54+
'This is a task with overlapping attributes and tags');
55+
expect(task.status, 'completed');
56+
expect(task.project, 'work');
57+
expect(task.priority, isNull);
58+
expect(task.due, isNull);
59+
expect(task.wait, isNull);
60+
expect(task.until, isNull);
61+
expect(task.tags, ['tag1', 'tag2']);
62+
});
63+
});
64+
}

0 commit comments

Comments
 (0)