Skip to content

Commit ca8320b

Browse files
committed
Add u.False & u.True
1 parent a282df7 commit ca8320b

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

README.md

+7
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,12 @@ fmt.Println(myVar.IsSet()) // false
9090
```go
9191
type MyStruct struct {
9292
MyVar u.Int
93+
MyOption u.Bool
9394
}
9495

9596
myStruct := MyStruct{
9697
MyVar: u.NewInt(42),
98+
MyOption: u.True,
9799
}
98100
```
99101

@@ -122,6 +124,11 @@ Yes, that's one way you can solve this issue. Personally, I try to avoid having
122124
- `u.Byte`
123125
- `u.Rune`
124126

127+
## Values
128+
129+
- `u.True`
130+
- `u.False`
131+
125132
## Custom types
126133

127134
Any type can be used with this library by creating a `u.Var` of that type. For example:

u.go

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
package u
22

3+
// True is a `bool` that is set to true
4+
var True = NewBool(true)
5+
6+
// False is a `bool` that is set to false
7+
var False = NewBool(false)
8+
39
// Bool is a `bool` that can be unset
410
type Bool = Var[bool]
511

u_test.go

+10-5
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,8 @@ func TestVar_Struct(t *testing.T) {
457457
Value15 u.Complex64
458458
Value16 u.Complex128
459459
Value17 u.Bool
460-
Value18 u.String
460+
Value18 u.Bool
461+
Value19 u.String
461462
}
462463

463464
prefs := Preferences{
@@ -477,8 +478,9 @@ func TestVar_Struct(t *testing.T) {
477478
Value14: u.NewRune('x'),
478479
Value15: u.NewComplex64(42 + 42i),
479480
Value16: u.NewComplex128(42 + 42i),
480-
Value17: u.NewBool(true),
481-
Value18: u.NewString("hello"),
481+
Value17: u.True,
482+
Value18: u.False,
483+
Value19: u.NewString("hello"),
482484
}
483485

484486
if prefs.Value1.Get() != 42 {
@@ -532,7 +534,10 @@ func TestVar_Struct(t *testing.T) {
532534
if prefs.Value17.Get() != true {
533535
t.Errorf("Get() = %v, want true", prefs.Value17.Get())
534536
}
535-
if prefs.Value18.Get() != "hello" {
536-
t.Errorf("Get() = %v, want \"hello\"", prefs.Value18.Get())
537+
if prefs.Value18.Get() != false {
538+
t.Errorf("Get() = %v, want false", prefs.Value18.Get())
539+
}
540+
if prefs.Value19.Get() != "hello" {
541+
t.Errorf("Get() = %v, want \"hello\"", prefs.Value19.Get())
537542
}
538543
}

0 commit comments

Comments
 (0)