diff --git a/function/function_test.go b/function/function_test.go new file mode 100644 index 0000000..7c942ca --- /dev/null +++ b/function/function_test.go @@ -0,0 +1,44 @@ +package function_test + +import ( + "os" + "path/filepath" + "strings" + "testing" + + "tangled.org/cosmeak.tngl.sh/weave" + "tangled.org/cosmeak.tngl.sh/weave/function" +) + +func TestFunctionGeneration(t *testing.T) { + out := t.TempDir() + + pack := weave. + MkDatapack("test", "Test pack", 88, 88, []string{"vanilla"}). + AddFeature(function.MkFunction( + "set_day", + "time set day", + "say Daytime!", + )) + + if err := pack.Generate(out); err != nil { + t.Fatalf("generate failed: %v", err) + } + + path := filepath.Join( + out, + "test", "data", "test", "function", "set_day.mcfunction", + ) + + data, err := os.ReadFile(path) + if err != nil { + t.Fatalf("expected file not found: %v", err) + } + + got := strings.TrimSpace(string(data)) + want := "time set day\nsay Daytime!" + + if got != want { + t.Errorf("unexpected file content:\n%s", got) + } +}