1
# -*- coding: utf-8 -*-
2
# -----------------------------------------------------------------------------
3
# Getting Things GNOME! - a personal organizer for the GNOME desktop
4
# Copyright (c) 2008-2014 - Lionel Dricot & Bertrand Rousseau
6
# This program is free software: you can redistribute it and/or modify it under
7
# the terms of the GNU General Public License as published by the Free Software
8
# Foundation, either version 3 of the License, or (at your option) any later
11
# This program is distributed in the hope that it will be useful, but WITHOUT
12
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
16
# You should have received a copy of the GNU General Public License along with
17
# this program. If not, see <http://www.gnu.org/licenses/>.
18
# -----------------------------------------------------------------------------
20
from unittest import TestCase
22
from GTG.tools.tags import extract_tags_from_text, parse_tag_list
25
class TestExtractTags(TestCase):
26
""" extract_tags_from_text """
28
def assertTags(self, text, expected_tags):
29
tag_list = extract_tags_from_text(text)
30
self.assertEqual(expected_tags, tag_list)
32
def test_doesnt_find_empty_tag(self):
33
self.assertTags("", [])
35
def test_finds_tag_at_beginning(self):
36
self.assertTags("@tag some other text", ["@tag"])
38
def test_finds_tag_at_end(self):
39
self.assertTags("some text ended with @endtag", ["@endtag"])
41
def test_ignores_emails(self):
43
"no @emails allowed: invernizzi.l@gmail.com", ["@emails"])
45
def test_ignores_diffs(self):
46
self.assertTags("no @@diff stuff", [])
48
def test_accepts_hypen_in_tag(self):
49
self.assertTags("@do-this-today", ["@do-this-today"])
50
self.assertTags("@con--tinuous---hypen-s", ["@con--tinuous---hypen-s"])
52
def test_ignores_hypen_at_end_of_tag(self):
53
self.assertTags("@hypen-at-end- some other text", ["@hypen-at-end"])
54
self.assertTags("@hypen-at-end-, with comma", ["@hypen-at-end"])
56
def test_accepts_dot_in_tag(self):
57
self.assertTags("text @gtg-0.3", ["@gtg-0.3"])
59
def test_ignores_dot_at_end_of_tag(self):
60
self.assertTags("@tag.", ["@tag"])
62
def test_accepts_slash_in_tag(self):
63
self.assertTags("@do/this/today", ["@do/this/today"])
65
def test_ignores_slash_at_end_of_tag(self):
66
self.assertTags("@slash/es/", ["@slash/es"])
68
def test_accepts_colon_in_tag(self):
69
self.assertTags("@my:tag", ["@my:tag"])
71
def ignore_colon_at_end(self):
72
self.assertTags("@:a:b:c:", ["@:a:b:c"])
75
class TestParseTagList(TestCase):
76
""" parse_tag_list """
78
def test_parses_positive_single_tag(self):
79
self.assertEqual(parse_tag_list("tag"), [("@tag", True)])
80
self.assertEqual(parse_tag_list("@tag"), [("@tag", True)])
82
def test_parses_postivie_tag_list(self):
84
parse_tag_list("a b c"),
85
[("@a", True), ("@b", True), ("@c", True)],
88
parse_tag_list("@a @b @c"),
89
[("@a", True), ("@b", True), ("@c", True)],
92
def test_parses_negative_single_tag(self):
93
self.assertEqual(parse_tag_list("!tag"), [("@tag", False)])
94
self.assertEqual(parse_tag_list("!@tag"), [("@tag", False)])
96
def test_parses_negative_tag_list(self):
98
parse_tag_list("!a !b !c"),
99
[("@a", False), ("@b", False), ("@c", False)],
102
parse_tag_list("!@a !@b !@c"),
103
[("@a", False), ("@b", False), ("@c", False)],
106
def test_parses_mixed_tags(self):
108
parse_tag_list("add !remove"),
109
[("@add", True), ("@remove", False)],
112
parse_tag_list("!@remove @add"),
113
[("@remove", False), ("@add", True)],