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:
KtorZ
2023-09-08 12:12:11 +02:00
parent 5cfc3de7bf
commit 8ba5946c32
7 changed files with 74 additions and 6 deletions

View File

@@ -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!(

View 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"