Repository: biwascheme/biwascheme
Pull request #339 (2024-02-21 07:34:37)

Add console test
This PR installs some tests under test/r7rs/ and also setups github actions.


Patch:
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
new file mode 100644
index 0000000..61bb053
--- /dev/null
+++ b/.github/workflows/ci.yml
@@ -0,0 +1,33 @@
+name: CI
+
+on:
+  - push
+  - pull_request
+
+jobs:
+  build:
+    runs-on: ubuntu-latest
+
+    steps:
+      - name: Checkout repository
+        uses: actions/checkout@v2
+
+    - name: Cache Node.js modules
+      uses: actions/cache@v2
+      with:
+        path: |
+          node_modules
+        key: ${{ runner.os }}-npm-${{ hashFiles('**/package-lock.json') }}
+        restore-keys: |
+          ${{ runner.os }}-npm-
+
+    - name: Setup Node.js
+      uses: actions/setup-node@v3
+        with:
+          node-version: 20
+
+    - name: Install dependencies
+      run: npm install
+
+    - name: Run jest
+      run: npm run test
diff --git a/jest.config.mjs b/jest.config.mjs
index b88754e..c69a3d9 100644
--- a/jest.config.mjs
+++ b/jest.config.mjs
@@ -155,7 +155,7 @@ const config = {
 
   // The glob patterns Jest uses to detect test files
   testMatch: [
-    "**/test/new_expander_test.js"
+    "**/test/**/*.test.js",
   //   "**/__tests__/**/*.[jt]s?(x)",
   //   "**/?(*.)+(spec|test).[tj]s?(x)"
   ],
diff --git a/package.json b/package.json
index 4da7f12..42b4f31 100644
--- a/package.json
+++ b/package.json
@@ -1,4 +1,5 @@
 {
+    "type": "module",
     "name": "biwascheme",
     "description": "A practical Scheme interpreter written in JavaScript",
     "version": "0.8.0",


Test patch:
diff --git a/test/helper.js b/test/helper.js
new file mode 100644
index 0000000..38f2f51
--- /dev/null
+++ b/test/helper.js
@@ -0,0 +1,11 @@
+import BiwaScheme from "../src/main.js"
+
+var on_error = function(e){
+  console.warn(e);
+  throw e;
+}
+function ev(str, func) {
+  return expect((new BiwaScheme.Interpreter(on_error)).evaluate(str, func||new Function()));
+}
+
+export { ev }
diff --git a/test/new_expander_test.js b/test/new_expander.test.js
similarity index 100%
rename from test/new_expander_test.js
rename to test/new_expander.test.js
diff --git a/test/r7rs/base.test.js b/test/r7rs/base.test.js
new file mode 100644
index 0000000..b1583e4
--- /dev/null
+++ b/test/r7rs/base.test.js
@@ -0,0 +1,35 @@
+import { ev } from "../helper.js"
+
+describe('11.5 Equivalence predicates', () => {
+  test('eqv?', function(){
+    ev("(eqv? 'a 'a)").toBe(true);
+    ev("(eqv? 'a 'b)").toBe(false);
+    ev("(eqv? 2 2)").toBe(true);
+    ev("(eqv? '() '())").toBe(true);
+    ev("(eqv? 100000000 100000000)").toBe(true)
+    ev("(eqv? (cons 1 2) (cons 1 2))").toBe(false)
+    ev("(eqv? (lambda () 1) (lambda () 2))").toBe(false);
+    ev("(eqv? #f 'nil)").toBe(false);
+  });
+  test('eq?', function(){
+    ev("(eq? 'a 'a)").toBe(true);
+    ev("(eq? (list 'a) (list 'a))").toBe(false);
+    ev("(eq? '() '())").toBe(true);
+    ev("(eq? car car)").toBe(true);
+    ev("(let ((x '(a))) (eq? x x))").toBe(true)
+  });
+  test('equal?', function(){
+    ev("(equal? 'a 'a)").toBe(true);
+    ev("(equal? '(a) '(a))").toBe(true);
+    ev("(equal? '(a (b) c) '(a (b) c))").toBe(true);
+    ev('(equal? "abc" "abc")').toBe(true);
+    ev("(equal? 2 2)").toBe(true);
+    ev("(equal? (make-vector 5 'a) (make-vector 5 'a))").toBe(true);
+    //ev("(equal? '#vu8(1 2 3 4 5)
+    //        (u8-list->bytevector
+    //         '(1 2 3 4 5))                  ⇒  #t
+    ev(`(let* ((x (list 'a)) (y (list 'a)) (z (list x y)))
+          (vector (equal? z (list y x))
+          (equal? z (list x x))))`).toEqual([true,true]);
+  });
+})