Skip to content

Commit

Permalink
Merge pull request #353 from moonbitlang/moonfmt-cli-interface
Browse files Browse the repository at this point in the history
internal: track interfaces of moonfmt cli
  • Loading branch information
lijunchen authored Sep 29, 2024
2 parents 2c2079e + d039aa6 commit 989f4d4
Showing 1 changed file with 72 additions and 0 deletions.
72 changes: 72 additions & 0 deletions crates/moon/tests/test_cases/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6771,3 +6771,75 @@ fn test_bad_version() {
"#]],
);
}

#[test]
fn test_moonfmt() {
let dir = TestDir::new("general.in");
let oneline = r#"pub fn hello() -> String { "Hello, world!" }"#;

std::fs::write(dir.join("src/lib/hello.mbt"), oneline).unwrap();

let out = std::process::Command::new("moonfmt")
.args(["./src/lib/hello.mbt"])
.current_dir(&dir)
.output()
.unwrap();
let out = replace_crlf_to_lf(&String::from_utf8(out.stdout).unwrap());
check(
&out,
expect![[r#"
pub fn hello() -> String {
"Hello, world!"
}
"#]],
);

check(
&read(&dir.join("src/lib/hello.mbt")),
expect![[r#"pub fn hello() -> String { "Hello, world!" }"#]],
);

let out = std::process::Command::new("moonfmt")
.args(["-i", "./src/lib/hello.mbt"])
.current_dir(&dir)
.output()
.unwrap();
let _ = String::from_utf8(out.stdout).unwrap();
check(
&read(&dir.join("src/lib/hello.mbt")),
expect![[r#"
pub fn hello() -> String {
"Hello, world!"
}
"#]],
);

std::fs::write(dir.join("src/lib/hello.mbt"), oneline).unwrap();
check(
&read(&dir.join("src/lib/hello.mbt")),
expect![[r#"pub fn hello() -> String { "Hello, world!" }"#]],
);

let out = std::process::Command::new("moonfmt")
.args(["-i", "./src/lib/hello.mbt", "-o", "./src/lib/hello.txt"])
.current_dir(&dir)
.output()
.unwrap();
let _ = String::from_utf8(out.stdout).unwrap();
check(
&read(&dir.join("src/lib/hello.mbt")),
expect![[r#"
pub fn hello() -> String {
"Hello, world!"
}
"#]],
);
check(
&read(&dir.join("src/lib/hello.txt")),
expect![[r#"
pub fn hello() -> String {
"Hello, world!"
}
"#]],
);
}

0 comments on commit 989f4d4

Please sign in to comment.