mirror of
https://github.com/zaphar/ucg.git
synced 2025-07-22 18:19:54 -04:00
FEATURE: Improvements to func expression pretty printing.
This commit is contained in:
parent
0d78438c2a
commit
9b99bc026c
@ -271,8 +271,14 @@ where
|
|||||||
}
|
}
|
||||||
Expression::Func(_def) => {
|
Expression::Func(_def) => {
|
||||||
self.w.write("func (".as_bytes())?;
|
self.w.write("func (".as_bytes())?;
|
||||||
for n in _def.argdefs.iter() {
|
if _def.argdefs.len() == 1 {
|
||||||
write!(self.w, "{}, ", n.val)?;
|
write!(self.w, "{}", _def.argdefs.first().unwrap())?;
|
||||||
|
} else {
|
||||||
|
let mut prefix = "";
|
||||||
|
for n in _def.argdefs.iter() {
|
||||||
|
write!(self.w, "{}{}", prefix, n.val)?;
|
||||||
|
prefix = ", ";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
self.w.write(") => ".as_bytes())?;
|
self.w.write(") => ".as_bytes())?;
|
||||||
self.render_expr(&_def.fields)?;
|
self.render_expr(&_def.fields)?;
|
||||||
|
@ -306,3 +306,30 @@ fn test_module_with_out_expr_printing() {
|
|||||||
assert!(printer.err.is_none());
|
assert!(printer.err.is_none());
|
||||||
assert_eq!(String::from_utf8(buffer).unwrap(), format!("{}\n", input));
|
assert_eq!(String::from_utf8(buffer).unwrap(), format!("{}\n", input));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_func_expr_printing() {
|
||||||
|
let input = "let f = func (foo, bar) => {
|
||||||
|
foo = foo,
|
||||||
|
bar = bar,
|
||||||
|
};";
|
||||||
|
let stmts = assert_parse(input);
|
||||||
|
let mut buffer: Vec<u8> = Vec::new();
|
||||||
|
let mut printer = AstPrinter::new(2, &mut buffer);
|
||||||
|
printer.render(&stmts);
|
||||||
|
assert!(printer.err.is_none());
|
||||||
|
assert_eq!(String::from_utf8(buffer).unwrap(), format!("{}\n", input));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_func_expr_single_arg_printing() {
|
||||||
|
let input = "let f = func (foo) => {
|
||||||
|
foo = foo,
|
||||||
|
};";
|
||||||
|
let stmts = assert_parse(input);
|
||||||
|
let mut buffer: Vec<u8> = Vec::new();
|
||||||
|
let mut printer = AstPrinter::new(2, &mut buffer);
|
||||||
|
printer.render(&stmts);
|
||||||
|
assert!(printer.err.is_none());
|
||||||
|
assert_eq!(String::from_utf8(buffer).unwrap(), format!("{}\n", input));
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user