~parthpanchl/gtg/fix-calendar

« back to all changes in this revision

Viewing changes to tests/tools/test_tags.py

  • Committer: Nimit Shah
  • Date: 2014-03-10 03:37:32 UTC
  • mfrom: (1360.2.18 test-cleanup)
  • Revision ID: nimit.svnit@gmail.com-20140310033732-n4od1z8npybs4ooc
Rework of test-suite, by Izidor Matušov

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
5
#
 
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
 
9
# version.
 
10
#
 
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
 
14
# details.
 
15
#
 
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
# -----------------------------------------------------------------------------
 
19
 
 
20
from unittest import TestCase
 
21
 
 
22
from GTG.tools.tags import extract_tags_from_text, parse_tag_list
 
23
 
 
24
 
 
25
class TestExtractTags(TestCase):
 
26
    """ extract_tags_from_text """
 
27
 
 
28
    def assertTags(self, text, expected_tags):
 
29
        tag_list = extract_tags_from_text(text)
 
30
        self.assertEqual(expected_tags, tag_list)
 
31
 
 
32
    def test_doesnt_find_empty_tag(self):
 
33
        self.assertTags("", [])
 
34
 
 
35
    def test_finds_tag_at_beginning(self):
 
36
        self.assertTags("@tag some other text", ["@tag"])
 
37
 
 
38
    def test_finds_tag_at_end(self):
 
39
        self.assertTags("some text ended with @endtag", ["@endtag"])
 
40
 
 
41
    def test_ignores_emails(self):
 
42
        self.assertTags(
 
43
            "no @emails allowed: invernizzi.l@gmail.com", ["@emails"])
 
44
 
 
45
    def test_ignores_diffs(self):
 
46
        self.assertTags("no @@diff stuff", [])
 
47
 
 
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"])
 
51
 
 
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"])
 
55
 
 
56
    def test_accepts_dot_in_tag(self):
 
57
        self.assertTags("text @gtg-0.3", ["@gtg-0.3"])
 
58
 
 
59
    def test_ignores_dot_at_end_of_tag(self):
 
60
        self.assertTags("@tag.", ["@tag"])
 
61
 
 
62
    def test_accepts_slash_in_tag(self):
 
63
        self.assertTags("@do/this/today", ["@do/this/today"])
 
64
 
 
65
    def test_ignores_slash_at_end_of_tag(self):
 
66
        self.assertTags("@slash/es/", ["@slash/es"])
 
67
 
 
68
    def test_accepts_colon_in_tag(self):
 
69
        self.assertTags("@my:tag", ["@my:tag"])
 
70
 
 
71
    def ignore_colon_at_end(self):
 
72
        self.assertTags("@:a:b:c:", ["@:a:b:c"])
 
73
 
 
74
 
 
75
class TestParseTagList(TestCase):
 
76
    """ parse_tag_list """
 
77
 
 
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)])
 
81
 
 
82
    def test_parses_postivie_tag_list(self):
 
83
        self.assertEqual(
 
84
            parse_tag_list("a b c"),
 
85
            [("@a", True), ("@b", True), ("@c", True)],
 
86
        )
 
87
        self.assertEqual(
 
88
            parse_tag_list("@a @b @c"),
 
89
            [("@a", True), ("@b", True), ("@c", True)],
 
90
        )
 
91
 
 
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)])
 
95
 
 
96
    def test_parses_negative_tag_list(self):
 
97
        self.assertEqual(
 
98
            parse_tag_list("!a !b !c"),
 
99
            [("@a", False), ("@b", False), ("@c", False)],
 
100
        )
 
101
        self.assertEqual(
 
102
            parse_tag_list("!@a !@b !@c"),
 
103
            [("@a", False), ("@b", False), ("@c", False)],
 
104
        )
 
105
 
 
106
    def test_parses_mixed_tags(self):
 
107
        self.assertEqual(
 
108
            parse_tag_list("add !remove"),
 
109
            [("@add", True), ("@remove", False)],
 
110
        )
 
111
        self.assertEqual(
 
112
            parse_tag_list("!@remove @add"),
 
113
            [("@remove", False), ("@add", True)],
 
114
        )