-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bb8ecc9
commit 05442d7
Showing
4 changed files
with
68 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package typex | ||
|
||
import "reflect" | ||
|
||
func TypeOf[T any]() reflect.Type { | ||
var t T | ||
return reflect.TypeOf(t) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package typex | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestMultiType(t *testing.T) { | ||
m := NewMultiType2WithT1[double, string](1) | ||
if !m.IsT1() { | ||
t.Errorf("IsT1 failed") | ||
t.Fail() | ||
} | ||
if m.IsT2() { | ||
t.Errorf("IsT2 failed") | ||
t.Fail() | ||
} | ||
m.SetT2("hello") | ||
if !m.IsT2() { | ||
t.Errorf("IsT2 failed") | ||
t.Fail() | ||
} | ||
if m.IsT1() { | ||
t.Errorf("IsT1 failed") | ||
t.Fail() | ||
} | ||
if m.GetT2() != "hello" { | ||
t.Errorf("GetT2 failed") | ||
t.Fail() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,3 +10,4 @@ type u32 uint32 | |
type u64 uint64 | ||
type f32 float32 | ||
type f64 float64 | ||
type double float64 |