This repository has been archived by the owner on Feb 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 353
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
99be40a
commit ec88ea7
Showing
2 changed files
with
124 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
from django.test import TestCase | ||
|
||
from ..models import Tag | ||
|
||
|
||
class TestTagMatching(TestCase): | ||
|
||
def test_match_all(self): | ||
|
||
t = Tag.objects.create( | ||
name="Test 0", | ||
match="alpha charlie gamma", | ||
matching_algorithm=Tag.MATCH_ALL | ||
) | ||
self.assertFalse(t.matches("I have alpha in me")) | ||
self.assertFalse(t.matches("I have charlie in me")) | ||
self.assertFalse(t.matches("I have gamma in me")) | ||
self.assertFalse(t.matches("I have alpha and charlie in me")) | ||
self.assertTrue(t.matches("I have alpha, charlie, and gamma in me")) | ||
self.assertFalse(t.matches("I have alphas, charlie, and gamma in me")) | ||
self.assertFalse(t.matches("I have alphas in me")) | ||
self.assertFalse(t.matches("I have bravo in me")) | ||
|
||
t = Tag.objects.create( | ||
name="Test 1", | ||
match="12 34 56", | ||
matching_algorithm=Tag.MATCH_ALL | ||
) | ||
self.assertFalse(t.matches("I have 12 in me")) | ||
self.assertFalse(t.matches("I have 34 in me")) | ||
self.assertFalse(t.matches("I have 56 in me")) | ||
self.assertFalse(t.matches("I have 12 and 34 in me")) | ||
self.assertTrue(t.matches("I have 12 34, and 56 in me")) | ||
self.assertFalse(t.matches("I have 120, 34, and 56 in me")) | ||
self.assertFalse(t.matches("I have 123456 in me")) | ||
self.assertFalse(t.matches("I have 01234567 in me")) | ||
|
||
def test_match_any(self): | ||
|
||
t = Tag.objects.create( | ||
name="Test 0", | ||
match="alpha charlie gamma", | ||
matching_algorithm=Tag.MATCH_ANY | ||
) | ||
|
||
self.assertTrue(t.matches("I have alpha in me")) | ||
self.assertTrue(t.matches("I have charlie in me")) | ||
self.assertTrue(t.matches("I have gamma in me")) | ||
self.assertTrue(t.matches("I have alpha and charlie in me")) | ||
self.assertFalse(t.matches("I have alphas in me")) | ||
self.assertFalse(t.matches("I have bravo in me")) | ||
|
||
t = Tag.objects.create( | ||
name="Test 1", | ||
match="12 34 56", | ||
matching_algorithm=Tag.MATCH_ANY | ||
) | ||
self.assertTrue(t.matches("I have 12 in me")) | ||
self.assertTrue(t.matches("I have 34 in me")) | ||
self.assertTrue(t.matches("I have 56 in me")) | ||
self.assertTrue(t.matches("I have 12 and 34 in me")) | ||
self.assertTrue(t.matches("I have 12 34, and 56 in me")) | ||
self.assertTrue(t.matches("I have 120, 34, and 560 in me")) | ||
self.assertFalse(t.matches("I have 120, 340, and 560 in me")) | ||
self.assertFalse(t.matches("I have 123456 in me")) | ||
self.assertFalse(t.matches("I have 01234567 in me")) | ||
|
||
def test_match_literal(self): | ||
|
||
t = Tag.objects.create( | ||
name="Test 0", | ||
match="alpha charlie gamma", | ||
matching_algorithm=Tag.MATCH_LITERAL | ||
) | ||
|
||
self.assertFalse(t.matches("I have alpha in me")) | ||
self.assertFalse(t.matches("I have charlie in me")) | ||
self.assertFalse(t.matches("I have gamma in me")) | ||
self.assertFalse(t.matches("I have alpha and charlie in me")) | ||
self.assertFalse(t.matches("I have alpha, charlie, and gamma in me")) | ||
self.assertFalse(t.matches("I have alphas, charlie, and gamma in me")) | ||
self.assertTrue(t.matches("I have 'alpha charlie gamma' in me")) | ||
self.assertFalse(t.matches("I have alphas in me")) | ||
self.assertFalse(t.matches("I have bravo in me")) | ||
|
||
t = Tag.objects.create( | ||
name="Test 1", | ||
match="12 34 56", | ||
matching_algorithm=Tag.MATCH_LITERAL | ||
) | ||
self.assertFalse(t.matches("I have 12 in me")) | ||
self.assertFalse(t.matches("I have 34 in me")) | ||
self.assertFalse(t.matches("I have 56 in me")) | ||
self.assertFalse(t.matches("I have 12 and 34 in me")) | ||
self.assertFalse(t.matches("I have 12 34, and 56 in me")) | ||
self.assertFalse(t.matches("I have 120, 34, and 560 in me")) | ||
self.assertFalse(t.matches("I have 120, 340, and 560 in me")) | ||
self.assertFalse(t.matches("I have 123456 in me")) | ||
self.assertFalse(t.matches("I have 01234567 in me")) | ||
self.assertTrue(t.matches("I have 12 34 56 in me")) | ||
|
||
def test_match_regex(self): | ||
|
||
t = Tag.objects.create( | ||
name="Test 0", | ||
match="alpha\w+gamma", | ||
matching_algorithm=Tag.MATCH_REGEX | ||
) | ||
|
||
self.assertFalse(t.matches("I have alpha in me")) | ||
self.assertFalse(t.matches("I have gamma in me")) | ||
self.assertFalse(t.matches("I have alpha and charlie in me")) | ||
self.assertTrue(t.matches("I have alpha_and_gamma in me")) | ||
self.assertTrue(t.matches("I have alphas_and_gamma in me")) | ||
self.assertFalse(t.matches("I have alpha,and,gamma in me")) | ||
self.assertFalse(t.matches("I have alpha and gamma in me")) | ||
self.assertFalse(t.matches("I have alpha, charlie, and gamma in me")) | ||
self.assertFalse(t.matches("I have alphas, charlie, and gamma in me")) | ||
self.assertFalse(t.matches("I have alphas in me")) | ||
|