-
-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add handle recursive expressions #25
Changes from all commits
fefd23a
1b3cab3
50c8173
bcf25e1
b096ae6
5adc7cc
0cc5dd3
6a78aca
51f9230
53be82f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,47 @@ metatests.test('Expression chain', async (test) => { | |
test.end(); | ||
}); | ||
|
||
metatests.test('Recursive expressions', async (test) => { | ||
const sheet = new Sheet(); | ||
sheet.cells['A1'] = 100; | ||
sheet.cells['B1'] = 2; | ||
sheet.cells['C1'] = '= A1 *E1'; | ||
sheet.cells['D1'] = '=C1+8'; | ||
sheet.cells['E1'] = '=D1/2'; | ||
|
||
try { | ||
test.strictSame(sheet.values['D1'], 208); | ||
} catch (error) { | ||
test.strictSame(error.constructor.name === 'Error', true); | ||
test.strictSame(error.message, 'Recursive expression error'); | ||
} | ||
|
||
try { | ||
test.strictSame(sheet.values['E1'], 104); | ||
} catch (error) { | ||
test.strictSame(error.constructor.name === 'Error', true); | ||
test.strictSame(error.message, 'Recursive expression error'); | ||
} | ||
test.end(); | ||
}); | ||
|
||
metatests.test( | ||
'Exit from recursive expression use Math.random', | ||
async (test) => { | ||
const sheet = new Sheet(); | ||
sheet.cells['A1'] = 100; | ||
sheet.cells['B1'] = 2; | ||
sheet.cells['C1'] = '=Math.round(Math.random()) ? A1 * E1 : 5'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Exit from recursive expression use Math.random ........ 0/1
not ok fail
--- wanted
+++ found
-[null]
+{
+ "message": "Recursive expression error"
+ "name": "Error"
+ "stack": "Error: Recursive expression error There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, ok, thanks There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
How we can change cell's value? @tshemsedinov |
||
sheet.cells['D1'] = '=C1+8'; | ||
sheet.cells['E1'] = '=D1/2'; | ||
|
||
const D1 = sheet.values['D1']; | ||
test.strictSame(!(D1 & 0) || D1 === 13, true); | ||
|
||
test.end(); | ||
}, | ||
); | ||
|
||
metatests.test('JavaScript Math', async (test) => { | ||
const sheet = new Sheet(); | ||
sheet.cells['A1'] = 100; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.