...

Source file src/github.com/aws/smithy-go/encoding/xml/array_test.go

Documentation: github.com/aws/smithy-go/encoding/xml

     1  package xml
     2  
     3  import (
     4  	"bytes"
     5  	"testing"
     6  )
     7  
     8  func TestWrappedArray(t *testing.T) {
     9  	buffer := bytes.NewBuffer(nil)
    10  	scratch := make([]byte, 64)
    11  
    12  	root := StartElement{Name: Name{Local: "array"}}
    13  	a := newArray(buffer, &scratch, arrayMemberWrapper, root, false)
    14  	a.Member().String("bar")
    15  	a.Member().String("baz")
    16  
    17  	e := []byte(`<member>bar</member><member>baz</member>`)
    18  	if a := buffer.Bytes(); bytes.Compare(e, a) != 0 {
    19  		t.Errorf("expected %+q, but got %+q", e, a)
    20  	}
    21  }
    22  
    23  func TestWrappedArrayWithCustomName(t *testing.T) {
    24  	buffer := bytes.NewBuffer(nil)
    25  	scratch := make([]byte, 64)
    26  
    27  	root := StartElement{Name: Name{Local: "array"}}
    28  	item := StartElement{Name: Name{Local: "item"}}
    29  	a := newArray(buffer, &scratch, item, root, false)
    30  	a.Member().String("bar")
    31  	a.Member().String("baz")
    32  
    33  	e := []byte(`<item>bar</item><item>baz</item>`)
    34  	if a := buffer.Bytes(); bytes.Compare(e, a) != 0 {
    35  		t.Errorf("expected %+q, but got %+q", e, a)
    36  	}
    37  }
    38  
    39  func TestFlattenedArray(t *testing.T) {
    40  	buffer := bytes.NewBuffer(nil)
    41  	scratch := make([]byte, 64)
    42  
    43  	root := StartElement{Name: Name{Local: "array"}}
    44  	a := newArray(buffer, &scratch, arrayMemberWrapper, root, true)
    45  	a.Member().String("bar")
    46  	a.Member().String("bix")
    47  
    48  	e := []byte(`<array>bar</array><array>bix</array>`)
    49  	if a := buffer.Bytes(); bytes.Compare(e, a) != 0 {
    50  		t.Errorf("expected %+q, but got %+q", e, a)
    51  	}
    52  }
    53  

View as plain text