Repository: ruby/yarp
Pull request #1437 (2023-09-11 11:15:16)

Fix Regexp flag order
This fixes the flag values so they match MRI:

```ruby
irb(main):001:0> Regexp::IGNORECASE
=> 1
irb(main):002:0> Regexp::EXTENDED
=> 2
irb(main):003:0> Regexp::MULTILINE
=> 4
```



Patch:
diff --git a/config.yml b/config.yml
index e63c2bb8..1d96410f 100644
--- a/config.yml
+++ b/config.yml
@@ -345,10 +345,10 @@ flags:
     values:
       - name: IGNORE_CASE
         comment: "i - ignores the case of characters when matching"
-      - name: MULTI_LINE
-        comment: "m - allows $ to match the end of lines within strings"
       - name: EXTENDED
         comment: "x - ignores whitespace and allows comments in regular expressions"
+      - name: MULTI_LINE
+        comment: "m - allows $ to match the end of lines within strings"
       - name: EUC_JP
         comment: "e - forces the EUC-JP encoding"
       - name: ASCII_8BIT


Test patch:
diff --git a/test/yarp/regexp_test.rb b/test/yarp/regexp_test.rb
index 9863a547..2fcc7d13 100644
--- a/test/yarp/regexp_test.rb
+++ b/test/yarp/regexp_test.rb
@@ -192,10 +192,35 @@ module YARP
       refute_nil(named_captures("foo{1, 2}"))
     end
 
+    ##############################################################################
+    # These test that flag values are correct.
+    ##############################################################################
+
+    def test_flag_ignorecase
+      assert_equal(Regexp::IGNORECASE, flags("i"))
+    end
+
+    def test_flag_extended
+      assert_equal(Regexp::EXTENDED, flags("x"))
+    end
+
+    def test_flag_multiline
+      assert_equal(Regexp::MULTILINE, flags("m"))
+    end
+
+    def test_flag_combined
+      value = Regexp::IGNORECASE | Regexp::MULTILINE | Regexp::EXTENDED
+      assert_equal(value, flags("mix"))
+    end
+
     private
 
     def named_captures(source)
       Debug.named_captures(source)
     end
+
+    def flags(str)
+      YARP.parse("/foo/#{str}").value.child_nodes.first.child_nodes.first.flags
+    end
   end
 end
diff --git a/test/yarp/snapshots/seattlerb/regexp.txt b/test/yarp/snapshots/seattlerb/regexp.txt
index 122d26a2..f642008b 100644
--- a/test/yarp/snapshots/seattlerb/regexp.txt
+++ b/test/yarp/snapshots/seattlerb/regexp.txt
@@ -2,7 +2,7 @@ ProgramNode(0...45)(
   [],
   StatementsNode(0...45)(
     [RegularExpressionNode(0...5)((0...1), (1...4), (4...5), "wtf", 0),
-     RegularExpressionNode(7...13)((7...8), (8...11), (11...13), "wtf", 2),
+     RegularExpressionNode(7...13)((7...8), (8...11), (11...13), "wtf", 4),
      RegularExpressionNode(15...21)(
        (15...16),
        (16...19),
@@ -15,14 +15,14 @@ ProgramNode(0...45)(
        (24...27),
        (27...30),
        "wtf",
-       18
+       20
      ),
      RegularExpressionNode(32...45)(
        (32...33),
        (33...36),
        (36...45),
        "wtf",
-       18
+       20
      )]
   )
 )
diff --git a/test/yarp/snapshots/unparser/corpus/literal/literal.txt b/test/yarp/snapshots/unparser/corpus/literal/literal.txt
index 8af9ea3c..0a77cb7f 100644
--- a/test/yarp/snapshots/unparser/corpus/literal/literal.txt
+++ b/test/yarp/snapshots/unparser/corpus/literal/literal.txt
@@ -359,14 +359,14 @@ ProgramNode(0...916)(
        (569...571),
        (571...573),
        "\n",
-       4
+       2
      ),
      RegularExpressionNode(574...581)(
        (574...575),
        (575...579),
        (579...581),
        "//",
-       4
+       2
      ),
      InterpolatedSymbolNode(582...597)(
        (582...584),
diff --git a/test/yarp/snapshots/whitequark/bug_regex_verification.txt b/test/yarp/snapshots/whitequark/bug_regex_verification.txt
index e1fc0ec0..0c78794f 100644
--- a/test/yarp/snapshots/whitequark/bug_regex_verification.txt
+++ b/test/yarp/snapshots/whitequark/bug_regex_verification.txt
@@ -1,6 +1,6 @@
 ProgramNode(0...5)(
   [],
   StatementsNode(0...5)(
-    [RegularExpressionNode(0...5)((0...1), (1...3), (3...5), "#)", 4)]
+    [RegularExpressionNode(0...5)((0...1), (1...3), (3...5), "#)", 2)]
   )
 )
diff --git a/test/yarp/snapshots/whitequark/regex_plain.txt b/test/yarp/snapshots/whitequark/regex_plain.txt
index cf272806..695adbaf 100644
--- a/test/yarp/snapshots/whitequark/regex_plain.txt
+++ b/test/yarp/snapshots/whitequark/regex_plain.txt
@@ -1,6 +1,6 @@
 ProgramNode(0...10)(
   [],
   StatementsNode(0...10)(
-    [RegularExpressionNode(0...10)((0...1), (1...7), (7...10), "source", 3)]
+    [RegularExpressionNode(0...10)((0...1), (1...7), (7...10), "source", 5)]
   )
 )
diff --git a/test/yarp/snapshots/whitequark/ruby_bug_11873.txt b/test/yarp/snapshots/whitequark/ruby_bug_11873.txt
index 5c63deed..9c988bcf 100644
--- a/test/yarp/snapshots/whitequark/ruby_bug_11873.txt
+++ b/test/yarp/snapshots/whitequark/ruby_bug_11873.txt
@@ -149,7 +149,7 @@ ProgramNode(0...272)(
             (55...56),
             (56...58),
             "x",
-            2
+            4
           )]
        ),
        nil,
@@ -305,7 +305,7 @@ ProgramNode(0...272)(
             (125...126),
             (126...128),
             "x",
-            2
+            4
           )]
        ),
        nil,
@@ -479,7 +479,7 @@ ProgramNode(0...272)(
             (192...193),
             (193...195),
             "x",
-            2
+            4
           )]
        ),
        nil,
@@ -653,7 +653,7 @@ ProgramNode(0...272)(
             (262...263),
             (263...265),
             "x",
-            2
+            4
           )]
        ),
        nil,