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{} {
50
50
// TypeOf implements the jsonata $type function that returns the data type of
51
51
// the argument
52
52
func TypeOf (x interface {}) (string , error ) {
53
+ if x == nil {
54
+ return "null" , nil
55
+ }
53
56
v := reflect .ValueOf (x )
54
57
if jtypes .IsCallable (v ) {
55
58
return "function" , nil
Original file line number Diff line number Diff line change @@ -8122,7 +8122,49 @@ func readJSON(filename string) interface{} {
8122
8122
func TestNullValue (t * testing.T ) {
8123
8123
nv := nullValue ()
8124
8124
require .True (t , nv .IsValid ())
8125
+ require .True (t , nv .IsZero ())
8125
8126
require .True (t , nv .IsNil ())
8126
8127
require .True (t , nv .CanInterface ())
8127
8128
require .True (t , nv .Interface () == nil )
8128
8129
}
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