Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('should support for ... of (ES5 style)', () => {
const obj = new LetterCount().$create(constant('also pointless')) as any;
const result = [];
// tslint:disable-next-line:prefer-for-of
for (let i = 0; i < obj.length; i++) {
result.push(obj[i].$value);
}
expect(result).to.deep.equal('also pointless'.split(''));
});
it('should reuse proxies as much as possible', () => {
const cache = derivableCache({ derivableFactory: constant });
const proxy1 = cache('abc');
const proxy2 = cache('abc');
// Cannot remember proxies without connection, because we don't know when to evict them.
expect(proxy2).to.not.equal(proxy1);
proxy1.autoCache().get();
// But when connected we can automatically reuse proxies when using simple keys.
expect(cache('abc')).to.equal(proxy1);
// Not possible when using derivables as input of course
expect(cache(constant('abc'))).to.not.equal(proxy1);
});
it('should unwrap parameters before handing them over to the provided function', () => {
const a$ = constant('a');
const b$ = constant('b');
const n$ = constant(123);
const f = lift(monadic);
expect(f(a$).get()).to.equal('monadic (a)');
expect(f('a').get()).to.equal('monadic (a)');
const g = lift(dyadic);
expect(g(a$, n$).get()).to.equal('dyadic (a,123)');
expect(g('a', n$).get()).to.equal('dyadic (a,123)');
const h = lift(triadic);
expect(h(a$, n$, b$).get()).to.equal('triadic (a,123,b)');
expect(h('a', n$, b$).get()).to.equal('triadic (a,123,b)');
});
});
it('should unwrap parameters before handing them over to the provided function', () => {
const a$ = constant('a');
const b$ = constant('b');
const n$ = constant(123);
const f = lift(monadic);
expect(f(a$).get()).to.equal('monadic (a)');
expect(f('a').get()).to.equal('monadic (a)');
const g = lift(dyadic);
expect(g(a$, n$).get()).to.equal('dyadic (a,123)');
expect(g('a', n$).get()).to.equal('dyadic (a,123)');
const h = lift(triadic);
expect(h(a$, n$, b$).get()).to.equal('triadic (a,123,b)');
expect(h('a', n$, b$).get()).to.equal('triadic (a,123,b)');
});
});
it('should not be settable when the target is not an Atom', () => {
const pd = new ProxyDescriptor();
pd.$target = constant('abc');
expect(() => pd.$targetValue = 'def').to.throw();
});
it('should not be settable when the target is not an Atom', () => {
const px = new ProxyDescriptor().$create(constant('abc'));
expect(() => px.$value = 'def').to.throw();
});
it('should be possible to override the default $pluck behavior', () => {
const pd = new ProxyDescriptor();
pd.$pluck = function (this: ProxyDescriptor, prop: string | number) {
return this.$create(this.$target.map(v => (v + ' ' + prop).trim()), extendExpression(this.$expression, prop));
};
const px = pd.$create(constant('')) as any;
expect(px.this.is.awkward.in.more.than[10].ways.$value).to.equal('this is awkward in more than 10 ways');
});
it('should unwrap parameters before handing them over to the provided function', () => {
const a$ = constant('a');
const b$ = constant('b');
const n$ = constant(123);
const f = lift(monadic);
expect(f(a$).get()).to.equal('monadic (a)');
expect(f('a').get()).to.equal('monadic (a)');
const g = lift(dyadic);
expect(g(a$, n$).get()).to.equal('dyadic (a,123)');
expect(g('a', n$).get()).to.equal('dyadic (a,123)');
const h = lift(triadic);
expect(h(a$, n$, b$).get()).to.equal('triadic (a,123,b)');
expect(h('a', n$, b$).get()).to.equal('triadic (a,123,b)');
});
});
const derivableFactory = spy((v: number) => constant(v));
const identityCache = derivableCache({ derivableFactory });
derivableFactory = spy((k: string) => constant('result from ' + k));
resultCache = derivableCache({ derivableFactory });