patch 9.0.1973: Clean up cmdline option completion code

Problem:  Clean up cmdline option completion code
Solution: Fix various minor problems

- Fix manual array size calculations to just use `ARRAY_LENGTH()`.
- Fix unintentional typo in comments due to copy-paste error.
- Fix assert_equal() usages to pass the expected value to first
  parameter instead of 2nd one to avoid confusion.
- Fix signed vs unsigned warnings
- Correct misplaced comments about set_op_T and set_prefix_T
  and fix a typo in another comment

closes: #13249
closes: #13237

Signed-off-by: Christian Brabandt <cb@256bit.org>
Co-authored-by: Yee Cheng Chin <ychin.git@gmail.com>
Co-authored-by: zeertzjq <zeertzjq@outlook.com>
diff --git a/src/optionstr.c b/src/optionstr.c
index 5a3dd6e..dbef8ea 100644
--- a/src/optionstr.c
+++ b/src/optionstr.c
@@ -737,7 +737,7 @@
 expand_set_opt_string(
 	optexpand_T *args,
 	char **values,
-	int numValues,
+	size_t numValues,
 	int *numMatches,
 	char_u ***matches)
 {
@@ -863,7 +863,7 @@
     int	    append = args->oe_append;
     int	    include_orig_val = args->oe_include_orig_val && (*option_val != NUL);
 
-    int num_flags = STRLEN(flags);
+    size_t num_flags = STRLEN(flags);
 
     // Assume we only have small number of flags, so just allocate max size.
     *matches = ALLOC_MULT(char_u *, num_flags + 1);
@@ -940,7 +940,7 @@
     return expand_set_opt_string(
 	    args,
 	    p_ambw_values,
-	    sizeof(p_ambw_values) / sizeof(p_ambw_values[0]) - 1,
+	    ARRAY_LENGTH(p_ambw_values) - 1,
 	    numMatches,
 	    matches);
 }
@@ -987,7 +987,7 @@
     return expand_set_opt_string(
 	    args,
 	    p_bg_values,
-	    sizeof(p_bg_values) / sizeof(p_bg_values[0]) - 1,
+	    ARRAY_LENGTH(p_bg_values) - 1,
 	    numMatches,
 	    matches);
 }
@@ -1015,7 +1015,7 @@
     return expand_set_opt_string(
 	    args,
 	    p_bs_values,
-	    sizeof(p_bs_values) / sizeof(p_bs_values[0]) - 1,
+	    ARRAY_LENGTH(p_bs_values) - 1,
 	    numMatches,
 	    matches);
 }
@@ -1063,7 +1063,7 @@
     return expand_set_opt_string(
 	    args,
 	    p_bkc_values,
-	    sizeof(p_bkc_values) / sizeof(p_bkc_values[0]) - 1,
+	    ARRAY_LENGTH(p_bkc_values) - 1,
 	    numMatches,
 	    matches);
 }
@@ -1096,7 +1096,7 @@
     return expand_set_opt_string(
 	    args,
 	    p_bo_values,
-	    sizeof(p_bo_values) / sizeof(p_bo_values[0]) - 1,
+	    ARRAY_LENGTH(p_bo_values) - 1,
 	    numMatches,
 	    matches);
 }
@@ -1125,7 +1125,7 @@
     return expand_set_opt_string(
 	    args,
 	    p_briopt_values,
-	    sizeof(p_briopt_values) / sizeof(p_briopt_values[0]) - 1,
+	    ARRAY_LENGTH(p_briopt_values) - 1,
 	    numMatches,
 	    matches);
 }
@@ -1151,7 +1151,7 @@
     return expand_set_opt_string(
 	    args,
 	    p_bsdir_values,
-	    sizeof(p_bsdir_values) / sizeof(p_bsdir_values[0]) - 1,
+	    ARRAY_LENGTH(p_bsdir_values) - 1,
 	    numMatches,
 	    matches);
 }
@@ -1172,7 +1172,7 @@
     return expand_set_opt_string(
 	    args,
 	    p_bufhidden_values,
-	    sizeof(p_bufhidden_values) / sizeof(p_bufhidden_values[0]) - 1,
+	    ARRAY_LENGTH(p_bufhidden_values) - 1,
 	    numMatches,
 	    matches);
 }
@@ -1203,7 +1203,7 @@
     return expand_set_opt_string(
 	    args,
 	    p_buftype_values,
-	    sizeof(p_buftype_values) / sizeof(p_buftype_values[0]) - 1,
+	    ARRAY_LENGTH(p_buftype_values) - 1,
 	    numMatches,
 	    matches);
 }
@@ -1223,7 +1223,7 @@
     return expand_set_opt_string(
 	    args,
 	    p_cmp_values,
-	    sizeof(p_cmp_values) / sizeof(p_cmp_values[0]) - 1,
+	    ARRAY_LENGTH(p_cmp_values) - 1,
 	    numMatches,
 	    matches);
 }
@@ -1235,7 +1235,7 @@
     return expand_set_opt_string(
 	    args,
 	    p_cb_values,
-	    sizeof(p_cb_values) / sizeof(p_cb_values[0]) - 1,
+	    ARRAY_LENGTH(p_cb_values) - 1,
 	    numMatches,
 	    matches);
 }
@@ -1461,7 +1461,7 @@
     return expand_set_opt_string(
 	    args,
 	    p_cpt_values,
-	    sizeof(p_cpt_values) / sizeof(p_cpt_values[0]) - 1,
+	    ARRAY_LENGTH(p_cpt_values) - 1,
 	    numMatches,
 	    matches);
 }
@@ -1485,7 +1485,7 @@
     return expand_set_opt_string(
 	    args,
 	    p_cot_values,
-	    sizeof(p_cot_values) / sizeof(p_cot_values[0]) - 1,
+	    ARRAY_LENGTH(p_cot_values) - 1,
 	    numMatches,
 	    matches);
 }
@@ -1525,7 +1525,7 @@
     return expand_set_opt_string(
 	    args,
 	    p_csl_values,
-	    sizeof(p_csl_values) / sizeof(p_csl_values[0]) - 1,
+	    ARRAY_LENGTH(p_csl_values) - 1,
 	    numMatches,
 	    matches);
 }
@@ -1664,7 +1664,7 @@
     return expand_set_opt_string(
 	    args,
 	    p_cm_values,
-	    sizeof(p_cm_values) / sizeof(p_cm_values[0]) - 1,
+	    ARRAY_LENGTH(p_cm_values) - 1,
 	    numMatches,
 	    matches);
 }
@@ -1722,7 +1722,7 @@
     return expand_set_opt_string(
 	    args,
 	    p_culopt_values,
-	    sizeof(p_culopt_values) / sizeof(p_culopt_values[0]) - 1,
+	    ARRAY_LENGTH(p_culopt_values) - 1,
 	    numMatches,
 	    matches);
 }
@@ -1743,7 +1743,7 @@
     return expand_set_opt_string(
 	    args,
 	    p_debug_values,
-	    sizeof(p_debug_values) / sizeof(p_debug_values[0]) - 1,
+	    ARRAY_LENGTH(p_debug_values) - 1,
 	    numMatches,
 	    matches);
 }
@@ -1769,14 +1769,14 @@
     if (xp->xp_pattern > args->oe_set_arg && *(xp->xp_pattern-1) == ':')
     {
 	// Within "algorithm:", we have a subgroup of possible options.
-	int algo_len = STRLEN("algorithm:");
+	int algo_len = (int)STRLEN("algorithm:");
 	if (xp->xp_pattern - args->oe_set_arg >= algo_len &&
 		STRNCMP(xp->xp_pattern - algo_len, "algorithm:", algo_len) == 0)
 	{
 	    return expand_set_opt_string(
 		    args,
 		    p_dip_algorithm_values,
-		    sizeof(p_dip_algorithm_values) / sizeof(p_dip_algorithm_values[0]) - 1,
+		    ARRAY_LENGTH(p_dip_algorithm_values) - 1,
 		    numMatches,
 		    matches);
 	}
@@ -1786,7 +1786,7 @@
     return expand_set_opt_string(
 	    args,
 	    p_dip_values,
-	    sizeof(p_dip_values) / sizeof(p_dip_values[0]) - 1,
+	    ARRAY_LENGTH(p_dip_values) - 1,
 	    numMatches,
 	    matches);
 }
@@ -1811,7 +1811,7 @@
     return expand_set_opt_string(
 	    args,
 	    p_dy_values,
-	    sizeof(p_dy_values) / sizeof(p_dy_values[0]) - 1,
+	    ARRAY_LENGTH(p_dy_values) - 1,
 	    numMatches,
 	    matches);
 }
@@ -1831,7 +1831,7 @@
     return expand_set_opt_string(
 	    args,
 	    p_ead_values,
-	    sizeof(p_ead_values) / sizeof(p_ead_values[0]) - 1,
+	    ARRAY_LENGTH(p_ead_values) - 1,
 	    numMatches,
 	    matches);
 }
@@ -2005,7 +2005,7 @@
     return expand_set_opt_string(
 	    args,
 	    p_ff_values,
-	    sizeof(p_ff_values) / sizeof(p_ff_values[0]) - 1,
+	    ARRAY_LENGTH(p_ff_values) - 1,
 	    numMatches,
 	    matches);
 }
@@ -2064,7 +2064,7 @@
     return expand_set_opt_string(
 	    args,
 	    p_fcl_values,
-	    sizeof(p_fcl_values) / sizeof(p_fcl_values[0]) - 1,
+	    ARRAY_LENGTH(p_fcl_values) - 1,
 	    numMatches,
 	    matches);
 }
@@ -2140,7 +2140,7 @@
     return expand_set_opt_string(
 	    args,
 	    p_fdm_values,
-	    sizeof(p_fdm_values) / sizeof(p_fdm_values[0]) - 1,
+	    ARRAY_LENGTH(p_fdm_values) - 1,
 	    numMatches,
 	    matches);
 }
@@ -2160,7 +2160,7 @@
     return expand_set_opt_string(
 	    args,
 	    p_fdo_values,
-	    sizeof(p_fdo_values) / sizeof(p_fdo_values[0]) - 1,
+	    ARRAY_LENGTH(p_fdo_values) - 1,
 	    numMatches,
 	    matches);
 }
@@ -2381,7 +2381,7 @@
     char_u	    *p;
     expand_T	    *xp = args->oe_xp;
     static char_u   hl_flags[HLF_COUNT] = HL_FLAGS;
-    int		    i;
+    size_t 	    i;
     int		    count = 0;
 
     if (xp->xp_pattern > args->oe_set_arg && *(xp->xp_pattern-1) == ':')
@@ -2446,15 +2446,15 @@
     // the returned match.
 
     // Note: Keep this in sync with highlight_changed()
-    static char p_hl_mode_values[] =
+    static char_u p_hl_mode_values[] =
 	{':', 'b', 'i', '-', 'n', 'r', 's', 'u', 'c', '2', 'd', '=', 't'};
-    int num_hl_modes = sizeof(p_hl_mode_values) / sizeof(p_hl_mode_values[0]);
+    size_t num_hl_modes = ARRAY_LENGTH(p_hl_mode_values);
 
     *matches = ALLOC_MULT(char_u *, num_hl_modes);
     if (*matches == NULL)
 	return FAIL;
 
-    int pattern_len = STRLEN(xp->xp_pattern);
+    size_t pattern_len = STRLEN(xp->xp_pattern);
 
     for (i = 0; i < num_hl_modes; i++)
     {
@@ -2576,7 +2576,7 @@
     return expand_set_opt_string(
 	    args,
 	    p_jop_values,
-	    sizeof(p_jop_values) / sizeof(p_jop_values[0]) - 1,
+	    ARRAY_LENGTH(p_jop_values) - 1,
 	    numMatches,
 	    matches);
 }
@@ -2660,7 +2660,7 @@
     return expand_set_opt_string(
 	    args,
 	    p_km_values,
-	    sizeof(p_km_values) / sizeof(p_km_values[0]) - 1,
+	    ARRAY_LENGTH(p_km_values) - 1,
 	    numMatches,
 	    matches);
 }
@@ -2692,7 +2692,7 @@
 	return expand_set_opt_string(
 		args,
 		p_kpc_protocol_values,
-		sizeof(p_kpc_protocol_values) / sizeof(p_kpc_protocol_values[0]) - 1,
+		ARRAY_LENGTH(p_kpc_protocol_values) - 1,
 		numMatches,
 		matches);
     }
@@ -2725,7 +2725,7 @@
     return expand_set_opt_string(
 	    args,
 	    p_lop_values,
-	    sizeof(p_lop_values) / sizeof(p_lop_values[0]) - 1,
+	    ARRAY_LENGTH(p_lop_values) - 1,
 	    numMatches,
 	    matches);
 }
@@ -2831,7 +2831,7 @@
     return expand_set_opt_string(
 	    args,
 	    p_mousem_values,
-	    sizeof(p_mousem_values) / sizeof(p_mousem_values[0]) - 1,
+	    ARRAY_LENGTH(p_mousem_values) - 1,
 	    numMatches,
 	    matches);
 }
@@ -2866,7 +2866,7 @@
     return expand_set_opt_string(
 	    args,
 	    p_nf_values,
-	    sizeof(p_nf_values) / sizeof(p_nf_values[0]) - 1,
+	    ARRAY_LENGTH(p_nf_values) - 1,
 	    numMatches,
 	    matches);
 }
@@ -2940,29 +2940,29 @@
     if (xp->xp_pattern > args->oe_set_arg && *(xp->xp_pattern-1) == ':')
     {
 	// Within "highlight:"/"border:"/"align:", we have a subgroup of possible options.
-	int border_len = STRLEN("border:");
+	int border_len = (int)STRLEN("border:");
 	if (xp->xp_pattern - args->oe_set_arg >= border_len &&
 		STRNCMP(xp->xp_pattern - border_len, "border:", border_len) == 0)
 	{
 	    return expand_set_opt_string(
 		    args,
 		    p_popup_option_border_values,
-		    sizeof(p_popup_option_border_values) / sizeof(p_popup_option_border_values[0]) - 1,
+		    ARRAY_LENGTH(p_popup_option_border_values) - 1,
 		    numMatches,
 		    matches);
 	}
-	int align_len = STRLEN("align:");
+	int align_len = (int)STRLEN("align:");
 	if (xp->xp_pattern - args->oe_set_arg >= align_len &&
 		STRNCMP(xp->xp_pattern - align_len, "align:", align_len) == 0)
 	{
 	    return expand_set_opt_string(
 		    args,
 		    p_popup_option_align_values,
-		    sizeof(p_popup_option_align_values) / sizeof(p_popup_option_align_values[0]) - 1,
+		    ARRAY_LENGTH(p_popup_option_align_values) - 1,
 		    numMatches,
 		    matches);
 	}
-	int highlight_len = STRLEN("highlight:");
+	int highlight_len = (int)STRLEN("highlight:");
 	if (xp->xp_pattern - args->oe_set_arg >= highlight_len &&
 		STRNCMP(xp->xp_pattern - highlight_len, "highlight:", highlight_len) == 0)
 	{
@@ -2979,7 +2979,7 @@
     return expand_set_opt_string(
 	    args,
 	    p_popup_option_values,
-	    sizeof(p_popup_option_values) / sizeof(p_popup_option_values[0]) - 1,
+	    ARRAY_LENGTH(p_popup_option_values) - 1,
 	    numMatches,
 	    matches);
 }
@@ -3022,7 +3022,7 @@
     static char_u *
 get_printoptions_names(expand_T *xp UNUSED, int idx)
 {
-    if (idx >= (int)(sizeof(printer_opts) / sizeof(printer_opts[0])))
+    if (idx >= (int)ARRAY_LENGTH(printer_opts))
 	return NULL;
     return (char_u*)printer_opts[idx].name;
 }
@@ -3115,7 +3115,7 @@
     return expand_set_opt_string(
 	    args,
 	    p_rlc_values,
-	    sizeof(p_rlc_values) / sizeof(p_rlc_values[0]) - 1,
+	    ARRAY_LENGTH(p_rlc_values) - 1,
 	    numMatches,
 	    matches);
 }
@@ -3147,7 +3147,7 @@
     return expand_set_opt_string(
 	    args,
 	    p_scbopt_values,
-	    sizeof(p_scbopt_values) / sizeof(p_scbopt_values[0]) - 1,
+	    ARRAY_LENGTH(p_scbopt_values) - 1,
 	    numMatches,
 	    matches);
 }
@@ -3170,7 +3170,7 @@
     return expand_set_opt_string(
 	    args,
 	    p_sel_values,
-	    sizeof(p_sel_values) / sizeof(p_sel_values[0]) - 1,
+	    ARRAY_LENGTH(p_sel_values) - 1,
 	    numMatches,
 	    matches);
 }
@@ -3190,7 +3190,7 @@
     return expand_set_opt_string(
 	    args,
 	    p_slm_values,
-	    sizeof(p_slm_values) / sizeof(p_slm_values[0]) - 1,
+	    ARRAY_LENGTH(p_slm_values) - 1,
 	    numMatches,
 	    matches);
 }
@@ -3221,7 +3221,7 @@
     return expand_set_opt_string(
 	    args,
 	    p_ssop_values,
-	    sizeof(p_ssop_values) / sizeof(p_ssop_values[0]) - 1,
+	    ARRAY_LENGTH(p_ssop_values) - 1,
 	    numMatches,
 	    matches);
 }
@@ -3280,7 +3280,7 @@
     return expand_set_opt_string(
 	    args,
 	    p_sloc_values,
-	    sizeof(p_sloc_values) / sizeof(p_sloc_values[0]) - 1,
+	    ARRAY_LENGTH(p_sloc_values) - 1,
 	    numMatches,
 	    matches);
 }
@@ -3312,7 +3312,7 @@
     return expand_set_opt_string(
 	    args,
 	    p_scl_values,
-	    sizeof(p_scl_values) / sizeof(p_scl_values[0]) - 1,
+	    ARRAY_LENGTH(p_scl_values) - 1,
 	    numMatches,
 	    matches);
 }
@@ -3382,7 +3382,7 @@
     return expand_set_opt_string(
 	    args,
 	    p_spo_values,
-	    sizeof(p_spo_values) / sizeof(p_spo_values[0]) - 1,
+	    ARRAY_LENGTH(p_spo_values) - 1,
 	    numMatches,
 	    matches);
 }
@@ -3405,7 +3405,7 @@
     return expand_set_opt_string(
 	    args,
 	    p_sps_values,
-	    sizeof(p_sps_values) / sizeof(p_sps_values[0]) - 1,
+	    ARRAY_LENGTH(p_sps_values) - 1,
 	    numMatches,
 	    matches);
 }
@@ -3426,7 +3426,7 @@
     return expand_set_opt_string(
 	    args,
 	    p_spk_values,
-	    sizeof(p_spk_values) / sizeof(p_spk_values[0]) - 1,
+	    ARRAY_LENGTH(p_spk_values) - 1,
 	    numMatches,
 	    matches);
 }
@@ -3457,7 +3457,7 @@
     return expand_set_opt_string(
 	    args,
 	    p_sws_values,
-	    sizeof(p_sws_values) / sizeof(p_sws_values[0]) - 1,
+	    ARRAY_LENGTH(p_sws_values) - 1,
 	    numMatches,
 	    matches);
 }
@@ -3477,7 +3477,7 @@
     return expand_set_opt_string(
 	    args,
 	    p_swb_values,
-	    sizeof(p_swb_values) / sizeof(p_swb_values[0]) - 1,
+	    ARRAY_LENGTH(p_swb_values) - 1,
 	    numMatches,
 	    matches);
 }
@@ -3529,7 +3529,7 @@
     return expand_set_opt_string(
 	    args,
 	    p_tc_values,
-	    sizeof(p_tc_values) / sizeof(p_tc_values[0]) - 1,
+	    ARRAY_LENGTH(p_tc_values) - 1,
 	    numMatches,
 	    matches);
 }
@@ -3674,7 +3674,7 @@
     return expand_set_opt_string(
 	    args,
 	    p_twt_values,
-	    sizeof(p_twt_values) / sizeof(p_twt_values[0]) - 1,
+	    ARRAY_LENGTH(p_twt_values) - 1,
 	    numMatches,
 	    matches);
 }
@@ -3718,7 +3718,7 @@
     return expand_set_opt_string(
 	    args,
 	    p_toolbar_values,
-	    sizeof(p_toolbar_values) / sizeof(p_toolbar_values[0]) - 1,
+	    ARRAY_LENGTH(p_toolbar_values) - 1,
 	    numMatches,
 	    matches);
 }
@@ -3746,7 +3746,7 @@
     return expand_set_opt_string(
 	    args,
 	    p_tbis_values,
-	    sizeof(p_tbis_values) / sizeof(p_tbis_values[0]) - 1,
+	    ARRAY_LENGTH(p_tbis_values) - 1,
 	    numMatches,
 	    matches);
 }
@@ -3780,7 +3780,7 @@
     return expand_set_opt_string(
 	    args,
 	    p_ttym_values,
-	    sizeof(p_ttym_values) / sizeof(p_ttym_values[0]) - 1,
+	    ARRAY_LENGTH(p_ttym_values) - 1,
 	    numMatches,
 	    matches);
 }
@@ -3996,7 +3996,7 @@
     return expand_set_opt_string(
 	    args,
 	    p_ve_values,
-	    sizeof(p_ve_values) / sizeof(p_ve_values[0]) - 1,
+	    ARRAY_LENGTH(p_ve_values) - 1,
 	    numMatches,
 	    matches);
 }
@@ -4037,7 +4037,7 @@
     return expand_set_opt_string(
 	    args,
 	    p_wim_values,
-	    sizeof(p_wim_values) / sizeof(p_wim_values[0]) - 1,
+	    ARRAY_LENGTH(p_wim_values) - 1,
 	    numMatches,
 	    matches);
 }
@@ -4057,7 +4057,7 @@
     return expand_set_opt_string(
 	    args,
 	    p_wop_values,
-	    sizeof(p_wop_values) / sizeof(p_wop_values[0]) - 1,
+	    ARRAY_LENGTH(p_wop_values) - 1,
 	    numMatches,
 	    matches);
 }
@@ -4091,7 +4091,7 @@
     return expand_set_opt_string(
 	    args,
 	    p_wak_values,
-	    sizeof(p_wak_values) / sizeof(p_wak_values[0]) - 1,
+	    ARRAY_LENGTH(p_wak_values) - 1,
 	    numMatches,
 	    matches);
 }