-
-
Notifications
You must be signed in to change notification settings - Fork 389
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 specs for reserved keywords #1187
base: master
Are you sure you want to change the base?
Conversation
8908ead
to
2cc6546
Compare
# Copied from Prism::Translation::Ripper | ||
keywords = [ |
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.
TODO: It would be nice to have one canonical list that can be used in all these places:
spec/ruby/language/hash_spec.rb
spec/ruby/language/reserved_keywords.rb
lib/prism/translation/ripper.rb
- Ideally, it would also be nice to generate
doc/keywords.rdoc
from that list, to ensure that all keywords are documented.
Where should such a canonical list live?
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.
There is no way to avoid duplication there, since it's files in different repositories.
So for ruby/spec let's have it as a new file under language/fixtures
.
I think a %w[]
array would be nice for this BTW.
FWIW in ruby/ruby there is also defs/keywords
.
|
||
invalid_ivar_names = ["defined?"] | ||
|
||
if invalid_ivar_names.include?(kw) |
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.
if
outside examples like this are pretty much an anti-pattern in ruby/spec.
Same for looping around it
.
Instead, the loops should be inside the it
.
That also makes it easier to read, e.g. (keywords - %w[defined?]).each
.
|
||
# Evaluates the given Ruby source in a temporary Module, to prevent | ||
# the surrounding context from being polluted with the new methods. | ||
def sandboxed_eval(ruby_src) |
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.
This seems pretty expensive (creating a module for each keyword * spec examples).
Since in ruby/spec every file has its own separate Object instance as top-level self
, I think we don't need to worry about this can just define on the self
.
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.
Adding these specs seems good but they should match the existing style and structure of ruby/spec, I'll review in more details once it does.
Add specifications for all the reserved keywords, documenting which of them can be used as: