<commit_before>import {expect} from 'chai';
import * as Rx from '../../dist/cjs/Rx.KitchenSink';
import {ArrayObservable} from '../../dist/cjs/observable/ArrayObservable';
import {ScalarObservable} from '../../dist/cjs/observable/ScalarObservable';
import {EmptyObservable} from '../../dist/cjs/observable/EmptyObservable';

declare const expectObservable;
declare const rxTestScheduler: Rx.TestScheduler;
const Observable = Rx.Observable;

/** @test {of} */
describe('Observable.of', () => {
  it('should create an observable from the provided values', (done: MochaDone) => {
    const x = { foo: 'bar' };
    const expected = [1, 'a', x];
    let i = 0;

    Observable.of<any>(1, 'a', x)
      .subscribe((y: any) => {
        expect(y).to.equal(expected[i++]);
      }, (x) => {
        done(new Error('should not be called'));
      }, () => {
        done();
      });
  });

  it('should return a scalar observable if only passed one value', () => {
    const obs = Observable.of('one');
    expect(obs instanceof ScalarObservable).to.be.true;
  });

  it('should return a scalar observable if only passed one value and a scheduler', () => {
    const obs = Observable.of<string>('one', Rx.Scheduler.queue);
    expect(obs instanceof ScalarObservable).to.be.true;
  });

  it('should return an array observable if passed many values', () => {
    const obs = Observable.of('one', 'two', 'three');
    expect(obs instanceof ArrayObservable).to.be.true;
  });

  it('should return an empty observable if passed no values', () => {
    const obs = Observable.of();
    expect(obs instanceof EmptyObservable).to.be.true;
  });

  it('should return an empty observable if passed only a scheduler', () => {
    const obs = Observable.of(Rx.Scheduler.queue);
    expect(obs instanceof EmptyObservable).to.be.true;
  });

  it('should emit one value', (done: MochaDone) => {
    let calls = 0;

    Observable.of(42).subscribe((x: number) => {
      expect(++calls).to.equal(1);
      expect(x).to.equal(42);
    }, (err: any) => {
      done(new Error('should not be called'));
    }, () => {
      done();
    });
  });

  it('should handle an Observable as the only value', () => {
    const source = Observable.of<Rx.Observable<string>>(
      Observable.of<string>('a', 'b', 'c', rxTestScheduler),
      rxTestScheduler
    );
    expect(source instanceof ScalarObservable).to.be.true;
    const result = source.concatAll();
    expectObservable(result).toBe('(abc|)');
  });

  it('should handle many Observable as the given values', () => {
    const source = Observable.of<Rx.Observable<string>>(
      Observable.of<string>('a', 'b', 'c', rxTestScheduler),
      Observable.of<string>('d', 'e', 'f', rxTestScheduler),
      rxTestScheduler
    );
    expect(source instanceof ArrayObservable).to.be.true;

    const result = source.concatAll();
    expectObservable(result).toBe('(abcdef|)');
  });
});<commit_msg>test(ArrayObservable): add a test for PNG diagram generation<commit_after>import {expect} from 'chai';
import * as Rx from '../../dist/cjs/Rx.KitchenSink';
import {ArrayObservable} from '../../dist/cjs/observable/ArrayObservable';
import {ScalarObservable} from '../../dist/cjs/observable/ScalarObservable';
import {EmptyObservable} from '../../dist/cjs/observable/EmptyObservable';

declare const {hot, asDiagram, expectObservable, expectSubscriptions};
declare const rxTestScheduler: Rx.TestScheduler;
const Observable = Rx.Observable;

/** @test {of} */
describe('Observable.of', () => {
  asDiagram('of(1, 2, 3)')('should create a cold observable that emits 1, 2, 3', () => {
    const e1 = Observable.of(1, 2, 3)
      // for the purpose of making a nice diagram, spread out the synchronous emissions
      .concatMap((x, i) => Observable.of(x).delay(i === 0 ? 0 : 20, rxTestScheduler));
    const expected = 'x-y-(z|)';
    expectObservable(e1).toBe(expected, {x: 1, y: 2, z: 3});
  });

  it('should create an observable from the provided values', (done: MochaDone) => {
    const x = { foo: 'bar' };
    const expected = [1, 'a', x];
    let i = 0;

    Observable.of<any>(1, 'a', x)
      .subscribe((y: any) => {
        expect(y).to.equal(expected[i++]);
      }, (x) => {
        done(new Error('should not be called'));
      }, () => {
        done();
      });
  });

  it('should return a scalar observable if only passed one value', () => {
    const obs = Observable.of('one');
    expect(obs instanceof ScalarObservable).to.be.true;
  });

  it('should return a scalar observable if only passed one value and a scheduler', () => {
    const obs = Observable.of<string>('one', Rx.Scheduler.queue);
    expect(obs instanceof ScalarObservable).to.be.true;
  });

  it('should return an array observable if passed many values', () => {
    const obs = Observable.of('one', 'two', 'three');
    expect(obs instanceof ArrayObservable).to.be.true;
  });

  it('should return an empty observable if passed no values', () => {
    const obs = Observable.of();
    expect(obs instanceof EmptyObservable).to.be.true;
  });

  it('should return an empty observable if passed only a scheduler', () => {
    const obs = Observable.of(Rx.Scheduler.queue);
    expect(obs instanceof EmptyObservable).to.be.true;
  });

  it('should emit one value', (done: MochaDone) => {
    let calls = 0;

    Observable.of(42).subscribe((x: number) => {
      expect(++calls).to.equal(1);
      expect(x).to.equal(42);
    }, (err: any) => {
      done(new Error('should not be called'));
    }, () => {
      done();
    });
  });

  it('should handle an Observable as the only value', () => {
    const source = Observable.of<Rx.Observable<string>>(
      Observable.of<string>('a', 'b', 'c', rxTestScheduler),
      rxTestScheduler
    );
    expect(source instanceof ScalarObservable).to.be.true;
    const result = source.concatAll();
    expectObservable(result).toBe('(abc|)');
  });

  it('should handle many Observable as the given values', () => {
    const source = Observable.of<Rx.Observable<string>>(
      Observable.of<string>('a', 'b', 'c', rxTestScheduler),
      Observable.of<string>('d', 'e', 'f', rxTestScheduler),
      rxTestScheduler
    );
    expect(source instanceof ArrayObservable).to.be.true;

    const result = source.concatAll();
    expectObservable(result).toBe('(abcdef|)');
  });
});
{'fraction_non_alphanumeric': 0.1751144797094584, 'fraction_numerical': 0.005684509711037423, 'mean_word_length': 3.4324702589223235, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 55, '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': '1524991', 'n_tokens_mistral': 2027, 'n_tokens_neox': 1966, 'n_words': 505}