patch 9.1.0883: message history cleanup is missing some tests

Problem:  message history cleanup is missing some tests
Solution: Add tests, refactor common code into did_set_msghistory()
          (Shougo Matsushita)

closes: #16078

Co-authored-by: zeertzjq <zeertzjq@outlook.com>
Co-authored-by: Milly <milly.ca@gmail.com>
Signed-off-by: Shougo Matsushita <Shougo.Matsu@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
diff --git a/src/option.c b/src/option.c
index 4616d63..226c31d 100644
--- a/src/option.c
+++ b/src/option.c
@@ -3864,6 +3864,31 @@
     return NULL;
 }
 
+/*
+ * Process the updated 'msghistory' option value.
+ */
+    char *
+did_set_msghistory(optset_T *args UNUSED)
+{
+    char *errmsg = NULL;
+
+    // 'msghistory' must be positive
+    if (p_mhi < 0)
+    {
+	errmsg = e_argument_must_be_positive;
+	p_mhi = 0;
+    }
+    else if (p_mhi > 10000)
+    {
+	errmsg = e_invalid_argument;
+	p_mhi = 10000;
+    }
+
+    check_msg_hist();
+
+    return errmsg;
+}
+
 #if defined(FEAT_LINEBREAK) || defined(PROTO)
 /*
  * Process the new 'numberwidth' option value.
@@ -4914,16 +4939,6 @@
 	errmsg = e_invalid_argument;
 	p_hi = 10000;
     }
-    if (p_mhi < 0)
-    {
-	errmsg = e_argument_must_be_positive;
-	p_mhi = 0;
-    }
-    else if (p_mhi > 10000)
-    {
-	errmsg = e_invalid_argument;
-	p_mhi = 10000;
-    }
     if (p_re < 0 || p_re > 2)
     {
 	errmsg = e_invalid_argument;