SyFi  0.3
codeformatter.CodeFormattingTest Class Reference

List of all members.

Public Member Functions

def setUp
def test_switch
def test_gen_tokens
def test_functions

Private Member Functions

def _compare_codes

Private Attributes

 _text

Detailed Description

Definition at line 50 of file newtests/codeformatter.py.


Member Function Documentation

def codeformatter.CodeFormattingTest._compare_codes (   self,
  code,
  correct 
) [private]

Definition at line 55 of file newtests/codeformatter.py.

Referenced by codeformatter.CodeFormattingTest.test_functions(), codeformatter.CodeFormattingTest.test_gen_tokens(), and codeformatter.CodeFormattingTest.test_switch().

00055 
00056     def _compare_codes(self, code, correct):
00057         "Compare codes and print codes if this fails."
00058         if code != correct:
00059             print "Failure, got code:"
00060             print '"""%s"""' % code
00061             print "but expecting:"
00062             print '"""%s"""' % correct
00063         self.assertTrue(code == correct)
    

Definition at line 52 of file newtests/codeformatter.py.

00052 
00053     def setUp(self):
00054         pass
    

Definition at line 109 of file newtests/codeformatter.py.

References codeformatter.CodeFormattingTest._compare_codes().

00109 
00110     def test_functions(self):
00111         code = CodeFormatter()
00112         
00113         name = "myfunction"
00114 
00115         argnames = ["a", "b", "c"]
00116         args = [("double", name, "[3]") for name in argnames]
00117         
00118         code.declare_function(name, args=args, const=True, inline=True)
00119         code.new_line("")
00120 
00121         body = "// Empty body!"
00122         code.define_function(name, args=args, const=True, inline=True, body=body)
00123         code.new_line("")
00124 
00125         code.call_function(name, args=argnames)
00126         code.new_line("")
00127         
00128         code = str(code)
00129 
00130         self._compare_codes(code, functions_result)

Definition at line 82 of file newtests/codeformatter.py.

References codeformatter.CodeFormattingTest._compare_codes(), and codeformatter.CodeFormattingTest._text.

00082 
00083     def test_gen_tokens(self):
00084         code = CodeFormatter()
00085         class MockObject:
00086             def __init__(self, text):
00087                 self._text = text
00088             def printc(self):
00089                 return self._text
00090             def __str__(self):
00091                 return self._text
00092         s1 = MockObject("s1")
00093         e1 = MockObject("e1")
00094         s2 = MockObject("s2")
00095         e2 = MockObject("e2")
00096         tokens = [(s1, e1), (s2, e2)]
00097         code.begin_block()
00098         code += gen_token_declarations(tokens)
00099         code.end_block()
00100         code.indent()
00101         code.indent()
00102         code += gen_token_definitions(tokens)
00103         code.dedent()
00104         code += gen_token_definitions(tokens)
00105         code.dedent()
00106         code = str(code)
00107 
00108         self._compare_codes(code, gen_tokens_result)

Definition at line 64 of file newtests/codeformatter.py.

References codeformatter.CodeFormattingTest._compare_codes().

00064 
00065     def test_switch(self):
00066         code = CodeFormatter()
00067         code.begin_switch("facet")
00068         facet_dofs = [(2, 0, 1), (5, 3, 4), (6, 7, 8)]
00069         for i, dofs in enumerate(facet_dofs):
00070             code.begin_case(i)
00071             for j, d in enumerate(dofs):
00072                 code += "dofs[%d] = %d;" % (j, d)
00073             code.end_case()
00074         code += "default:"
00075         code.indent()
00076         code += 'throw std::runtime_error("Invalid facet number.");'
00077         code.dedent()
00078         code.end_switch()
00079         code = str(code)
00080         
00081         self._compare_codes(code, test_switch_result)
    

Member Data Documentation


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines