summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorKevin Newton <kddnewton@gmail.com>2023-09-11 11:31:52 -0400
committergit <svn-admin@ruby-lang.org>2023-09-11 16:18:32 +0000
commit719f83446613f1e18f1a38cff0e00e7be88bbe14 (patch)
tree4d8a9bb90a13b24f93296f579d367393c2675822 /test
parent05a853c2f21f60f9e1c544c2d0709f10de453571 (diff)
[ruby/yarp] Mark flags as private
The flags integer is an implementation detail. We want people to use the query methods to access the individual fields so we are freed from having to maintain a specific order. As such, this commit changes the Ruby API to mark all flags fields as private attr_readers. The only one that has a clear use case is returning the set of options given to regular expressions, to mirror the Regexp#options API. So, to support this use case, this commit introduces RegularExpressionNode#options and InterpolatedRegularExpressionNode#options. These APIs provide back the same integer so that they can be used interchangeably. https://github.com/ruby/yarp/commit/4e6d5dd99f
Diffstat (limited to 'test')
-rw-r--r--test/yarp/regexp_test.rb23
1 files changed, 17 insertions, 6 deletions
diff --git a/test/yarp/regexp_test.rb b/test/yarp/regexp_test.rb
index 2fcc7d13f3..c2f92e2bd1 100644
--- a/test/yarp/regexp_test.rb
+++ b/test/yarp/regexp_test.rb
@@ -197,20 +197,20 @@ module YARP
##############################################################################
def test_flag_ignorecase
- assert_equal(Regexp::IGNORECASE, flags("i"))
+ assert_equal(Regexp::IGNORECASE, options("i"))
end
def test_flag_extended
- assert_equal(Regexp::EXTENDED, flags("x"))
+ assert_equal(Regexp::EXTENDED, options("x"))
end
def test_flag_multiline
- assert_equal(Regexp::MULTILINE, flags("m"))
+ assert_equal(Regexp::MULTILINE, options("m"))
end
def test_flag_combined
value = Regexp::IGNORECASE | Regexp::MULTILINE | Regexp::EXTENDED
- assert_equal(value, flags("mix"))
+ assert_equal(value, options("mix"))
end
private
@@ -219,8 +219,19 @@ module YARP
Debug.named_captures(source)
end
- def flags(str)
- YARP.parse("/foo/#{str}").value.child_nodes.first.child_nodes.first.flags
+ def options(flags)
+ options =
+ ["/foo/#{flags}", "/foo\#{1}/#{flags}"].map do |source|
+ YARP.parse(source).value.statements.body.first.options
+ end
+
+ # Check that we get the same set of options from both regular expressions
+ # and interpolated regular expressions.
+ assert_equal(1, options.uniq.length)
+
+ # Return the options from the first regular expression since we know they
+ # are the same.
+ options.first
end
end
end