Browse Source

Create list function

master
Dylan Baker 5 years ago
parent
commit
acc88c3df9
2 changed files with 23 additions and 0 deletions
  1. 5
    0
      src/env.js
  2. 18
    0
      test/coreTest.js

+ 5
- 0
src/env.js View File

@@ -20,6 +20,11 @@ module.exports = class Env {
20 20
         '<': (a, b) => new AST.Boolean({ value: a.value < b.value }),
21 21
         '>=': (a, b) => new AST.Boolean({ value: a.value >= b.value }),
22 22
         '<=': (a, b) => new AST.Boolean({ value: a.value <= b.value }),
23
+        'list': function () {
24
+          return new AST.List({
25
+            elements: Object.keys(arguments).map(arg => arguments[arg])
26
+          })
27
+        }
23 28
       }
24 29
     }
25 30
   }

+ 18
- 0
test/coreTest.js View File

@@ -0,0 +1,18 @@
1
+const test = require('tape')
2
+const helpers = require('./helpers')
3
+
4
+const AST = require('../src/ast')
5
+const OsloError = require('../src/osloError')
6
+
7
+test('list function', t => {
8
+  t.plan(1)
9
+
10
+  const tree = helpers.evaluate('(list 1 2 3)')
11
+  t.deepEqual(tree[0], new AST.List({
12
+    elements: [
13
+      new AST.Number({ value: 1 }),
14
+      new AST.Number({ value: 2 }),
15
+      new AST.Number({ value: 3 }),
16
+    ]
17
+  }))
18
+})

Loading…
Cancel
Save