Repository: barrust/pyspellchecker

Issue:
Case Sensitive bug
Case sensitive parameter has no affect bcz in "_parse_into_words" method text is made lower irrespective of case sensitive parameter, need to avoid it to make case-sensitive valid

Discussion:

Patch:
diff --git a/spellchecker/utils.py b/spellchecker/utils.py
index 437a7aa..7260d42 100644
--- a/spellchecker/utils.py
+++ b/spellchecker/utils.py
@@ -1,8 +1,8 @@
 """ Additional utility functions """
 import contextlib
 import gzip
-import re
 import functools
+import re
 import warnings
 
 from .info import __version__
@@ -135,4 +135,4 @@ def _parse_into_words(text):
             text (str): The text to split into words
     """
     # see: https://stackoverflow.com/a/12705513
-    return re.findall(r"(\w[\w']*\w|\w)", text.lower())
+    return re.findall(r"(\w[\w']*\w|\w)", text)


Test patch:
diff --git a/tests/spellchecker_test.py b/tests/spellchecker_test.py
index bf13fa4..772ac1b 100644
--- a/tests/spellchecker_test.py
+++ b/tests/spellchecker_test.py
@@ -36,13 +36,13 @@ class TestSpellChecker(unittest.TestCase):
     def test_words(self):
         ''' test the parsing of words '''
         spell = SpellChecker()
-        res = ['this', 'is', 'a', 'test', 'of', 'this']
+        res = ['This', 'is', 'a', 'test', 'of', 'this']
         self.assertEqual(spell.split_words('This is a test of this'), res)
 
     def test_words_more_complete(self):
         ''' test the parsing of words '''
         spell = SpellChecker()
-        res = ['this', 'is', 'a', 'test', 'of', 'the', 'word', 'parser', 'it', 'should', 'work', 'correctly']
+        res = ['This', 'is', 'a', 'test', 'of', 'the', 'word', 'parser', 'It', 'should', 'work', 'correctly']
         self.assertEqual(spell.split_words('This is a test of the word parser. It should work correctly!!!'), res)
 
     def test_word_frequency(self):
@@ -413,7 +413,7 @@ class TestSpellChecker(unittest.TestCase):
         ''' test using split_words '''
         spell = SpellChecker()
         res = spell.split_words("This isn't a good test, but it is a test!!!!")
-        self.assertEqual(set(res), set(["this", "isn't", "a", "good", "test", "but", "it", "is", "a", "test"]))
+        self.assertEqual(set(res), set(["This", "isn't", "a", "good", "test", "but", "it", "is", "a", "test"]))
 
     def test_iter_spellchecker(self):
         """ Test using the iterator on the SpellChecker """
@@ -440,3 +440,17 @@ class TestSpellChecker(unittest.TestCase):
             self.assertTrue(word in spell)
             cnt += 1
         self.assertEqual(cnt, len(spell.word_frequency.dictionary))
+
+    def test_case_sensitive_parse_words(self):
+        """ Test using the parse words to generate a case sensitive dict """
+        spell = SpellChecker(language=None, case_sensitive=True)
+        spell.word_frequency.load_text("This is a Test of the test!")
+        self.assertTrue("This" in spell)
+        self.assertFalse("this" in spell)
+
+    def test_case_insensitive_parse_words(self):
+        """ Test using the parse words to generate a case insensitive dict """
+        spell = SpellChecker(language=None, case_sensitive=False)
+        spell.word_frequency.load_text("This is a Test of the test!")
+        # in makes sure it is lower case in this instance
+        self.assertTrue("this" in spell)