patch 9.0.1442: mapset() does not restore non-script context

Problem:    mapset() does not restore non-script context.
Solution:   Also accept negative sid. (closes #12132)
diff --git a/src/testdir/test_map_functions.vim b/src/testdir/test_map_functions.vim
index a750cd7..d76c79c 100644
--- a/src/testdir/test_map_functions.vim
+++ b/src/testdir/test_map_functions.vim
@@ -1,6 +1,8 @@
 " Tests for maparg(), mapcheck(), mapset(), maplist()
 " Also test utf8 map with a 0x80 byte.
 
+source shared.vim
+
 func s:SID()
   return str2nr(matchstr(expand('<sfile>'), '<SNR>\zs\d\+\ze_SID$'))
 endfunc
@@ -490,7 +492,28 @@
   call Check_ctrlb_map(dsimp, 0)
 
   nunmap <C-B>
+endfunc
 
+" Test restoring the script context of a mapping
+func Test_map_restore_sid()
+  let after =<< trim [CODE]
+    call assert_equal("\tLast set from --cmd argument",
+          \ execute('verbose nmap ,n')->trim()->split("\n")[-1])
+    let d = maparg(',n', 'n', 0, 1)
+    nunmap ,n
+    call assert_equal('No mapping found',
+          \ execute('verbose nmap ,n')->trim()->split("\n")[-1])
+    call mapset('n', 0, d)
+    call assert_equal("\tLast set from --cmd argument",
+          \ execute('verbose nmap ,n')->trim()->split("\n")[-1])
+    call writefile(v:errors, 'Xresult')
+    qall!
+  [CODE]
+
+  if RunVim([], after, '--clean --cmd "nmap ,n <Nop>"')
+    call assert_equal([], readfile('Xresult'))
+  endif
+  call delete('Xresult')
 endfunc
 
 def Test_maplist()