Skip to content

Commit

Permalink
feat: change void to use interface{}
Browse files Browse the repository at this point in the history
  • Loading branch information
hjwalt committed Dec 6, 2023
1 parent 6b07e64 commit a87d3ec
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion structure/void.go
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{}
28 changes: 28 additions & 0 deletions structure/void_test.go
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")
}

0 comments on commit a87d3ec

Please sign in to comment.