A Minecraft datapack generator written in go.

feat(function): add basic testing

+44
+44
function/function_test.go
··· 1 + package function_test 2 + 3 + import ( 4 + "os" 5 + "path/filepath" 6 + "strings" 7 + "testing" 8 + 9 + "tangled.org/cosmeak.tngl.sh/weave" 10 + "tangled.org/cosmeak.tngl.sh/weave/function" 11 + ) 12 + 13 + func TestFunctionGeneration(t *testing.T) { 14 + out := t.TempDir() 15 + 16 + pack := weave. 17 + MkDatapack("test", "Test pack", 88, 88, []string{"vanilla"}). 18 + AddFeature(function.MkFunction( 19 + "set_day", 20 + "time set day", 21 + "say Daytime!", 22 + )) 23 + 24 + if err := pack.Generate(out); err != nil { 25 + t.Fatalf("generate failed: %v", err) 26 + } 27 + 28 + path := filepath.Join( 29 + out, 30 + "test", "data", "test", "function", "set_day.mcfunction", 31 + ) 32 + 33 + data, err := os.ReadFile(path) 34 + if err != nil { 35 + t.Fatalf("expected file not found: %v", err) 36 + } 37 + 38 + got := strings.TrimSpace(string(data)) 39 + want := "time set day\nsay Daytime!" 40 + 41 + if got != want { 42 + t.Errorf("unexpected file content:\n%s", got) 43 + } 44 + }