summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorThomas Lively <tlively@google.com>2024-02-06 13:35:29 -0800
committerGitHub <noreply@github.com>2024-02-06 13:35:29 -0800
commit8cce4d103a2ee54e7f09e81fc25b982b060d0e41 (patch)
treebfea5d74173a307b5e802cbbaeb4284f12894dc1 /test
parent41b365e99ffd68f427b561121c364028f2c2d2f9 (diff)
downloadbinaryen-8cce4d103a2ee54e7f09e81fc25b982b060d0e41.tar.gz
binaryen-8cce4d103a2ee54e7f09e81fc25b982b060d0e41.tar.bz2
binaryen-8cce4d103a2ee54e7f09e81fc25b982b060d0e41.zip
[Parser] Support string-style identifiers (#6278)
In addition to normal identifiers, support parsing identifiers of the format `$"..."`. This format is not yet allowed by the standard, but it is a popular proposed extension (see https://github.com/WebAssembly/spec/issues/617 and https://github.com/WebAssembly/annotations/issues/21). Binaryen has historically allowed a similar format and has supported arbitrary non-standard identifier characters, so it's much easier to support this extended syntax than to fix everything to use the restricted standard syntax.
Diffstat (limited to 'test')
-rw-r--r--test/gtest/wat-lexer.cpp27
-rw-r--r--test/lit/wat-kitchen-sink.wast11
2 files changed, 35 insertions, 3 deletions
diff --git a/test/gtest/wat-lexer.cpp b/test/gtest/wat-lexer.cpp
index b46f9927f..b62644682 100644
--- a/test/gtest/wat-lexer.cpp
+++ b/test/gtest/wat-lexer.cpp
@@ -1377,6 +1377,33 @@ TEST(LexerTest, LexIdent) {
Lexer lexer("$"sv);
EXPECT_TRUE(lexer.empty());
}
+
+ // String IDs
+ {
+ Lexer lexer("$\"\"");
+ ASSERT_FALSE(lexer.empty());
+ Token expected{"$\"\""sv, IdTok{true, std::nullopt}};
+ EXPECT_EQ(*lexer, expected);
+ EXPECT_TRUE(lexer->getID());
+ EXPECT_EQ(*lexer->getID(), ""sv);
+ }
+ {
+ Lexer lexer("$\"hello\"");
+ ASSERT_FALSE(lexer.empty());
+ Token expected{"$\"hello\""sv, IdTok{true, std::nullopt}};
+ EXPECT_EQ(*lexer, expected);
+ EXPECT_TRUE(lexer->getID());
+ EXPECT_EQ(*lexer->getID(), "hello"sv);
+ }
+ {
+ // _$_£_€_𐍈_
+ auto unicode = "$\"_\\u{24}_\\u{00a3}_\\u{20AC}_\\u{10348}_\""sv;
+ Lexer lexer(unicode);
+ ASSERT_FALSE(lexer.empty());
+ std::string escaped{"_$_\xC2\xA3_\xE2\x82\xAC_\xF0\x90\x8D\x88_"};
+ Token expected{unicode, IdTok{true, {escaped}}};
+ EXPECT_EQ(*lexer, expected);
+ }
}
TEST(LexerTest, LexString) {
diff --git a/test/lit/wat-kitchen-sink.wast b/test/lit/wat-kitchen-sink.wast
index 1ab8e7516..32a70d913 100644
--- a/test/lit/wat-kitchen-sink.wast
+++ b/test/lit/wat-kitchen-sink.wast
@@ -380,7 +380,7 @@
;; CHECK: (elem $passive-2 anyref (struct.new_default $s0) (struct.new_default $s0))
(elem $passive-2 anyref (item struct.new $s0) (struct.new $s0))
- ;; CHECK: (elem declare func $ref-func $ref-is-null $table-fill $table-grow $table-set)
+ ;; CHECK: (elem declare func $ref-func $table-fill $table-grow $table-set)
(elem declare func 0 1 2 3)
(elem $declare-2 declare funcref (item ref.func 0) (ref.func 1) (item (ref.func 2)))
@@ -467,6 +467,11 @@
;; CHECK-NEXT: )
(func $f4 (type 18) (local i32 i64) (local $l f32))
+ ;; CHECK: (func $"[quoted_name]" (type $void)
+ ;; CHECK-NEXT: (nop)
+ ;; CHECK-NEXT: )
+ (func $"[quoted_name]")
+
;; CHECK: (func $nop-skate (type $void)
;; CHECK-NEXT: (nop)
;; CHECK-NEXT: (nop)
@@ -3622,13 +3627,13 @@
;; CHECK-NEXT: (ref.func $ref-func)
;; CHECK-NEXT: )
;; CHECK-NEXT: (drop
- ;; CHECK-NEXT: (ref.func $ref-is-null)
+ ;; CHECK-NEXT: (ref.func $ref-func)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
(func $ref-func
ref.func $ref-func
drop
- ref.func 154
+ ref.func 156
drop
)