diff options
author | Logan Saso <logansaso+tech@gmail.com> | 2020-10-04 15:29:20 -0700 |
---|---|---|
committer | David Peter <sharkdp@users.noreply.github.com> | 2020-10-11 21:31:34 +0200 |
commit | f3c760c25f5270424ded2fd55765da3d20d167ba (patch) | |
tree | 0c56bafadf721318f0c7fa94ffdf2d1894835781 | |
parent | 24fe946c0630b8ec0a6831ffe07eb7dbac5f26bc (diff) |
#1244 Use [].copy and path.exists instead of more cumbersome solutions
#1244 Slightly optimized create_highlighted_versions.py so that it won't walk the source path when it should be skipping the file
#1244 Updated README.md in plaintext source folder
#1244 Added extra option loading from `bat_options` file in directory and significantly reduced size of plaintext source
#1244 Updated create_highlighted_versions.py to ignore README.md files and use the --show-all option for manually-defined binary files
#1244 Updated plaintext file with command
bat -A --no-config --style=plain --color=always --theme='1337' --italic-text=always src/Plaintext/plaintext.txt > highlighted/Plaintext/plaintext.txt
#1244 Added example plaintext file
-rwxr-xr-x | tests/syntax-tests/create_highlighted_versions.py | 30 | ||||
-rw-r--r-- | tests/syntax-tests/highlighted/Plaintext/plaintext.txt | 178 | ||||
-rw-r--r-- | tests/syntax-tests/source/Plaintext/README.md | 10 | ||||
-rw-r--r-- | tests/syntax-tests/source/Plaintext/bat_options | 1 | ||||
-rw-r--r-- | tests/syntax-tests/source/Plaintext/plaintext.txt | bin | 0 -> 436 bytes |
5 files changed, 213 insertions, 6 deletions
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 @@ +[38;2;166;226;46m␀[0m[38;2;249;38;114m␊[0m +[38;2;117;113;94m\u{1}[0m[38;2;249;38;114m␊[0m +[38;2;117;113;94m\u{2}[0m[38;2;249;38;114m␊[0m +[38;2;117;113;94m\u{3}[0m[38;2;249;38;114m␊[0m +[38;2;117;113;94m\u{4}[0m[38;2;249;38;114m␊[0m +[38;2;117;113;94m\u{5}[0m[38;2;249;38;114m␊[0m +[38;2;117;113;94m\u{6}[0m[38;2;249;38;114m␊[0m +[38;2;166;226;46m␇[0m[38;2;249;38;114m␊[0m +[38;2;166;226;46m␈[0m[38;2;249;38;114m␊[0m +[38;2;190;132;255m├──┤[0m[38;2;249;38;114m␊[0m +[38;2;249;38;114m␊[0m +[38;2;249;38;114m␊[0m +[38;2;117;113;94m\u{b}[0m[38;2;249;38;114m␊[0m +[38;2;117;113;94m\u{c}[0m[38;2;249;38;114m␊[0m +[38;2;249;38;114m␊[0m +[38;2;117;113;94m\u{e}[0m[38;2;249;38;114m␊[0m +[38;2;117;113;94m\u{f}[0m[38;2;249;38;114m␊[0m +[38;2;117;113;94m\u{10}[0m[38;2;249;38;114m␊[0m +[38;2;117;113;94m\u{11}[0m[38;2;249;38;114m␊[0m +[38;2;117;113;94m\u{12}[0m[38;2;249;38;114m␊[0m +[38;2;117;113;94m\u{13}[0m[38;2;249;38;114m␊[0m +[38;2;117;113;94m\u{14}[0m[38;2;249;38;114m␊[0m +[38;2;117;113;94m\u{15}[0m[38;2;249;38;114m␊[0m +[38;2;117;113;94m\u{16}[0m[38;2;249;38;114m␊[0m +[38;2;117;113;94m\u{17}[0m[38;2;249;38;114m␊[0m +[38;2;117;113;94m\u{18}[0m[38;2;249;38;114m␊[0m +[38;2;117;113;94m\u{19}[0m[38;2;249;38;114m␊[0m +[38;2;117;113;94m\u{1a}[0m[38;2;249;38;114m␊[0m +[38;2;166;226;46m␛[0m[38;2;249;38;114m␊[0m +[38;2;117;113;94m\u{1c}[0m[38;2;249;38;114m␊[0m +[38;2;117;113;94m\u{1d}[0m[38;2;249;38;114m␊[0m +[38;2;117;113;94m\u{1e}[0m[38;2;249;38;114m␊[0m +[38;2;117;113;94m\u{1f}[0m[38;2;249;38;114m␊[0m +[38;2;102;217;239m·[0m[38;2;249;38;114m␊[0m +[38;2;248;248;242m![0m[38;2;249;38;114m␊[0m +[38;2;248;248;242m"[0m[38;2;249;38;114m␊[0m +[38;2;248;248;242m#[0m[38;2;249;38;114m␊[0m +[38;2;248;248;242m$[0m[38;2;249;38;114m␊[0m +[38;2;248;248;242m%[0m[38;2;249;38;114m␊[0m +[38;2;248;248;242m&[0m[38;2;249;38;114m␊[0m +[38;2;248;248;242m'[0m[38;2;249;38;114m␊[0m +[38;2;248;248;242m([0m[38;2;249;38;114m␊[0m +[38;2;248;248;242m)[0m[38;2;249;38;114m␊[0m +[38;2;248;248;242m*[0m[38;2;249;38;114m␊[0m +[38;2;248;248;242m+[0m[38;2;249;38;114m␊[0m +[38;2;248;248;242m,[0m[38;2;249;38;114m␊[0m +[38;2;248;248;242m-[0m[38;2;249;38;114m␊[0m +[38;2;248;248;242m.[0m[38;2;249;38;114m␊[0m +[38;2;248;248;242m/[0m[38;2;249;38;114m␊[0m +[38;2;248;248;242m0[0m[38;2;249;38;114m␊[0m +[38;2;248;248;242m1[0m[38;2;249;38;114m␊[0m +[38;2;248;248;242m2[0m[38;2;249;38;114m␊[0m +[38;2;248;248;242m3[0m[38;2;249;38;114m␊[0m +[38;2;248;248;242m4[0m[38;2;249;38;114m␊[0m +[38;2;248;248;242m5[0m[38;2;249;38;114m␊[0m +[38;2;248;248;242m6[0m[38;2;249;38;114m␊[0m +[38;2;248;248;242m7[0m[38;2;249;38;114m␊[0m +[38;2;248;248;242m8[0m[38;2;249;38;114m␊[0m +[38;2;248;248;242m9[0m[38;2;249;38;114m␊[0m +[38;2;248;248;242m:[0m[38;2;249;38;114m␊[0m +[38;2;248;248;242m;[0m[38;2;249;38;114m␊[0m +[38;2;248;248;242m<[0m[38;2;249;38;114m␊[0m +[38;2;248;248;242m=[0m[38;2;249;38;114m␊[0m +[38;2;248;248;242m>[0m[38;2;249;38;114m␊[0m +[38;2;248;248;242m?[0m[38;2;249;38;114m␊[0m +[38;2;248;248;242m@[0m[38;2;249;38;114m␊[0m +[38;2;248;248;242mA[0m[38;2;249;38;114m␊[0m +[38;2;248;248;242mB[0m[38;2;249;38;114m␊[0m +[38;2;248;248;242mC[0m[38;2;249;38;114m␊[0m +[38;2;248;248;242mD[0m[38;2;249;38;114m␊[0m +[38;2;248;248;242mE[0m[38;2;249;38;114m␊[0m +[38;2;248;248;242mF[0m[38;2;249;38;114m␊[0m +[38;2;248;248;242mG[0m[38;2;249;38;114m␊[0m +[38;2;248;248;242mH[0m[38;2;249;38;114m␊[0m +[38;2;248;248;242mI[0m[38;2;249;38;114m␊[0m +[38;2;248;248;242mJ[0m[38;2;249;38;114m␊[0m +[38;2;248;248;242mK[0m[38;2;249;38;114m␊[0m +[38;2;248;248;242mL[0m[38;2;249;38;114m␊[0m +[38;2;248;248;242mM[0m[38;2;249;38;114m␊[0m +[38;2;248;248;242mN[0m[38;2;249;38;114m␊[0m +[38;2;248;248;242mO[0m[38;2;249;38;114m␊[0m +[38;2;248;248;242mP[0m[38;2;249;38;114m␊[0m +[38;2;248;248;242mQ[0m[38;2;249;38;114m␊[0m +[38;2;248;248;242mR[0m[38;2;249;38;114m␊[0m +[38;2;248;248;242mS[0m[38;2;249;38;114m␊[0m +[38;2;248;248;242mT[0m[38;2;249;38;114m␊[0m +[38;2;248;248;242mU[0m[38;2;249;38;114m␊[0m +[38;2;248;248;242mV[0m[38;2;249;38;114m␊[0m +[38;2;248;248;242mW[0m[38;2;249;38;114m␊[0m +[38;2;248;248;242mX[0m[38;2;249;38;114m␊[0m +[38;2;248;248;242mY[0m[38;2;249;38;114m␊[0m +[38;2;248;248;242mZ[0m[38;2;249;38;114m␊[0m +[38;2;248;248;242m[[0m[38;2;249;38;114m␊[0m +[38;2;248;248;242m\[0m[38;2;249;38;114m␊[0m +[38;2;248;248;242m][0m[38;2;249;38;114m␊[0m +[38;2;248;248;242m^[0m[38;2;249;38;114m␊[0m +[38;2;248;248;242m_[0m[38;2;249;38;114m␊[0m +[38;2;248;248;242m`[0m[38;2;249;38;114m␊[0m +[38;2;248;248;242ma[0m[38;2;249;38;114m␊[0m +[38;2;248;248;242mb[0m[38;2;249;38;114m␊[0m +[38;2;248;248;242mc[0m[38;2;249;38;114m␊[0m +[38;2;248;248;242md[0m[38;2;249;38;114m␊[0m +[38;2;248;248;242me[0m[38;2;249;38;114m␊[0m +[38;2;248;248;242mf[0m[38;2;249;38;114m␊[0m +[38;2;248;248;242mg[0m[38;2;249;38;114m␊[0m +[38;2;248;248;242mh[0m[38;2;249;38;114m␊[0m +[38;2;248;248;242mi[0m[38;2;249;38;114m␊[0m +[38;2;248;248;242mj[0m[38;2;249;38;114m␊[0m +[38;2;248;248;242mk[0m[38;2;249;38;114m␊[0m +[38;2;248;248;242ml[0m[38;2;249;38;114m␊[0m +[38;2;248;248;242mm[0m[38;2;249;38;114m␊[0m +[38;2;248;248;242mn[0m[38;2;249;38;114m␊[0m +[38;2;248;248;242mo[0m[38;2;249;38;114m␊[0m +[38;2;248;248;242mp[0m[38;2;249;38;114m␊[0m +[38;2;248;248;242mq[0m[38;2;249;38;114m␊[0m +[38;2;248;248;242mr[0m[38;2;249;38;114m␊[0m +[38;2;248;248;242ms[0m[38;2;249;38;114m␊[0m +[38;2;248;248;242mt[0m[38;2;249;38;114m␊[0m +[38;2;248;248;242mu[0m[38;2;249;38;114m␊[0m +[38;2;248;248;242mv[0m[38;2;249;38;114m␊[0m +[38;2;248;248;242mw[0m[38;2;249;38;114m␊[0m +[38;2;248;248;242mx[0m[38;2;249;38;114m␊[0m +[38;2;248;248;242my[0m[38;2;249;38;114m␊[0m +[38;2;248;248;242mz[0m[38;2;249;38;114m␊[0m +[38;2;248;248;242m{[0m[38;2;249;38;114m␊[0m +[38;2;248;248;242m|[0m[38;2;249;38;114m␊[0m +[38;2;248;248;242m}[0m[38;2;249;38;114m␊[0m +[38;2;248;248;242m~[0m[38;2;249;38;114m␊[0m +[38;2;117;113;94m\u{7f}[0m[38;2;249;38;114m␊[0m +[38;2;117;113;94m\u{80}[0m[38;2;249;38;114m␊[0m +[38;2;117;113;94m\u{81}[0m[38;2;249;38;114m␊[0m +[38;2;117;113;94m\u{82}[0m[38;2;249;38;114m␊[0m +[38;2;117;113;94m\u{83}[0m[38;2;249;38;114m␊[0m +[38;2;117;113;94m\u{84}[0m[38;2;249;38;114m␊[0m +[38;2;117;113;94m\u{85}[0m[38;2;249;38;114m␊[0m +[38;2;117;113;94m\u{86}[0m[38;2;249;38;114m␊[0m +[38;2;117;113;94m\u{87}[0m[38;2;249;38;114m␊[0m +[38;2;117;113;94m\u{88}[0m[38;2;249;38;114m␊[0m +[38;2;117;113;94m\u{89}[0m[38;2;249;38;114m␊[0m +[38;2;117;113;94m\u{8a}[0m[38;2;249;38;114m␊[0m +[38;2;117;113;94m\u{8b}[0m[38;2;249;38;114m␊[0m +[38;2;117;113;94m\u{8c}[0m[38;2;249;38;114m␊[0m +[38;2;117;113;94m\u{8d}[0m[38;2;249;38;114m␊[0m +[38;2;117;113;94m\u{8e}[0m[38;2;249;38;114m␊[0m +[38;2;117;113;94m\u{8f}[0m[38;2;249;38;114m␊[0m +[38;2;117;113;94m\u{90}[0m[38;2;249;38;114m␊[0m +[38;2;117;113;94m\u{91}[0m[38;2;249;38;114m␊[0m +[38;2;117;113;94m\u{92}[0m[38;2;249;38;114m␊[0m +[38;2;117;113;94m\u{93}[0m[38;2;249;38;114m␊[0m +[38;2;117;113;94m\u{94}[0m[38;2;249;38;114m␊[0m +[38;2;117;113;94m\u{95}[0m[38;2;249;38;114m␊[0m +[38;2;117;113;94m\u{96}[0m[38;2;249;38;114m␊[0m +[38;2;117;113;94m\u{97}[0m[38;2;249;38;114m␊[0m +[38;2;117;113;94m\u{98}[0m[38;2;249;38;114m␊[0m +[38;2;117;113;94m\u{99}[0m[38;2;249;38;114m␊[0m +[38;2;117;113;94m\u{9a}[0m[38;2;249;38;114m␊[0m +[38;2;117;113;94m\u{9b}[0m[38;2;249;38;114m␊[0m +[38;2;117;113;94m\u{9c}[0m[38;2;249;38;114m␊[0m +[38;2;117;113;94m\u{9d}[0m[38;2;249;38;114m␊[0m +[38;2;117;113;94m\u{9e}[0m[38;2;249;38;114m␊[0m +[38;2;117;113;94m\u{9f}[0m[38;2;249;38;114m␊[0m +[38;2;117;113;94m\u{a0}[0m[38;2;249;38;114m␊[0m +[38;2;117;113;94m\u{a1}[0m[38;2;249;38;114m␊[0m +[38;2;117;113;94m\u{a2}[0m[38;2;249;38;114m␊[0m +[38;2;117;113;94m\u{a3}[0m[38;2;249;38;114m␊[0m +[38;2;117;113;94m\u{a4}[0m[38;2;249;38;114m␊[0m +[38;2;117;113;94m\u{a5}[0m[38;2;249;38;114m␊[0m +[38;2;117;113;94m\u{a6}[0m[38;2;249;38;114m␊[0m +[38;2;117;113;94m\u{a7}[0m[38;2;249;38;114m␊[0m +[38;2;117;113;94m\u{a8}[0m[38;2;249;38;114m␊[0m +[38;2;117;113;94m\u{a9}[0m[38;2;249;38;114m␊[0m +[38;2;117;113;94m\u{aa}[0m[38;2;249;38;114m␊[0m +[38;2;117;113;94m\u{ab}[0m[38;2;249;38;114m␊[0m +[38;2;117;113;94m\u{ac}[0m[38;2;249;38;114m␊[0m +[38;2;117;113;94m\u{ad}[0m[38;2;249;38;114m␊[0m +[38;2;117;113;94m\u{ae}[0m[38;2;249;38;114m␊[0m +[38;2;249;38;114m␊[0m +[38;2;248;248;242mHere's[0m[38;2;102;217;239m·[0m[38;2;248;248;242ma[0m[38;2;102;217;239m·[0m[38;2;248;248;242mline[0m[38;2;102;217;239m·[0m[38;2;248;248;242mwith[0m[38;2;102;217;239m·[0m[38;2;248;248;242mmultiple[0m[38;2;102;217;239m·[0m[38;2;248;248;242mcharacters.[0m 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 Binary files differnew file mode 100644 index 00000000..42da1207 --- /dev/null +++ b/tests/syntax-tests/source/Plaintext/plaintext.txt |