File: tag_test.go

package info (click to toggle)
golang-github-aws-aws-sdk-go-v2 1.24.1-2~bpo12%2B1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-backports
  • size: 554,032 kB
  • sloc: java: 15,941; makefile: 419; sh: 175
file content (47 lines) | stat: -rw-r--r-- 1,638 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package attributevalue

import (
	"reflect"
	"testing"
)

func TestTagParse(t *testing.T) {
	cases := []struct {
		in       reflect.StructTag
		json, av bool
		expect   tag
	}{
		{`json:""`, true, false, tag{}},
		{`json:"name"`, true, false, tag{Name: "name"}},
		{`json:"name,omitempty"`, true, false, tag{Name: "name", OmitEmpty: true}},
		{`json:"-"`, true, false, tag{Ignore: true}},
		{`json:",omitempty"`, true, false, tag{OmitEmpty: true}},
		{`json:",string"`, true, false, tag{AsString: true}},
		{`dynamodbav:""`, false, true, tag{}},
		{`dynamodbav:","`, false, true, tag{}},
		{`dynamodbav:"name"`, false, true, tag{Name: "name"}},
		{`dynamodbav:"name"`, false, true, tag{Name: "name"}},
		{`dynamodbav:"-"`, false, true, tag{Ignore: true}},
		{`dynamodbav:",omitempty"`, false, true, tag{OmitEmpty: true}},
		{`dynamodbav:",omitemptyelem"`, false, true, tag{OmitEmptyElem: true}},
		{`dynamodbav:",string"`, false, true, tag{AsString: true}},
		{`dynamodbav:",binaryset"`, false, true, tag{AsBinSet: true}},
		{`dynamodbav:",numberset"`, false, true, tag{AsNumSet: true}},
		{`dynamodbav:",stringset"`, false, true, tag{AsStrSet: true}},
		{`dynamodbav:",stringset,omitemptyelem"`, false, true, tag{AsStrSet: true, OmitEmptyElem: true}},
		{`dynamodbav:"name,stringset,omitemptyelem"`, false, true, tag{Name: "name", AsStrSet: true, OmitEmptyElem: true}},
	}

	for i, c := range cases {
		actual := tag{}
		if c.json {
			actual.parseStructTag("json", c.in)
		}
		if c.av {
			actual.parseAVTag(c.in)
		}
		if e, a := c.expect, actual; !reflect.DeepEqual(e, a) {
			t.Errorf("case %d, expect %v, got %v", i, e, a)
		}
	}
}