-
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.
feat: change void to use interface{}
- Loading branch information
Showing
2 changed files
with
29 additions
and
1 deletion.
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package structure | ||
|
||
// denoting no value for generic | ||
type Void struct{} | ||
type Void = interface{} |
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,28 @@ | ||
package structure_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/hjwalt/runway/structure" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestVoidCast(t *testing.T) { | ||
assert := assert.New(t) | ||
|
||
var voidValue structure.Void | ||
|
||
voidValue = 1 | ||
assert.Equal(voidValue, 1) | ||
|
||
intValue := 2 | ||
voidValue = structure.Void(intValue) | ||
assert.Equal(voidValue, 2) | ||
|
||
castTest, castSuccessful := voidValue.(int) | ||
assert.Equal(castTest, 2) | ||
assert.True(castSuccessful) | ||
|
||
voidValue = "string" | ||
assert.Equal(voidValue, "string") | ||
} |