Пример #1
0
    def test_tryWriteBdeGroupOneLine(self):
        f =  lambda x, w: bdeformatutil.tryWriteBdeGroupOneLine(
                                 [bdeformatutil.parseElement(e) for e in x], w)
        A = self.assertEqual

        l = ["int     a,", "char    *b,", "some other type x)"]
        s = "int a, char *b, some other type x)"

        A(f(l, len(s) + 1), s)
        A(f(l, len(s)), s)
        A(f(l, len(s) - 1), None)
Пример #2
0
        def T(s, commentStr=""):
            expected = []
            prevPipePos = s.find("|")
            pipePos = s.find("|", prevPipePos + 1)
            while prevPipePos != -1 and pipePos != -1:
                expected.append(s[prevPipePos + 1:pipePos].strip(" /"))
                prevPipePos = pipePos
                pipePos = s.find("|", pipePos + 1)

            if len(commentStr) > 0:
                expected[5] = commentStr

            self.assertEqual(bdeformatutil.parseElement(
                                                       s.translate(None, "|")),
                                                       tuple(expected))
Пример #3
0
    def test_writeAlignedElements(self):
        f = lambda x: bdeformatutil.writeAlignedElements(
                        bdeformatutil.alignElementParts(
                                   [bdeformatutil.parseElement(e) for e in x]))
        A = self.assertEqual

        l = ["int            a;",
             "char           character = 0;",
             "unsigned char  x         = 'c';",
             "void          *d;"]
        A(f(l), ([(x, "") for x in l], 15))

        l = ["a,",
             "bcd,",
             "**eg,",
             "&h)"]
        A(f(l), ([(x, "") for x in l], 0))
Пример #4
0
    def test_writeBdeGroupMultiline(self):
        f =  lambda x, w, p, s: bdeformatutil.writeBdeGroupMultiline(
                            [bdeformatutil.parseElement(e) for e in x], w, p,s)
        A = self.assertEqual

        l = ["int a,",
             "char character = 0,",
             "unsigned char  x         = 'c',",
             "void *d)"]
        out = ["foo(int            a,",
               "    char           character = 0,",
               "    unsigned char  x         = 'c',",
               "    void          *d);"]
        A(f(l, 80, "foo(", ";"), ([(x, "") for x in out], 19))

        out = ["foobarbazzzzzz(",
               "         int            a,",
               "         char           character = 0,",
               "         unsigned char  x         = 'c',",
               "         void          *d);"]
        A(f(l, 40, "foobarbazzzzzz(", ";"), ([(x, "") for x in out], 24))
Пример #5
0
    def test_alignElementParts(self):
        # 'f' takes a list of strings, replaces '|' with some spaces in
        # each, calls 'parseElement' on each to build a list suitable for
        # 'alignElementParts', and then joins each element of the returned
        # list back with "|"
        f = lambda x: ["|".join(a) for a in
                        bdeformatutil.alignElementParts(
                                         [bdeformatutil.parseElement(
                                           e.replace("|", "   ")) for e in x])]
        A = self.assertEqual

        l = ["int         | |a||,|",
             "char        | |b||,|",
             "void        |*|c||,|",
             "another type| |x|= 2|,|"]
        A(f(l), l)

        l = ["int         |   |abc|= 123|,|",
             "char        |   |b  |= 2345|,|",
             "void        |***|c||,|",
             "void ***&   |***|c||,|",
             "another type|   |x  |= 2|,|"]
        A(f(l), l)