aboutsummaryrefslogtreecommitdiffstats
path: root/test/yarp
diff options
context:
space:
mode:
authorMike Dalessio <mike.dalessio@gmail.com>2023-09-15 21:17:37 -0400
committergit <svn-admin@ruby-lang.org>2023-09-19 16:14:31 +0000
commit0cda3ac45441a8325d40ab71074e93fe4c628c97 (patch)
tree379202ca03fbb559f6ed3f5fd8ddb8d824f7f779 /test/yarp
parentffc1fc7a6df2c5d8d9f85d4db7c19e8af6fb6682 (diff)
downloadruby-0cda3ac45441a8325d40ab71074e93fe4c628c97.tar.gz
[ruby/yarp] fix: handling escaped whitespace in a %w list
Introduces a new flavor of unescaping, YP_UNESCAPE_WHITESPACE, which is the same as MINIMAL but also unescapes whitespace. Note that a spanning_heredoc.txt fixture test is updated to be less wrong, but YARP's behavior doesn't yet fully match Ruby in this case. Fixes https://github.com/ruby/yarp/pull/1505 https://github.com/ruby/yarp/commit/0af69bdeb1
Diffstat (limited to 'test/yarp')
-rw-r--r--test/yarp/snapshots/spanning_heredoc.txt2
-rw-r--r--test/yarp/snapshots/strings.txt4
-rw-r--r--test/yarp/snapshots/whitequark/parser_slash_slash_n_escaping_in_literals.txt2
-rw-r--r--test/yarp/unescape_test.rb7
4 files changed, 11 insertions, 4 deletions
diff --git a/test/yarp/snapshots/spanning_heredoc.txt b/test/yarp/snapshots/spanning_heredoc.txt
index 63a9727927..591f4bbf7e 100644
--- a/test/yarp/snapshots/spanning_heredoc.txt
+++ b/test/yarp/snapshots/spanning_heredoc.txt
@@ -179,7 +179,7 @@
│ │ │ │ ├── opening_loc: ∅
│ │ │ │ ├── content_loc: (532...535) = "j\\\n"
│ │ │ │ ├── closing_loc: ∅
- │ │ │ │ └── unescaped: "j\\\n"
+ │ │ │ │ └── unescaped: "j\n"
│ │ │ └── @ StringNode (location: (539...540))
│ │ │ ├── flags: ∅
│ │ │ ├── opening_loc: ∅
diff --git a/test/yarp/snapshots/strings.txt b/test/yarp/snapshots/strings.txt
index ef08cb6994..0040191d3e 100644
--- a/test/yarp/snapshots/strings.txt
+++ b/test/yarp/snapshots/strings.txt
@@ -292,7 +292,7 @@
│ │ │ ├── opening_loc: ∅
│ │ │ ├── content_loc: (290...298) = "foo\\ bar"
│ │ │ ├── closing_loc: ∅
- │ │ │ └── unescaped: "foo\\ bar"
+ │ │ │ └── unescaped: "foo bar"
│ │ └── @ StringNode (location: (299...304))
│ │ ├── flags: ∅
│ │ ├── opening_loc: ∅
@@ -308,7 +308,7 @@
│ │ │ ├── opening_loc: ∅
│ │ │ ├── content_loc: (310...318) = "foo\\ bar"
│ │ │ ├── closing_loc: ∅
- │ │ │ └── unescaped: "foo\\ bar"
+ │ │ │ └── unescaped: "foo bar"
│ │ └── @ StringNode (location: (319...322))
│ │ ├── flags: ∅
│ │ ├── opening_loc: ∅
diff --git a/test/yarp/snapshots/whitequark/parser_slash_slash_n_escaping_in_literals.txt b/test/yarp/snapshots/whitequark/parser_slash_slash_n_escaping_in_literals.txt
index ae5873a7fa..ee11d2662c 100644
--- a/test/yarp/snapshots/whitequark/parser_slash_slash_n_escaping_in_literals.txt
+++ b/test/yarp/snapshots/whitequark/parser_slash_slash_n_escaping_in_literals.txt
@@ -67,7 +67,7 @@
│ │ ├── opening_loc: ∅
│ │ ├── content_loc: (81...85) = "a\\\nb"
│ │ ├── closing_loc: ∅
- │ │ └── unescaped: "a\\\nb"
+ │ │ └── unescaped: "a\nb"
│ ├── opening_loc: (78...81) = "%w{"
│ └── closing_loc: (85...86) = "}"
├── @ XStringNode (location: (88...96))
diff --git a/test/yarp/unescape_test.rb b/test/yarp/unescape_test.rb
index f39bdd0e39..a7d955b315 100644
--- a/test/yarp/unescape_test.rb
+++ b/test/yarp/unescape_test.rb
@@ -136,6 +136,13 @@ module YARP
assert_unescape_all("g", "\\g")
end
+ def test_whitespace_escaping_string_list
+ assert_equal("a b", Debug.unescape_whitespace("a\\ b"))
+ assert_equal("a\tb", Debug.unescape_whitespace("a\\\tb"))
+ assert_equal("a\nb", Debug.unescape_whitespace("a\\\nb"))
+ assert_equal("a\nb", Debug.unescape_whitespace("a\\\r\nb"))
+ end
+
private
def unescape_all(source)