diff options
-rw-r--r-- | kronos/parser.py | 9 | ||||
-rw-r--r-- | kronos/tests/test_parser.py | 39 |
2 files changed, 12 insertions, 36 deletions
diff --git a/kronos/parser.py b/kronos/parser.py index 147682f..cf848e0 100644 --- a/kronos/parser.py +++ b/kronos/parser.py | |||
@@ -11,16 +11,15 @@ from kronos.model import Activity | |||
11 | 11 | ||
12 | 12 | ||
13 | def parse_activity(text): | 13 | def parse_activity(text): |
14 | tokens = text.split(' ') | ||
15 | tags = _parse_tags(tokens) | ||
16 | text = _strip_tags(tokens) | ||
17 | |||
14 | description = None | 18 | description = None |
15 | tags = [] | ||
16 | if ',' in text: | 19 | if ',' in text: |
17 | text, description = text.split(',', 1) | 20 | text, description = text.split(',', 1) |
18 | description = description.strip() | 21 | description = description.strip() |
19 | 22 | ||
20 | tokens = description.split(' ') | ||
21 | tags = _parse_tags(tokens) | ||
22 | description = _strip_tags(tokens) | ||
23 | |||
24 | category = None | 23 | category = None |
25 | if '@' in text: | 24 | if '@' in text: |
26 | text, category = text.split('@', 1) | 25 | text, category = text.split('@', 1) |
diff --git a/kronos/tests/test_parser.py b/kronos/tests/test_parser.py index 8a82a65..b08152a 100644 --- a/kronos/tests/test_parser.py +++ b/kronos/tests/test_parser.py | |||
@@ -50,38 +50,15 @@ class TestWhenParsingBasicFormat(object): | |||
50 | 50 | ||
51 | class TestWhenParsingWithTags(object): | 51 | class TestWhenParsingWithTags(object): |
52 | 52 | ||
53 | def setup(self): | ||
54 | test_input = "my activity@Home, Some cool stuff! #tag1 #tag2" | ||
55 | self.results = parse_activity(test_input) | ||
56 | |||
57 | def test_should_get_tags(self): | 53 | def test_should_get_tags(self): |
58 | assert_equals(self.results.tags, ['tag1', 'tag2']) | 54 | test = parse_activity("my activity@Home, Some cool stuff! #tag1 #tag2") |
55 | assert_equals(test.tags, ['tag1', 'tag2']) | ||
59 | 56 | ||
60 | def test_should_not_include_tags_in_description(self): | 57 | def test_should_not_include_tags_in_description(self): |
61 | assert_equals(self.results.description, "Some cool stuff!") | 58 | test = parse_activity("my activity@Home, Some cool stuff! #tag1 #tag2") |
62 | 59 | assert_equals(test.description, "Some cool stuff!") | |
63 | |||
64 | # TODO: Implement this functionality when I need it. | ||
65 | class TestWhenParsingWithTimeOffset(object): | ||
66 | |||
67 | def test_should_understand_minutes(self): | ||
68 | test_input = "my activity@Home, Some cool stuff! 10m" | ||
69 | test_input = "my activity@Home, Some cool stuff! 10M" | ||
70 | |||
71 | def test_should_understand_hours(self): | ||
72 | test_input = "my activity@Home, Some cool stuff! 10h" | ||
73 | test_input = "my activity@Home, Some cool stuff! 10H" | ||
74 | |||
75 | def test_should_understand_seconds(self): | ||
76 | test_input = "my activity@Home, Some cool stuff! 10s" | ||
77 | test_input = "my activity@Home, Some cool stuff! 10S" | ||
78 | |||
79 | |||
80 | class TestWhenParsingWithAbsoluteTime(object): | ||
81 | |||
82 | def test_should_understand_military_time(self): | ||
83 | test_input = "my activity@Home, Some cool stuff! 11:30-14:40" | ||
84 | 60 | ||
85 | def test_should_understand_simple_time(self): | 61 | def test_should_not_include_tags_in_category(self): |
86 | test_input = "my activity@Home, Some cool stuff! 11:30AM-2:40PM" | 62 | test = parse_activity("my activity@Home #tag1 #tag2") |
87 | test_input = "my activity@Home, Some cool stuff! 11:30A-2:40P" | 63 | assert_equals(test.tags, ['tag1', 'tag2']) |
64 | assert_equals(test.category, 'Home') | ||