Skip to content

Commit

Permalink
add erlang version of template test
Browse files Browse the repository at this point in the history
  • Loading branch information
bwireman committed Jul 20, 2024
1 parent e8b974c commit a6fc0fc
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 28 deletions.
3 changes: 2 additions & 1 deletion src/cactus/write.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -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"]))
})
Expand Down
48 changes: 21 additions & 27 deletions test/write_test.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 -- "))
}

0 comments on commit a6fc0fc

Please sign in to comment.