swh:1:snp:3af1a03cd091600016317ad7197cfc7dfd1319c7
Raw File
Tip revision: f3504df53a41500f4447a497d0aff6b39e58d12b authored by Andreas Stuhlmüller on 25 May 2016, 22:31:08 UTC
0.7.0
Tip revision: f3504df
test-caching.js
'use strict';

var _ = require('underscore');
var parse = require('esprima').parse;
var caching = require('../src/transforms/caching');

var hasCachingDirectiveTests = {
  test1: { code: "'no caching'", expected: true },
  test2: { code: '"no caching";\n', expected: true },
  test3: { code: '\n"no caching";\n1+1', expected: true },
  test4: { code: '1 + 1', expected: false },
  test5: { code: "1 + 1;\n'no caching'", expected: false },
  test6: { code: '', expected: false }
};

var transformRequiredTests = {
  test1: { code: 'IncrementalMH(model, 0);', expected: true },
  test2: { code: 'Enumerate(model);', expected: false },
  test3: { code: 'Infer(model, {method: "incrementalMH"});', expected: true },
  test4: { code: 'Infer(model, {method: "enumerate"});', expected: false },
  test5: { code: '({method: "incrementalMH"})', expected: true },
  test6: { code: '({method: "enumerate"})', expected: false },
  test7: { code: '({"method": "incrementalMH"})', expected: true },
  test8: { code: '({"method": "enumerate"})', expected: false }
};

function generateTests(cases, testFn) {
  return _.mapObject(cases, function(caseDef) {
    return function(test) {
      test.strictEqual(testFn(parse(caseDef.code)), caseDef.expected);
      test.done();
    };
  });
}

module.exports = {
  hasNoCachingDirective: generateTests(hasCachingDirectiveTests, caching.hasNoCachingDirective),
  transformRequired: generateTests(transformRequiredTests, caching.transformRequired)
};
back to top