blob: 31ab7e7fcbb23841a849509a7e0b6f8990bc91cb (plain)
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
#!/bin/sh

# Checks syntax-highlight.lua, the shipped source-filter. The real Scintillua
# collection is not assumed anywhere, because the fake lexer module under
# extensions/fake-lexers drives every path through the filter
# deterministically. The unit checks run twice per interpreter, once with the
# fake lexers found and once with an empty directory so the escaped fallback
# is what everything renders through. The run through cgit itself places the
# fake lexers beside the config file, which is the probe the filter documents
# for a scintillua directory next to cgitrc.

test_description='Check the shipped syntax-highlight extension'
CGIT_TEST_NO_CREATE_REPOS=YesPlease
. ./setup.sh
. "$TEST_OUTPUT_DIRECTORY/extensions/lib.sh"

interpreters=$(ext_lua_interpreters 5)
test -z "$interpreters" &&
	say 'no standalone lua on the path, unit checks skipped'

for lua in $interpreters
do
	test_expect_success "highlighting checks under $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 "fallback checks without lexers under $lua" "
		mkdir -p empty-lexers &&
		CGIT_SCINTILLUA_PATH=\"\$PWD/empty-lexers\" \
		'$lua' '$EXT_TEST_DIRECTORY/test-syntax-highlight.lua' \
			'$EXTENSIONS_DIRECTORY/syntax-highlight.lua' nolexers
	"
done

test "$CGIT_HAS_LUA" -eq 1 && test_set_prereq CGIT_LUA
test "$CGIT_HAS_LUA" -eq 1 ||
	say 'cgit built without lua, filter checks through cgit skipped'

test_expect_success 'create a repository holding a lexable file' '
	test_create_repo repos/fake &&
	(
		cd repos/fake &&
		echo "if 42 & zz" >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
	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_url "fake/tree/hello.fake" >tmp &&
	grep "<span class=.hl-keyword.>if</span>" tmp &&
	grep "<span class=.hl-number.>42</span>" tmp
'

test_expect_success CGIT_LUA 'bytes between tokens reach the page escaped' '
	grep "<span class=.hl-number.>42</span> &amp; " tmp
'

test_done