1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
test_description='Check the shipped syntax-highlight extension'
CGIT_TEST_NO_CREATE_REPOS=YesPlease
. ./setup.sh
. "$TEST_OUTPUT_DIRECTORY/extensions/lib.sh"
for lua in ${interpreters:-lua}
do
test_expect_success STANDALONE_LUA "highlighting checks under $(lua_version "$lua")" '
CGIT_SCINTILLUA_PATH="$EXT_TEST_DIRECTORY/fake-lexers" \
"$lua" "$EXT_TEST_DIRECTORY/test-syntax-highlight.lua" \
"$EXTENSIONS_DIRECTORY/syntax-highlight.lua" highlight
'
test_expect_success STANDALONE_LUA "fallback checks without lexers under $(lua_version "$lua")" '
mkdir -p empty-lexers &&
without_lua_modules env CGIT_SCINTILLUA_PATH="$PWD/empty-lexers" \
"$lua" "$EXT_TEST_DIRECTORY/test-syntax-highlight.lua" \
"$EXTENSIONS_DIRECTORY/syntax-highlight.lua" nolexers
'
done
test_expect_success 'every class the filter writes is styled' '
sed -n "s/^.*= \"\(hl-[a-z]*\)\",$/\1/p" "$EXTENSIONS_DIRECTORY/syntax-highlight.lua" |
sort -u >classes &&
test -s classes &&
while read class
do
test_grep "^div#cgit \.$class {" "$TEST_OUTPUT_DIRECTORY/../assets/cgit.css" || return 1
done <classes
'
test_expect_success 'create a repository holding a lexable file' '
test_create_repo repos/fake &&
(
cd repos/fake &&
echo "if 42 & zz $SQ<b>$SQ" >hello.fake &&
git add hello.fake &&
git commit -m "add hello"
)
'
test_expect_success 'place the fake lexers beside a config naming the filter' '
mkdir -p scintillua &&
cp -R "$EXT_TEST_DIRECTORY/fake-lexers" scintillua/lexers &&
cat >cgitrc <<-EOF
virtual-root=/
cache-size=0
enable-blame=1
repo.url=fake
repo.path=$PWD/repos/fake/.git
repo.source-filter=lua:$EXTENSIONS_DIRECTORY/syntax-highlight.lua
EOF
'
test_expect_success CGIT_LUA 'the tree view is highlighted' '
cgit_ok_url "fake/tree/hello.fake" >tmp &&
test_grep "<span class=.hl-keyword.>if</span>" tmp &&
test_grep "<span class=.hl-number.>42</span>" tmp &&
test_grep "<span class=.hl-string.>.<b>.</span>" tmp
'
test_expect_success CGIT_LUA 'the blame view is highlighted too' '
cgit_ok_url "fake/blame/hello.fake" >tmp &&
test_grep "<span class=.hl-keyword.>if</span>" tmp &&
test_grep "<span class=.hl-string.>.<b>.</span>" tmp
'
test_expect_success CGIT_LUA 'bytes between tokens reach the page escaped' '
cgit_ok_url "fake/tree/hello.fake" >tmp &&
test_grep "<span class=.hl-number.>42</span> & " tmp
'
test_expect_success CGIT_LUA 'without scintillua the source is served escaped' '
echo "[cgit] Unable to load the Scintillua lexers: module ${SQ}lexer${SQ} not found:" >expect &&
without_lua_modules env CGIT_SCINTILLUA_PATH=/nonexistent CGIT_CONFIG="$PWD/cgitrc" \
QUERY_STRING="url=fake/tree/hello.fake" cgit >tmp 2>err &&
test_cmp expect err &&
test_grep "^Status: 200" tmp &&
test_grep "</html>" tmp &&
test_grep "if 42 & zz" tmp &&
test_grep ! "hl-keyword" tmp
'
test_expect_success CGIT_LUA 'a lone carriage return reaches the page as an escape' '
(
cd repos/fake &&
printf "if\\rzz\\n" >cr.fake &&
git add cr.fake &&
git commit -m "add a lone carriage return"
) &&
cgit_ok_url "fake/tree/cr.fake" >tmp &&
test_grep "<span class=.hl-keyword.>if</span><span class=.escape.>\\\\r</span>" tmp
'
test_done
|