From a6e7d8670a1b9d36375172680b4e6c6138d0eb4a Mon Sep 17 00:00:00 2001 From: Roy Jacobs Date: Wed, 24 Mar 2021 15:06:53 +0100 Subject: [PATCH] Fix import formatting. Closes #99. --- src/formatting/mod.rs | 20 +++++++++++++++----- test/cli/format/valid-formatted.asm | 8 +++++++- test/cli/format/valid-unformatted.asm | 3 +++ 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/formatting/mod.rs b/src/formatting/mod.rs index cc3dc03..20fc6c5 100644 --- a/src/formatting/mod.rs +++ b/src/formatting/mod.rs @@ -521,10 +521,17 @@ impl CodeFormatter { fn format_specific_import_args(&mut self, args: &[ArgItem]) -> Fmt { let mut fmt = Fmt::new(); for (path, comma) in args { - fmt = fmt - .fmt(self, path.map(|p| p.to_string())) - .fmt(self, comma) - .spc_if_next(); + fmt = fmt.fmt(self, &path.data.path.map(|p| p.to_string())); + + if let Some((tag_as, id_as)) = &path.data.as_ { + fmt = fmt + .spc() + .fmt(self, tag_as) + .spc() + .fmt(self, &id_as.map(|p| p.to_string())); + } + + fmt = fmt.fmt(self, comma).spc_if_next(); } fmt } @@ -1052,7 +1059,10 @@ mod tests { } fn get_source(src: &str) -> Arc> { - InMemoryParsingSource::new().add("test.asm", src).into() + InMemoryParsingSource::new() + .add("test.asm", src) + .add("other.asm", "nop") + .into() } // Cross-platform eq diff --git a/test/cli/format/valid-formatted.asm b/test/cli/format/valid-formatted.asm index 089e51e..53b4eef 100644 --- a/test/cli/format/valid-formatted.asm +++ b/test/cli/format/valid-formatted.asm @@ -49,4 +49,10 @@ nop .macro MyMacro(arg1, arg2) { brk -} \ No newline at end of file +} + +.import foo as bar from "other.asm" { + nop +} + +.export data as boop diff --git a/test/cli/format/valid-unformatted.asm b/test/cli/format/valid-unformatted.asm index 5622f21..de70528 100644 --- a/test/cli/format/valid-unformatted.asm +++ b/test/cli/format/valid-unformatted.asm @@ -28,3 +28,6 @@ start=$2000 + 4 -%00100} nop .macro MyMacro(arg1,arg2){brk} + + .import foo as bar from "other.asm" {nop} + .export data as boop