Comparing version 0.13.4 to 0.13.5
@@ -221,89 +221,22 @@ import { konsole } from './Konsole'; | ||
// ifMatch(m1, ifMatch(m2, router)) === ifMatch(matchAll(m1, m2), router) | ||
export function matchAll <M extends Match, Z extends Match> (m1: Matcher<M, Z>): Matcher<M, Z> | ||
export function matchAll <M extends Match> (p1: Predicate<M>): Matcher<M, M> | ||
export function matchAll <M extends Match, N extends Match, Z extends Match> (m1: Matcher<M, N>, m2: Matcher<N, Z>): Matcher<M, Z> | ||
export function matchAll <M extends Match, Z extends Match> (p1: Predicate<M>, m2: Matcher<M, Z>,): Matcher<M, Z> | ||
export function matchAll <M extends Match, Z extends Match> (m1: Matcher<M, Z>, p2: Predicate<Z>): Matcher<M, Z> | ||
export function matchAll <M extends Match> (p1: Predicate<M>, p2: Predicate<M>): Matcher<M, M> | ||
export function matchAll <M extends Match, N extends Match, O extends Match, Z extends Match> (m1: Matcher<M, N>, m2: Matcher<N, O>, m3: Matcher<O, Z>): Matcher<M, Z> | ||
export function matchAll <M extends Match, N extends Match, Z extends Match> (p1: Predicate<M>, m2: Matcher<M, N>, m3: Matcher<N, Z>, routerOrHandler: RouterOrHandler<Z>): Matcher<M, Z> | ||
export function matchAll <M extends Match, N extends Match, Z extends Match> (m1: Matcher<M, N>, p2: Predicate<N>, m3: Matcher<N, Z>, routerOrHandler: RouterOrHandler<Z>): Matcher<M, Z> | ||
export function matchAll <M extends Match, N extends Match, Z extends Match> (m1: Matcher<M, N>, m2: Matcher<N, Z>, p3: Predicate<Z>, routerOrHandler: RouterOrHandler<Z>): Matcher<M, Z> | ||
export function matchAll <M extends Match, Z extends Match> (m1: Matcher<M, Z>, p2: Predicate<Z>, p3: Predicate<Z>, routerOrHandler: RouterOrHandler<Z>): Matcher<M, Z> | ||
export function matchAll <M extends Match, Z extends Match> (p1: Matcher<M>, m2: Matcher<M, Z>, p3: Predicate<Z>, routerOrHandler: RouterOrHandler<Z>): Matcher<M, Z> | ||
export function matchAll <M extends Match, Z extends Match> (p1: Predicate<M>, p2: Predicate<M>, m3: Matcher<M, Z>, routerOrHandler: RouterOrHandler<Z>): Matcher<M, Z> | ||
export function matchAll <M extends Match> (p1: Predicate<M>, p2: Predicate<M>, p3: Predicate<M>): Matcher<M, M> | ||
export function matchAll <M extends Match> (... predicatesOrMatchers: (Predicate | Matcher)[]): Matcher<M> | ||
export function matchAll <M extends Match> (... predicatesOrMatchers: (Predicate | Matcher)[]): Matcher<M> { | ||
return m => { | ||
konsole.log("matchAll", predicatesOrMatchers, m) | ||
return Observable.from(predicatesOrMatchers) | ||
.reduce<Predicate | Matcher, Observable<Match>> ( | ||
(prevObservable, currentMatcher, i) => | ||
prevObservable | ||
.flatMap(prevMatch => { | ||
konsole.log(`calling matcher #${i}`, currentMatcher); | ||
return tryMatch(currentMatcher, prevMatch) | ||
.do(result => konsole.log("result", result)) | ||
.map((n: Match) => { | ||
const score = combineScores(prevMatch.score, n.score); | ||
return toScore(n.score) === score | ||
? n | ||
: { | ||
... n, | ||
score | ||
}; | ||
}) | ||
}), | ||
Observable.of(m) | ||
) | ||
.mergeAll(); | ||
} | ||
export function before <M extends Match> (beforeHandler: Handler<M>, routerOrHandler: RouterOrHandler<M>) { | ||
const router = toRouter(routerOrHandler); | ||
return new Router<M>(m => router.getRoute(m) | ||
.map(route => ({ | ||
... route, | ||
action: () => toObservable(beforeHandler(m)) | ||
.flatMap(_ => toObservable(route.action())) | ||
})) | ||
); | ||
} | ||
// ifMatch(firstMatch(m1, m2), router) === first(ifMatch(m1, router), ifMatch(m2, router)) | ||
export function firstMatch <M extends Match> (... predicatesOrMatchers: (Predicate<M> | Matcher<M>)[]): Matcher<M> { | ||
konsole.log("firstMatch", predicatesOrMatchers); | ||
return m => | ||
Observable.from(predicatesOrMatchers) | ||
.concatMap(predicateOrMatcher => tryMatch(predicateOrMatcher, m)) | ||
.take(1); | ||
export function after <M extends Match> (routerOrHandler: RouterOrHandler<M>, afterHandler: Handler<M>) { | ||
const router = toRouter(routerOrHandler); | ||
return new Router<M>(m => router.getRoute(m) | ||
.map(route => ({ | ||
... route, | ||
action: () => toObservable(route.action()) | ||
.flatMap(_ => toObservable(afterHandler(m))) | ||
})) | ||
); | ||
} | ||
// ifMatch(bestMatch(m1, m2), router) === best(ifMatch(m1, router), ifMatch(m2, router)) | ||
export function bestMatch <M extends Match> (... predicatesOrMatchers: (Predicate<M> | Matcher<M>)[]): Matcher<M> { | ||
konsole.log("bestMatch", predicatesOrMatchers); | ||
return m => new Observable<Match>(observer => { | ||
let bestMatch: Match = { score: 0 }; | ||
const subscription = Observable.from(predicatesOrMatchers) | ||
.takeWhile(_ => toScore(bestMatch.score) < 1) | ||
.concatMap(predicateOrMatcher => tryMatch(predicateOrMatcher, m)) | ||
.subscribe( | ||
(match: Match) => { | ||
if (toScore(match.score) > toScore(bestMatch.score)) { | ||
bestMatch = match; | ||
if (toScore(bestMatch.score) === 1) { | ||
observer.next(bestMatch); | ||
observer.complete(); | ||
} | ||
} | ||
}, | ||
error => | ||
observer.error(error), | ||
() => { | ||
if (toScore(bestMatch.score) > 0) | ||
observer.next(bestMatch); | ||
observer.complete(); | ||
} | ||
) | ||
}); | ||
} |
@@ -48,18 +48,3 @@ import { Observable } from 'rxjs'; | ||
export declare function catchRoute<M extends Match>(routerOrHandler: RouterOrHandler<M>): Router<M>; | ||
export declare function matchAll<M extends Match, Z extends Match>(m1: Matcher<M, Z>): Matcher<M, Z>; | ||
export declare function matchAll<M extends Match>(p1: Predicate<M>): Matcher<M, M>; | ||
export declare function matchAll<M extends Match, N extends Match, Z extends Match>(m1: Matcher<M, N>, m2: Matcher<N, Z>): Matcher<M, Z>; | ||
export declare function matchAll<M extends Match, Z extends Match>(p1: Predicate<M>, m2: Matcher<M, Z>): Matcher<M, Z>; | ||
export declare function matchAll<M extends Match, Z extends Match>(m1: Matcher<M, Z>, p2: Predicate<Z>): Matcher<M, Z>; | ||
export declare function matchAll<M extends Match>(p1: Predicate<M>, p2: Predicate<M>): Matcher<M, M>; | ||
export declare function matchAll<M extends Match, N extends Match, O extends Match, Z extends Match>(m1: Matcher<M, N>, m2: Matcher<N, O>, m3: Matcher<O, Z>): Matcher<M, Z>; | ||
export declare function matchAll<M extends Match, N extends Match, Z extends Match>(p1: Predicate<M>, m2: Matcher<M, N>, m3: Matcher<N, Z>, routerOrHandler: RouterOrHandler<Z>): Matcher<M, Z>; | ||
export declare function matchAll<M extends Match, N extends Match, Z extends Match>(m1: Matcher<M, N>, p2: Predicate<N>, m3: Matcher<N, Z>, routerOrHandler: RouterOrHandler<Z>): Matcher<M, Z>; | ||
export declare function matchAll<M extends Match, N extends Match, Z extends Match>(m1: Matcher<M, N>, m2: Matcher<N, Z>, p3: Predicate<Z>, routerOrHandler: RouterOrHandler<Z>): Matcher<M, Z>; | ||
export declare function matchAll<M extends Match, Z extends Match>(m1: Matcher<M, Z>, p2: Predicate<Z>, p3: Predicate<Z>, routerOrHandler: RouterOrHandler<Z>): Matcher<M, Z>; | ||
export declare function matchAll<M extends Match, Z extends Match>(p1: Matcher<M>, m2: Matcher<M, Z>, p3: Predicate<Z>, routerOrHandler: RouterOrHandler<Z>): Matcher<M, Z>; | ||
export declare function matchAll<M extends Match, Z extends Match>(p1: Predicate<M>, p2: Predicate<M>, m3: Matcher<M, Z>, routerOrHandler: RouterOrHandler<Z>): Matcher<M, Z>; | ||
export declare function matchAll<M extends Match>(p1: Predicate<M>, p2: Predicate<M>, p3: Predicate<M>): Matcher<M, M>; | ||
export declare function matchAll<M extends Match>(...predicatesOrMatchers: (Predicate | Matcher)[]): Matcher<M>; | ||
export declare function firstMatch<M extends Match>(...predicatesOrMatchers: (Predicate<M> | Matcher<M>)[]): Matcher<M>; | ||
export declare function bestMatch<M extends Match>(...predicatesOrMatchers: (Predicate<M> | Matcher<M>)[]): Matcher<M>; | ||
export declare function before<M extends Match>(beforeHandler: Handler<M>, routerOrHandler: RouterOrHandler<M>): Router<M>; | ||
export declare function after<M extends Match>(routerOrHandler: RouterOrHandler<M>, afterHandler: Handler<M>): Router<M>; |
@@ -181,72 +181,16 @@ "use strict"; | ||
exports.catchRoute = catchRoute; | ||
function matchAll() { | ||
var predicatesOrMatchers = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
predicatesOrMatchers[_i] = arguments[_i]; | ||
} | ||
return function (m) { | ||
Konsole_1.konsole.log("matchAll", predicatesOrMatchers, m); | ||
return rxjs_1.Observable.from(predicatesOrMatchers) | ||
.reduce(function (prevObservable, currentMatcher, i) { | ||
return prevObservable | ||
.flatMap(function (prevMatch) { | ||
Konsole_1.konsole.log("calling matcher #" + i, currentMatcher); | ||
return tryMatch(currentMatcher, prevMatch) | ||
.do(function (result) { return Konsole_1.konsole.log("result", result); }) | ||
.map(function (n) { | ||
var score = combineScores(prevMatch.score, n.score); | ||
return toScore(n.score) === score | ||
? n | ||
: __assign({}, n, { score: score }); | ||
}); | ||
}); | ||
}, rxjs_1.Observable.of(m)) | ||
.mergeAll(); | ||
}; | ||
function before(beforeHandler, routerOrHandler) { | ||
var router = toRouter(routerOrHandler); | ||
return new Router(function (m) { return router.getRoute(m) | ||
.map(function (route) { return (__assign({}, route, { action: function () { return toObservable(beforeHandler(m)) | ||
.flatMap(function (_) { return toObservable(route.action()); }); } })); }); }); | ||
} | ||
exports.matchAll = matchAll; | ||
// ifMatch(firstMatch(m1, m2), router) === first(ifMatch(m1, router), ifMatch(m2, router)) | ||
function firstMatch() { | ||
var predicatesOrMatchers = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
predicatesOrMatchers[_i] = arguments[_i]; | ||
} | ||
Konsole_1.konsole.log("firstMatch", predicatesOrMatchers); | ||
return function (m) { | ||
return rxjs_1.Observable.from(predicatesOrMatchers) | ||
.concatMap(function (predicateOrMatcher) { return tryMatch(predicateOrMatcher, m); }) | ||
.take(1); | ||
}; | ||
exports.before = before; | ||
function after(routerOrHandler, afterHandler) { | ||
var router = toRouter(routerOrHandler); | ||
return new Router(function (m) { return router.getRoute(m) | ||
.map(function (route) { return (__assign({}, route, { action: function () { return toObservable(route.action()) | ||
.flatMap(function (_) { return toObservable(afterHandler(m)); }); } })); }); }); | ||
} | ||
exports.firstMatch = firstMatch; | ||
// ifMatch(bestMatch(m1, m2), router) === best(ifMatch(m1, router), ifMatch(m2, router)) | ||
function bestMatch() { | ||
var predicatesOrMatchers = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
predicatesOrMatchers[_i] = arguments[_i]; | ||
} | ||
Konsole_1.konsole.log("bestMatch", predicatesOrMatchers); | ||
return function (m) { return new rxjs_1.Observable(function (observer) { | ||
var bestMatch = { score: 0 }; | ||
var subscription = rxjs_1.Observable.from(predicatesOrMatchers) | ||
.takeWhile(function (_) { return toScore(bestMatch.score) < 1; }) | ||
.concatMap(function (predicateOrMatcher) { return tryMatch(predicateOrMatcher, m); }) | ||
.subscribe(function (match) { | ||
if (toScore(match.score) > toScore(bestMatch.score)) { | ||
bestMatch = match; | ||
if (toScore(bestMatch.score) === 1) { | ||
observer.next(bestMatch); | ||
observer.complete(); | ||
} | ||
} | ||
}, function (error) { | ||
return observer.error(error); | ||
}, function () { | ||
if (toScore(bestMatch.score) > 0) | ||
observer.next(bestMatch); | ||
observer.complete(); | ||
}); | ||
}); }; | ||
} | ||
exports.bestMatch = bestMatch; | ||
exports.after = after; | ||
//# sourceMappingURL=Router.js.map |
@@ -7,3 +7,3 @@ { | ||
}, | ||
"version": "0.13.4", | ||
"version": "0.13.5", | ||
"description": "rules-based app engine", | ||
@@ -10,0 +10,0 @@ "main": "dist/prague.js", |
@@ -6,3 +6,3 @@ "use strict"; | ||
const expect = chai.expect; | ||
const { toObservable, toFilteredObservable, isRouter, simpleRouter, toRouter, routeMessage, first, best, run, tryMatch, toScore, routeWithCombinedScore, ifMatch, nullRouter, throwRoute, catchRoute, matchAll, firstMatch, bestMatch } = require('../dist/prague.js'); | ||
const { toObservable, toFilteredObservable, isRouter, simpleRouter, toRouter, routeMessage, first, best, run, tryMatch, toScore, routeWithCombinedScore, ifMatch, nullRouter, throwRoute, catchRoute, matchAll, firstMatch, bestMatch, before, after } = require('../dist/prague.js'); | ||
const { Observable } = require('rxjs'); | ||
@@ -1309,65 +1309,30 @@ | ||
describe('matchAll', () => { | ||
it('should complete and never emit on false predicate', (done) => | ||
tryMatch(matchAll(m => false), foo) | ||
describe("before", () => { | ||
it("should complete and never emit with null router", (done) => { | ||
routeMessage( | ||
before( | ||
throwErr, | ||
nullRouter | ||
), | ||
foo | ||
) | ||
.subscribe(throwErr, passErr, done) | ||
); | ||
it('should pass through true predicate', (done) => { | ||
tryMatch(matchAll(m => true), foo).subscribe(n => { | ||
expect(n).to.containSubset(foo); | ||
done(); | ||
}); | ||
}); | ||
it('should pass through match', (done) => { | ||
tryMatch(matchAll(addBar), foo).subscribe(n => { | ||
expect(n).to.containSubset(fooPlusBar); | ||
done(); | ||
}); | ||
}); | ||
it('should pass through no match', (done) => { | ||
tryMatch(addBar, notFoo) | ||
.subscribe(throwErr, passErr, done) | ||
}); | ||
it('should complete and never emit on false predicate', (done) => { | ||
tryMatch(matchAll(m => false, addBar), foo) | ||
.subscribe(throwErr, passErr, done) | ||
}); | ||
it('should pass through true predicate to match', (done) => { | ||
tryMatch(matchAll(m => true, addBar), foo).subscribe(n => { | ||
expect(n).to.containSubset(fooPlusBar); | ||
done(); | ||
}); | ||
}); | ||
it('should pass through true predicate to no match, then complete and never emit', (done) => { | ||
tryMatch(matchAll(m => true, addBar), notFoo) | ||
.subscribe(throwErr, passErr, done) | ||
}); | ||
it('should pass through match to true predicate', (done) => { | ||
tryMatch(matchAll(addBar, m => true), foo).subscribe(n => { | ||
expect(n).to.containSubset(fooPlusBar); | ||
done(); | ||
}); | ||
}); | ||
it('should pass through match to false predicate, then complete and never emit', (done) => { | ||
tryMatch(matchAll(addBar, m => false), foo) | ||
.subscribe(throwErr, passErr, done) | ||
}); | ||
it('should complete and never emit on no match', (done) => { | ||
tryMatch(matchAll(addBar, m => true), notFoo) | ||
.subscribe(throwErr, passErr, done) | ||
}); | ||
it('should combine scores', (done) => { | ||
tryMatch(matchAll(m => ({ score: .4 }), m => ({ score: .25 })), foo) | ||
it("should run 'before' handler and then router's action when handler is supplied", (done) => { | ||
let handled; | ||
let routed; | ||
routeMessage( | ||
before( | ||
m => { | ||
handled = true; | ||
}, | ||
m => { | ||
expect(handled).to.be.true; | ||
routed = true; | ||
} | ||
)) | ||
.subscribe(n => { | ||
expect(n.score).to.eql(.1); | ||
expect(routed).to.be.true; | ||
done(); | ||
@@ -1377,6 +1342,18 @@ }); | ||
it('should combine scores, treating true predicates as 1', (done) => { | ||
tryMatch(matchAll(m => ({ score: .4 }), m => true), foo) | ||
it("should run 'before' handler and then router's action when router is supplied", (done) => { | ||
let handled; | ||
let routed; | ||
routeMessage( | ||
before( | ||
m => { | ||
handled = true; | ||
}, | ||
simpleRouter(m => { | ||
expect(handled).to.be.true; | ||
routed = true; | ||
}) | ||
)) | ||
.subscribe(n => { | ||
expect(n.score).to.eql(.4); | ||
expect(routed).to.be.true; | ||
done(); | ||
@@ -1386,192 +1363,57 @@ }); | ||
it('should combine scores, treating scoreless matchers as 1', (done) => { | ||
tryMatch(matchAll(m => ({ score: .4 }), m => ({})), foo) | ||
.subscribe(n => { | ||
expect(n.score).to.eql(.4); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
describe('firstMatch', () => { | ||
it('should complete and never emit on false predicate', (done) => | ||
tryMatch(firstMatch(m => false), foo) | ||
.subscribe(throwErr, passErr, done) | ||
); | ||
it('should complete and never emit on no match', (done) => | ||
tryMatch(firstMatch(addBar), notFoo) | ||
describe("after", () => { | ||
it("should complete and never emit with null router", (done) => { | ||
routeMessage( | ||
after( | ||
nullRouter, | ||
throwErr | ||
), | ||
foo | ||
) | ||
.subscribe(throwErr, passErr, done) | ||
); | ||
it('should pass through true predicate', (done) => { | ||
tryMatch(firstMatch(m => true), foo).subscribe(n => { | ||
expect(n).to.containSubset(foo); | ||
done(); | ||
}); | ||
}); | ||
it('should pass through match', (done) => { | ||
tryMatch(matchAll(addBar), foo).subscribe(n => { | ||
expect(n).to.containSubset(fooPlusBar); | ||
done(); | ||
}); | ||
it("should run router's action and then 'after' handler when handler is supplied", (done) => { | ||
let handled; | ||
let routed; | ||
routeMessage( | ||
after( | ||
m => { | ||
routed = true; | ||
}, | ||
m => { | ||
expect(routed).to.be.true; | ||
handled = true; | ||
} | ||
)) | ||
.subscribe(n => { | ||
expect(handled).to.be.true; | ||
done(); | ||
}); | ||
}); | ||
it('should complete and never emit on false predicate, no match', (done) => | ||
tryMatch(firstMatch(m => false, addBar), notFoo) | ||
.subscribe(throwErr, passErr, done) | ||
); | ||
it('should complete and never emit on no match, false predicate', (done) => | ||
tryMatch(firstMatch(addBar, m => false), notFoo) | ||
.subscribe(throwErr, passErr, done) | ||
); | ||
it('should pass through true predicate, no match', (done) => | ||
tryMatch(firstMatch(m => true, addBar), notFoo).subscribe(n => { | ||
expect(n).to.containSubset(notFoo); | ||
done(); | ||
}) | ||
); | ||
it('should pass through true predicate, match', (done) => | ||
tryMatch(firstMatch(m => true, addBar), foo).subscribe(n => { | ||
expect(n).to.containSubset(foo); | ||
done(); | ||
}) | ||
); | ||
it('should complete and never emit on false predicate, no match', (done) => | ||
tryMatch(firstMatch(m => false, addBar), notFoo) | ||
.subscribe(throwErr, passErr, done) | ||
); | ||
it('should skip false predicate, pass through match', (done) => | ||
tryMatch(firstMatch(m => false, addBar), foo).subscribe(n => { | ||
expect(n).to.containSubset(fooPlusBar); | ||
done(); | ||
}) | ||
); | ||
it('should pass through match, false predicate', (done) => | ||
tryMatch(firstMatch(addBar, m => false), foo).subscribe(n => { | ||
expect(n).to.containSubset(fooPlusBar); | ||
done(); | ||
}) | ||
); | ||
it('should pass through match, true predicate', (done) => | ||
tryMatch(firstMatch(addBar, m => true), foo).subscribe(n => { | ||
expect(n).to.containSubset(fooPlusBar); | ||
done(); | ||
}) | ||
); | ||
}); | ||
describe('bestMatch', () => { | ||
it('should complete and never emit on false predicate', (done) => | ||
tryMatch(bestMatch(m => false), foo) | ||
.subscribe(throwErr, passErr, done) | ||
); | ||
it('should complete and never emit on no match', (done) => | ||
tryMatch(bestMatch(addBar), notFoo) | ||
.subscribe(throwErr, passErr, done) | ||
); | ||
it('should pass through true predicate', (done) => { | ||
tryMatch(bestMatch(m => true), foo).subscribe(n => { | ||
expect(n).to.containSubset(foo); | ||
done(); | ||
}); | ||
it("should run router's action and then 'after' router when router is supplied", (done) => { | ||
let handled; | ||
let routed; | ||
routeMessage( | ||
after( | ||
simpleRouter(m => { | ||
routed = true; | ||
}), | ||
m => { | ||
expect(routed).to.be.true; | ||
handled = true; | ||
} | ||
)) | ||
.subscribe(n => { | ||
expect(handled).to.be.true; | ||
done(); | ||
}); | ||
}); | ||
it('should pass through match', (done) => { | ||
tryMatch(bestMatch(addBar), foo).subscribe(n => { | ||
expect(n).to.containSubset(fooPlusBar); | ||
done(); | ||
}); | ||
}); | ||
it('should complete and never emit on false predicate, no match', (done) => | ||
tryMatch(bestMatch(m => false, addBar), notFoo) | ||
.subscribe(throwErr, passErr, done) | ||
); | ||
it('should complete and never emit on no match, false predicate', (done) => | ||
tryMatch(bestMatch(addBar, m => false), notFoo) | ||
.subscribe(throwErr, passErr, done) | ||
); | ||
it('should pass through true predicate, no match', (done) => | ||
tryMatch(bestMatch(m => true, addBar), notFoo).subscribe(n => { | ||
expect(n).to.containSubset(notFoo); | ||
done(); | ||
}) | ||
); | ||
it('should pass through true predicate, scoreless match', (done) => | ||
tryMatch(bestMatch(m => true, addBar), foo).subscribe(n => { | ||
expect(n).to.containSubset(foo); | ||
done(); | ||
}) | ||
); | ||
it('should complete and never emit on false predicate, no match', (done) => | ||
tryMatch(bestMatch(m => false, addBar), notFoo) | ||
.subscribe(throwErr, passErr, done) | ||
); | ||
it('should skip false predicate, pass through match', (done) => | ||
tryMatch(bestMatch(m => false, addBar), foo).subscribe(n => { | ||
expect(n).to.containSubset(fooPlusBar); | ||
done(); | ||
}) | ||
); | ||
it('should pass through scoreless match, ignore false predicate', (done) => | ||
tryMatch(bestMatch(addBar, m => false), foo).subscribe(n => { | ||
expect(n).to.containSubset(fooPlusBar); | ||
done(); | ||
}) | ||
); | ||
it('should pass through scoreless match, ignore true predicate', (done) => | ||
tryMatch(bestMatch(addBar, m => true), foo).subscribe(n => { | ||
expect(n).to.containSubset(fooPlusBar); | ||
done(); | ||
}) | ||
); | ||
it('should pass through true predicate, ignore subsequent matcher', (done) => | ||
tryMatch(bestMatch(m => true, throwErr), foo).subscribe(n => { | ||
expect(toScore(n.score)).to.eql(1); | ||
done(); | ||
}) | ||
); | ||
it('should pass through score=1 match, ignore subsequent matcher', (done) => | ||
tryMatch(bestMatch(m => ({ score: 1 }), throwErr), foo).subscribe(n => { | ||
expect(toScore(n.score)).to.eql(1); | ||
done(); | ||
}) | ||
); | ||
it('should skip <1 match, pass through true predicate', (done) => | ||
tryMatch(bestMatch(m => ({ score: .5}), m => true), foo).subscribe(n => { | ||
expect(toScore(n.score)).to.eql(1); | ||
done(); | ||
}) | ||
); | ||
it('should return higher-scoring match', (done) => | ||
tryMatch(bestMatch(m => ({ score: .5}), m => ({ score: .25})), foo).subscribe(n => { | ||
expect(toScore(n.score)).to.eql(.5); | ||
done(); | ||
}) | ||
); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
98179
1753