Sha256: 8db73aaf0b4a4ea2362c8c26fa09f13cdf502edbfd659c591268cf6855de7af8

Contents?: true

Size: 796 Bytes

Versions: 44

Compression:

Stored size: 796 Bytes

Contents

var tape = require('tape')
var genfun = require('./')

tape('generate add function', function(t) {
  var fn = genfun()
    ('function add(n) {')
      ('return n + %d', 42)
    ('}')

  t.same(fn.toString(), 'function add(n) {\n  return n + 42\n}', 'code is indented')
  t.same(fn.toFunction()(10), 52, 'function works')
  t.end()
})

tape('generate function + closed variables', function(t) {
  var fn = genfun()
    ('function add(n) {')
      ('return n + %d + number', 42)
    ('}')

  var notGood = fn.toFunction()
  var good = fn.toFunction({number:10})

  try {
    notGood(10)
    t.ok(false, 'function should not work')
  } catch (err) {
    t.same(err.message, 'number is not defined', 'throws reference error')
  }

  t.same(good(11), 63, 'function with closed var works')
  t.end()
})

Version data entries

44 entries across 39 versions & 12 rubygems

Version Path
optimacms-0.4.3 spec/dummy/node_modules/generate-function/test.js
optimacms-0.4.2 spec/dummy/node_modules/generate-function/test.js
locomotivecms-3.4.0 app/javascript/node_modules/generate-function/test.js
guard-sass-lint-0.1.2 node_modules/generate-function/test.js
guard-sass-lint-0.1.1 node_modules/generate-function/test.js
lanes-0.8.0 node_modules/fsevents/node_modules/generate-function/test.js
lanes-0.8.0 node_modules/generate-function/test.js
node-compiler-0.9.1 vendor/node/deps/npm/node_modules/request/node_modules/har-validator/node_modules/is-my-json-valid/node_modules/generate-function/test.js
node-compiler-0.9.0 vendor/node-v7.2.1/deps/npm/node_modules/request/node_modules/har-validator/node_modules/is-my-json-valid/node_modules/generate-function/test.js
select_all-rails-0.3.1 node_modules/generate-function/test.js
node-compiler-0.8.0 vendor/node-v7.2.0/deps/npm/node_modules/request/node_modules/har-validator/node_modules/is-my-json-valid/node_modules/generate-function/test.js
node-compiler-0.7.0 vendor/node-v6.9.1/deps/npm/node_modules/request/node_modules/har-validator/node_modules/is-my-json-valid/node_modules/generate-function/test.js
node-compiler-0.7.0 vendor/node-v7.1.0/deps/npm/node_modules/request/node_modules/har-validator/node_modules/is-my-json-valid/node_modules/generate-function/test.js
tck-lambdas-0.3.10 lib/tck/lambdas/chistacojs/source/node_modules/request/node_modules/har-validator/node_modules/is-my-json-valid/node_modules/generate-function/test.js
tck-lambdas-0.3.9 lib/tck/lambdas/chistacojs/source/node_modules/request/node_modules/har-validator/node_modules/is-my-json-valid/node_modules/generate-function/test.js
tck-lambdas-0.3.8 lib/tck/lambdas/chistacojs/source/node_modules/request/node_modules/har-validator/node_modules/is-my-json-valid/node_modules/generate-function/test.js
tck-lambdas-0.3.7 lib/tck/lambdas/chistacojs/source/node_modules/request/node_modules/har-validator/node_modules/is-my-json-valid/node_modules/generate-function/test.js
tck-lambdas-0.3.6 lib/tck/lambdas/chistacojs/source/node_modules/request/node_modules/har-validator/node_modules/is-my-json-valid/node_modules/generate-function/test.js
tck-lambdas-0.3.5 lib/tck/lambdas/chistacojs/source/node_modules/request/node_modules/har-validator/node_modules/is-my-json-valid/node_modules/generate-function/test.js
tck-lambdas-0.3.4 lib/tck/lambdas/chistacojs/source/node_modules/request/node_modules/har-validator/node_modules/is-my-json-valid/node_modules/generate-function/test.js