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

describe('Observable.prototype.repeat()', function () {
  it('should resubscribe count number of times', function () {
    var e1 =   cold('--a--b--|                ');
    var subs =     ['^       !                ',
                    '        ^       !        ',
                    '                ^       !'];
    var expected =  '--a--b----a--b----a--b--|';

    expectObservable(e1.repeat(3)).toBe(expected);
    expectSubscriptions(e1.subscriptions).toBe(subs);
  });

  it('should resubscribe multiple times', function () {
    var e1 =   cold('--a--b--|                        ');
    var subs =     ['^       !                        ',
                    '        ^       !                ',
                    '                ^       !        ',
                    '                        ^       !'];
    var expected =  '--a--b----a--b----a--b----a--b--|';

    expectObservable(e1.repeat(2).repeat(2)).toBe(expected);
    expectSubscriptions(e1.subscriptions).toBe(subs);
  });

  it('should complete without emit when count is zero', function () {
    var e1 =  cold('--a--b--|');
    var subs = [];
    var expected = '|';

    expectObservable(e1.repeat(0)).toBe(expected);
    expectSubscriptions(e1.subscriptions).toBe(subs);
  });

  it('should emit source once when count is one', function () {
    var e1 =  cold('--a--b--|');
    var subs =     '^       !';
    var expected = '--a--b--|';

    expectObservable(e1.repeat(1)).toBe(expected);
    expectSubscriptions(e1.subscriptions).toBe(subs);
  });

  it('should repeat until gets unsubscribed', function () {
    var e1 =  cold('--a--b--|      ');
    var subs =    ['^       !      ',
                   '        ^     !'];
    var unsub =    '              !';
    var expected = '--a--b----a--b-';

    expectObservable(e1.repeat(10), unsub).toBe(expected);
    expectSubscriptions(e1.subscriptions).toBe(subs);
  });

  it('should be able to repeat indefinitely until unsubscribed', function () {
    var e1 =  cold('--a--b--|                                    ');
    var subs =    ['^       !                                    ',
                   '        ^       !                            ',
                   '                ^       !                    ',
                   '                        ^       !            ',
                   '                                ^       !    ',
                   '                                        ^   !'];
    var unsub =    '                                            !';
    var expected = '--a--b----a--b----a--b----a--b----a--b----a--';

    expectObservable(e1.repeat(), unsub).toBe(expected);
    expectSubscriptions(e1.subscriptions).toBe(subs);
  });

  it('should consider negative count as repeat indefinitely', function () {
    var e1 =  cold('--a--b--|                                    ');
    var subs =    ['^       !                                    ',
                   '        ^       !                            ',
                   '                ^       !                    ',
                   '                        ^       !            ',
                   '                                ^       !    ',<commit_msg>test(repeat): add test against breaking unsubscription chain<commit_after>/* globals describe, it, expect, expectObservable, expectSubscriptions, hot, cold, rxTestScheduler */
var Rx = require('../../dist/cjs/Rx');
var Observable = Rx.Observable;

describe('Observable.prototype.repeat()', function () {
  it('should resubscribe count number of times', function () {
    var e1 =   cold('--a--b--|                ');
    var subs =     ['^       !                ',
                    '        ^       !        ',
                    '                ^       !'];
    var expected =  '--a--b----a--b----a--b--|';

    expectObservable(e1.repeat(3)).toBe(expected);
    expectSubscriptions(e1.subscriptions).toBe(subs);
  });

  it('should resubscribe multiple times', function () {
    var e1 =   cold('--a--b--|                        ');
    var subs =     ['^       !                        ',
                    '        ^       !                ',
                    '                ^       !        ',
                    '                        ^       !'];
    var expected =  '--a--b----a--b----a--b----a--b--|';

    expectObservable(e1.repeat(2).repeat(2)).toBe(expected);
    expectSubscriptions(e1.subscriptions).toBe(subs);
  });

  it('should complete without emit when count is zero', function () {
    var e1 =  cold('--a--b--|');
    var subs = [];
    var expected = '|';

    expectObservable(e1.repeat(0)).toBe(expected);
    expectSubscriptions(e1.subscriptions).toBe(subs);
  });

  it('should emit source once when count is one', function () {
    var e1 =  cold('--a--b--|');
    var subs =     '^       !';
    var expected = '--a--b--|';

    expectObservable(e1.repeat(1)).toBe(expected);
    expectSubscriptions(e1.subscriptions).toBe(subs);
  });

  it('should repeat until gets unsubscribed', function () {
    var e1 =  cold('--a--b--|      ');
    var subs =    ['^       !      ',
                   '        ^     !'];
    var unsub =    '              !';
    var expected = '--a--b----a--b-';

    expectObservable(e1.repeat(10), unsub).toBe(expected);
    expectSubscriptions(e1.subscriptions).toBe(subs);
  });

  it('should be able to repeat indefinitely until unsubscribed', function () {
    var e1 =  cold('--a--b--|                                    ');
    var subs =    ['^       !                                    ',
                   '        ^       !                            ',
                   '                ^       !                    ',
                   '                        ^       !            ',
                   '                                ^       !    ',
                   '                                        ^   !'];
    var unsub =    '                                            !';
    var expected = '--a--b----a--b----a--b----a--b----a--b----a--';

    expectObservable(e1.repeat(), unsub).toBe(expected);
    expectSubscriptions(e1.subscriptions).toBe(subs);
  });

  it('should not break unsubscription chain when unsubscribed explicitly', function () {
    var e1 =  cold('--a--b--|                                    ');
    var subs =    ['^       !                                    ',
                   '        ^       !                            ',
                   '                ^       !                    ',
                   '                        ^       !            ',
                   '                                ^       !    ',
                   '                                        ^   !'];
    var unsub =    '                                            !';
    var expected = '--a--b----a--b----a--b----a--b----a--b----a--';

    var result = e1
      .mergeMap(function (x) { return Observable.of(x); })
      .repeat()
      .mergeMap(function (x) { return Observable.of(x); });

    expectObservable(result, unsub).toBe(expected);
    expectSubscriptions(e1.subscriptions).toBe(subs);
  });

  it('should consider negative count as repeat indefinitely', function () {
    var e1 =  cold('--a--b--|                                    ');
    var subs =    ['^       !                                    ',
                   '        ^       !                            ',
                   '                ^       !                    ',
                   '                        ^       !            ',
                   '                                ^       !    ',
{'fraction_non_alphanumeric': 0.1602809706257982, 'fraction_numerical': 0.0070242656449553, 'mean_word_length': 0.8975042403683062, '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': 95, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3371089', 'n_tokens_mistral': 2126, 'n_tokens_neox': 1990, 'n_words': 322}