~samwhited/xmpp

3b5828294bc515b5744115a2dfa77fa2c8c20886 — Sam Whited 5 years ago 2e9893e
jid: Add some tests to make sure MustParse panics
1 files changed, 25 insertions(+), 0 deletions(-)

M jid/jid_test.go
M jid/jid_test.go => jid/jid_test.go +25 -0
@@ 79,3 79,28 @@ func TestMarshalEmpty(t *testing.T) {
		t.Fail()
	}
}

func TestMustParsePanics(t *testing.T) {
	handleErr := func(shouldPanic bool) {
		r := recover()
		switch {
		case shouldPanic && r == nil:
			t.Error("Must parse should panic on invalid JID")
		case !shouldPanic && r != nil:
			t.Error("Must parse should not panic on valid JID")
		}
	}
	for _, t := range []struct {
		jid         string
		shouldPanic bool
	}{
		{"@me", true},
		{"@`me", true},
		{"e@example.net", false},
	} {
		func() {
			defer handleErr(t.shouldPanic)
			MustParse(t.jid)
		}()
	}
}