t9902-completion: add tests for the __git_find_on_cmdline() helper
The following two patches will refactor and extend the __git_find_on_cmdline() helper function, so let's add a few tests first to make sure that its basic behavior doesn't change. Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
SZEDER Gábor committed
Dec 19, 2019 at 16:09 UTC
2712e91564077f1b004ca02dd862e00be13451cb
1 file changed
+28
t/t9902-completion.sh
+28
@@ -1363,6 +1363,34 @@ test_expect_success 'teardown after path completion tests' '
1363
BS\\dir '$'separators\034in\035dir''
1364
'
1365
1366
+test_expect_success '__git_find_on_cmdline - single match' '
1367
+ echo list >expect &&
1368
+ (
1369
+ words=(git command --opt list) &&
1370
+ cword=${#words[@]} &&
1371
+ __git_find_on_cmdline "add list remove" >actual
1372
+ ) &&
1373
+ test_cmp expect actual
1374
+'
1375
+
1376
+test_expect_success '__git_find_on_cmdline - multiple matches' '
1377
+ echo remove >expect &&
1378
+ (
1379
+ words=(git command -o --opt remove list add) &&
1380
+ cword=${#words[@]} &&
1381
+ __git_find_on_cmdline "add list remove" >actual
1382
+ ) &&
1383
+ test_cmp expect actual
1384
+'
1385
+
1386
+test_expect_success '__git_find_on_cmdline - no match' '
1387
+ (
1388
+ words=(git command --opt branch) &&
1389
+ cword=${#words[@]} &&
1390
+ __git_find_on_cmdline "add list remove" >actual
1391
+ ) &&
1392
+ test_must_be_empty actual
1393
+'
1394
1395
test_expect_success '__git_get_config_variables' '
1396
cat >expect <<-EOF &&