Public Member Functions | |
def | setUp |
def | test_switch |
def | test_gen_tokens |
def | test_functions |
Private Member Functions | |
def | _compare_codes |
Private Attributes | |
_text |
Definition at line 50 of file newtests/codeformatter.py.
def codeformatter::CodeFormattingTest::_compare_codes | ( | self, | ||
code, | ||||
correct | ||||
) | [private] |
Definition at line 55 of file newtests/codeformatter.py.
00055 : 00056 "Compare codes and print codes if this fails." 00057 if code != correct: 00058 print "Failure, got code:" 00059 print '"""%s"""' % code 00060 print "but expecting:" 00061 print '"""%s"""' % correct 00062 self.assertTrue(code == correct) 00063 def test_switch(self):
def codeformatter::CodeFormattingTest::setUp | ( | self | ) |
Definition at line 52 of file newtests/codeformatter.py.
00052 : 00053 pass 00054 def _compare_codes(self, code, correct):
def codeformatter::CodeFormattingTest::test_functions | ( | self | ) |
Definition at line 109 of file newtests/codeformatter.py.
00109 : 00110 code = CodeFormatter() 00111 00112 name = "myfunction" 00113 00114 argnames = ["a", "b", "c"] 00115 args = [("double", name, "[3]") for name in argnames] 00116 00117 code.declare_function(name, args=args, const=True, inline=True) 00118 code.new_line("") 00119 00120 body = "// Empty body!" 00121 code.define_function(name, args=args, const=True, inline=True, body=body) 00122 code.new_line("") 00123 00124 code.call_function(name, args=argnames) 00125 code.new_line("") 00126 00127 code = str(code) 00128 00129 self._compare_codes(code, functions_result) 00130 tests = [CodeFormattingTest]
def codeformatter::CodeFormattingTest::test_gen_tokens | ( | self | ) |
Definition at line 82 of file newtests/codeformatter.py.
00082 : 00083 code = CodeFormatter() 00084 class MockObject: 00085 def __init__(self, text): 00086 self._text = text 00087 def printc(self): 00088 return self._text 00089 def __str__(self): 00090 return self._text 00091 s1 = MockObject("s1") 00092 e1 = MockObject("e1") 00093 s2 = MockObject("s2") 00094 e2 = MockObject("e2") 00095 tokens = [(s1, e1), (s2, e2)] 00096 code.begin_block() 00097 code += gen_token_declarations(tokens) 00098 code.end_block() 00099 code.indent() 00100 code.indent() 00101 code += gen_token_definitions(tokens) 00102 code.dedent() 00103 code += gen_token_definitions(tokens) 00104 code.dedent() 00105 code = str(code) 00106 00107 self._compare_codes(code, gen_tokens_result) 00108 def test_functions(self):
def codeformatter::CodeFormattingTest::test_switch | ( | self | ) |
Definition at line 64 of file newtests/codeformatter.py.
00064 : 00065 code = CodeFormatter() 00066 code.begin_switch("facet") 00067 facet_dofs = [(2, 0, 1), (5, 3, 4), (6, 7, 8)] 00068 for i, dofs in enumerate(facet_dofs): 00069 code.begin_case(i) 00070 for j, d in enumerate(dofs): 00071 code += "dofs[%d] = %d;" % (j, d) 00072 code.end_case() 00073 code += "default:" 00074 code.indent() 00075 code += 'throw std::runtime_error("Invalid facet number.");' 00076 code.dedent() 00077 code.end_switch() 00078 code = str(code) 00079 00080 self._compare_codes(code, test_switch_result) 00081 def test_gen_tokens(self):
codeformatter::CodeFormattingTest::_text [private] |
Definition at line 86 of file newtests/codeformatter.py.