You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

26 lines
886 B

2 years ago
  1. var test = require('tap').test;
  2. var detective = require('../');
  3. var fs = require('fs');
  4. // in order to use detective to find any function
  5. // it needs to properly handle functions called without args
  6. var src = [ 'fn();', 'otherfn();', 'fn();' ].join('\n')
  7. test('noargs', function (t) {
  8. t.plan(1);
  9. t.deepEqual(detective(src, { word: 'fn' }).length, 0, 'finds no arg id');
  10. });
  11. test('find noargs with nodes', function (t) {
  12. t.plan(4);
  13. var modules = detective.find(src, { word: 'fn', nodes: true });
  14. t.equal(modules.strings.length, 0, 'finds no arg id');
  15. t.equal(modules.expressions.length, 0, 'finds no expressions');
  16. t.equal(modules.nodes.length, 2, 'finds a node for each matching function call');
  17. t.equal(
  18. modules.nodes.filter(function (x) {
  19. return x.callee.name === 'fn'
  20. }).length, 2,
  21. 'all matches are correct'
  22. );
  23. });