structs_test.go
changeset 34 7b1f924c75e2
parent 31 1dc47df5c99f
child 38 2839fece923e
equal deleted inserted replaced
33:571713f49494 34:7b1f924c75e2
    50 }
    50 }
    51 
    51 
    52 func TestStreamMarshal(t *testing.T) {
    52 func TestStreamMarshal(t *testing.T) {
    53 	s := &stream{To: "bob"}
    53 	s := &stream{To: "bob"}
    54 	exp := `<stream:stream xmlns="jabber:client"` +
    54 	exp := `<stream:stream xmlns="jabber:client"` +
    55 		` xmlns:stream="` + nsStream + `" to="bob">`
    55 		` xmlns:stream="` + NsStream + `" to="bob">`
    56 	assertMarshal(t, exp, s)
    56 	assertMarshal(t, exp, s)
    57 
    57 
    58 	s = &stream{To: "bob", From: "alice", Id: "#3", Version: "5.3"}
    58 	s = &stream{To: "bob", From: "alice", Id: "#3", Version: "5.3"}
    59 	exp = `<stream:stream xmlns="jabber:client"` +
    59 	exp = `<stream:stream xmlns="jabber:client"` +
    60 		` xmlns:stream="` + nsStream + `" to="bob" from="alice"` +
    60 		` xmlns:stream="` + NsStream + `" to="bob" from="alice"` +
    61 		` id="#3" version="5.3">`
    61 		` id="#3" version="5.3">`
    62 	assertMarshal(t, exp, s)
    62 	assertMarshal(t, exp, s)
    63 
    63 
    64 	s = &stream{Lang: "en_US"}
    64 	s = &stream{Lang: "en_US"}
    65 	exp = `<stream:stream xmlns="jabber:client"` +
    65 	exp = `<stream:stream xmlns="jabber:client"` +
    66 		` xmlns:stream="` + nsStream + `" xml:lang="en_US">`
    66 		` xmlns:stream="` + NsStream + `" xml:lang="en_US">`
    67 	assertMarshal(t, exp, s)
    67 	assertMarshal(t, exp, s)
    68 }
    68 }
    69 
    69 
    70 func TestStreamErrorMarshal(t *testing.T) {
    70 func TestStreamErrorMarshal(t *testing.T) {
    71 	name := xml.Name{Space: nsStreams, Local: "ack"}
    71 	name := xml.Name{Space: NsStreams, Local: "ack"}
    72 	e := &streamError{Any: Generic{XMLName: name}}
    72 	e := &streamError{Any: Generic{XMLName: name}}
    73 	exp := `<stream:error><ack xmlns="` + nsStreams +
    73 	exp := `<stream:error><ack xmlns="` + NsStreams +
    74 		`"></ack></stream:error>`;
    74 		`"></ack></stream:error>`;
    75 	assertMarshal(t, exp, e)
    75 	assertMarshal(t, exp, e)
    76 
    76 
    77 	txt := errText{Lang: "pt", Text: "things happen"}
    77 	txt := errText{Lang: "pt", Text: "things happen"}
    78 	e = &streamError{Any: Generic{XMLName: name}, Text: &txt}
    78 	e = &streamError{Any: Generic{XMLName: name}, Text: &txt}
    79 	exp = `<stream:error><ack xmlns="` + nsStreams +
    79 	exp = `<stream:error><ack xmlns="` + NsStreams +
    80 		`"></ack><text xmlns="` + nsStreams +
    80 		`"></ack><text xmlns="` + NsStreams +
    81 		`" xml:lang="pt">things happen</text></stream:error>`
    81 		`" xml:lang="pt">things happen</text></stream:error>`
    82 	assertMarshal(t, exp, e)
    82 	assertMarshal(t, exp, e)
    83 }
    83 }
    84 
    84 
    85 func TestIqMarshal(t *testing.T) {
    85 func TestIqMarshal(t *testing.T) {
    86 	iq := &Iq{Type: "set", Id: "3", Any: &Generic{XMLName:
    86 	iq := &Iq{Type: "set", Id: "3", Any: &Generic{XMLName:
    87 			xml.Name{Space: nsBind, Local: "bind"}}}
    87 			xml.Name{Space: NsBind, Local: "bind"}}}
    88 	exp := `<iq id="3" type="set"><bind xmlns="` + nsBind +
    88 	exp := `<iq id="3" type="set"><bind xmlns="` + NsBind +
    89 		`"></bind></iq>`
    89 		`"></bind></iq>`
    90 	assertMarshal(t, exp, iq)
    90 	assertMarshal(t, exp, iq)
    91 }
    91 }
    92 
    92 
    93 func TestParseStanza(t *testing.T) {
    93 func TestParseStanza(t *testing.T) {