-
Notifications
You must be signed in to change notification settings - Fork 174
Improve tests for slang rttc #45
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
Conversation
| return isBool(value) ? undefined : new TypeError(node, '', 'boolean', typeOf(value)) | ||
| default: | ||
| return | ||
| if ((operator === '+' || operator === '-') && !isNumber(value)) { |
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.
I feel like the switch case used previously is clearer, although simplifying the logic would help with more operators
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.
So the thing is that with the switch case, in order to get 100% test coverage there would need to be a call to checkUnaryExpression(context, ''. value). Otherwise, the default case would not be covered by the tests.
So assuming we want 100% test coverage, it was either that, or to change the switch case to the if/else here. Since there isn't much sense in checking for an empty operator, I decided to go with the latter instead.
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.
Can the default case be used to test for an unspecified unary operator (e.g delete or typeof)? If so, it can be meaningfully used
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.
That sounds like a good idea, tbh.
Unspecified operators are currently checked for in the linting step at at noUnspecifiedOperators. Checking the operators again during runtime seems redundant at first, but I feel like it's extra safety without any real performance hits.
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.
@evansb Can we check, what's the best practice here?
1. Had to make changes to src/mocks/context.ts in order to for the mock Closure to use the Closure constructor (our own typeOf uses typeof, which checks the constructor to determine object types). 2. To get 100% test coverage, there was a need to call the elaborate method of TypeError. Went ahead and replaced that with explain() since it's probably better than 'TODO'. 3. Best way to test the error messages was with snapshots, IMO. Resolves #38. * Fix typing Typescript thinks that errors could possible be undefined. * Add tests for valid binary <, >, <=, >= Also fixed the test title ('<==|>==' -> '<=|>=')
|
Had to do some git stuff to get github to mark this PR as merged after merging on the CLI. (refer to 1559e07 for the changes) |
|
Nevermind, it still marks this PR as closed instead of merged. |
* Add unspecified operators rule * Remove strict equality * Update error message slightly
Features
src/slang/utils/rttc.tstoBeUndefined,toBeInstanceOfIssues fixed