<commit_before>/* globals describe, it, expect, expectObservable, hot, cold */
var Rx = require('../../dist/cjs/Rx');

describe('Observable.prototype.single()', function () {
  it('Should raise error from empty predicate if observable does not emit', function () {
    var e1 = hot('--a--^--|');
    var expected =    '---#';

    expectObservable(e1.single()).toBe(expected, null, new Rx.EmptyError());
  });

  it('Should return only element from empty predicate if observable emits only once', function () {
    var e1 =    hot('--a--|');
    var expected =  '-----(a|)';

    expectObservable(e1.single()).toBe(expected);
  });

  it('Should raise error from empty predicate if observable emits multiple time', function () {
    var e1 =    hot('--a--b--c--|');
    var expected =  '-----#';

    expectObservable(e1.single()).toBe(expected, null, 'Sequence contains more than one element');
  });

  it('Should raise error from empty predicate if observable emits error', function () {
    var e1 =    hot('--a--b^--#');
    var expected =        '---#';

    expectObservable(e1.single()).toBe(expected);
  });

  it('Should raise error from predicate if observable emits error', function () {
    var e1 =    hot('--a--b^--#');
    var expected =        '---#';

    var predicate = function (value) {
      return value === 'c';
    };

    expectObservable(e1.single(predicate)).toBe(expected);
  });

  it('Should raise error if predicate throws error', function () {
    var e1 =    hot('--a--b--c--d--|');
    var expected =  '-----------#';

    var predicate = function (value) {
      if (value !== 'd') {
        return false;
      }
      throw 'error';
    };

    expectObservable(e1.single(predicate)).toBe(expected);
  });

  it('Should return element from predicate if observable have single matching element', function () {
    var e1 =    hot('--a--b--c--|');
    var expected =  '-----------(b|)';

    var predicate = function (value) {
      return value === 'b';
    };

    expectObservable(e1.single(predicate)).toBe(expected);
  });

  it('Should raise error from predicate if observable have multiple matching element', function () {
    var e1 =    hot('--a--b--a--b--b--|');
    var expected =  '-----------#';

    var predicate = function (value) {
      return value === 'b';
    };

    expectObservable(e1.single(predicate)).toBe(expected, null, 'Sequence contains more than one element');
  });

  it('Should raise error from predicate if observable does not emit', function () {
    var e1 = hot('--a--^--|');
    var expected =    '---#';

    var predicate = function (value) {
      return value === 'a';
    };

    expectObservable(e1.single(predicate)).toBe(expected, null, new Rx.EmptyError());
  });

  it('Should return undefined from predicate if observable does not contain matching element', function () {
    var e1 =    hot('--a--b--c--|');
    var expected =  '-----------(z|)';

    var predicate = function (value) {
      return value === 'x';
    };

    expectObservable(e1.single(predicate)).toBe(expected, {z: undefined});
  });
});<commit_msg>test(single): add subscription assertions on single() tests<commit_after>/* globals describe, it, expect, expectObservable, expectSubscriptions, hot, cold */
var Rx = require('../../dist/cjs/Rx');

describe('Observable.prototype.single()', function () {
  it('should raise error from empty predicate if observable does not emit', function () {
    var e1 = hot('--a--^--|');
    var e1subs =      '^  !';
    var expected =    '---#';

    expectObservable(e1.single()).toBe(expected, null, new Rx.EmptyError());
    expectSubscriptions(e1.subscriptions).toBe(e1subs);
  });

  it('should return only element from empty predicate if observable emits only once', function () {
    var e1 =    hot('--a--|');
    var e1subs =    '^    !';
    var expected =  '-----(a|)';

    expectObservable(e1.single()).toBe(expected);
    expectSubscriptions(e1.subscriptions).toBe(e1subs);
  });

  it('should raise error from empty predicate if observable emits multiple time', function () {
    var e1 =    hot('--a--b--c--|');
    var e1subs =    '^    !      ';
    var expected =  '-----#      ';

    expectObservable(e1.single()).toBe(expected, null, 'Sequence contains more than one element');
    expectSubscriptions(e1.subscriptions).toBe(e1subs);
  });

  it('should allow unsubscribing explicitly and early', function () {
    var e1 =    hot('--a--b--c--|');
    var unsub =     '   !        ';
    var e1subs =    '^  !        ';
    var expected =  '----        ';

    expectObservable(e1.single(), unsub).toBe(expected);
    expectSubscriptions(e1.subscriptions).toBe(e1subs);
  });

  it('should raise error from empty predicate if observable emits error', function () {
    var e1 =    hot('--a--b^--#');
    var e1subs =          '^  !';
    var expected =        '---#';

    expectObservable(e1.single()).toBe(expected);
    expectSubscriptions(e1.subscriptions).toBe(e1subs);
  });

  it('should raise error from predicate if observable emits error', function () {
    var e1 =    hot('--a--b^--#');
    var e1subs =          '^  !';
    var expected =        '---#';

    var predicate = function (value) {
      return value === 'c';
    };

    expectObservable(e1.single(predicate)).toBe(expected);
    expectSubscriptions(e1.subscriptions).toBe(e1subs);
  });

  it('should raise error if predicate throws error', function () {
    var e1 =    hot('--a--b--c--d--|');
    var e1subs =    '^          !   ';
    var expected =  '-----------#   ';

    var predicate = function (value) {
      if (value !== 'd') {
        return false;
      }
      throw 'error';
    };

    expectObservable(e1.single(predicate)).toBe(expected);
    expectSubscriptions(e1.subscriptions).toBe(e1subs);
  });

  it('should return element from predicate if observable have single matching element', function () {
    var e1 =    hot('--a--b--c--|');
    var e1subs =    '^          !';
    var expected =  '-----------(b|)';

    var predicate = function (value) {
      return value === 'b';
    };

    expectObservable(e1.single(predicate)).toBe(expected);
    expectSubscriptions(e1.subscriptions).toBe(e1subs);
  });

  it('should raise error from predicate if observable have multiple matching element', function () {
    var e1 =    hot('--a--b--a--b--b--|');
    var e1subs =    '^          !      ';
    var expected =  '-----------#      ';

    var predicate = function (value) {
      return value === 'b';
    };

    expectObservable(e1.single(predicate)).toBe(expected, null, 'Sequence contains more than one element');
    expectSubscriptions(e1.subscriptions).toBe(e1subs);
  });

  it('should raise error from predicate if observable does not emit', function () {
    var e1 = hot('--a--^--|');
    var e1subs =      '^  !';
    var expected =    '---#';

    var predicate = function (value) {
      return value === 'a';
    };

    expectObservable(e1.single(predicate)).toBe(expected, null, new Rx.EmptyError());
    expectSubscriptions(e1.subscriptions).toBe(e1subs);
  });

  it('should return undefined from predicate if observable does not contain matching element', function () {
    var e1 =    hot('--a--b--c--|');
    var e1subs =    '^          !';
    var expected =  '-----------(z|)';

    var predicate = function (value) {
      return value === 'x';
    };

    expectObservable(e1.single(predicate)).toBe(expected, {z: undefined});
    expectSubscriptions(e1.subscriptions).toBe(e1subs);
  });
});
{'fraction_non_alphanumeric': 0.1855191619148654, 'fraction_numerical': 0.009945630552977059, 'mean_word_length': 2.5525200188412622, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5603795', 'n_tokens_mistral': 2391, 'n_tokens_neox': 2251, 'n_words': 572}