-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathsyntaxhighlight_spec.moon
More file actions
106 lines (83 loc) · 8.38 KB
/
syntaxhighlight_spec.moon
File metadata and controls
106 lines (83 loc) · 8.38 KB
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
describe "syntaxhighlight", ->
it "highlights moonscript", ->
out = require("syntaxhighlight").highlight_to_html "moonscript", "print 'hello' for i=1,20"
assert.same [[<pre class="sh_highlight"><span class="sh_function">print</span><span class="sh_moonscript_whitespace sh_whitespace"> </span><span class="sh_string">'hello'</span><span class="sh_moonscript_whitespace sh_whitespace"> </span><span class="sh_keyword">for</span><span class="sh_moonscript_whitespace sh_whitespace"> </span><span class="sh_identifier">i</span><span class="sh_operator">=</span><span class="sh_number">1</span><span class="sh_operator">,</span><span class="sh_number">20</span></pre>]], out
it "highlights html", ->
out = require("syntaxhighlight").highlight_to_html "moonscript", [[
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
</body>
</html>
]]
assert.same [[<pre class="sh_highlight"><span class="sh_moonscript_whitespace sh_whitespace"> </span><span class="sh_operator"><!</span><span class="sh_proper_ident sh_class">DOCTYPE</span><span class="sh_moonscript_whitespace sh_whitespace"> </span><span class="sh_proper_ident sh_class">HTML</span><span class="sh_operator">></span><span class="sh_moonscript_whitespace sh_whitespace">
</span><span class="sh_operator"><</span><span class="sh_identifier">html</span><span class="sh_moonscript_whitespace sh_whitespace"> </span><span class="sh_identifier">lang</span><span class="sh_operator">=</span><span class="sh_string">"en"</span><span class="sh_operator">></span><span class="sh_moonscript_whitespace sh_whitespace">
</span><span class="sh_operator"><</span><span class="sh_identifier">head</span><span class="sh_operator">></span><span class="sh_moonscript_whitespace sh_whitespace">
</span><span class="sh_operator"><</span><span class="sh_identifier">meta</span><span class="sh_moonscript_whitespace sh_whitespace"> </span><span class="sh_identifier">charset</span><span class="sh_operator">=</span><span class="sh_string">"UTF-8"</span><span class="sh_operator">></span><span class="sh_moonscript_whitespace sh_whitespace">
</span><span class="sh_operator"><</span><span class="sh_identifier">title</span><span class="sh_operator">></</span><span class="sh_identifier">title</span><span class="sh_operator">></span><span class="sh_moonscript_whitespace sh_whitespace">
</span><span class="sh_operator"></</span><span class="sh_identifier">head</span><span class="sh_operator">></span><span class="sh_moonscript_whitespace sh_whitespace">
</span><span class="sh_operator"><</span><span class="sh_identifier">body</span><span class="sh_operator">></span><span class="sh_moonscript_whitespace sh_whitespace">
</span><span class="sh_operator"></</span><span class="sh_identifier">body</span><span class="sh_operator">></span><span class="sh_moonscript_whitespace sh_whitespace">
</span><span class="sh_operator"></</span><span class="sh_identifier">html</span><span class="sh_operator">></span><span class="sh_moonscript_whitespace sh_whitespace">
</span></pre>]], out
it "highlights moonscript with custom changes", ->
out = assert require("syntaxhighlight").highlight_to_html "moonscript", [[{for: @}]]
assert.same [[<pre class="sh_highlight"><span class="sh_symbol sh_embedded">{</span><span class="sh_tbl_key sh_regex">for:</span><span class="sh_moonscript_whitespace sh_whitespace"> </span><span class="sh_self_ref sh_label">@</span><span class="sh_symbol sh_embedded">}</span></pre>]], out
it "highlights html with css", ->
out = assert require("syntaxhighlight").highlight_to_html "html", [[
<!DOCTYPE HTML>
<html lang="en">
<style type="text/css">
body {
color: blue;
}
</style>
]]
assert.same [[<pre class="sh_highlight"><span class="sh_html_whitespace sh_whitespace"> </span><span class="sh_doctype sh_comment"><!DOCTYPE HTML></span><span class="sh_html_whitespace sh_whitespace">
</span><span class="sh_element sh_keyword"><html</span><span class="sh_html_whitespace sh_whitespace"> </span><span class="sh_attribute sh_type">lang</span><span class="sh_default">=</span><span class="sh_string">"en"</span><span class="sh_element sh_keyword">></span><span class="sh_html_whitespace sh_whitespace">
</span><span class="sh_element sh_keyword"><style</span><span class="sh_html_whitespace sh_whitespace"> </span><span class="sh_attribute sh_type">type</span><span class="sh_operator">=</span><span class="sh_string">"text/css"</span><span class="sh_element sh_keyword">></span><span class="sh_css_whitespace sh_whitespace">
</span><span class="sh_identifier">body</span><span class="sh_css_whitespace sh_whitespace"> </span><span class="sh_operator">{</span><span class="sh_css_whitespace sh_whitespace">
</span><span class="sh_property sh_keyword">color</span><span class="sh_operator">:</span><span class="sh_css_whitespace sh_whitespace"> </span><span class="sh_value sh_constant">blue</span><span class="sh_operator">;</span><span class="sh_css_whitespace sh_whitespace">
</span><span class="sh_operator">}</span><span class="sh_css_whitespace sh_whitespace">
</span><span class="sh_element sh_keyword"></style></span><span class="sh_html_whitespace sh_whitespace">
</span></pre>]], out
it "highlights yaml", ->
out = assert require("syntaxhighlight").highlight_to_html "yaml", [[
name: test
on: [push]
jobs:
test:
runs-on: ubuntu-latest
]]
assert.same [[<pre class="sh_highlight"><span class="sh_keyword">name</span><span class="sh_operator">:</span><span class="sh_yaml_whitespace sh_whitespace"> </span><span class="sh_literal sh_default">test</span><span class="sh_yaml_whitespace sh_whitespace">
</span><span class="sh_keyword">on</span><span class="sh_operator">:</span><span class="sh_yaml_whitespace sh_whitespace"> </span><span class="sh_operator">[</span><span class="sh_literal sh_default">push</span><span class="sh_operator">]</span><span class="sh_yaml_whitespace sh_whitespace">
</span><span class="sh_keyword">jobs</span><span class="sh_operator">:</span><span class="sh_yaml_whitespace sh_whitespace">
</span><span class="sh_keyword">test</span><span class="sh_operator">:</span><span class="sh_yaml_whitespace sh_whitespace">
</span><span class="sh_keyword">runs-on</span><span class="sh_operator">:</span><span class="sh_yaml_whitespace sh_whitespace"> </span><span class="sh_literal sh_default">ubuntu-latest</span><span class="sh_yaml_whitespace sh_whitespace">
</span></pre>]], out
it "highlights nginx (a lexer only provided in this library)", ->
out = require("syntaxhighlight").highlight_to_html "nginx", [[location /home { return 404; }]], bare: true
assert.same [[<span class="sh_keyword">location</span><span class="sh_string"> /home</span><span class="sh_default"> { return </span><span class="sh_number">404</span><span class="sh_default">; }</span>]], out
it "highlights vim", ->
out = require("syntaxhighlight").highlight_to_html "nginx", [["hello"]], bare: true
assert.same [[<span class="sh_string">"hello"</span>]], out
it "highlights bare: true", ->
out = require("syntaxhighlight").highlight_to_html "lua", [[print('hi')]], bare: true
assert.same [[<span class="sh_function">print</span><span class="sh_operator">(</span><span class="sh_string">'hi'</span><span class="sh_operator">)</span>]], out
it "highlights bare: true", ->
out = require("syntaxhighlight").highlight_to_html "lua", [[print('hi')]], bare: true
assert.same [[<span class="sh_function">print</span><span class="sh_operator">(</span><span class="sh_string">'hi'</span><span class="sh_operator">)</span>]], out
it "highlights css_prefix: cool-", ->
out = require("syntaxhighlight").highlight_to_html "lua", [[print('hi')]], class_prefix: "cool-"
assert.same [[<pre class="cool-highlight"><span class="cool-function">print</span><span class="cool-operator">(</span><span class="cool-string">'hi'</span><span class="cool-operator">)</span></pre>]], out
it "handles invalid lexer", ->
assert.same {
nil
"failed to find lexer for fartlang"
}, {
require("syntaxhighlight").highlight_to_html "fartlang", "print 'hello'"
}