File tree Expand file tree Collapse file tree 2 files changed +45
-0
lines changed
Expand file tree Collapse file tree 2 files changed +45
-0
lines changed Original file line number Diff line number Diff line change @@ -50,6 +50,9 @@ func (s StringCallable) toInterface() interface{} {
5050// TypeOf implements the jsonata $type function that returns the data type of
5151// the argument
5252func TypeOf (x interface {}) (string , error ) {
53+ if x == nil {
54+ return "null" , nil
55+ }
5356 v := reflect .ValueOf (x )
5457 if jtypes .IsCallable (v ) {
5558 return "function" , nil
Original file line number Diff line number Diff line change @@ -8122,7 +8122,49 @@ func readJSON(filename string) interface{} {
81228122func TestNullValue (t * testing.T ) {
81238123 nv := nullValue ()
81248124 require .True (t , nv .IsValid ())
8125+ require .True (t , nv .IsZero ())
81258126 require .True (t , nv .IsNil ())
81268127 require .True (t , nv .CanInterface ())
81278128 require .True (t , nv .Interface () == nil )
81288129}
8130+
8131+ func TestFuncType (t * testing.T ) {
8132+ runTestCases (t , nil , []* testCase {
8133+ {
8134+ Expression : []string {
8135+ `$type("Hello World")` ,
8136+ },
8137+ Output : "string" ,
8138+ },
8139+ {
8140+ Expression : []string {
8141+ `$type(true)` ,
8142+ },
8143+ Output : "boolean" ,
8144+ },
8145+ {
8146+ Expression : []string {
8147+ `$type(2.3)` ,
8148+ },
8149+ Output : "number" ,
8150+ },
8151+ {
8152+ Expression : []string {
8153+ `$type(3)` ,
8154+ },
8155+ Output : "number" ,
8156+ },
8157+ {
8158+ Expression : []string {
8159+ `$type(null)` ,
8160+ },
8161+ Output : "null" ,
8162+ },
8163+ {
8164+ Expression : []string {
8165+ `$type(a)` ,
8166+ },
8167+ Error : ErrUndefined ,
8168+ },
8169+ })
8170+ }
You can’t perform that action at this time.
0 commit comments