( pattern: ExpressionInput, expr: Expression | MathJsonExpression, options?: PatternMatchOptions )
| 12 | const ce = engine; |
| 13 | |
| 14 | function match( |
| 15 | pattern: ExpressionInput, |
| 16 | expr: Expression | MathJsonExpression, |
| 17 | options?: PatternMatchOptions |
| 18 | ): Substitution | null { |
| 19 | // Avoid re-boxing both expr & pattern so as to preserve canonical-status |
| 20 | expr = |
| 21 | expr instanceof _BoxedExpression ? (expr as Expression) : ce.expr(expr); |
| 22 | pattern = |
| 23 | pattern instanceof _BoxedExpression |
| 24 | ? (pattern as Expression) |
| 25 | : ce.expr(pattern); |
| 26 | |
| 27 | const result = expr.match(pattern, { |
| 28 | useVariations: true, |
| 29 | ...options, |
| 30 | }); |
| 31 | if (result === null) return null; |
| 32 | const r = {}; |
| 33 | for (const key of Object.keys(result)) r[key] = result[key]; |
| 34 | return r; |
| 35 | } |
| 36 | |
| 37 | describe('Examples from Patterns and Rules guide', () => { |
| 38 | const pattern: MathJsonExpression = ['Add', '_', 'x']; |
no test coverage detected