Skip to content

Commit fdda83f

Browse files
committed
Match sure to match functions
1 parent d206dfb commit fdda83f

File tree

4 files changed

+31
-2
lines changed

4 files changed

+31
-2
lines changed

lib/tailored.js

Lines changed: 12 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "tailored",
3-
"version": "2.4.5",
3+
"version": "2.4.6",
44
"description": "Pattern matching library",
55
"main": "lib/tailored.js",
66
"jsnext:main": "src/index.js",

src/tailored/match.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ patternMap.set(Symbol.prototype, Resolvers.resolveSymbol);
2424
patternMap.set(Array.prototype, Resolvers.resolveArray);
2525
patternMap.set(String.prototype, Resolvers.resolveString);
2626
patternMap.set(Boolean.prototype, Resolvers.resolveBoolean);
27+
patternMap.set(Function.prototype, Resolvers.resolveFunction);
2728
patternMap.set(Object.prototype, Resolvers.resolveObject);
2829

2930
export function buildMatch(pattern) {

test/defmatch.spec.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,5 +329,22 @@ describe('defmatch', () => {
329329
expect(fn(1, 5, 4)).to.equal(13);
330330
expect(fn(1, 5, 7, 4)).to.equal(17);
331331
});
332+
333+
it('must match on objects with symbol keys', () => {
334+
const bound_value = {
335+
[Symbol.for('__struct__')]: Symbol.for('Elixir.Blueprint.AssertError'),
336+
};
337+
338+
const value = {
339+
[Symbol.for('__struct__')]: Symbol.for('Elixir.Blueprint.AssertError'),
340+
[Symbol.for('msg')]: 'somthing',
341+
};
342+
343+
let fn = Tailored.defmatch(
344+
Tailored.clause([Tailored.bound(bound_value)], val => true),
345+
);
346+
347+
expect(fn(value)).to.equal(true);
348+
});
332349
});
333350
});

0 commit comments

Comments
 (0)