diff --git a/tests/syntax-tests/create_highlighted_versions.py b/tests/syntax-tests/create_highlighted_versions.py index c03a0742..b82cc8cd 100755 --- a/tests/syntax-tests/create_highlighted_versions.py +++ b/tests/syntax-tests/create_highlighted_versions.py @@ -16,6 +16,17 @@ BAT_OPTIONS = [ "--italic-text=always", ] +SKIP_FILENAMES = [ + "LICENSE.md", + "README.md", + "bat_options", +] + + +def get_extra_options(source): + with open(path.join(source, "bat_options"), "r") as f: + return list(map(lambda x: x.rstrip(), f.readlines())) + def create_highlighted_versions(output_basepath): root = os.path.dirname(os.path.abspath(__file__)) @@ -31,16 +42,23 @@ def create_highlighted_versions(output_basepath): env.pop("BAT_TABS", None) env["COLORTERM"] = "truecolor" # make sure to output 24bit colors - bat_output = subprocess.check_output( - ["bat"] + BAT_OPTIONS + [source], stderr=subprocess.PIPE, env=env, - ) - - source_dirname = path.basename(path.dirname(source)) + source_dirpath = path.dirname(source) + source_dirname = path.basename(source_dirpath) source_filename = path.basename(source) - if source_filename == "LICENSE.md": + if source_filename in SKIP_FILENAMES: continue + options = BAT_OPTIONS.copy() + # If a directory is empty, `files` could possibly be 0-length + if path.exists(path.join(source_dirpath, "bat_options")): + options += get_extra_options(source_dirpath) + + bat_output = subprocess.check_output( + ["bat"] + options + [source], + stderr=subprocess.PIPE, env=env, + ) + output_dir = path.join(output_basepath, source_dirname) output_path = path.join(output_dir, source_filename) diff --git a/tests/syntax-tests/highlighted/Plaintext/plaintext.txt b/tests/syntax-tests/highlighted/Plaintext/plaintext.txt new file mode 100644 index 00000000..807728e1 --- /dev/null +++ b/tests/syntax-tests/highlighted/Plaintext/plaintext.txt @@ -0,0 +1,178 @@ +␀␊ +\u{1}␊ +\u{2}␊ +\u{3}␊ +\u{4}␊ +\u{5}␊ +\u{6}␊ +␇␊ +␈␊ +├──┤␊ +␊ +␊ +\u{b}␊ +\u{c}␊ +␊ +\u{e}␊ +\u{f}␊ +\u{10}␊ +\u{11}␊ +\u{12}␊ +\u{13}␊ +\u{14}␊ +\u{15}␊ +\u{16}␊ +\u{17}␊ +\u{18}␊ +\u{19}␊ +\u{1a}␊ +␛␊ +\u{1c}␊ +\u{1d}␊ +\u{1e}␊ +\u{1f}␊ +·␊ +!␊ +"␊ +#␊ +$␊ +%␊ +&␊ +'␊ +(␊ +)␊ +*␊ ++␊ +,␊ +-␊ +.␊ +/␊ +0␊ +1␊ +2␊ +3␊ +4␊ +5␊ +6␊ +7␊ +8␊ +9␊ +:␊ +;␊ +<␊ +=␊ +>␊ +?␊ +@␊ +A␊ +B␊ +C␊ +D␊ +E␊ +F␊ +G␊ +H␊ +I␊ +J␊ +K␊ +L␊ +M␊ +N␊ +O␊ +P␊ +Q␊ +R␊ +S␊ +T␊ +U␊ +V␊ +W␊ +X␊ +Y␊ +Z␊ +[␊ +\␊ +]␊ +^␊ +_␊ +`␊ +a␊ +b␊ +c␊ +d␊ +e␊ +f␊ +g␊ +h␊ +i␊ +j␊ +k␊ +l␊ +m␊ +n␊ +o␊ +p␊ +q␊ +r␊ +s␊ +t␊ +u␊ +v␊ +w␊ +x␊ +y␊ +z␊ +{␊ +|␊ +}␊ +~␊ +\u{7f}␊ +\u{80}␊ +\u{81}␊ +\u{82}␊ +\u{83}␊ +\u{84}␊ +\u{85}␊ +\u{86}␊ +\u{87}␊ +\u{88}␊ +\u{89}␊ +\u{8a}␊ +\u{8b}␊ +\u{8c}␊ +\u{8d}␊ +\u{8e}␊ +\u{8f}␊ +\u{90}␊ +\u{91}␊ +\u{92}␊ +\u{93}␊ +\u{94}␊ +\u{95}␊ +\u{96}␊ +\u{97}␊ +\u{98}␊ +\u{99}␊ +\u{9a}␊ +\u{9b}␊ +\u{9c}␊ +\u{9d}␊ +\u{9e}␊ +\u{9f}␊ +\u{a0}␊ +\u{a1}␊ +\u{a2}␊ +\u{a3}␊ +\u{a4}␊ +\u{a5}␊ +\u{a6}␊ +\u{a7}␊ +\u{a8}␊ +\u{a9}␊ +\u{aa}␊ +\u{ab}␊ +\u{ac}␊ +\u{ad}␊ +\u{ae}␊ +␊ +Here's·a·line·with·multiple·characters. diff --git a/tests/syntax-tests/source/Plaintext/README.md b/tests/syntax-tests/source/Plaintext/README.md new file mode 100644 index 00000000..95679324 --- /dev/null +++ b/tests/syntax-tests/source/Plaintext/README.md @@ -0,0 +1,10 @@ +This text file was generated with the following script. Certain invalid characters were removed manually: + +```python +with open("plaintext.txt", "w"): + for i in range(0x10FFFF): + try: + f.write(chr(i) + "\n") + except: + pass +``` diff --git a/tests/syntax-tests/source/Plaintext/bat_options b/tests/syntax-tests/source/Plaintext/bat_options new file mode 100644 index 00000000..e5dd9b4e --- /dev/null +++ b/tests/syntax-tests/source/Plaintext/bat_options @@ -0,0 +1 @@ +--show-all diff --git a/tests/syntax-tests/source/Plaintext/plaintext.txt b/tests/syntax-tests/source/Plaintext/plaintext.txt new file mode 100644 index 00000000..42da1207 Binary files /dev/null and b/tests/syntax-tests/source/Plaintext/plaintext.txt differ