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