Skip to content
quarry Artifact [6b2c1f9c39]
Login

Artifact [6b2c1f9c39]

Artifact 6b2c1f9c39b35bef5e597e2c2293802f41033969aa6034827c815d295fdea57d:


package index

import "testing"

// A line note is written and read back by the same two functions, so
// the header can only have one dialect; anything else is a remark.
func TestALineNoteRoundTrips(t *testing.T) {
	n := LineNote{File: "internal/web/web.go", Side: "new", Line: 2251, At: "8a0ba3d4805e"}
	body := FormatLineNote(n, "Record this before the tickets close.\n\nSecond paragraph.")
	got, prose, ok := ParseLineNote(body)
	if !ok || got != n {
		t.Fatalf("FAIL: read back %+v ok=%v from %q", got, ok, body)
	}
	if prose != "Record this before the tickets close.\n\nSecond paragraph." {
		t.Errorf("FAIL: prose %q", prose)
	}
	for _, other := range []string{
		"just a remark",
		"zit-line: 1\nfile: a.go\nside: sideways\nline: 3\n\nbad side",
		"zit-line: 1\nfile: a.go\nside: new\nline: zero\n\nbad line",
		"zit-landing: 1\nbranch: x\n\nthe opener",
		"zit-line: 1\nfile: a.go\nside: new\nline: 3\nat: NOT-HEX\n\nbad at",
	} {
		if _, _, ok := ParseLineNote(other); ok {
			t.Errorf("FAIL: %q read as a line note", other)
		}
	}
}

// A reply that records a landing event reads, as text, as whatever the
// author said with it — never the machine line zit writes first (G-45).
// The event itself is reported in its own field.
func TestALandingReplyReadsWithoutItsEventHeader(t *testing.T) {
	for _, tc := range []struct{ name, body, want string }{
		{"an accept with a remark", "zit-landing-state: accepted\n\nShipped, thanks.", "Shipped, thanks."},
		{"an accept alone", "zit-landing-state: accepted", ""},
		{"a retarget", "zit-landing-target: trunk\n\nmoved", "moved"},
		{"an update", "zit-landing-updated: abc123\n", ""},
		{"a plain comment", "looks good\nzit-landing-state: accepted", "looks good\nzit-landing-state: accepted"},
	} {
		if got := LandingReplyProse(tc.body); got != tc.want {
			t.Errorf("FAIL: %s: got %q, want %q", tc.name, got, tc.want)
		} else {
			t.Logf("ok: %s", tc.name)
		}
	}
}