Esempio n. 1
0
    def test_empty_observable(self):
        text = '----->'

        expected_result = [{
            'obs': [[],
                    [
                        {
                            'ts': '-'
                        },
                        {
                            'ts': '-'
                        },
                        {
                            'ts': '-'
                        },
                        {
                            'ts': '-'
                        },
                        {
                            'ts': '-'
                        },
                    ], '>']
        }]

        idl = Idl()
        ast = idl.parse(text)
        self.assertEqual(expected_result, ast)
Esempio n. 2
0
    def test_child_observable(self):
        text = '+-a->'

        expected_result = [{
            'obs': [[], '+',
                    [
                        {
                            'ts': '-',
                            'item': None
                        },
                        {
                            'ts': None,
                            'item': 'a'
                        },
                        {
                            'ts': '-',
                            'item': None
                        },
                    ], '>'],
            'op':
            None
        }]

        idl = Idl()
        ast = idl.parse(text)
        print(ast)
        self.assertEqual(expected_result, ast)
 def render_marble(text, outfname):
     with open('/home/erik/temp', 'a') as w:
         w.write('render marble ' + text + '\n')
         w.flush()
     idl = Idl()
     ast = idl.parse(text)
     marble = create_marble_from_ast(ast)
     render_to_file(marble, outfname, default_theme)
Esempio n. 4
0
    def test_operator(self):
        text = '[ map(i: i*2) ]'

        expected_result = [{'op': ['[', ' map(i: i*2) ', ']']}]

        idl = Idl()
        ast = idl.parse(text)
        print(ast)
        self.assertEqual(expected_result, ast)
Esempio n. 5
0
def main():
    args = parse_arguments()

    idl_file = open(args.input, 'r')
    idl_text = idl_file.read()

    idl = Idl()
    ast = idl.parse(idl_text)

    #print(ast)
    marble = create_marble_from_ast(ast)
    render_to_file(marble, args.output, default_theme)
Esempio n. 6
0
def render_marble(self, node):
    refname, outfname = generate_name(self, node)
    if os.path.exists(outfname):
        return refname, outfname

    ensuredir(os.path.dirname(outfname))
    idl = Idl()
    ast = idl.parse(node['text'])

    marble = create_marble_from_ast(ast)
    render_to_file(marble, outfname, default_theme)
    return refname, outfname
Esempio n. 7
0
    def test_multiple_observables(self):
        text = '''-a-b->
-1-2->
'''

        expected_result = [{
            'obs': [[],
                    [
                        {
                            'ts': '-'
                        },
                        {
                            'item': 'a'
                        },
                        {
                            'ts': '-'
                        },
                        {
                            'item': 'b'
                        },
                        {
                            'ts': '-'
                        },
                    ], '>']
        }, {
            'obs': [[],
                    [
                        {
                            'ts': '-'
                        },
                        {
                            'item': '1'
                        },
                        {
                            'ts': '-'
                        },
                        {
                            'item': '2'
                        },
                        {
                            'ts': '-'
                        },
                    ], '>']
        }]

        idl = Idl()
        ast = idl.parse(text)
        print(ast)
        self.assertEqual(expected_result, ast)
Esempio n. 8
0
    def test_observable_skipspan(self):
        text = '  -a-b-c-->'

        expected_result = [{
            'obs': [[' ', ' '],
                    [
                        {
                            'ts': '-',
                            'item': None
                        },
                        {
                            'ts': None,
                            'item': 'a'
                        },
                        {
                            'ts': '-',
                            'item': None
                        },
                        {
                            'ts': None,
                            'item': 'b'
                        },
                        {
                            'ts': '-',
                            'item': None
                        },
                        {
                            'ts': None,
                            'item': 'c'
                        },
                        {
                            'ts': '-',
                            'item': None
                        },
                        {
                            'ts': '-',
                            'item': None
                        },
                    ], '>'],
            'op':
            None
        }]

        idl = Idl()
        ast = idl.parse(text)
        print(ast)
        self.assertEqual(expected_result, ast)
Esempio n. 9
0
    def test_higer_order_observable(self):
        text = '-+->'

        expected_result = [{
            'obs': [[], [
                {
                    'ts': '-'
                },
                {
                    'item': '+'
                },
                {
                    'ts': '-'
                },
            ], '>']
        }]

        idl = Idl()
        ast = idl.parse(text)
        print(ast)
        self.assertEqual(expected_result, ast)
Esempio n. 10
0
    def test_observable_items(self):
        text = '-a-b-c-->'

        expected_result = [{
            'obs': [[],
                    [
                        {
                            'ts': '-'
                        },
                        {
                            'item': 'a'
                        },
                        {
                            'ts': '-'
                        },
                        {
                            'item': 'b'
                        },
                        {
                            'ts': '-'
                        },
                        {
                            'item': 'c'
                        },
                        {
                            'ts': '-'
                        },
                        {
                            'ts': '-'
                        },
                    ], '>']
        }]

        idl = Idl()
        ast = idl.parse(text)
        print(ast)
        self.assertEqual(expected_result, ast)