structs_test.go
changeset 6 8e425e340ca1
parent 3 6121aa2f21b1
child 7 4f0f66f9a441
equal deleted inserted replaced
5:faef59c8db05 6:8e425e340ca1
    48 	observed := string(buf.Bytes())
    48 	observed := string(buf.Bytes())
    49 	assertEquals(t, expected, observed)
    49 	assertEquals(t, expected, observed)
    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 to="bob">`
    54 	exp := `<stream:stream xmlns="jabber:client"` +
       
    55 		` xmlns:stream="` + nsStream + `" to="bob">`
    55 	assertMarshal(t, exp, s)
    56 	assertMarshal(t, exp, s)
    56 
    57 
    57 	s = &Stream{to: "bob", from: "alice", id: "#3", version: "5.3"}
    58 	s = &Stream{To: "bob", From: "alice", Id: "#3", Version: "5.3"}
    58 	exp = `<stream:stream to="bob" from="alice" id="#3" version="5.3">`
    59 	exp = `<stream:stream xmlns="jabber:client"` +
       
    60 		` xmlns:stream="` + nsStream + `" to="bob" from="alice"` +
       
    61 		` id="#3" version="5.3">`
    59 	assertMarshal(t, exp, s)
    62 	assertMarshal(t, exp, s)
    60 
    63 
    61 	s = &Stream{lang: "en_US"}
    64 	s = &Stream{Lang: "en_US"}
    62 	exp = `<stream:stream xml:lang="en_US">`
    65 	exp = `<stream:stream xmlns="jabber:client"` +
       
    66 		` xmlns:stream="` + nsStream + `" xml:lang="en_US">`
    63 	assertMarshal(t, exp, s)
    67 	assertMarshal(t, exp, s)
    64 }
    68 }
    65 
    69 
    66 func TestStreamErrorMarshal(t *testing.T) {
    70 func TestStreamErrorMarshal(t *testing.T) {
    67 	name := xml.Name{Space: nsStreams, Local: "ack"}
    71 	name := xml.Name{Space: nsStreams, Local: "ack"}
    68 	e := &StreamError{cond: definedCondition{name}}
    72 	e := &StreamError{Any: definedCondition{name}}
    69 	exp := `<stream:error><ack xmlns="` + nsStreams +
    73 	exp := `<stream:error><ack xmlns="` + nsStreams +
    70 		`"></ack></stream:error>`;
    74 		`"></ack></stream:error>`;
    71 	assertMarshal(t, exp, e)
    75 	assertMarshal(t, exp, e)
    72 
    76 
    73 	txt := errText{Lang: "pt", text: "things happen"}
    77 	txt := errText{Lang: "pt", Text: "things happen"}
    74 	e = &StreamError{cond: definedCondition{name}, text: &txt}
    78 	e = &StreamError{Any: definedCondition{name}, Text: &txt}
    75 	exp = `<stream:error><ack xmlns="` + nsStreams +
    79 	exp = `<stream:error><ack xmlns="` + nsStreams +
    76 		`"></ack><text xmlns="` + nsStreams +
    80 		`"></ack><text xmlns="` + nsStreams +
    77 		`" xml:lang="pt">things happen</text></stream:error>`
    81 		`" xml:lang="pt">things happen</text></stream:error>`
    78 	assertMarshal(t, exp, e)
    82 	assertMarshal(t, exp, e)
    79 }
    83 }