Diff options
Diffstat (limited to 'tests')
| -rwxr-xr-x | tests/t0104-tree.sh | 58 |
1 file changed, 51 insertions, 7 deletions
diff --git a/tests/t0104-tree.sh b/tests/t0104-tree.sh index dcdeea3..f17dd34 100755 --- a/tests/t0104-tree.sh +++ b/tests/t0104-tree.sh @@ -33,13 +33,53 @@ test_expect_success 'the file table is read as layout' ' grep "<table class=.blob. role=.presentation.>" tmp ' +# Prints, in stylesheet order, the declarations of the properties named +# second that the rules for the selector named first make, so the last line +# is the one a browser applies wherever the rules stand. A rule names the +# selector when one entry of its list is that selector whole, and a rule +# inside a media query counts like any other. +css_declarations() { + awk -v target="$1" -v properties="$2" ' + BEGIN { + RS = "}" + n = split(properties, list, " ") + for (i = 1; i <= n; i++) + wanted[list[i]] = 1 + } + { + n = split($0, part, "[{]") + if (n < 2) + next + named = 0 + m = split(part[n - 1], selector, ",") + for (i = 1; i <= m; i++) { + s = selector[i] + gsub(/^[ \t\n]+|[ \t\n]+$/, "", s) + if (s == target) + named = 1 + } + if (!named) + next + m = split(part[n], declaration, ";") + for (i = 1; i <= m; i++) { + d = declaration[i] + gsub(/^[ \t\n]+|[ \t\n]+$/, "", d) + name = substr(d, 1, index(d, ":") - 1) + if (name in wanted) + print d + } + } + ' "$TEST_OUTPUT_DIRECTORY/../assets/cgit.css" +} + # The numbers and the code are two columns of text that a browser keeps in # step only while both are set in one font. Only a browser shows the drift, # so this checks the rule that prevents it. test_expect_success 'the code is set in the font of its line numbers' ' - sed -n "/^div#cgit table.blob code {/,/^}/p" \ - "$TEST_OUTPUT_DIRECTORY/../assets/cgit.css" >rule && - grep "^ font: inherit;$" rule + css_declarations "div#cgit table.blob code" "font font-family font-size" >decls && + tail -n 1 decls >actual && + echo "font: inherit" >expect && + test_cmp expect actual ' # A browser starts a new line at more characters than git ends one at, and @@ -321,10 +361,14 @@ test_expect_success 'a binary file in the tree shows as a hex dump' ' # The dump scrolls sideways inside its own table, which a keyboard reaches # by focusing the table, so the table takes the focus ring links have. test_expect_success 'a focused hex dump shows the focus ring' ' - sed -n "/^div#cgit a:focus-visible,$/,/^}/p" \ - "$TEST_OUTPUT_DIRECTORY/../assets/cgit.css" >rule && - grep "^div#cgit table.bin-blob:focus-visible" rule && - grep "^ outline: solid 2px var(--link);$" rule + ring="outline outline-style outline-width outline-color" && + css_declarations "div#cgit a:focus-visible" "$ring" >decls && + tail -n 1 decls >expect && + echo "outline: solid 2px var(--link)" >ring && + test_cmp ring expect && + css_declarations "div#cgit table.bin-blob:focus-visible" "$ring" >decls && + tail -n 1 decls >actual && + test_cmp expect actual ' # Each byte of the dump costs several bytes of markup, so a large binary is |
