<commit_before>import {Cancelable} from './cancelable';

describe('Unit: lib/cancelable', () => {
  describe('Cancelable', () => {
    it('promise', done => {
      const cancelable = new Cancelable();
      Promise.resolve(0)
        .then(n => cancelable.promise(++n))
        .then(n => ++n)
        .then(cancelable.promise)
        .then(n => (cancelable.cancel(n), ++n))
        .then(_ => NaN)
        .then(_ => cancelable.promise(NaN))
        .then(_ => NaN)
        .catch(n => assert(++n === 3) || done());
    });

    it('maybe', () => {
      const cancelable = new Cancelable();
      assert(cancelable.maybe(1).extract() === 1);
      cancelable.cancel(NaN);
      assert(cancelable.maybe(1).extract(() => 0) === 0);
    });

    it('either', () => {
      const cancelable = new Cancelable<number>();
      assert(cancelable.either(1).extract() === 1);
      cancelable.cancel(NaN);
      assert(cancelable.either(1).extract(n => (assert(isNaN(n)), 0)) === 0);
    });

    it('listeners', done => {
      let cnt = 0;
      const cancelable = new Cancelable<number>();
      cancelable.listeners.add(n => (
        assert(++cnt === 1),
        assert(n === 0)));
      cancelable.cancel(0);
      cancelable.listeners.add(n => (
        assert(++cnt === 2),
        assert(n === 0),
        done()));
    });

  });

});
<commit_msg>test(cancelable): don't use the global isNaN<commit_after>import {Cancelable} from './cancelable';

describe('Unit: lib/cancelable', () => {
  describe('Cancelable', () => {
    it('promise', done => {
      const cancelable = new Cancelable();
      Promise.resolve(0)
        .then(n => cancelable.promise(++n))
        .then(n => ++n)
        .then(cancelable.promise)
        .then(n => (cancelable.cancel(n), ++n))
        .then(_ => NaN)
        .then(_ => cancelable.promise(NaN))
        .then(_ => NaN)
        .catch(n => assert(++n === 3) || done());
    });

    it('maybe', () => {
      const cancelable = new Cancelable();
      assert(cancelable.maybe(1).extract() === 1);
      cancelable.cancel(NaN);
      assert(cancelable.maybe(1).extract(() => 0) === 0);
    });

    it('either', () => {
      const cancelable = new Cancelable<number>();
      assert(cancelable.either(1).extract() === 1);
      cancelable.cancel(NaN);
      assert(cancelable.either(1).extract(n => (assert(Number.isNaN(n)), 0)) === 0);
    });

    it('listeners', done => {
      let cnt = 0;
      const cancelable = new Cancelable<number>();
      cancelable.listeners.add(n => (
        assert(++cnt === 1),
        assert(n === 0)));
      cancelable.cancel(0);
      cancelable.listeners.add(n => (
        assert(++cnt === 2),
        assert(n === 0),
        done()));
    });

  });

});

{'fraction_non_alphanumeric': 0.2162654996353027, 'fraction_numerical': 0.01312910284463895, 'mean_word_length': 2.459016393442623, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6407853', 'n_tokens_mistral': 927, 'n_tokens_neox': 883, 'n_words': 157}