diff website/issues/extensions/local_replace.py @ 6281:042c50d5e06e

Make rev 2345:acbed367 use hash not revision number Change regexp to make rev[whitespace][rev#]:[hash] refer to repo using hash not rev#. Similar for hg[whitespace][rev#]:[hash]. Also enhance quicktest to search for input token in output by default. Set substr=False on invocation if you don't want this check. Using substr can show incorrect parsing/reconstitution of original string in output.
author John Rouillard <rouilj@ieee.org>
date Thu, 29 Oct 2020 23:43:05 -0400
parents 9af22cfa3a2b
children ca62a7cc3c9b
line wrap: on
line diff
--- a/website/issues/extensions/local_replace.py	Thu Oct 29 23:15:31 2020 -0400
+++ b/website/issues/extensions/local_replace.py	Thu Oct 29 23:43:05 2020 -0400
@@ -11,7 +11,7 @@
                    r"\g<prews><a href='issue\g<id>'>issue\g<ws>\g<id></a>" ),
                   # matching the typical number:hash format of hg's own output
                   # and then use use hash instead of the number
-                  (re.compile(r'(?P<prews>(^|\s+))(?P<revstr>(rev|hg|changeset:   ))(?P<revnumber>\d+):(?P<refhash>[0-9a-fA-F]{12,40})(?P<post>\W+|$)'),
+                  (re.compile(r'(?P<prews>(^|\s+))(?P<revstr>(rev\s*|hg\s*|changeset:   ))(?P<revnumber>\d+):(?P<refhash>[0-9a-fA-F]{12,40})(?P<post>\W+|$)'),
                       r'\g<prews><a href="' + hg_url_base + '\g<refhash>">\g<revstr>\g<revnumber>:\g<refhash></a>\g<post>'),
                   # matching hg revison number or hash
                   (re.compile(r'(?P<prews>(^|\s+))(?P<revstr>(revision|rev|r)\s?)(?P<revision>([1-9][0-9]*)|[0-9a-fA-F]{4,40})(?P<post>\W+|$)'),
@@ -29,13 +29,16 @@
 def init(instance):
     instance.registerUtil('localReplace', local_replace)
 
-def quicktest(msgstr, should_replace = True):
+def quicktest(msgstr, should_replace = True, substr = True):
     testcount['run'] += 1
     replacedstr = local_replace(msgstr)
 
     if not (not replacedstr == msgstr ) == should_replace:
         print("(fail)", end=' ')
         testcount['failed'] += 1
+    elif substr and (msgstr not in replacedstr):
+        print("(fail)", end=' ')
+        testcount['failed'] += 1
 
     if replacedstr == msgstr:
         print( "'%s'" % (msgstr,))
@@ -45,11 +48,11 @@
 if "__main__" == __name__:
     testcount = {'run':0 , 'failed': 0}
     print("Replacement examples:")
-    quicktest(" debian:#222")
-    quicktest(" #555")
+    quicktest(" debian:#222", substr=False)
+    quicktest(" #555", substr=False)
     quicktest("issue333")
-    quicktest(" revision 222")
-    quicktest(" r 222")
+    quicktest(" revision 222", substr=False)
+    quicktest(" r 222", substr=False)
     quicktest(" wordthatendswithr 222", False)
     quicktest(" references", False)
     quicktest(" too many spaces r  222", False)
@@ -58,12 +61,14 @@
     quicktest("rev 012", False) # too short for a hg hash
     quicktest("rev 0123")
     quicktest("re140eb")
-    quicktest(" r7140eb")
-    quicktest(" rev7140eb ")
+    quicktest(" r7140eb", substr=False)
+    quicktest(" rev7140eb ", substr=False)
     quicktest("rev7140eb")
-    quicktest("rev7140eb,")
+    quicktest("rev7140eb,", substr=False)
     quicktest("rev4891:ad3d628e73f2")
     quicktest("hg4891:ad3d628e73f2")
     quicktest("changeset:   4542:46239c21a1eb")
+    quicktest("rev 4542:46239c21a1eb")
+    quicktest("rev    4542:46239c21a1eb") # many spaces
     print()
     print(testcount)

Roundup Issue Tracker: http://roundup-tracker.org/