summaryrefslogtreecommitdiffstats
path: root/debian/uncrustify-trinity/uncrustify-trinity-0.78.1/tests/test_uncrustify/selector.py
blob: 93646257aa6e624716fd858e54c741e10c28354c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# Utility class to match test filters.
#
# * @author  Matthew Woehlke    June 2018
#


# =============================================================================
class Selector(object):
    # -------------------------------------------------------------------------
    def __init__(self, s):
        class Range(object):
            pass

        self.ranges = []
        for p in s.split(','):
            r = Range()
            if ':' in p:
                r.group, p = p.split(':')
            else:
                r.group = None
            if '-' in p:
                r.lower, r.upper = map(int, p.split('-'))
            else:
                r.lower = int(p)
                r.upper = int(p)
            self.ranges.append(r)

    # -------------------------------------------------------------------------
    def test(self, name):
        group, num = name.split(':')
        num = int(num)

        for r in self.ranges:
            if r.group is not None and r.group != group:
                continue
            if num < r.lower or num > r.upper:
                continue
            return True

        return False