]> granicus.if.org Git - vim/commitdiff
patch 7.4.1157 v7.4.1157
authorBram Moolenaar <Bram@vim.org>
Sat, 23 Jan 2016 20:59:52 +0000 (21:59 +0100)
committerBram Moolenaar <Bram@vim.org>
Sat, 23 Jan 2016 20:59:52 +0000 (21:59 +0100)
Problem:    type() does not work for v:true, v:none, etc.
Solution:   Add new type numbers.

src/eval.c
src/testdir/test_json.vim
src/testdir/test_viml.vim
src/version.c

index c41e4a55a1ee147b5b9ab3f004088b6a94ed96fb..7edae39147c6ff4a2faf41d2f36c7f85ef7bc135 100644 (file)
@@ -20157,6 +20157,13 @@ f_type(argvars, rettv)
 #ifdef FEAT_FLOAT
        case VAR_FLOAT:  n = 5; break;
 #endif
+       case VAR_SPECIAL:
+                        if (argvars[0].vval.v_number == VVAL_FALSE
+                                || argvars[0].vval.v_number == VVAL_TRUE)
+                            n = 6;
+                        else
+                            n = 7;
+                        break;
        default: EMSG2(_(e_intern2), "f_type()"); n = 0; break;
     }
     rettv->vval.v_number = n;
index e658c9778e1c322790e031f5e55b2cf6063ed301..b30647947fdb3aceb5d5056c68a85f37a6c786a1 100644 (file)
@@ -88,4 +88,18 @@ func Test_decode()
   call assert_equal(s:vard2x, jsondecode(s:jsond2))
 
   call assert_equal(s:varvals, jsondecode(s:jsonvals))
+
+  call assert_equal(v:true, jsondecode('true'))
+  call assert_equal(type(v:true), type(jsondecode('true')))
+  call assert_equal(v:none, jsondecode(''))
+  call assert_equal(type(v:none), type(jsondecode('')))
+  call assert_equal("", jsondecode('""'))
+
+  call assert_fails('call jsondecode("\"")', "E474:")
+  call assert_fails('call jsondecode("{-}")', "E474:")
+  call assert_fails('call jsondecode("blah")', "E474:")
+  call assert_fails('call jsondecode("true blah")', "E474:")
+  call assert_fails('call jsondecode("<foobar>")', "E474:")
+  call assert_fails('call jsondecode("[foobar]")', "E474:")
+  call assert_fails('call jsondecode("{foobar}")', "E474:")
 endfunc
index 07286fb0243c9ab60cb642579cce894fddbdfce9..39c0667b81409b9aeedaf22e2e86612a60a4051c 100644 (file)
@@ -921,6 +921,23 @@ func Test_curlies()
     call assert_equal(77, g:a['t'])
 endfunc
 
+"-------------------------------------------------------------------------------
+" Test 91:  using type().                                          {{{1
+"-------------------------------------------------------------------------------
+
+func Test_type()
+    call assert_equal(0, type(0))
+    call assert_equal(1, type(""))
+    call assert_equal(2, type(function("tr")))
+    call assert_equal(3, type([]))
+    call assert_equal(4, type({}))
+    call assert_equal(5, type(0.0))
+    call assert_equal(6, type(v:false))
+    call assert_equal(6, type(v:true))
+    call assert_equal(7, type(v:none))
+    call assert_equal(7, type(v:null))
+endfunc
+
 "-------------------------------------------------------------------------------
 " Modelines                                                                {{{1
 " vim: ts=8 sw=4 tw=80 fdm=marker
index d646665c9dde55778271e7852d9d608444812ade..2c9911057c6fe70f1ef43e58004a3a26ec5d76fe 100644 (file)
@@ -741,6 +741,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1157,
 /**/
     1156,
 /**/