Armin Rigo avatar Armin Rigo committed f91b529

(fijal, antocuni, arigo) Start with a few tests

Comments (0)

Files changed (2)

src/test/test_math.py

+from ffi import FFI
+import math
+
+
+def test_sin():
+    ffi = FFI()
+    ffi.cdef("""
+        double sin(double x);
+    """)
+    m = ffi.load("m")
+    x = m.sin(1.23)
+    assert x == math.sin(1.23)

src/test/test_parsing.py

+from ffi import FFI
+
+
+class FakeBackend(object):
+    
+    def load_library(self, name):
+        assert name == "foobar"
+        return FakeLibrary()
+
+    def new_primitive_type(self, name):
+        return '<%s>' % name
+
+class FakeLibrary(object):
+    
+    def load_function(self, name, args, result):
+        return FakeFunction(name, args, result)
+
+class FakeFunction(object):
+
+    def __init__(self, name, args, result):
+        self.name = name
+        self.args = args
+        self.result = result
+
+
+def test_simple():
+    ffi = FFI(backend=FakeBackend())
+    ffi.cdef("double sin(double x);")
+    m = ffi.load("foobar")
+    func = m.sin    # should be a callable on real backends
+    assert func.name == 'sin'
+    assert func.args == ['<double>']
+    assert func.result == '<double>'
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.