Skip to content
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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

amomchilov
Copy link

Add specifications for all the reserved keywords, documenting which of them can be used as:

  1. local variables
  2. instance variables
  3. global variables
  4. positional parameter names
  5. keyword parameter names
  6. method names

Comment on lines +4 to +5
# Copied from Prism::Translation::Ripper
keywords = [
Copy link
Author

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:

  1. spec/ruby/language/hash_spec.rb
  2. spec/ruby/language/reserved_keywords.rb
  3. lib/prism/translation/ripper.rb
  4. 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?

Copy link
Member

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)
Copy link
Member

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)
Copy link
Member

@eregon eregon Jul 31, 2024

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.

Copy link
Member

@eregon eregon left a 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants