mirror of
https://github.com/MSWS/Chess.git
synced 2025-12-05 21:30:23 -08:00
Compare commits
2 Commits
097a054644
...
89c940dfc8
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
89c940dfc8 | ||
|
|
137e694a38 |
@@ -2,6 +2,7 @@ package uci
|
||||
|
||||
import (
|
||||
"io"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
@@ -13,22 +14,48 @@ func base() (Engine, io.Reader, io.Writer) {
|
||||
}
|
||||
|
||||
func TestInit(t *testing.T) {
|
||||
e, in, _ := base()
|
||||
e, out, _ := base()
|
||||
|
||||
go e.Init()
|
||||
|
||||
buf := make([]byte, 1024)
|
||||
n, err := in.Read(buf)
|
||||
expectLine(t, out, "id name GoChess2")
|
||||
expectLine(t, out, "id author MS")
|
||||
expectLine(t, out, "uciok")
|
||||
}
|
||||
|
||||
func TestPrint(t *testing.T) {
|
||||
e, out, _ := base()
|
||||
|
||||
go e.Print("Hello, World!")
|
||||
|
||||
expectLine(t, out, "Hello, World!")
|
||||
}
|
||||
|
||||
func TestCopyProtection(t *testing.T) {
|
||||
e, out, _ := base()
|
||||
|
||||
go e.CopyProtection()
|
||||
|
||||
expectLine(t, out, "copyprotection ok")
|
||||
}
|
||||
|
||||
func expectLine(t *testing.T, in io.Reader, expected string) {
|
||||
line, err := readLine(in)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
t.Fatalf("Error reading line: %v", err)
|
||||
}
|
||||
|
||||
if n == 0 {
|
||||
t.Error("No data read")
|
||||
}
|
||||
|
||||
if string(buf[:n]) != "id name GoChess2\n" {
|
||||
t.Error("Unexpected output, got:", string(buf[:n]))
|
||||
if line != expected {
|
||||
t.Fatalf("Expected '%s', got '%s'", expected, line)
|
||||
}
|
||||
}
|
||||
|
||||
func readLine(in io.Reader) (string, error) {
|
||||
buf := make([]byte, 1024)
|
||||
n, err := in.Read(buf)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return strings.Trim(string(buf[:n]), "\n"), nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user