Пример #1
0
 def testHelloWorldExample(self):
     code=b'-- hello world\n-- by zep\n\nt = 0\n\nmusic(0)\n\nfunction _update()\n t += 1\nend\n\nfunction _draw()\n cls()\n  \n for i=1,11 do\n  for j0=0,7 do\n  j = 7-j0\n  col = 7+j\n  t1 = t + i*4 - j*2\n  x = cos(t0)*5\n  y = 38 + j + cos(t1/50)*5\n  pal(7,col)\n  spr(16+i, 8+i*8 + x, y)\n  end\n end\n \n  print("this is pico-8",\n    37, 70, 14) --8+(t/4)%8)\n\n print("nice to meet you",\n    34, 80, 12) --8+(t/4)%8)\n\n  spr(1, 64-4, 90)\nend\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n'
     lxr = lexer.Lexer(version=4)
     lxr.process_lines([code])
     tokens = lxr.tokens
     self.assertEqual(lexer.TokComment(b'-- hello world'), tokens[0])
     self.assertEqual(lexer.TokNewline(b'\n'), tokens[1])
     self.assertEqual(lexer.TokComment(b'-- by zep'), tokens[2])
     self.assertEqual(lexer.TokNewline(b'\n'), tokens[3])
Пример #2
0
 def testFromP8PNGFileV0(self):
     pngpath = os.path.join(self.testdata_path, 'test_cart.p8.png')
     with open(pngpath, 'rb') as fh:
         pnggame = game.Game.from_p8png_file(fh)
     first_stat = pnggame.lua.root.stats[0]
     self.assertTrue(isinstance(first_stat, parser.StatFunctionCall))
     tokens = pnggame.lua.tokens
     self.assertEqual(lexer.TokComment('-- memory dump'), tokens[0])
     self.assertEqual(lexer.TokNewline('\n'), tokens[1])
     self.assertEqual(lexer.TokComment('-- by dddaaannn'), tokens[2])
     self.assertEqual(lexer.TokNewline('\n'), tokens[3])
Пример #3
0
 def testTokenAndComment(self):
     lxr = lexer.Lexer(version=4)
     lxr._process_line('and-- comment text and stuff\n')
     self.assertEqual(3, len(lxr._tokens))
     self.assertEqual(lexer.TokKeyword('and'), lxr._tokens[0])
     self.assertEqual(lexer.TokComment('-- comment text and stuff'),
                      lxr._tokens[1])
Пример #4
0
 def testMultilineCommentMultipleCalls(self):
     lxr = lexer.Lexer(version=8)
     lxr._process_line(b'--[[comment text\n')
     lxr._process_line(b'and "stuff\n')
     lxr._process_line(b']]\n')
     self.assertEqual(2, len(lxr._tokens))
     self.assertEqual(lexer.TokComment(b'--[[comment text\nand "stuff\n]]'),
                      lxr._tokens[0])
Пример #5
0
 def testMultilineCommentNoLinebreaks(self):
     lxr = lexer.Lexer(version=8)
     lxr._process_line(b'--[[comment text and "stuff]]\n')
     self.assertEqual(2, len(lxr._tokens))
     self.assertEqual(lexer.TokComment(b'--[[comment text and "stuff]]'),
                      lxr._tokens[0])
Пример #6
0
 def testCommentUnofficialDoubleSlash(self):
     lxr = lexer.Lexer(version=4)
     lxr._process_line(b'// comment text and stuff\n')
     self.assertEqual(2, len(lxr._tokens))
     self.assertEqual(lexer.TokComment(b'// comment text and stuff'),
                      lxr._tokens[0])
Пример #7
0
 def testComment(self):
     lxr = lexer.Lexer(version=4)
     lxr._process_line(b'-- comment text and stuff\n')
     self.assertEqual(2, len(lxr._tokens))
     self.assertEqual(lexer.TokComment(b'-- comment text and stuff'),
                      lxr._tokens[0])