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

Implement remaining tests for $if directive #584

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

smmr0
Copy link

@smmr0 smmr0 commented Aug 20, 2023

The remaining tests are mode, term, version, and variable.

Links:


It looks like there were plans to implement these tests, but those plans were abandoned.

@@ -1,3 +1,4 @@
module Reline
VERSION = '0.3.8'
COMPATIBLE_READLINE_VERSION = '8.2'
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is needed for the version test. I put the current version of Readline here, but I can't really say whether Reline is truly compatible with this version. Additionally, this will have to be kept up-to-date as necessary in order to properly support the version test.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the description.

whether Reline is truly compatible with this version

The first goal is to make $if version directive work, and I think we can't say we officially support 8.2. It's better to define this in config.rb as a private constant for now.

class Reline::Config
  ...
  COMPATIBLE_READLINE_VERSION = '8.0'
  private_constant : COMPATIBLE_READLINE_VERSION
end

For now, I think specifying major version 8.0 is better. (Until checking Reline really supports feature added between 8.0 and 8.2)

@@ -227,18 +239,36 @@ def read_lines(lines, file = nil)
end

def handle_directive(directive, file, no)
directive, args = directive.split(' ')
directive, args = directive.split(/\s+/, 2)
args, _comment = args.split(/\s+#\s*/, 2) if args
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Readline only supports /^#.*/ style comment and /^\$if\s+version[comparator][value]\s*#.*/ style comment.
It may look like supporting comment, but as far as readling gnu readline source code, it does not. $if mode = foo # comment is same as $if mode=foo garbage.

elsif %w[Ruby Reline].include?(args) # application name
true
elsif %w[= == !=].include?(stripped_operator) # variable
parse_variable(lhs, rhs).all? do |var_name, rhs_value|
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

parse_variable might return nil, it wrongly compares variables which readline does not.
I think validating lhs and then directly compare to instance variable is enough.

if VARIABLE_NAMES.include?(lhs) && get_value_as_string(lhs) == rhs.downcase
# readline 8.2

# on will set bell-style to audible
set bell-style on
# this is evaluated to true
$if bell-style = audible
# this is evaluated to false. "audible" != "on"
$if bell-style = on

# invalid value will set to off
set colored-completion-prefix on
set colored-completion-prefix offfff
# evaluated to true.
$if colored-completion-prefix = off
# evaluated to false because "off" != "offfff"
$if colored-completion-prefix = offfff

@@ -256,81 +286,103 @@ def handle_directive(directive, file, no)
end
end

def bind_variable(name, value)
def parse_variable(name, value)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you revert this change? I think this change is not needed.
I added a comment where parse_variable is used.

@@ -1,3 +1,4 @@
module Reline
VERSION = '0.3.8'
COMPATIBLE_READLINE_VERSION = '8.2'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the description.

whether Reline is truly compatible with this version

The first goal is to make $if version directive work, and I think we can't say we officially support 8.2. It's better to define this in config.rb as a private constant for now.

class Reline::Config
  ...
  COMPATIBLE_READLINE_VERSION = '8.0'
  private_constant : COMPATIBLE_READLINE_VERSION
end

For now, I think specifying major version 8.0 is better. (Until checking Reline really supports feature added between 8.0 and 8.2)

condition = true if args == 'Reline'
end
lhs, operator, rhs = args.partition(/\s*(==|=|!=|<=|>=|<|>)\s*/)
stripped_operator = $1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think stripped_operator is not needed. operator is enough.

@ima1zumi
Copy link
Member

@smmr0 Hi. Just checking in on this PR since it's been quiet for a while. Do you plan to continue working on it? If not, I'd be happy to take over. Let me know!

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.

None yet

3 participants