summaryrefslogtreecommitdiff
path: root/src/strings/astring.py
blob: f4cbf668ef7b6d1c28fa134136d8e3551c00e679 (plain) (blame)
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
class AString(object):
    __slots__ = ('_value')
    name = 'tmwa::strings::AString'
    enabled = True

    def __init__(self, value):
        self._value = value

    def to_string(self):
        return None

    def children(self):
        b = self._value['data']
        s = self._value['special']
        b = b[0].address
        if s == 255:
            b = b.cast(gdb.lookup_type('tmwa::strings::RString').pointer())
            yield 'allocated', b.dereference()
        else:
            n = 255
            d = n - s
            yield 'contained', b.lazy_string(length=d)

    str256 = '0123456789abcdef' * 16

    test_extra = '''
    using tmwa::operator "" _s;
    #include "../src/strings/zstring.hpp"
    '''

    tests = [
            ('tmwa::AString(""_s)', '{allocated = ""}'),
            ('tmwa::AString(tmwa::ZString(""_s))', '{allocated = ""}'),
            ('tmwa::AString(tmwa::RString(""_s))', '{allocated = ""}'),
            ('tmwa::AString(tmwa::RString(tmwa::ZString(""_s)))', '{allocated = ""}'),
            ('tmwa::AString("Hello"_s)', '{allocated = "Hello"}'),
            ('tmwa::AString(tmwa::ZString("Hello"_s))', '{contained = "Hello"}'),
            ('tmwa::AString(tmwa::RString("Hello"_s))', '{allocated = "Hello"}'),
            ('tmwa::AString(tmwa::RString(tmwa::ZString("Hello"_s)))', '{allocated = "Hello" = {count = 0}}'),
            ('tmwa::AString("' + str256[:-2] + '"_s)', '{allocated = "' + str256[:-2] + '"}'),
            ('tmwa::AString(tmwa::ZString("' + str256[:-2] + '"_s))', '{contained = "' + str256[:-2] + '"}'),
            ('tmwa::AString(tmwa::RString("' + str256[:-2] + '"_s))', '{allocated = "' + str256[:-2] + '"}'),
            ('tmwa::AString(tmwa::RString(tmwa::ZString("' + str256[:-2] + '"_s)))', '{allocated = "' + str256[:-2] + '" = {count = 0}}'),
            ('tmwa::AString("' + str256[:-1] + '"_s)', '{allocated = "' + str256[:-1] + '"}'),
            ('tmwa::AString(tmwa::ZString("' + str256[:-1] + '"_s))', '{contained = "' + str256[:-1] + '"}'),
            ('tmwa::AString(tmwa::RString("' + str256[:-1] + '"_s))', '{allocated = "' + str256[:-1] + '"}'),
            ('tmwa::AString(tmwa::RString(tmwa::ZString("' + str256[:-1] + '"_s)))', '{allocated = "' + str256[:-1] + '" = {count = 0}}'),
            ('tmwa::AString("' + str256 + '"_s)', '{allocated = "' + str256 + '"}'),
            ('tmwa::AString(tmwa::ZString("' + str256 + '"_s))', '{allocated = "' + str256 + '" = {count = 0}}'),
            ('tmwa::AString(tmwa::RString("' + str256 + '"_s))', '{allocated = "' + str256 + '"}'),
            ('tmwa::AString(tmwa::RString(tmwa::ZString("' + str256 + '"_s)))', '{allocated = "' + str256 + '" = {count = 0}}'),
            ('tmwa::AString("' + str256 + 'x"_s)', '{allocated = "' + str256 + 'x"}'),
            ('tmwa::AString(tmwa::ZString("' + str256 + 'x"_s))', '{allocated = "' + str256 + 'x" = {count = 0}}'),
            ('tmwa::AString(tmwa::RString("' + str256 + 'x"_s))', '{allocated = "' + str256 + 'x"}'),
            ('tmwa::AString(tmwa::RString(tmwa::ZString("' + str256 + 'x"_s)))', '{allocated = "' + str256 + 'x" = {count = 0}}'),
    ]