package markup
import "testing"
func refIDs(refs []RefToken) []string {
var out []string
for _, r := range refs {
out = append(out, r.ID)
}
return out
}
// addresses is the verb for work on a ticket that does not finish it.
// Same grammar, same link, and no effect on the ticket's state.
func TestAddressesParsesLikeClosesAndActsLikeNothing(t *testing.T) {
const msg = "landings: the second half\n\naddresses a488d7fa42 and closes 0eafaa1984."
if got := refIDs(AddressingRefs(msg)); len(got) != 1 || got[0] != "a488d7fa42" {
t.Errorf("FAIL: addresses read %q, want [a488d7fa42]", got)
}
if got := refIDs(ClosingRefs(msg)); len(got) != 1 || got[0] != "0eafaa1984" {
t.Errorf("FAIL: closes read %q, want [0eafaa1984]", got)
}
}
// The two verbs never read each other's references. A landing that
// addresses a ticket must not close it, and that separation is the
// whole reason the second verb exists.
func TestTheTwoVerbsDoNotOverlap(t *testing.T) {
if got := ClosingRefs("addresses a488d7fa42"); len(got) != 0 {
t.Errorf("FAIL: an addresses was read as a close: %q", refIDs(got))
}
if got := AddressingRefs("closes a488d7fa42"); len(got) != 0 {
t.Errorf("FAIL: a close was read as an addresses: %q", refIDs(got))
}
}
// Same distance rule as closes: the reference must follow the verb, or
// prose that happens to contain both words would act.
func TestAddressesNeedsTheReferenceRightAfterTheVerb(t *testing.T) {
if got := AddressingRefs("this addresses the gap that a488d7fa42 describes"); len(got) != 0 {
t.Errorf("FAIL: prose was read as a declaration: %q", refIDs(got))
}
if got := refIDs(AddressingRefs("addresses: [a488d7fa42]")); len(got) != 1 || got[0] != "a488d7fa42" {
t.Errorf("FAIL: the bracketed spelling read %q", got)
}
}