mirror of
				https://github.com/MontFerret/ferret.git
				synced 2025-10-30 23:37:40 +02:00 
			
		
		
		
	add unit tests for runtime/core - helpers (#78)
* add unit tests for runtime/core - helpers * update helpers to ignore struct/unsafe ptr
This commit is contained in:
		| @@ -11,12 +11,13 @@ func IsNil(input interface{}) bool { | ||||
| 		reflect.Array, | ||||
| 		reflect.Slice, | ||||
| 		reflect.Map, | ||||
| 		reflect.Struct, | ||||
| 		reflect.Func, | ||||
| 		reflect.Interface, | ||||
| 		reflect.Chan, | ||||
| 		reflect.UnsafePointer: | ||||
| 		reflect.Chan: | ||||
| 		return val.IsNil() | ||||
| 	case reflect.Struct, | ||||
| 		reflect.UnsafePointer: | ||||
| 		return false | ||||
| 	case reflect.Invalid: | ||||
| 		return true | ||||
| 	default: | ||||
|   | ||||
							
								
								
									
										72
									
								
								pkg/runtime/core/helpers_test.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										72
									
								
								pkg/runtime/core/helpers_test.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,72 @@ | ||||
| package core_test | ||||
|  | ||||
| import ( | ||||
| 	"testing" | ||||
| 	"unsafe" | ||||
|  | ||||
| 	"github.com/MontFerret/ferret/pkg/runtime/core" | ||||
| 	. "github.com/smartystreets/goconvey/convey" | ||||
| ) | ||||
|  | ||||
| type DummyInterface interface { | ||||
| 	DummyFunc() string | ||||
| } | ||||
|  | ||||
| type DummyStruct struct{} | ||||
|  | ||||
| func (d DummyStruct) DummyFunc() string { | ||||
| 	return "testing" | ||||
| } | ||||
|  | ||||
| func TestIsNil(t *testing.T) { | ||||
| 	Convey("Should match", t, func() { | ||||
| 		// nil == invalid | ||||
| 		t := core.IsNil(nil) | ||||
|  | ||||
| 		So(t, ShouldBeTrue) | ||||
|  | ||||
| 		a := []string{} | ||||
| 		t = core.IsNil(a) | ||||
|  | ||||
| 		So(t, ShouldBeFalse) | ||||
|  | ||||
| 		b := make([]string, 1) | ||||
| 		t = core.IsNil(b) | ||||
|  | ||||
| 		So(t, ShouldBeFalse) | ||||
|  | ||||
| 		c := make(map[string]string) | ||||
| 		t = core.IsNil(c) | ||||
|  | ||||
| 		So(t, ShouldBeFalse) | ||||
|  | ||||
| 		var s struct { | ||||
| 			Test string | ||||
| 		} | ||||
| 		t = core.IsNil(s) | ||||
|  | ||||
| 		So(t, ShouldBeFalse) | ||||
|  | ||||
| 		f := func() {} | ||||
| 		t = core.IsNil(f) | ||||
|  | ||||
| 		So(t, ShouldBeFalse) | ||||
|  | ||||
| 		i := DummyStruct{} | ||||
| 		t = core.IsNil(i) | ||||
|  | ||||
| 		So(t, ShouldBeFalse) | ||||
|  | ||||
| 		ch := make(chan string) | ||||
| 		t = core.IsNil(ch) | ||||
|  | ||||
| 		So(t, ShouldBeFalse) | ||||
|  | ||||
| 		var y unsafe.Pointer | ||||
| 		var vy int | ||||
| 		y = unsafe.Pointer(&vy) | ||||
| 		t = core.IsNil(y) | ||||
|  | ||||
| 		So(t, ShouldBeFalse) | ||||
| 	}) | ||||
| } | ||||
		Reference in New Issue
	
	Block a user