diff --git a/test/more/run-tests.py b/test/more/run-tests.py index 01c377a..393e8cc 100755 --- a/test/more/run-tests.py +++ b/test/more/run-tests.py @@ -12,6 +12,7 @@ Usage: python build_docs.py [--generate-gold] import difflib, getopt, os, re, sys import lxml.ElementInclude from lxml import etree +from collections import defaultdict # Globals @@ -82,7 +83,7 @@ def run_boostbook(parser, boostbook_xsl, file): def normalize_boostbook_ids(doc): ids = {} - id_bases = {} + id_bases = defaultdict(int) for node in doc.xpath("//*[starts-with(@id, 'id') or contains(@id, '_id')]"): id = node.get('id') @@ -90,13 +91,14 @@ def normalize_boostbook_ids(doc): if(id in ids): print 'Duplicate id: ' + id - match = re.match("(id|.+_id)([mp]?\d+)((?:-bb)?)", id) + match = re.match("(.+_id|id)([mp]?\d+)((?:-bb)?)", id) if(match): - count = 1 - if(match.group(1) in id_bases): - count = id_bases[match.group(1)] + 1 - id_bases[match.group(1)] = count - ids[id] = match.group(1) + str(count) + match.group(3) + # Truncate id name, as it sometimes has different lengths... + match2 = re.match("(.*?)([^.]*?)(_?id)", match.group(1)) + base = match2.group(1) + match2.group(2)[:14] + match2.group(3) + count = id_bases[base] + 1 + id_bases[base] = count + ids[id] = base + str(count) + match.group(3) for node in doc.xpath("//*[@linkend or @id]"): x = node.get('linkend')