1
1
mirror of https://github.com/tweag/nickel.git synced 2024-09-21 00:19:57 +03:00

Double quote simple strings in the pretty printer

The pretty printer neglected to double quote strings appearing as
`Term::Str` in terms. This change adds double quoting together with a
test to ensure parity with `StrChunks` pretty printing.
This commit is contained in:
Viktor Kleen 2022-10-04 15:52:14 +00:00
parent 5fdb8155eb
commit 69bbafa032
No known key found for this signature in database
2 changed files with 10 additions and 2 deletions

View File

@ -261,7 +261,7 @@ where
Null => allocator.text("null"),
Bool(v) => allocator.as_string(v),
Num(v) => allocator.as_string(v),
Str(v) => allocator.escaped_string(v),
Str(v) => allocator.escaped_string(v).double_quotes(),
StrChunks(chunks) => {
let multiline = chunks.len() > 1;
let nb_perc = chunks

View File

@ -1,5 +1,5 @@
use nickel_lang::pretty::*;
use nickel_lang::term::RichTerm;
use nickel_lang::term::{RichTerm, StrChunk, Term};
use nickel_lang_utilities::parse;
use pretty::BoxAllocator;
@ -138,3 +138,11 @@ fn importing() {
fn overriding() {
check_file("overriding.ncl");
}
#[test]
fn str_vs_strchunks() {
assert_eq!(
pretty(&Term::Str("string".to_string()).into()),
pretty(&Term::StrChunks(vec![StrChunk::Literal("string".to_string())]).into())
);
}