package dsl import "testing" func newTest() *Test { return &Test{ InFiles: map[string]string{}, OutFiles: map[string]string{}, } } func TestSetInputFile(t *testing.T) { tst := newTest() tst.SetInputFile("input.txt", []byte("hello")) if got := tst.InFiles["input.txt"]; got != "hello" { t.Errorf("InFiles[input.txt] = %q, want %q", got, "hello") } if tst.Stdin != nil { t.Errorf("Stdin should remain nil, got %v", *tst.Stdin) } } func TestSetStdin(t *testing.T) { tst := newTest() tst.SetStdin([]byte("data\n")) if tst.Stdin == nil { t.Fatal("Stdin is nil") } if *tst.Stdin != "data\n" { t.Errorf("Stdin = %q, want %q", *tst.Stdin, "data\n") } if len(tst.InFiles) != 0 { t.Errorf("InFiles should be empty, got %v", tst.InFiles) } } func TestSetOutputFileSetsNoMatcher(t *testing.T) { tst := newTest() tst.SetOutputFile("out.txt", []byte("result")) if got := tst.OutFiles["out.txt"]; got != "result" { t.Errorf("OutFiles[out.txt] = %q, want %q", got, "result") } if _, ok := tst.Stdout.(NoMatcher); !ok { t.Errorf("Stdout = %T, want NoMatcher", tst.Stdout) } } func TestSetStdoutSetsExactMatcher(t *testing.T) { tst := newTest() tst.SetStdout([]byte("expected\n")) m, ok := tst.Stdout.(ExactMatcher) if !ok { t.Fatalf("Stdout = %T, want ExactMatcher", tst.Stdout) } if m.Value != "expected\n" { t.Errorf("ExactMatcher.Value = %q, want %q", m.Value, "expected\n") } if len(tst.OutFiles) != 0 { t.Errorf("OutFiles should be empty, got %v", tst.OutFiles) } } func TestIsDirModeTrue(t *testing.T) { p := &Pattern{DirsGlob: "tests/*"} if !p.IsDirMode() { t.Error("IsDirMode() = false, want true") } } func TestIsDirModeFalse(t *testing.T) { p := &Pattern{InputGlob: "tests/*.in"} if p.IsDirMode() { t.Error("IsDirMode() = true, want false") } }