Skip to content

Commit 5008880

Browse files
committed
test: refine Symbol::For conversion coverage
Signed-off-by: umuoy1 <burningdian@gmail.com>
1 parent 2e92c98 commit 5008880

1 file changed

Lines changed: 9 additions & 15 deletions

File tree

test/symbol.cc

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -41,23 +41,20 @@ struct StringReferenceLike {
4141
std::string_view viewValue;
4242
};
4343

44-
struct ImplicitStringViewLike {
45-
operator std::string_view() const { return value; }
44+
struct ImplicitAndExplicitStringViewLike {
45+
operator std::string() const { return "unexpected-string-key"; }
4646

47-
std::string_view value;
48-
};
47+
// Copy-initialization must ignore the explicit conversion below.
48+
// Direct-initialization would prefer it for a non-const lvalue.
49+
operator std::string_view() const& { return value; }
4950

50-
struct ExplicitStringViewLike {
51-
explicit operator std::string_view() const { return value; }
51+
explicit operator std::string_view() & {
52+
return "unexpected-explicit-string-view-key";
53+
}
5254

5355
std::string_view value;
5456
};
5557

56-
struct ImplicitAndExplicitStringViewLike : ImplicitStringViewLike,
57-
ExplicitStringViewLike {
58-
operator std::string() const { return "unexpected-string-key"; }
59-
};
60-
6158
} // namespace
6259

6360
Symbol CreateNewSymbolWithNoArgs(const Napi::CallbackInfo&) {
@@ -150,10 +147,7 @@ Symbol FetchSymbolFromGlobalRegistryWithStringReferenceKey(
150147
Symbol FetchSymbolFromGlobalRegistryWithImplicitViewKey(
151148
const Napi::CallbackInfo& info) {
152149
std::string value = info[0].As<String>().Utf8Value();
153-
ImplicitAndExplicitStringViewLike key;
154-
static_cast<ImplicitStringViewLike&>(key).value = value;
155-
static_cast<ExplicitStringViewLike&>(key).value =
156-
"unexpected-explicit-string-view-key";
150+
ImplicitAndExplicitStringViewLike key{value};
157151
return MaybeUnwrap(Symbol::For(info.Env(), key));
158152
}
159153

0 commit comments

Comments
 (0)