on master help sign in
#1244 Use [].copy and path.exists instead of more cumbersome solutions
f3c760cLogan Saso
tests/syntax-tests/create_highlighted_versions.py+24−6
@@ -16,6 +16,17 @@ BAT_OPTIONS = [
16 "--italic-text=always",
16 "--italic-text=always",
17]
17]
18
18
19+SKIP_FILENAMES = [
20+ "LICENSE.md",
21+ "README.md",
22+ "bat_options",
23+]
24+
25+
26+def get_extra_options(source):
27+ with open(path.join(source, "bat_options"), "r") as f:
28+ return list(map(lambda x: x.rstrip(), f.readlines()))
29+
19
30
20def create_highlighted_versions(output_basepath):
31def create_highlighted_versions(output_basepath):
21 root = os.path.dirname(os.path.abspath(__file__))
32 root = os.path.dirname(os.path.abspath(__file__))
@@ -31,16 +42,23 @@ def create_highlighted_versions(output_basepath):
31 env.pop("BAT_TABS", None)
42 env.pop("BAT_TABS", None)
32 env["COLORTERM"] = "truecolor" # make sure to output 24bit colors
43 env["COLORTERM"] = "truecolor" # make sure to output 24bit colors
33
44
34− bat_output = subprocess.check_output(
45+ source_dirpath = path.dirname(source)
35− ["bat"] + BAT_OPTIONS + [source], stderr=subprocess.PIPE, env=env,
36− )
37−
38− source_dirname = path.basename(path.dirname(source))
46+ source_dirname = path.basename(source_dirpath)
39 source_filename = path.basename(source)
47 source_filename = path.basename(source)
40
48
41− if source_filename == "LICENSE.md":
49+ if source_filename in SKIP_FILENAMES:
42 continue
50 continue
43
51
52+ options = BAT_OPTIONS.copy()
53+ # If a directory is empty, `files` could possibly be 0-length
54+ if path.exists(path.join(source_dirpath, "bat_options")):
55+ options += get_extra_options(source_dirpath)
56+
57+ bat_output = subprocess.check_output(
58+ ["bat"] + options + [source],
59+ stderr=subprocess.PIPE, env=env,
60+ )
61+
44 output_dir = path.join(output_basepath, source_dirname)
62 output_dir = path.join(output_basepath, source_dirname)
45 output_path = path.join(output_dir, source_filename)
63 output_path = path.join(output_dir, source_filename)
46
64
tests/syntax-tests/highlighted/Plaintext/plaintext.txtnew file+178
@@ -0,0 +1,178 @@
1+␀␊
2+\u{1}␊
3+\u{2}␊
4+\u{3}␊
5+\u{4}␊
6+\u{5}␊
7+\u{6}␊
8+␇␊
9+␈␊
10+├──┤␊
11+␊
12+␊
13+\u{b}␊
14+\u{c}␊
15+␊
16+\u{e}␊
17+\u{f}␊
18+\u{10}␊
19+\u{11}␊
20+\u{12}␊
21+\u{13}␊
22+\u{14}␊
23+\u{15}␊
24+\u{16}␊
25+\u{17}␊
26+\u{18}␊
27+\u{19}␊
28+\u{1a}␊
29+␛␊
30+\u{1c}␊
31+\u{1d}␊
32+\u{1e}␊
33+\u{1f}␊
34+·␊
35+!␊
36+"␊
37+#␊
38+$␊
39+%␊
40+&␊
41+'␊
42+(␊
43+)␊
44+*␊
45++␊
46+,␊
47+-␊
48+.␊
49+/␊
50+0␊
51+1␊
52+2␊
53+3␊
54+4␊
55+5␊
56+6␊
57+7␊
58+8␊
59+9␊
60+:␊
61+;␊
62+<␊
63+=␊
64+>␊
65+?␊
66+@␊
67+A␊
68+B␊
69+C␊
70+D␊
71+E␊
72+F␊
73+G␊
74+H␊
75+I␊
76+J␊
77+K␊
78+L␊
79+M␊
80+N␊
81+O␊
82+P␊
83+Q␊
84+R␊
85+S␊
86+T␊
87+U␊
88+V␊
89+W␊
90+X␊
91+Y␊
92+Z␊
93+[␊
94+\␊
95+]␊
96+^␊
97+_␊
98+`␊
99+a␊
100+b␊
101+c␊
102+d␊
103+e␊
104+f␊
105+g␊
106+h␊
107+i␊
108+j␊
109+k␊
110+l␊
111+m␊
112+n␊
113+o␊
114+p␊
115+q␊
116+r␊
117+s␊
118+t␊
119+u␊
120+v␊
121+w␊
122+x␊
123+y␊
124+z␊
125+{␊
126+|␊
127+}␊
128+~␊
129+\u{7f}␊
130+\u{80}␊
131+\u{81}␊
132+\u{82}␊
133+\u{83}␊
134+\u{84}␊
135+\u{85}␊
136+\u{86}␊
137+\u{87}␊
138+\u{88}␊
139+\u{89}␊
140+\u{8a}␊
141+\u{8b}␊
142+\u{8c}␊
143+\u{8d}␊
144+\u{8e}␊
145+\u{8f}␊
146+\u{90}␊
147+\u{91}␊
148+\u{92}␊
149+\u{93}␊
150+\u{94}␊
151+\u{95}␊
152+\u{96}␊
153+\u{97}␊
154+\u{98}␊
155+\u{99}␊
156+\u{9a}␊
157+\u{9b}␊
158+\u{9c}␊
159+\u{9d}␊
160+\u{9e}␊
161+\u{9f}␊
162+\u{a0}␊
163+\u{a1}␊
164+\u{a2}␊
165+\u{a3}␊
166+\u{a4}␊
167+\u{a5}␊
168+\u{a6}␊
169+\u{a7}␊
170+\u{a8}␊
171+\u{a9}␊
172+\u{aa}␊
173+\u{ab}␊
174+\u{ac}␊
175+\u{ad}␊
176+\u{ae}␊
177+␊
178+Here's·a·line·with·multiple·characters.
tests/syntax-tests/source/Plaintext/README.mdnew file+10
@@ -0,0 +1,10 @@
1+This text file was generated with the following script. Certain invalid characters were removed manually:
2+
3+```python
4+with open("plaintext.txt", "w"):
5+ for i in range(0x10FFFF):
6+ try:
7+ f.write(chr(i) + "\n")
8+ except:
9+ pass
10+```
tests/syntax-tests/source/Plaintext/bat_optionsnew file+1
@@ -0,0 +1 @@
1+--show-all
tests/syntax-tests/source/Plaintext/plaintext.txtnew file

Binary file not shown.