package gs232

import (
	"strconv"
	"strings"
	"testing"
)

// Real replies, as the controllers actually send them — a K3NG answering "C"
// with "+0140" and CR+LF among them (reported from a live controller).
func TestAzimuthReplies(t *testing.T) {
	cases := []struct {
		raw  string
		want int
	}{
		{"+0140\r\n", 140},         // GS-232A, K3NG firmware
		{"+0000\r", 0},             // due north
		{"+0359\r\n", 359},         // just short of it
		{"AZ=140\r\n", 140},        // GS-232B flavour
		{"AZ=140 EL=000\r\n", 140}, // GS-232B with elevation on the same line
		{"\r\n+0075\r\n", 75},      // a leftover terminator ahead of the answer
	}
	for _, c := range cases {
		m := azRe.FindStringSubmatch(strings.TrimSpace(c.raw))
		if m == nil {
			t.Errorf("no azimuth found in %q", c.raw)
			continue
		}
		got, _ := strconv.Atoi(m[1])
		if got%360 != c.want {
			t.Errorf("%q parsed as %d, want %d", c.raw, got%360, c.want)
		}
	}
}
