| 1 |
|
| 2 |
|
| 3 |
om> |
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 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: |
| 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) |