|
4 | 4 | package pprofile |
5 | 5 |
|
6 | 6 | import ( |
| 7 | + "errors" |
7 | 8 | "testing" |
8 | 9 |
|
9 | 10 | "github.com/stretchr/testify/assert" |
@@ -34,6 +35,118 @@ func TestProfileSwitchDictionary(t *testing.T) { |
34 | 35 | wantProfile: NewProfile(), |
35 | 36 | wantDictionary: NewProfilesDictionary(), |
36 | 37 | }, |
| 38 | + { |
| 39 | + name: "with an existing attribute", |
| 40 | + profile: func() Profile { |
| 41 | + p := NewProfile() |
| 42 | + p.AttributeIndices().Append(1) |
| 43 | + return p |
| 44 | + }(), |
| 45 | + |
| 46 | + src: func() ProfilesDictionary { |
| 47 | + d := NewProfilesDictionary() |
| 48 | + d.StringTable().Append("", "test") |
| 49 | + |
| 50 | + d.AttributeTable().AppendEmpty() |
| 51 | + a := d.AttributeTable().AppendEmpty() |
| 52 | + a.SetKeyStrindex(1) |
| 53 | + |
| 54 | + return d |
| 55 | + }(), |
| 56 | + dst: func() ProfilesDictionary { |
| 57 | + d := NewProfilesDictionary() |
| 58 | + d.StringTable().Append("", "foo") |
| 59 | + |
| 60 | + d.AttributeTable().AppendEmpty() |
| 61 | + d.AttributeTable().AppendEmpty() |
| 62 | + return d |
| 63 | + }(), |
| 64 | + |
| 65 | + wantProfile: func() Profile { |
| 66 | + p := NewProfile() |
| 67 | + p.AttributeIndices().Append(2) |
| 68 | + return p |
| 69 | + }(), |
| 70 | + wantDictionary: func() ProfilesDictionary { |
| 71 | + d := NewProfilesDictionary() |
| 72 | + d.StringTable().Append("", "foo", "test") |
| 73 | + |
| 74 | + d.AttributeTable().AppendEmpty() |
| 75 | + d.AttributeTable().AppendEmpty() |
| 76 | + a := d.AttributeTable().AppendEmpty() |
| 77 | + a.SetKeyStrindex(2) |
| 78 | + return d |
| 79 | + }(), |
| 80 | + }, |
| 81 | + { |
| 82 | + name: "with an attribute index that does not match anything", |
| 83 | + profile: func() Profile { |
| 84 | + p := NewProfile() |
| 85 | + p.AttributeIndices().Append(1) |
| 86 | + return p |
| 87 | + }(), |
| 88 | + |
| 89 | + src: NewProfilesDictionary(), |
| 90 | + dst: NewProfilesDictionary(), |
| 91 | + |
| 92 | + wantProfile: func() Profile { |
| 93 | + p := NewProfile() |
| 94 | + p.AttributeIndices().Append(1) |
| 95 | + return p |
| 96 | + }(), |
| 97 | + wantDictionary: NewProfilesDictionary(), |
| 98 | + wantErr: errors.New("invalid attribute index 1"), |
| 99 | + }, |
| 100 | + { |
| 101 | + name: "with an existing comment", |
| 102 | + profile: func() Profile { |
| 103 | + p := NewProfile() |
| 104 | + p.CommentStrindices().Append(1) |
| 105 | + return p |
| 106 | + }(), |
| 107 | + |
| 108 | + src: func() ProfilesDictionary { |
| 109 | + d := NewProfilesDictionary() |
| 110 | + d.StringTable().Append("", "test") |
| 111 | + return d |
| 112 | + }(), |
| 113 | + dst: func() ProfilesDictionary { |
| 114 | + d := NewProfilesDictionary() |
| 115 | + d.StringTable().Append("", "foo") |
| 116 | + return d |
| 117 | + }(), |
| 118 | + |
| 119 | + wantProfile: func() Profile { |
| 120 | + p := NewProfile() |
| 121 | + p.CommentStrindices().Append(2) |
| 122 | + return p |
| 123 | + }(), |
| 124 | + wantDictionary: func() ProfilesDictionary { |
| 125 | + d := NewProfilesDictionary() |
| 126 | + d.StringTable().Append("", "foo", "test") |
| 127 | + |
| 128 | + return d |
| 129 | + }(), |
| 130 | + }, |
| 131 | + { |
| 132 | + name: "with a comment index that does not match anything", |
| 133 | + profile: func() Profile { |
| 134 | + p := NewProfile() |
| 135 | + p.CommentStrindices().Append(1) |
| 136 | + return p |
| 137 | + }(), |
| 138 | + |
| 139 | + src: NewProfilesDictionary(), |
| 140 | + dst: NewProfilesDictionary(), |
| 141 | + |
| 142 | + wantProfile: func() Profile { |
| 143 | + p := NewProfile() |
| 144 | + p.CommentStrindices().Append(1) |
| 145 | + return p |
| 146 | + }(), |
| 147 | + wantDictionary: NewProfilesDictionary(), |
| 148 | + wantErr: errors.New("invalid comment index 1"), |
| 149 | + }, |
37 | 150 | { |
38 | 151 | name: "with a profile that has a sample", |
39 | 152 | profile: func() Profile { |
|
0 commit comments