]> gerrit.simantics Code Review - simantics/district.git/blob - org.simantics.maps.server/node/node-v4.8.0-win-x64/node_modules/npm/node_modules/request/node_modules/har-validator/node_modules/is-my-json-valid/node_modules/generate-function/test.js
Adding integrated tile server
[simantics/district.git] / org.simantics.maps.server / node / node-v4.8.0-win-x64 / node_modules / npm / node_modules / request / node_modules / har-validator / node_modules / is-my-json-valid / node_modules / generate-function / test.js
1 var tape = require('tape')
2 var genfun = require('./')
3
4 tape('generate add function', function(t) {
5   var fn = genfun()
6     ('function add(n) {')
7       ('return n + %d', 42)
8     ('}')
9
10   t.same(fn.toString(), 'function add(n) {\n  return n + 42\n}', 'code is indented')
11   t.same(fn.toFunction()(10), 52, 'function works')
12   t.end()
13 })
14
15 tape('generate function + closed variables', function(t) {
16   var fn = genfun()
17     ('function add(n) {')
18       ('return n + %d + number', 42)
19     ('}')
20
21   var notGood = fn.toFunction()
22   var good = fn.toFunction({number:10})
23
24   try {
25     notGood(10)
26     t.ok(false, 'function should not work')
27   } catch (err) {
28     t.same(err.message, 'number is not defined', 'throws reference error')
29   }
30
31   t.same(good(11), 63, 'function with closed var works')
32   t.end()
33 })