| 1 |
/* |
| 2 |
Copyright 2015 The Kubernetes Authors. |
| 3 |
|
| 4 |
Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 |
you may not use this file except in compliance with the License. |
| 6 |
You may obtain a copy of the License at |
| 7 |
|
| 8 |
http://www.apache.org/licenses/LICENSE-2.0 |
| 9 |
|
| 10 |
Unless required by applicable law or agreed to in writing, software |
| 11 |
distributed under the License is distributed on an "AS IS" BASIS, |
| 12 |
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 |
See the License for the specific language governing permissions and |
| 14 |
limitations under the License. |
| 15 |
*/ |
| 16 |
|
| 17 |
package types |
| 18 |
|
| 19 |
import ( |
| 20 |
"reflect" |
| 21 |
"testing" |
| 22 |
) |
| 23 |
|
| 24 |
func TestFlatten(t *testing.T) { |
| 25 |
mapType := &Type{ |
| 26 |
Name: Name{Package: "", Name: "map[string]string"}, |
| 27 |
Kind: Map, |
| 28 |
Key: String, |
| 29 |
Elem: String, |
| 30 |
} |
| 31 |
m := []Member{ |
| 32 |
{ |
| 33 |
Name: "Baz", |
| 34 |
Embedded: true, |
| 35 |
Type: &Type{ |
| 36 |
Name: Name{Package: "pkg", Name: "Baz"}, |
| 37 |
Kind: Struct, |
| 38 |
Members: []Member{ |
| 39 |
{Name: "Foo", Type: String}, |
| 40 |
{ |
| 41 |
Name: "Qux", |
| 42 |
Embedded: true, |
| 43 |
Type: &Type{ |
| 44 |
Name: Name{Package: "pkg", Name: "Qux"}, |
| 45 |
Kind: Struct, |
| 46 |
Members: []Member{{Name: "Zot", Type: String}}, |
| 47 |
}, |
| 48 |
}, |
| 49 |
}, |
| 50 |
}, |
| 51 |
}, |
| 52 |
{Name: "Bar", Type: String}, |
| 53 |
{ |
| 54 |
Name: "NotSureIfLegal", |
| 55 |
Embedded: true, |
| 56 |
Type: mapType, |
| 57 |
}, |
| 58 |
} |
| 59 |
e := []Member{ |
| 60 |
{Name: "Bar", Type: String}, |
| 61 |
{Name: "NotSureIfLegal", Type: mapType, Embedded: true}, |
| 62 |
{Name: "Foo", Type: String}, |
| 63 |
{Name: "Zot", Type: String}, |
| 64 |
} |
| 65 |
if a := FlattenMembers(m); !reflect.DeepEqual(e, a) { |
| 66 |
t.Errorf("Expected \n%#v\n, got \n%#v\n", e, a) |
| 67 |
} |
| 68 |
} |