From a6fc0fc6f2ee61d7ec2299d01afd37c842119b56 Mon Sep 17 00:00:00 2001 From: bwireman Date: Sat, 20 Jul 2024 12:18:28 -0500 Subject: [PATCH] add erlang version of template test --- src/cactus/write.gleam | 3 ++- test/write_test.gleam | 48 ++++++++++++++++++------------------------ 2 files changed, 23 insertions(+), 28 deletions(-) diff --git a/src/cactus/write.gleam b/src/cactus/write.gleam index 5cef6cf..be499f4 100644 --- a/src/cactus/write.gleam +++ b/src/cactus/write.gleam @@ -19,7 +19,8 @@ const valid_hooks = [ @target(javascript) pub fn tmpl(path: String) -> String { let runtime = - parse_gleam_toml(path) + path + |> parse_gleam_toml() |> try(fn(gleam_toml) { as_invalid_field_err(tom.get_table(gleam_toml, ["javascript"])) }) diff --git a/test/write_test.gleam b/test/write_test.gleam index 915505c..e980dc7 100644 --- a/test/write_test.gleam +++ b/test/write_test.gleam @@ -6,6 +6,12 @@ import simplifile const hook_dir = "test/testdata/scripts" +const node_files = [ + "./gleam.toml", "test/testdata/gleam/basic.toml", + "test/testdata/gleam/empty.toml", "foo/bar/baz", + "test/testdata/gleam/node.toml", "test/testdata/gleam/junk.toml", +] + pub fn init_test() { simplifile.delete_all([hook_dir]) |> should.be_ok @@ -30,39 +36,27 @@ pub fn create_script_test() { @target(javascript) pub fn template_test() { - write.tmpl("./gleam.toml") - |> should.equal( - "gleam run --target javascript --runtime nodejs -m cactus -- ", - ) - - write.tmpl("test/testdata/gleam/basic.toml") - |> should.equal( - "gleam run --target javascript --runtime nodejs -m cactus -- ", - ) - - write.tmpl("test/testdata/gleam/empty.toml") - |> should.equal( - "gleam run --target javascript --runtime nodejs -m cactus -- ", - ) - - write.tmpl("foo/bar/baz") - |> should.equal( - "gleam run --target javascript --runtime nodejs -m cactus -- ", - ) - - write.tmpl("test/testdata/gleam/node.toml") - |> should.equal( + node_files + |> list.map(write.tmpl) + |> list.each(should.equal( + _, "gleam run --target javascript --runtime nodejs -m cactus -- ", - ) + )) write.tmpl("test/testdata/gleam/bun.toml") |> should.equal("gleam run --target javascript --runtime bun -m cactus -- ") write.tmpl("test/testdata/gleam/deno.toml") |> should.equal("gleam run --target javascript --runtime deno -m cactus -- ") +} - write.tmpl("test/testdata/gleam/junk.toml") - |> should.equal( - "gleam run --target javascript --runtime nodejs -m cactus -- ", - ) +@target(erlang) +pub fn template_test() { + [ + "test/testdata/gleam/bun.toml", + "test/testdata/gleam/deno.toml", + ..node_files + ] + |> list.map(write.tmpl) + |> list.each(should.equal(_, "gleam run --target erlang -m cactus -- ")) }