xref: /AOO41X/main/toolkit/src2xml/source/macroexpander_test.py (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir#!/usr/bin/env python
2*cdf0e10cSrcweir
3*cdf0e10cSrcweirimport srclexer, srcparser, globals
4*cdf0e10cSrcweir
5*cdf0e10cSrcweirclass TestCase:
6*cdf0e10cSrcweir
7*cdf0e10cSrcweir    @staticmethod
8*cdf0e10cSrcweir    def run (tokens, defines):
9*cdf0e10cSrcweir        mcExpander = srcparser.MacroExpander(tokens, defines)
10*cdf0e10cSrcweir        mcExpander.debug = True
11*cdf0e10cSrcweir        mcExpander.expand()
12*cdf0e10cSrcweir        tokens = mcExpander.getTokens()
13*cdf0e10cSrcweir        print tokens
14*cdf0e10cSrcweir
15*cdf0e10cSrcweir    @staticmethod
16*cdf0e10cSrcweir    def simpleNoArgs ():
17*cdf0e10cSrcweir        tokens = ['FUNC_FOO', '(', 'left', ',', 'right', ')']
18*cdf0e10cSrcweir        defines = {}
19*cdf0e10cSrcweir        macro = globals.Macro('FUNC_FOO')
20*cdf0e10cSrcweir        macro.tokens = ['Here', 'comes', 'X', 'and', 'Y']
21*cdf0e10cSrcweir        defines['FUNC_FOO'] = macro
22*cdf0e10cSrcweir        TestCase.run(tokens, defines)
23*cdf0e10cSrcweir
24*cdf0e10cSrcweir    @staticmethod
25*cdf0e10cSrcweir    def simpleArgs ():
26*cdf0e10cSrcweir        tokens = ['FUNC_FOO', '(', 'left', ',', 'right', ')']
27*cdf0e10cSrcweir        defines = {}
28*cdf0e10cSrcweir        macro = globals.Macro('FUNC_FOO')
29*cdf0e10cSrcweir        macro.tokens = ['Here', 'comes', 'X', 'and', 'Y']
30*cdf0e10cSrcweir        macro.vars['X'] = 0
31*cdf0e10cSrcweir        macro.vars['Y'] = 1
32*cdf0e10cSrcweir        defines['FUNC_FOO'] = macro
33*cdf0e10cSrcweir        TestCase.run(tokens, defines)
34*cdf0e10cSrcweir
35*cdf0e10cSrcweir    @staticmethod
36*cdf0e10cSrcweir    def multiTokenArgs ():
37*cdf0e10cSrcweir        tokens = ['FUNC_FOO', '(', 'left1', 'left2', 'left3', ',', 'right', ')']
38*cdf0e10cSrcweir        defines = {}
39*cdf0e10cSrcweir        macro = globals.Macro('FUNC_FOO')
40*cdf0e10cSrcweir        macro.tokens = ['Here', 'comes', 'X', 'and', 'Y']
41*cdf0e10cSrcweir        macro.vars['X'] = 0
42*cdf0e10cSrcweir        macro.vars['Y'] = 1
43*cdf0e10cSrcweir        defines['FUNC_FOO'] = macro
44*cdf0e10cSrcweir        TestCase.run(tokens, defines)
45*cdf0e10cSrcweir
46*cdf0e10cSrcweir    @staticmethod
47*cdf0e10cSrcweir    def nestedTokenArgs ():
48*cdf0e10cSrcweir        tokens = ['FUNC_BAA', '(', 'left', ',', 'right', ')']
49*cdf0e10cSrcweir        defines = {}
50*cdf0e10cSrcweir        macro = globals.Macro('FUNC_FOO')
51*cdf0e10cSrcweir        macro.tokens = ['Here', 'comes', 'X', 'and', 'Y']
52*cdf0e10cSrcweir        macro.vars['X'] = 0
53*cdf0e10cSrcweir        macro.vars['Y'] = 1
54*cdf0e10cSrcweir        defines['FUNC_FOO'] = macro
55*cdf0e10cSrcweir        macro = globals.Macro('FUNC_BAA')
56*cdf0e10cSrcweir        macro.tokens = ['FUNC_FOO']
57*cdf0e10cSrcweir        defines['FUNC_BAA'] = macro
58*cdf0e10cSrcweir        TestCase.run(tokens, defines)
59*cdf0e10cSrcweir
60*cdf0e10cSrcweirdef main ():
61*cdf0e10cSrcweir    print "simple expansion with no arguments"
62*cdf0e10cSrcweir    TestCase.simpleNoArgs()
63*cdf0e10cSrcweir    print "simple argument expansion"
64*cdf0e10cSrcweir    TestCase.simpleArgs()
65*cdf0e10cSrcweir    print "multi-token argument expansion"
66*cdf0e10cSrcweir    TestCase.multiTokenArgs()
67*cdf0e10cSrcweir    print "nested argument expansion"
68*cdf0e10cSrcweir    TestCase.nestedTokenArgs()
69*cdf0e10cSrcweir
70*cdf0e10cSrcweirif __name__ ==  '__main__':
71*cdf0e10cSrcweir    main()
72