"use strict";

import test from 'ava';
import {just, interval} from './dist/streams';

test('just factory', t => {
    just(1).subscribe(v => t.is(1, v));
    just(2).subscribe(v => t.is(2, v));
    just('123').subscribe(v => t.is('123', v));
    just([1,2,3]).subscribe(v => t.deepEqual([1,2,3], v));
});

test('interval', async t => {
    const p = new Promise((res, rej) => {
        let i = 0, s = 0;
        const sub = interval(0, 123)
            .subscribe(v => {
                s += v;
                if (++i === 3) {
                    sub();
                    setTimeout(() => i === 3 ? res(s) : rej('too many calls'), 5)
                }
            });
    });
    t.is(await p, 369);
});

@@ -54,16 +54,27 @@
 interval
+, fromEvent
 %7D from '
@@ -708,12 +708,922 @@
 , 369);%0A%7D);%0A
+%0Atest('fromEvent', t =%3E %7B%0A    const el = %7B%0A        addEventListener: (event, clb) =%3E %7B%0A            setTimeout(clb, 0, 1234);%0A        %7D,%0A        removeEventListener: (event, clb) =%3E %7B%0A%0A        %7D%0A    %7D;%0A    function test(v) %7B%0A        t.is(v, 1234);%0A    %7D%0A    fromEvent(el, 'event').subscribe(test)%0A%7D);%0A%0Atest('fromEvent interval', async t =%3E %7B%0A    const result = new Promise((res, rej) =%3E %7B%0A        let i = 0;%0A        let interval = null;%0A        const el = %7B%0A            addEventListener: (event, clb) =%3E %7B%0A                interval = setInterval(clb, 5, 1);%0A            %7D,%0A            removeEventListener: (event, clb) =%3E %7B%0A                clearInterval(interval);%0A            %7D%0A        %7D;%0A        function test(v) %7B%0A            i += v;%0A        %7D%0A        const sub = fromEvent(el, 'event').subscribe(test);%0A        setTimeout(sub, 15);%0A        setTimeout(() =%3E res(i), 20);%0A    %7D);%0A    t.is(await result, 2);%0A%7D);

add fromEvent factory test