Preserve escape sequence after formatting
Bumped into this randomly. We do correctly parse escape sequence, but the format would simply but the unescaped string back on save. Now it properly re-escapes strings before flushing them back. I also removed the escape sequence for 'backspace' and 'new page' form feed as I don't see any use case for those in an Aiken program really...
This commit is contained in:
@@ -393,6 +393,20 @@ fn format_bytearray_literals() {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn escaped_utf8() {
|
||||
assert_format!(
|
||||
r#"
|
||||
const escaped_1 = "\"my_string\""
|
||||
const escaped_2 = "foo\nbar"
|
||||
const escaped_3 = "foo\rbar"
|
||||
const escaped_4 = "foo\tbar"
|
||||
const escaped_5 = "1/2"
|
||||
const escaped_6 = "1//2"
|
||||
"#
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn format_string_literal() {
|
||||
assert_format!(
|
||||
|
||||
16
crates/aiken-lang/src/tests/snapshots/escaped_utf8.snap
Normal file
16
crates/aiken-lang/src/tests/snapshots/escaped_utf8.snap
Normal file
@@ -0,0 +1,16 @@
|
||||
---
|
||||
source: crates/aiken-lang/src/tests/format.rs
|
||||
description: "Code:\n\nconst escaped_1 = \"\\\"my_string\\\"\"\nconst escaped_2 = \"foo\\nbar\"\nconst escaped_3 = \"foo\\rbar\"\nconst escaped_4 = \"foo\\tbar\"\nconst escaped_5 = \"1/2\"\nconst escaped_6 = \"1//2\"\n"
|
||||
---
|
||||
const escaped_1 = "\"my_string\""
|
||||
|
||||
const escaped_2 = "foo\nbar"
|
||||
|
||||
const escaped_3 = "foo\rbar"
|
||||
|
||||
const escaped_4 = "foo\tbar"
|
||||
|
||||
const escaped_5 = "1/2"
|
||||
|
||||
const escaped_6 = "1//2"
|
||||
|
||||
Reference in New Issue
Block a user