[pypy-svn] r44231 - in pypy/dist/pypy/lang/js: . test

santagada at codespeak.net santagada at codespeak.net
Wed Jun 13 17:46:24 CEST 2007


Author: santagada
Date: Wed Jun 13 17:46:22 2007
New Revision: 44231

Added:
   pypy/dist/pypy/lang/js/test/test_interactive.py
Modified:
   pypy/dist/pypy/lang/js/js_interactive.py
Log:
fixed a bug when sending an empty line and made tests for printing results

Modified: pypy/dist/pypy/lang/js/js_interactive.py
==============================================================================
--- pypy/dist/pypy/lang/js/js_interactive.py	(original)
+++ pypy/dist/pypy/lang/js/js_interactive.py	Wed Jun 13 17:46:22 2007
@@ -124,6 +124,9 @@
         self.lines = []
         self.level = 0
     
+    def emptyline(self):
+        pass
+    
     def default(self, line):
         # let's count lines and continue till matching proper nr of {
         # XXX: '{' will count as well

Added: pypy/dist/pypy/lang/js/test/test_interactive.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/lang/js/test/test_interactive.py	Wed Jun 13 17:46:22 2007
@@ -0,0 +1,62 @@
+import py
+import sys
+
+class TestInteraction:
+    """
+    These tests require pexpect (UNIX-only).
+    http://pexpect.sourceforge.net/
+    """
+
+    def _spawn(self, *args, **kwds):
+        try:
+            import pexpect
+        except ImportError, e:
+            py.test.skip(str(e))
+        kwds.setdefault('timeout', 10)
+        print 'SPAWN:', args, kwds
+        child = pexpect.spawn(*args, **kwds)
+        child.logfile = sys.stdout
+        return child
+
+    def spawn(self, argv):
+        return self._spawn('./js_interactive.py', argv)
+    
+    def prompt_send(self, message):
+        self.child.expect('js-pypy>')
+        self.child.sendline(message)
+    
+    def expect(self, message):
+        self.child.expect(message)
+
+    def sendline(self, message):
+        self.child.sendline(message)
+    
+    def continue_send(self, message):
+        self.child.expect('     ... ')
+        self.child.sendline(message)
+
+    def setup_method(cls, method):
+        cls.child = cls.spawn([])
+    
+    def test_interactive(self):
+        child = self.child
+        #child.expect('JS ')   # banner
+        self.prompt_send('x = "hello"')
+        self.expect('hello')
+        self.sendline('function f (x) {')
+        self.continue_send('return x;')
+        self.continue_send('')
+        self.continue_send('}')
+        self.prompt_send('f(100)')
+        self.expect('100')
+        self.prompt_send('this')
+        self.expect('[object Global]')
+
+    def test_prints(self):
+        self.prompt_send('x=123')
+        self.expect('123')
+        self.prompt_send('x=[1,2,3]')
+        self.expect('1,2,3')
+        self.prompt_send('x={1:1}')
+        self.expect('[object Object]')
+        



More information about the Pypy-commit mailing list