package twiml import ( "encoding/xml" "testing" "time" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) func TestSay(t *testing.T) { checkExp := func(exp Say, doc, expDoc string) { t.Helper() var s Say err := xml.Unmarshal([]byte(doc), &s) require.NoError(t, err) assert.Equal(t, exp, s) data, err := xml.Marshal(s) require.NoError(t, err) assert.Equal(t, expDoc, string(data)) } check := func(exp Say, doc string) { t.Helper() checkExp(exp, doc, doc) } check(Say{Content: "hi"}, `hi`) checkExp(Say{Content: "hi"}, `hi`, `hi`) checkExp(Say{Content: "hi", LoopCount: 1000}, `hi`, `hi`) check(Say{Content: "hi", LoopCount: 1}, `hi`) check(Say{Content: "hi", LoopCount: 1000}, `hi`) check(Say{Content: "hi", Voice: "foo"}, `hi`) } func TestPause(t *testing.T) { checkExp := func(exp Pause, doc, expDoc string) { t.Helper() var s Pause err := xml.Unmarshal([]byte(doc), &s) require.NoError(t, err) assert.Equal(t, exp, s) data, err := xml.Marshal(s) require.NoError(t, err) assert.Equal(t, expDoc, string(data)) } check := func(exp Pause, doc string) { t.Helper() checkExp(exp, doc, doc) } checkExp(Pause{Dur: time.Second}, ``, ``) checkExp(Pause{Dur: time.Second}, ``, ``) check(Pause{Dur: 2 * time.Second}, ``) check(Pause{Dur: time.Second}, ``) check(Pause{}, ``) }