Skip to content

Commit

Permalink
Fix import formatting. Closes #99.
Browse files Browse the repository at this point in the history
  • Loading branch information
sagacity committed Mar 24, 2021
1 parent 8fcd161 commit a6e7d86
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
20 changes: 15 additions & 5 deletions src/formatting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -521,10 +521,17 @@ impl CodeFormatter {
fn format_specific_import_args(&mut self, args: &[ArgItem<SpecificImportArg>]) -> 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
}
Expand Down Expand Up @@ -1052,7 +1059,10 @@ mod tests {
}

fn get_source(src: &str) -> Arc<RefCell<dyn ParsingSource>> {
InMemoryParsingSource::new().add("test.asm", src).into()
InMemoryParsingSource::new()
.add("test.asm", src)
.add("other.asm", "nop")
.into()
}

// Cross-platform eq
Expand Down
8 changes: 7 additions & 1 deletion test/cli/format/valid-formatted.asm
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,10 @@ nop

.macro MyMacro(arg1, arg2) {
brk
}
}

.import foo as bar from "other.asm" {
nop
}

.export data as boop
3 changes: 3 additions & 0 deletions test/cli/format/valid-unformatted.asm
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit a6e7d86

Please sign in to comment.