Skip to content

Commit d3f8a1b

Browse files
committed
the rest of the refinements
1 parent eb10bb5 commit d3f8a1b

File tree

8 files changed

+148
-4
lines changed

8 files changed

+148
-4
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright (c) HashiCorp, Inc.
2+
// SPDX-License-Identifier: MPL-2.0
3+
4+
package refinement
5+
6+
// TODO: doc
7+
type CollectionLengthLowerBound struct {
8+
value int64
9+
}
10+
11+
func (n CollectionLengthLowerBound) Equal(Refinement) bool {
12+
// TODO: implement
13+
return false
14+
}
15+
16+
func (n CollectionLengthLowerBound) String() string {
17+
// TODO: implement
18+
return "todo - CollectionLengthLowerBound"
19+
}
20+
21+
// TODO: doc
22+
func (n CollectionLengthLowerBound) LowerBound() int64 {
23+
return n.value
24+
}
25+
26+
func (n CollectionLengthLowerBound) unimplementable() {}
27+
28+
// TODO: doc
29+
func NewCollectionLengthLowerBound(value int64) Refinement {
30+
return CollectionLengthLowerBound{
31+
value: value,
32+
}
33+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright (c) HashiCorp, Inc.
2+
// SPDX-License-Identifier: MPL-2.0
3+
4+
package refinement
5+
6+
// TODO: doc
7+
type CollectionLengthUpperBound struct {
8+
value int64
9+
}
10+
11+
func (n CollectionLengthUpperBound) Equal(Refinement) bool {
12+
// TODO: implement
13+
return false
14+
}
15+
16+
func (n CollectionLengthUpperBound) String() string {
17+
// TODO: implement
18+
return "todo - CollectionLengthUpperBound"
19+
}
20+
21+
// TODO: doc
22+
func (n CollectionLengthUpperBound) UpperBound() int64 {
23+
return n.value
24+
}
25+
26+
func (n CollectionLengthUpperBound) unimplementable() {}
27+
28+
// TODO: doc
29+
func NewCollectionLengthUpperBound(value int64) Refinement {
30+
return CollectionLengthUpperBound{
31+
value: value,
32+
}
33+
}

tftypes/refinement/doc.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// Copyright (c) HashiCorp, Inc.
2+
// SPDX-License-Identifier: MPL-2.0
3+
4+
// TODO: docs
5+
package refinement

tftypes/refinement/nullness.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,31 @@
1+
// Copyright (c) HashiCorp, Inc.
2+
// SPDX-License-Identifier: MPL-2.0
3+
14
package refinement
25

6+
// TODO: doc
37
type Nullness struct {
48
value bool
59
}
610

711
func (n Nullness) Equal(Refinement) bool {
12+
// TODO: implement
813
return false
914
}
1015

1116
func (n Nullness) String() string {
17+
// TODO: implement
1218
return "todo - Nullness"
1319
}
1420

21+
// TODO: doc
1522
func (n Nullness) Nullness() bool {
1623
return n.value
1724
}
1825

1926
func (n Nullness) unimplementable() {}
2027

28+
// TODO: doc
2129
func NewNullness(value bool) Refinement {
2230
return Nullness{
2331
value: value,

tftypes/refinement/number_lower_bound.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,41 @@
1+
// Copyright (c) HashiCorp, Inc.
2+
// SPDX-License-Identifier: MPL-2.0
3+
14
package refinement
25

36
import (
47
"math/big"
58
)
69

10+
// TODO: doc
711
type NumberLowerBound struct {
812
inclusive bool
913
value *big.Float
1014
}
1115

1216
func (n NumberLowerBound) Equal(Refinement) bool {
17+
// TODO: implement
1318
return false
1419
}
1520

1621
func (n NumberLowerBound) String() string {
22+
// TODO: implement
1723
return "todo - NumberLowerBound"
1824
}
1925

26+
// TODO: doc
2027
func (n NumberLowerBound) IsInclusive() bool {
2128
return n.inclusive
2229
}
2330

31+
// TODO: doc
2432
func (n NumberLowerBound) LowerBound() *big.Float {
2533
return n.value
2634
}
2735

2836
func (n NumberLowerBound) unimplementable() {}
2937

38+
// TODO: doc
3039
func NewNumberLowerBound(value *big.Float, inclusive bool) Refinement {
3140
return NumberLowerBound{
3241
value: value,

tftypes/refinement/number_upper_bound.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,41 @@
1+
// Copyright (c) HashiCorp, Inc.
2+
// SPDX-License-Identifier: MPL-2.0
3+
14
package refinement
25

36
import (
47
"math/big"
58
)
69

10+
// TODO: doc
711
type NumberUpperBound struct {
812
inclusive bool
913
value *big.Float
1014
}
1115

1216
func (n NumberUpperBound) Equal(Refinement) bool {
17+
// TODO: implement
1318
return false
1419
}
1520

1621
func (n NumberUpperBound) String() string {
22+
// TODO: implement
1723
return "todo - NumberUpperBound"
1824
}
1925

26+
// TODO: doc
2027
func (n NumberUpperBound) IsInclusive() bool {
2128
return n.inclusive
2229
}
2330

31+
// TODO: doc
2432
func (n NumberUpperBound) UpperBound() *big.Float {
2533
return n.value
2634
}
2735

2836
func (n NumberUpperBound) unimplementable() {}
2937

38+
// TODO: doc
3039
func NewNumberUpperBound(value *big.Float, inclusive bool) Refinement {
3140
return NumberUpperBound{
3241
value: value,

tftypes/refinement/refinement.go

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// Copyright (c) HashiCorp, Inc.
2+
// SPDX-License-Identifier: MPL-2.0
3+
14
package refinement
25

36
import (
@@ -23,20 +26,56 @@ func (k Key) String() string {
2326
}
2427

2528
const (
26-
KeyNullness = Key(1)
27-
KeyStringPrefix = Key(2)
29+
// KeyNullness represents a refinement that specifies whether the final value will not be null.
30+
//
31+
// MAINTINAER NOTE: In practice, this refinement data will only contain "false", indicating the final value
32+
// cannot be null. If the refinement data was ever set to "true", that would indicate the final value will be null, in which
33+
// case the value is not unknown, it is known and should not have any refinement data.
34+
//
35+
// This refinement is relevant for all types except tftypes.DynamicPseudoType.
36+
KeyNullness = Key(1)
37+
38+
// KeyStringPrefix represents a refinement that specifies a known prefix of a final string value.
39+
//
40+
// This refinement is only relevant for tftypes.String.
41+
KeyStringPrefix = Key(2)
42+
43+
// KeyNumberLowerBound represents a refinement that specifies the lower bound of possible values for a final number value.
44+
// The refinement data contains a boolean which indicates whether the bound is inclusive.
45+
//
46+
// This refinement is only relevant for tftypes.Number.
2847
KeyNumberLowerBound = Key(3)
48+
49+
// KeyNumberUpperBound represents a refinement that specifies the upper bound of possible values for a final number value.
50+
// The refinement data contains a boolean which indicates whether the bound is inclusive.
51+
//
52+
// This refinement is only relevant for tftypes.Number.
2953
KeyNumberUpperBound = Key(4)
30-
// KeyCollectionLengthLowerBound = Key(5)
31-
// KeyCollectionLengthUpperBound = Key(6)
54+
55+
// KeyCollectionLengthLowerBound represents a refinement that specifies the lower bound of possible length for a final collection value.
56+
//
57+
// This refinement is only relevant for tftypes.List, tftypes.Set, and tftypes.Map.
58+
KeyCollectionLengthLowerBound = Key(5)
59+
60+
// KeyCollectionLengthUpperBound represents a refinement that specifies the upper bound of possible length for a final collection value.
61+
//
62+
// This refinement is only relevant for tftypes.List, tftypes.Set, and tftypes.Map.
63+
KeyCollectionLengthUpperBound = Key(6)
3264
)
3365

66+
// TODO: docs
3467
type Refinement interface {
68+
// Equal should return true if the Refinement is considered equivalent to the
69+
// Refinement passed as an argument.
3570
Equal(Refinement) bool
71+
72+
// String should return a human-friendly version of the Refinement.
3673
String() string
74+
3775
unimplementable() // prevents external implementations, all refinements are defined in the Terraform/HCL type system go-cty.
3876
}
3977

78+
// TODO: docs
4079
type Refinements map[Key]Refinement
4180

4281
func (r Refinements) Equal(o Refinements) bool {

tftypes/refinement/string_prefix.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,31 @@
1+
// Copyright (c) HashiCorp, Inc.
2+
// SPDX-License-Identifier: MPL-2.0
3+
14
package refinement
25

6+
// TODO: doc
37
type StringPrefix struct {
48
value string
59
}
610

711
func (s StringPrefix) Equal(Refinement) bool {
12+
// TODO: implement
813
return false
914
}
1015

1116
func (s StringPrefix) String() string {
17+
// TODO: implement
1218
return "todo - stringPrefix"
1319
}
1420

21+
// TODO: doc
1522
func (s StringPrefix) PrefixValue() string {
1623
return s.value
1724
}
1825

1926
func (s StringPrefix) unimplementable() {}
2027

28+
// TODO: doc
2129
func NewStringPrefix(value string) Refinement {
2230
return StringPrefix{
2331
value: value,

0 commit comments

Comments
 (0)