Debian Codegraph @

lib/tests/test_spellcheck.py

raw symbols SCIP
1 # -*- coding: utf-8 -*-
2 #
3 # Copyright (C) 2008 Lukáš Lalinský <[email protected]om>
4 #
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License
7 # as published by the Free Software Foundation; either version 2
8 # of the License, or (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18
19 """Tests for QBzr plugin."""
20
21 from breezy.tests import TestCase
22 try:
23 from breezy.tests.features import Feature
24 except ImportError: # bzr < 2.5
25 from breezy.tests import Feature
26 from breezy.plugins.qbrz.lib.spellcheck import SpellChecker
27
28
29 class _PyEnchantFeature(Feature):
30
31 def _probe(self):
32 try:
33 from breezy.plugins.qbrz.lib.spellcheck_enchant import EnchantSpellChecker
34 except ImportError:
35 return False
36 if "en-US" not in EnchantSpellChecker.list_languages():
37 return False
38 return True
39
40 PyEnchantFeature = _PyEnchantFeature()
41
42
43 class TestSpellcheck(TestCase):
44
45 _test_needs_features = [PyEnchantFeature]
46
47 def setUp(self):
48 super(TestSpellcheck, self).setUp()
49 def cleanup():
50 del self.checker
51 self.checker = SpellChecker("en-US")
52 self.addCleanup(cleanup)
53
54 def test_correct(self):
55 result = list(self.checker.check("yes"))
56 self.assertEqual([], result)
57
58 def test_incorrect(self):
59 result = list(self.checker.check("yess"))
60 self.assertEqual([(0, 4)], result)
61
62 def test_camel_case(self):
63 result = list(self.checker.check("YesNo"))
64 self.assertEqual([], result)
65
66 def test_camel_case_2(self):
67 result = list(self.checker.check("yesNo"))
68 self.assertEqual([], result)
69
70 def test_underscores(self):
71 result = list(self.checker.check("Yes_No"))
72 self.assertEqual([], result)
73
74 def test_email(self):
75 result = list(self.checker.check("yes [email protected] no"))
76 self.assertEqual([], result)
77
78 def test_url(self):
79 result = list(self.checker.check("yes http://example.com/foo/bar no"))
80 self.assertEqual([], result)