Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: resolve escaped string formatting issue #3165

Merged
merged 4 commits into from Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions tooling/nargo_fmt/src/visitor/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ impl FmtVisitor<'_> {
format!("{}[{}]", formatted_collection, formatted_index)
}
ExpressionKind::Literal(literal) => match literal {
Literal::Integer(_) => slice!(self, span.start(), span.end()).to_string(),
Literal::Integer(_) | Literal::Bool(_) | Literal::Str(_) | Literal::FmtStr(_) => {
slice!(self, span.start(), span.end()).to_string()
}
Literal::Array(ArrayLiteral::Repeated { repeated_element, length }) => {
format!("[{}; {length}]", self.format_expr(*repeated_element))
}
Expand All @@ -100,10 +102,7 @@ impl FmtVisitor<'_> {
exprs.into_iter().map(|expr| self.format_expr(expr)).collect();
format!("[{}]", contents.join(", "))
}

Literal::Bool(_) | Literal::Str(_) | Literal::FmtStr(_) | Literal::Unit => {
literal.to_string()
}
Literal::Unit => "()".to_string(),
},
ExpressionKind::Parenthesized(mut sub_expr) => {
let remove_nested_parens = self.config.remove_nested_parens;
Expand Down
8 changes: 8 additions & 0 deletions tooling/nargo_fmt/tests/expected/literals.nr
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,13 @@ fn main() {

"hello world";

"hell\0\"world";

f"i: {i}, j: {j}";

();

(/*test*/);

()
}
8 changes: 8 additions & 0 deletions tooling/nargo_fmt/tests/input/literals.nr
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,13 @@ fn main() {

"hello world";

"hell\0\"world";

f"i: {i}, j: {j}";

( );

(/*test*/);

()
}
Loading