SHARE
TWEET

Untitled

a guest Oct 12th, 2017 46 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. def printStatementTest():
  3.     printer = PrettyPrinter()
  4.     printer.visit(Print(BinaryOperation(Number(-1), '/', Number(0))))
  5.  
  6.  
  7. def readStatementTest():
  8.     printer = PrettyPrinter()
  9.     printer.visit(Read("GHCi"))
  10.  
  11.  
  12. def conditionalTest():
  13.     printer = PrettyPrinter()
  14.     printer.visit(Conditional(Number(14),
  15.                               [Print(Number(4)), Read("GHCi")],
  16.                               [Read("GHCi")]))
  17.  
  18.  
  19. def funcDefTest():
  20.     printer = PrettyPrinter()
  21.     printer.visit(FunctionDefinition('main', Function(['argc', 'argv'], [])))
  22.  
  23.  
  24. def funcCallTest():
  25.     printer = PrettyPrinter()
  26.     printer.visit(FunctionCall(Reference('main'), [Number(1), Number(14)]))
  27.  
  28.  
  29. def tests():
  30.     testWithCustomStdio(input='',
  31.                         expectedOutput='print ((-1)/(0));\n',
  32.                         func=printStatementTest)
  33.  
  34.     testWithCustomStdio(input='14',
  35.                         expectedOutput='read GHCi;\n',
  36.                         func=readStatementTest)
  37.  
  38.     testWithCustomStdio(input='14',
  39.                         expectedOutput='''if (14) {
  40.     print 4;
  41.     read GHCi;
  42. } else {
  43.     read GHCi;
  44. };
  45. ''',
  46.                         func=conditionalTest)
  47.  
  48.     testWithCustomStdio(input='14',
  49.                         expectedOutput='''def main(argc,argv) {
  50. };
  51. ''',
  52.                         func=funcDefTest)
  53.  
  54.     testWithCustomStdio(input='',
  55.                         expectedOutput='main(1,14);\n',
  56.                         func=funcCallTest)
  57.  
  58. if __name__ == '__main__':
  59.     tests()
RAW Paste Data
Top