Skip to content

Commit 4f45b74

Browse files
committed
test: add test case for convert_char_literal assist
1 parent b240b41 commit 4f45b74

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

src/tools/rust-analyzer/crates/ide-assists/src/handlers/convert_char_literal.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,47 @@ pub(crate) fn convert_char_literal(acc: &mut Assists, ctx: &AssistContext<'_>) -
4444

4545
Some(())
4646
}
47+
48+
#[cfg(test)]
49+
mod tests {
50+
use crate::tests::check_assist_by_label;
51+
52+
use super::convert_char_literal;
53+
54+
#[test]
55+
fn ascii_char_to_ascii_and_unicode() {
56+
let before = "const _: char = 'a'$0;";
57+
check_assist_by_label(
58+
convert_char_literal,
59+
before,
60+
"const _: char = '\\x61';",
61+
"Convert 'a' to '\\x61'",
62+
);
63+
check_assist_by_label(
64+
convert_char_literal,
65+
before,
66+
"const _: char = '\\u{61}';",
67+
"Convert 'a' to '\\u{61}'",
68+
);
69+
}
70+
71+
#[test]
72+
fn non_ascii_char_only_unicode() {
73+
check_assist_by_label(
74+
convert_char_literal,
75+
"const _: char = '😀'$0;",
76+
"const _: char = '\\u{1f600}';",
77+
"Convert '😀' to '\\u{1f600}'",
78+
);
79+
}
80+
81+
#[test]
82+
fn ascii_escape_can_convert_to_unicode() {
83+
check_assist_by_label(
84+
convert_char_literal,
85+
"const _: char = '\\x61'$0;",
86+
"const _: char = '\\u{61}';",
87+
"Convert '\\x61' to '\\u{61}'",
88+
);
89+
}
90+
}

0 commit comments

Comments
 (0)