{"size": 1132, "ext": "js", "max_stars_repo_path": "visit-if.test.js", "max_stars_repo_name": "jfmengels/eslint-enhanced-visitors", "max_stars_repo_stars_event_min_datetime": "2016-07-05T22:06:16.000Z", "max_stars_repo_stars_event_max_datetime": "2020-09-13T00:04:50.000Z", "max_issues_repo_path": "visit-if.test.js", "max_issues_repo_name": "jfmengels/eslint-enhanced-visitors", "max_issues_repo_issues_event_min_datetime": "2016-06-20T21:48:13.000Z", "max_issues_repo_issues_event_max_datetime": "2016-07-05T22:06:33.000Z", "max_forks_repo_path": "visit-if.test.js", "max_forks_repo_name": "jfmengels/eslint-enhanced-visitors", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 3, "max_issues_count": 1, "max_forks_count": null, "avg_line_length": 25.7272727273, "max_line_length": 78, "alphanum_fraction": 0.5362190813}
import _ from 'lodash/fp';
import test from 'ava';
import {visitIf} from './';

test('should call visitor function if all predicates return true', t => {
  t.plan(4);
  const pass = () => t.pass();
  const T = _.stubTrue;

  visitIf([])(pass)({});
  visitIf([T])(pass)({});
  visitIf([T, T])(pass)({});
  visitIf([T, T, T])(pass)({});
});

test('should not call visitor function if any predicate returns false', t => {
  const fail = () => t.fail();
  const T = _.stubTrue;
  const F = _.stubFalse;

  visitIf([F])(fail)({});
  visitIf([T, F])(fail)({});
  visitIf([F, T])(fail)({});
  visitIf([T, T, F])(fail)({});
  visitIf([T, F, T])(fail)({});
  visitIf([T, F, F])(fail)({});
  visitIf([F, T, T])(fail)({});
  visitIf([F, T, F])(fail)({});
  visitIf([F, F, T])(fail)({});
  visitIf([F, F, F])(fail)({});
});

test('should not call more predicates than necessary', t => {
  const fail = () => t.fail();
  const T = _.stubTrue;
  const F = _.stubFalse;

  visitIf([F, fail])(fail)({});
  visitIf([T, F, fail])(fail)({});
  visitIf([F, fail])(fail)({});
  visitIf([T, T, F, fail])(fail)({});
  visitIf([T, F, fail])(fail)({});
});
