diff options
Diffstat (limited to '')
| -rwxr-xr-x | tests/t0102-summary.sh | 77 |
1 file changed, 77 insertions, 0 deletions
diff --git a/tests/t0102-summary.sh b/tests/t0102-summary.sh index 181040d..e95f270 100755 --- a/tests/t0102-summary.sh +++ b/tests/t0102-summary.sh @@ -51,4 +51,81 @@ test_expect_success 'an scp clone url row links to the http url' ' ! grep "vcs-git. href=.git@" tmp ' +# Prints how many columns each row of the page's list table spans, one row to +# a line, counting a cell without a colspan as one. +row_widths() { + sed -n "/<table class='list/,/<\/table>/p" "$1" | awk ' + /^<tr[ >]/ { + width = 0 + row = $0 + while (match(row, /<t[dh][ >]/)) { + row = substr(row, RSTART + 3) + cell = substr(row, 1, index(row, ">")) + if (match(cell, /colspan=.[0-9]+/)) + width += substr(cell, RSTART + 9, RLENGTH - 9) + else + width++ + } + print width + } + ' +} + +# Fails unless every row of the list table at the url is as many columns wide +# as the second argument says. A third names a config other than colsrc. +test_widths() { + CGIT_CONFIG="$PWD/${3:-colsrc}" QUERY_STRING="url=$1" cgit >tmp && + row_widths tmp | sort -u >actual && + echo "$2" >expect && + test_cmp expect actual +} + +# The summary's sections share one table, so every row has to fill it, or the +# stripe of a shorter row stops short of the table's edge. The table is as +# wide as the log when both counts are on and as wide as a ref row otherwise. +# Each repo below shows the same history with different counts, and every +# section is cut short so that its [...] row is drawn too. +test_expect_success 'set up a repo cut short in every section' ' + mkrepo repos/cols 3 >/dev/null && + git -C repos/cols branch other HEAD~1 && + git -C repos/cols tag one HEAD~1 && + git -C repos/cols tag -a -m two two && + { + echo "virtual-root=/" && + echo "cache-size=0" && + echo "summary-branches=1" && + echo "summary-tags=1" && + echo "summary-log=2" && + echo "max-ref-count=1" && + echo "clone-url=https://example.org/\$CGIT_REPO_URL" && + echo "repo.url=none" && + echo "repo.path=$PWD/repos/cols/.git" && + echo "repo.url=lines" && + echo "repo.path=$PWD/repos/cols/.git" && + echo "repo.enable-log-linecount=1" && + echo "repo.url=both" && + echo "repo.path=$PWD/repos/cols/.git" && + echo "repo.enable-log-filecount=1" && + echo "repo.enable-log-linecount=1" + } >colsrc && + CGIT_CONFIG="$PWD/colsrc" QUERY_STRING="url=none" cgit >tmp && + grep "<tbody class=.tags.>" tmp && + grep "<tbody class=.clone.>" tmp && + test $(grep -c ">\[...\]</a>" tmp) = 3 +' + +test_expect_success 'a summary without counts fills four columns' 'test_widths none 4' +test_expect_success 'a summary with one count fills four columns' 'test_widths lines 4' +test_expect_success 'a summary with both counts fills five columns' 'test_widths both 5' + +test_expect_success 'a summary without a log fills four columns' ' + sed "s/^summary-log=2$/summary-log=0/" colsrc >nologrc && + test_widths both 4 nologrc +' + +# The refs page draws the same rows with nothing wider beside them. +test_expect_success 'the refs page fills four columns' 'test_widths both/refs/ 4' +test_expect_success 'a page of branches fills four columns' 'test_widths both/refs/heads 4' +test_expect_success 'a page of tags fills four columns' 'test_widths both/refs/tags 4' + test_done |
