summaryrefslogtreecommitdiff
path: root/src/strings/xstring.py
blob: b2e33bb4674663428b0ca2fa5f496e62f374e2ee (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
class XString(object):
    __slots__ = ('_value')
    name = 'tmwa::strings::XString'
    enabled = True

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

    def to_string(self):
        b = self._value['_b']['_ptr']
        e = self._value['_e']['_ptr']
        d = e - b
        return b.lazy_string(length=d)

    def children(self):
        yield 'base', self._value['_base']

    str256 = '0123456789abcdef' * 16

    test_extra = '''
    using tmwa::operator "" _s;
    '''

    tests = [
            ('tmwa::XString(""_s)', '"" = {base = 0x0}'),
            ('tmwa::XString("Hello"_s)', '"Hello" = {base = 0x0}'),
            ('tmwa::XString("' + str256[:-2] + '"_s)', '"' + str256[:-2] + '" = {base = 0x0}'),
            ('tmwa::XString("' + str256[:-1] + '"_s)', '"' + str256[:-1] + '" = {base = 0x0}'),
            ('tmwa::XString("' + str256 + '"_s)', '"' + str256 + '" = {base = 0x0}'),
            ('tmwa::XString("' + str256 + 'x"_s)', '"' + str256 + 'x" = {base = 0x0}'),
    ]