summaryrefslogtreecommitdiff
path: root/tests/parser.spec.ts
diff options
context:
space:
mode:
Diffstat (limited to 'tests/parser.spec.ts')
-rw-r--r--tests/parser.spec.ts57
1 files changed, 57 insertions, 0 deletions
diff --git a/tests/parser.spec.ts b/tests/parser.spec.ts
index 16480e6..6e8431d 100644
--- a/tests/parser.spec.ts
+++ b/tests/parser.spec.ts
@@ -285,5 +285,62 @@ describe('parser', () => {
}),
])
})
+
+ it('preserves order of operations (same operator)', () => {
+ expect(parse(`calc(30 - 5 - 3)`)).toEqual([
+ Expr.Call({
+ name: 'calc',
+ args: [
+ Expr.BinOp({
+ op: '-',
+ left: Expr.BinOp({
+ op: '-',
+ left: Expr.LiteralNumber({ value: 30, unit: '' }),
+ right: Expr.LiteralNumber({ value: 5, unit: '' }),
+ }),
+ right: Expr.LiteralNumber({ value: 3, unit: '' }),
+ }),
+ ],
+ }),
+ ])
+ })
+
+ it('preserves order of operations (different operators, same precedance)', () => {
+ expect(parse(`calc(30 + 5 - 3)`)).toEqual([
+ Expr.Call({
+ name: 'calc',
+ args: [
+ Expr.BinOp({
+ op: '-',
+ left: Expr.BinOp({
+ op: '+',
+ left: Expr.LiteralNumber({ value: 30, unit: '' }),
+ right: Expr.LiteralNumber({ value: 5, unit: '' }),
+ }),
+ right: Expr.LiteralNumber({ value: 3, unit: '' }),
+ }),
+ ],
+ }),
+ ])
+ })
+
+ it('preserves order of operations (different operators, different precedance)', () => {
+ expect(parse(`calc(30 / 5 * 3)`)).toEqual([
+ Expr.Call({
+ name: 'calc',
+ args: [
+ Expr.BinOp({
+ op: '*',
+ left: Expr.BinOp({
+ op: '/',
+ left: Expr.LiteralNumber({ value: 30, unit: '' }),
+ right: Expr.LiteralNumber({ value: 5, unit: '' }),
+ }),
+ right: Expr.LiteralNumber({ value: 3, unit: '' }),
+ }),
+ ],
+ }),
+ ])
+ })
})
})