Skip to content

Commit

Permalink
Merge pull request #518 from rami3l/fix/formatted-embed
Browse files Browse the repository at this point in the history
fix(tool): add `///|` before embedded toplevels
  • Loading branch information
Young-Flash authored Dec 9, 2024
2 parents 1d66b67 + 44553cc commit 2848796
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 20 deletions.
14 changes: 10 additions & 4 deletions crates/moon/src/cli/tool/embed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,11 @@ pub fn run_embed_text(cmd: Embed) -> anyhow::Result<i32> {
let input = std::fs::read_to_string(&cmd.input)?;
let name = cmd.name.unwrap_or_else(|| "resource".to_string());
let mut content = format!(
"// Generated by `moon tool embed --text`{}, do not edit.\n\n\
let {} : String =\n",
r#"// Generated by `moon tool embed --text`{}, do not edit.
///|
let {} : String =
"#,
if cmd.timestamp {
format!(" on {}", chrono::Local::now().format("%Y-%m-%d %H:%M:%S"))
} else {
Expand All @@ -60,8 +63,11 @@ pub fn run_embed_bin(cmd: Embed) -> anyhow::Result<i32> {
let input = std::fs::read(&cmd.input)?;
let name = cmd.name.unwrap_or_else(|| "resource".to_string());
let mut content = format!(
"// Generated by `moon tool embed --binary`{}, do not edit.\n\n\
let {} : Bytes = Bytes::of([\n",
r#"// Generated by `moon tool embed --binary`{}, do not edit.
///|
let {} : Bytes = Bytes::of([
"#,
if cmd.timestamp {
format!(" on {}", chrono::Local::now().format("%Y-%m-%d %H:%M:%S"))
} else {
Expand Down
35 changes: 19 additions & 16 deletions crates/moon/tests/test_cases/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7073,9 +7073,9 @@ fn test_pre_build() {
expect![[r#"
Executed 3 pre-build tasks, now up to date
Warning: [1002]
╭─[$ROOT/src/lib/a.mbt:3:5]
╭─[$ROOT/src/lib/a.mbt:4:5]
3 │ let resource : String =
4 │ let resource : String =
│ ────┬───
│ ╰───── Warning: Unused toplevel variable 'resource'. Note if the body contains side effect, it will not happen. Use `fn init { .. }` to wrap the effect.
───╯
Expand All @@ -7086,9 +7086,9 @@ fn test_pre_build() {
get_stderr(&dir, ["build"]),
expect![[r#"
Warning: [1002]
╭─[$ROOT/src/lib/a.mbt:3:5]
╭─[$ROOT/src/lib/a.mbt:4:5]
3 │ let resource : String =
4 │ let resource : String =
│ ────┬───
│ ╰───── Warning: Unused toplevel variable 'resource'. Note if the body contains side effect, it will not happen. Use `fn init { .. }` to wrap the effect.
───╯
Expand All @@ -7099,20 +7099,22 @@ fn test_pre_build() {
check(
read(dir.join("src/lib/a.mbt")),
expect![[r#"
// Generated by `moon tool embed --text`, do not edit.
// Generated by `moon tool embed --text`, do not edit.
let resource : String =
#|hello,
#|world
#|
"#]],
///|
let resource : String =
#|hello,
#|world
#|
"#]],
);
let content = read(dir.join("src/lib/b.mbt"));
check(
content,
expect![[r#"
// Generated by `moon tool embed --binary`, do not edit.
///|
let _b : Bytes = Bytes::of([
0x4d, 0x6f, 0x6f, 0x6e, 0x42, 0x69, 0x74, 0x20, 0x69, 0x73, 0x20, 0x61,
0x6e, 0x20, 0x65, 0x6e, 0x64, 0x2d, 0x74, 0x6f, 0x2d, 0x65, 0x6e, 0x64,
Expand Down Expand Up @@ -7140,13 +7142,14 @@ fn test_pre_build() {
check(
read(dir.join("src/lib/c.mbt")),
expect![[r#"
// Generated by `moon tool embed --text`, do not edit.
// Generated by `moon tool embed --text`, do not edit.
let _c : String =
#|hello,
#|world
#|
"#]],
///|
let _c : String =
#|hello,
#|world
#|
"#]],
);
}

Expand Down

0 comments on commit 2848796

Please sign in to comment.