|
44 | 44 | } |
45 | 45 | ] |
46 | 46 | }, |
| 47 | + { |
| 48 | + "category": "operator", |
| 49 | + "description": "should wrap operators with the same precedence in parenthesis when needed", |
| 50 | + "tests": [ |
| 51 | + { "input": ["multiply", 2, 3, 4], "output": "2 * 3 * 4" }, |
| 52 | + { "input": ["multiply", ["multiply", 2, 3], 4], "output": "2 * 3 * 4" }, |
| 53 | + { "input": ["multiply", 2, ["multiply", 3, 4]], "output": "2 * (3 * 4)" }, |
| 54 | + { "input": ["divide", 2, 3, 4], "output": "2 / 3 / 4" }, |
| 55 | + { "input": ["divide", ["divide", 2, 3], 4], "output": "2 / 3 / 4" }, |
| 56 | + { "input": ["divide", 2, ["divide", 3, 4]], "output": "2 / (3 / 4)" }, |
| 57 | + { "input": ["divide", ["multiply", 2, 3], 4], "output": "2 * 3 / 4" }, |
| 58 | + { "input": ["divide", 2, ["multiply", 3, 4]], "output": "2 / (3 * 4)" }, |
| 59 | + { "input": ["divide", 2, 3, ["multiply", 4, 5]], "output": "2 / 3 / (4 * 5)" }, |
| 60 | + { |
| 61 | + "input": ["divide", 2, ["multiply", 3, 4], ["multiply", 5, 6]], |
| 62 | + "output": "2 / (3 * 4) / (5 * 6)" |
| 63 | + }, |
| 64 | + { "input": ["multiply", ["divide", 2, 3], 4], "output": "2 / 3 * 4" }, |
| 65 | + { "input": ["mod", 2, 3, 4], "output": "2 % 3 % 4" }, |
| 66 | + { "input": ["mod", ["mod", 2, 3], 4], "output": "2 % 3 % 4" }, |
| 67 | + { "input": ["mod", 2, ["mod", 3, 4]], "output": "2 % (3 % 4)" }, |
| 68 | + { "input": ["mod", ["multiply", 2, 3], 4], "output": "2 * 3 % 4" }, |
| 69 | + { "input": ["multiply", ["mod", 2, 3], 4], "output": "2 % 3 * 4" }, |
| 70 | + { "input": ["add", 2, 3, 4], "output": "2 + 3 + 4" }, |
| 71 | + { "input": ["add", ["add", 2, 3], 4], "output": "2 + 3 + 4" }, |
| 72 | + { "input": ["add", 2, ["add", 3, 4]], "output": "2 + (3 + 4)" }, |
| 73 | + { "input": ["subtract", 2, 3, 4], "output": "2 - 3 - 4" }, |
| 74 | + { "input": ["subtract", ["subtract", 2, 3], 4], "output": "2 - 3 - 4" }, |
| 75 | + { "input": ["subtract", 2, ["subtract", 3, 4]], "output": "2 - (3 - 4)" }, |
| 76 | + { "input": ["subtract", ["add", 2, 3], 4], "output": "2 + 3 - 4" }, |
| 77 | + { "input": ["subtract", 2, ["add", 3, 4]], "output": "2 - (3 + 4)" }, |
| 78 | + { "input": ["add", ["subtract", 2, 3], 4], "output": "2 - 3 + 4" } |
| 79 | + ] |
| 80 | + }, |
47 | 81 | { |
48 | 82 | "category": "operator", |
49 | 83 | "description": "should wrap operators with differing precedence in parenthesis when needed", |
|
67 | 101 | }, |
68 | 102 | { |
69 | 103 | "category": "operator", |
70 | | - "description": "should wrap operators with the same precedence in parenthesis when needed (must maintain original JSON structure when parsing again)", |
| 104 | + "description": "should wrap operators in without vararg support in parenthesis", |
71 | 105 | "tests": [ |
72 | | - { "input": ["add", ["add", 2, 3], 4], "output": "(2 + 3) + 4" }, |
73 | | - { "input": ["add", ["subtract", 2, 3], 4], "output": "2 - 3 + 4" }, |
74 | | - { "input": ["add", 2, ["subtract", 3, 4]], "output": "2 + (3 - 4)" }, |
75 | | - { "input": ["add", 2, ["add", 3, 4]], "output": "2 + (3 + 4)" }, |
76 | | - { "input": ["subtract", ["subtract", 2, 3], 4], "output": "(2 - 3) - 4" }, |
77 | | - { "input": ["subtract", ["add", 2, 3], 4], "output": "2 + 3 - 4" }, |
78 | | - { "input": ["subtract", 2, ["add", 3, 4]], "output": "2 - (3 + 4)" }, |
79 | | - { "input": ["subtract", 2, ["subtract", 3, 4]], "output": "2 - (3 - 4)" }, |
80 | | - { "input": ["multiply", ["multiply", 2, 3], 4], "output": "(2 * 3) * 4" }, |
81 | | - { "input": ["multiply", ["divide", 2, 3], 4], "output": "2 / 3 * 4" }, |
82 | | - { "input": ["multiply", ["mod", 2, 3], 4], "output": "2 % 3 * 4" }, |
83 | | - { "input": ["multiply", 2, ["multiply", 3, 4]], "output": "2 * (3 * 4)" }, |
84 | | - { "input": ["divide", ["divide", 2, 3], 4], "output": "(2 / 3) / 4" }, |
85 | | - { "input": ["divide", ["multiply", 2, 3], 4], "output": "2 * 3 / 4" }, |
86 | | - { "input": ["divide", 2, ["divide", 3, 4]], "output": "2 / (3 / 4)" }, |
87 | | - { "input": ["divide", 2, ["multiply", 3, 4]], "output": "2 / (3 * 4)" }, |
88 | | - { "input": ["mod", ["mod", 2, 3], 4], "output": "(2 % 3) % 4" }, |
89 | | - { "input": ["mod", ["multiply", 2, 3], 4], "output": "2 * 3 % 4" }, |
90 | | - { "input": ["mod", ["divide", 2, 3], 4], "output": "2 / 3 % 4" }, |
91 | | - { "input": ["mod", 2, ["multiply", 3, 4]], "output": "2 % (3 * 4)" }, |
92 | | - { "input": ["mod", 2, ["mod", 3, 4]], "output": "2 % (3 % 4)" } |
| 106 | + { "input": ["pow", ["pow", 2, 3], 4], "output": "(2 ^ 3) ^ 4" }, |
| 107 | + { "input": ["pow", 2, ["pow", 3, 4]], "output": "2 ^ (3 ^ 4)" } |
93 | 108 | ] |
94 | 109 | }, |
95 | 110 | { |
|
108 | 123 | { "input": ["mod", 2, 3, 4], "output": "2 % 3 % 4" } |
109 | 124 | ] |
110 | 125 | }, |
111 | | - { |
112 | | - "category": "operator", |
113 | | - "description": "should wrap operators in parenthesis when needed because of a lack of vararg support", |
114 | | - "tests": [ |
115 | | - { "input": ["pow", ["pow", 2, 3], 4], "output": "(2 ^ 3) ^ 4" }, |
116 | | - { "input": ["pow", 2, ["pow", 3, 4]], "output": "2 ^ (3 ^ 4)" } |
117 | | - ] |
118 | | - }, |
119 | 126 | { |
120 | 127 | "category": "operator", |
121 | 128 | "description": "should stringify a custom operator", |
|
0 commit comments