@@ -9,6 +9,82 @@ import (
9
9
. "github.com/onsi/gomega"
10
10
)
11
11
12
+ var _ = Describe ("Inherit" , func () {
13
+ var child , parent * design.AttributeDefinition
14
+
15
+ BeforeEach (func () {
16
+ parent = & design.AttributeDefinition {Type : design.Object {}}
17
+ child = & design.AttributeDefinition {Type : design.Object {}}
18
+ })
19
+
20
+ JustBeforeEach (func () {
21
+ child .Inherit (parent )
22
+ })
23
+
24
+ Context ("with a empty parent" , func () {
25
+ const attName = "c"
26
+ BeforeEach (func () {
27
+ child .Type .(design.Object )[attName ] = & design.AttributeDefinition {Type : design .String }
28
+ })
29
+
30
+ It ("does not change" , func () {
31
+ obj := child .Type .(design.Object )
32
+ Ω (obj ).Should (HaveLen (1 ))
33
+ Ω (obj ).Should (HaveKey (attName ))
34
+ })
35
+ })
36
+
37
+ Context ("with a parent that defines no inherited attribute" , func () {
38
+ const (
39
+ attName = "c"
40
+ def = "default"
41
+ )
42
+
43
+ BeforeEach (func () {
44
+ child .Type .(design.Object )[attName ] = & design.AttributeDefinition {Type : design .String }
45
+ parent .Type .(design.Object )["other" ] = & design.AttributeDefinition {Type : design .String , DefaultValue : def }
46
+ })
47
+
48
+ It ("does not change" , func () {
49
+ obj := child .Type .(design.Object )
50
+ Ω (obj ).Should (HaveLen (1 ))
51
+ Ω (obj ).Should (HaveKey (attName ))
52
+ Ω (obj [attName ].DefaultValue ).Should (BeNil ())
53
+ })
54
+ })
55
+
56
+ Context ("with a parent that defines an inherited attribute" , func () {
57
+ const (
58
+ attName = "c"
59
+ def = "default"
60
+ )
61
+
62
+ BeforeEach (func () {
63
+ child .Type .(design.Object )[attName ] = & design.AttributeDefinition {Type : design .String }
64
+ parent .Type .(design.Object )[attName ] = & design.AttributeDefinition {Type : design .String , DefaultValue : def }
65
+ })
66
+
67
+ It ("inherits the default value" , func () {
68
+ obj := child .Type .(design.Object )
69
+ Ω (obj ).Should (HaveLen (1 ))
70
+ Ω (obj ).Should (HaveKey (attName ))
71
+ Ω (obj [attName ].DefaultValue ).Should (Equal (def ))
72
+ })
73
+ })
74
+
75
+ Context ("with recursive type definitions" , func () {
76
+ BeforeEach (func () {
77
+ po := design.Object {}
78
+ parent = & design.AttributeDefinition {Type : po }
79
+ child = & design.AttributeDefinition {Type : & design.UserTypeDefinition {AttributeDefinition : parent }}
80
+ po ["recurse" ] = child
81
+ })
82
+
83
+ It ("does not recurse infinitely" , func () {})
84
+ })
85
+
86
+ })
87
+
12
88
var _ = Describe ("IsRequired" , func () {
13
89
var required string
14
90
var attName string
0 commit comments