File tree 2 files changed +21
-1
lines changed
2 files changed +21
-1
lines changed Original file line number Diff line number Diff line change 30
30
# +? -- allow multiple of those, but be not greedy about the matching
31
31
# (?: ... ) -- wrap everything so that the pattern cannot escape when used in
32
32
# regexes.
33
- VERSION_SLUG_REGEX = '(?:[a-z0-9][-._a-z0-9]+ ?)'
33
+ VERSION_SLUG_REGEX = '(?:[a-z0-9][-._a-z0-9]* ?)'
34
34
35
35
36
36
class VersionSlugField (models .CharField ):
Original file line number Diff line number Diff line change
1
+ import re
1
2
from django .test import TestCase
2
3
3
4
from builds .models import Version
4
5
from builds .version_slug import VersionSlugField
6
+ from builds .version_slug import VERSION_SLUG_REGEX
5
7
from projects .models import Project
6
8
7
9
10
+ class VersionSlugPatternTests (TestCase ):
11
+ pattern = re .compile ('^{pattern}$' .format (pattern = VERSION_SLUG_REGEX ))
12
+
13
+ def test_single_char (self ):
14
+ self .assertTrue (self .pattern .match ('v' ))
15
+ self .assertFalse (self .pattern .match ('.' ))
16
+
17
+ def test_trailing_punctuation (self ):
18
+ self .assertTrue (self .pattern .match ('with_' ))
19
+ self .assertTrue (self .pattern .match ('with.' ))
20
+ self .assertTrue (self .pattern .match ('with-' ))
21
+ self .assertFalse (self .pattern .match ('with!' ))
22
+
23
+ def test_multiple_words (self ):
24
+ self .assertTrue (self .pattern .match ('release-1.0' ))
25
+ self .assertTrue (self .pattern .match ('fix_this-and-that.' ))
26
+
27
+
8
28
class VersionSlugFieldTests (TestCase ):
9
29
fixtures = ["eric" , "test_data" ]
10
30
You can’t perform that action at this time.
0 commit comments