mirror of
				https://github.com/paperless-ngx/paperless-ngx.git
				synced 2025-10-30 03:56:23 -05:00 
			
		
		
		
	Add tests and improve whitespace handling
This commit is contained in:
		| @@ -128,11 +128,11 @@ class MatchingModel(models.Model): | |||||||
|         Example: |         Example: | ||||||
|         '  some random  words "with   quotes  " and   spaces' |         '  some random  words "with   quotes  " and   spaces' | ||||||
|             ==> |             ==> | ||||||
|         ['some', 'random', 'words', 'with quotes', 'and', 'spaces'] |         ['some', 'random', 'words', 'with\s+quotes', 'and', 'spaces'] | ||||||
|         ''' |         ''' | ||||||
|         findterms = re.compile(r'"([^"]+)"|(\S+)').findall |         findterms = re.compile(r'"([^"]+)"|(\S+)').findall | ||||||
|         normspace = re.compile(r'\s{2,}').sub |         normspace = re.compile(r'\s+').sub | ||||||
|         return [normspace(' ', (t[0] or t[1]).strip()) for t in findterms(self.match)] |         return [normspace(r'\s+', (t[0] or t[1]).strip()) for t in findterms(self.match)] | ||||||
|  |  | ||||||
|     def save(self, *args, **kwargs): |     def save(self, *args, **kwargs): | ||||||
|  |  | ||||||
|   | |||||||
| @@ -16,9 +16,9 @@ class TestMatching(TestCase): | |||||||
|                 matching_algorithm=getattr(klass, algorithm) |                 matching_algorithm=getattr(klass, algorithm) | ||||||
|             ) |             ) | ||||||
|             for string in true: |             for string in true: | ||||||
|                 self.assertTrue(instance.matches(string)) |                 self.assertTrue(instance.matches(string), '"%s" should match "%s" but it does not' % (text, string)) | ||||||
|             for string in false: |             for string in false: | ||||||
|                 self.assertFalse(instance.matches(string)) |                 self.assertFalse(instance.matches(string), '"%s" should not match "%s" but it does' % (text, string)) | ||||||
|  |  | ||||||
|     def test_match_all(self): |     def test_match_all(self): | ||||||
|  |  | ||||||
| @@ -54,6 +54,21 @@ class TestMatching(TestCase): | |||||||
|             ) |             ) | ||||||
|         ) |         ) | ||||||
|  |  | ||||||
|  |         self._test_matching( | ||||||
|  |             'brown fox "lazy dogs"', | ||||||
|  |             "MATCH_ALL", | ||||||
|  |             ( | ||||||
|  |                 "the quick brown fox jumped over the lazy dogs", | ||||||
|  |                 "the quick brown fox jumped over the lazy  dogs", | ||||||
|  |             ), | ||||||
|  |             ( | ||||||
|  |                 "the quick fox jumped over the lazy dogs", | ||||||
|  |                 "the quick brown wolf jumped over the lazy dogs", | ||||||
|  |                 "the quick brown fox jumped over the fat dogs", | ||||||
|  |                 "the quick brown fox jumped over the lazy... dogs", | ||||||
|  |             ) | ||||||
|  |         ) | ||||||
|  |  | ||||||
|     def test_match_any(self): |     def test_match_any(self): | ||||||
|  |  | ||||||
|         self._test_matching( |         self._test_matching( | ||||||
| @@ -89,6 +104,18 @@ class TestMatching(TestCase): | |||||||
|             ) |             ) | ||||||
|         ) |         ) | ||||||
|  |  | ||||||
|  |         self._test_matching( | ||||||
|  |             '"brown fox" " lazy  dogs "', | ||||||
|  |             "MATCH_ANY", | ||||||
|  |             ( | ||||||
|  |                 "the quick brown fox", | ||||||
|  |                 "jumped over the lazy  dogs.", | ||||||
|  |             ), | ||||||
|  |             ( | ||||||
|  |                 "the lazy fox jumped over the brown dogs", | ||||||
|  |             ) | ||||||
|  |         ) | ||||||
|  |  | ||||||
|     def test_match_literal(self): |     def test_match_literal(self): | ||||||
|  |  | ||||||
|         self._test_matching( |         self._test_matching( | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 ishirav
					ishirav