summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorOliver Looney <88001922+Oliver-Looney@users.noreply.github.com>2024-02-11 22:53:48 +0000
committerGitHub <noreply@github.com>2024-02-11 22:53:48 +0000
commitc3f2ddf5092e9f81052e3183fdbf5ae68147a8af (patch)
tree5db103ecca22c96828cfed69dff304be35c4631f /tests
parent8a51172b119d95fd5984ad46639307140b675c1b (diff)
parent5a2a20af42e7a426943122524287844acc5ee975 (diff)
Merge branch 'master' into 2783-setting-terminal-title
Diffstat (limited to 'tests')
-rwxr-xr-xtests/benchmarks/run-benchmarks.sh53
-rw-r--r--tests/benchmarks/startup-time-src/Containerfile3
-rw-r--r--tests/benchmarks/startup-time-src/mystery-file3
-rw-r--r--tests/examples/regression_tests/issue_2541.txt1
-rw-r--r--tests/examples/this-file-path-is-really-long-and-would-have-broken-the-layout-of-the-header.txt1
-rw-r--r--tests/integration_tests.rs125
-rw-r--r--tests/syntax-tests/highlighted/JQ/sample.jq32
7 files changed, 201 insertions, 17 deletions
diff --git a/tests/benchmarks/run-benchmarks.sh b/tests/benchmarks/run-benchmarks.sh
index 0f43bc6b..2809ccbb 100755
--- a/tests/benchmarks/run-benchmarks.sh
+++ b/tests/benchmarks/run-benchmarks.sh
@@ -9,6 +9,13 @@ if ! command -v hyperfine > /dev/null 2>&1; then
exit 1
fi
+# Check that jq is installed.
+if ! command -v jq > /dev/null 2>&1; then
+ echo "'jq' does not seem to be installed."
+ echo "You can get it here: https://jqlang.github.io/jq/download/"
+ exit 1
+fi
+
# Check that python3 is installed.
if ! command -v python3 > /dev/null 2>&1; then
echo "'python3' does not seem to be installed."
@@ -95,10 +102,20 @@ hyperfine \
cat "$RESULT_DIR/startup-time.md" >> "$REPORT"
+heading "Startup time without syntax highlighting"
+hyperfine \
+ "$(printf "%q" "$BAT") --no-config startup-time-src/small-CpuInfo-file.cpuinfo" \
+ --command-name "bat … small-CpuInfo-file.cpuinfo" \
+ --warmup "$WARMUP_COUNT" \
+ --runs "$RUN_COUNT" \
+ --export-markdown "$RESULT_DIR/startup-time-without-syntax-highlighting.md" \
+ --export-json "$RESULT_DIR/startup-time-without-syntax-highlighting.json"
+cat "$RESULT_DIR/startup-time-without-syntax-highlighting.md" >> "$REPORT"
+
heading "Startup time with syntax highlighting"
hyperfine \
"$(printf "%q" "$BAT") --no-config --color=always startup-time-src/small-CpuInfo-file.cpuinfo" \
- --command-name "bat … small-CpuInfo-file.cpuinfo" \
+ --command-name "bat … --color=always small-CpuInfo-file.cpuinfo" \
--warmup "$WARMUP_COUNT" \
--runs "$RUN_COUNT" \
--export-markdown "$RESULT_DIR/startup-time-with-syntax-highlighting.md" \
@@ -117,6 +134,40 @@ hyperfine \
cat "$RESULT_DIR/startup-time-with-syntax-with-dependencies.md" >> "$REPORT"
+heading "Startup time with indeterminant syntax"
+hyperfine \
+ "$(printf "%q" "$BAT") --no-config --color=always startup-time-src/mystery-file" \
+ --shell none \
+ --command-name 'bat … mystery-file' \
+ --warmup "$WARMUP_COUNT" \
+ --runs "$RUN_COUNT" \
+ --export-markdown "$RESULT_DIR/startup-time-with-indeterminant-syntax.md" \
+ --export-json "$RESULT_DIR/startup-time-with-indeterminant-syntax.json"
+cat "$RESULT_DIR/startup-time-with-indeterminant-syntax.md" >> "$REPORT"
+
+heading "Startup time with manually set syntax"
+hyperfine \
+ "$(printf "%q" "$BAT") --no-config --color=always --language=Dockerfile startup-time-src/mystery-file" \
+ --shell none \
+ --command-name 'bat … --language=Dockerfile mystery-file' \
+ --warmup "$WARMUP_COUNT" \
+ --runs "$RUN_COUNT" \
+ --export-markdown "$RESULT_DIR/startup-time-with-manually-set-syntax.md" \
+ --export-json "$RESULT_DIR/startup-time-with-manually-set-syntax.json"
+cat "$RESULT_DIR/startup-time-with-manually-set-syntax.md" >> "$REPORT"
+
+heading "Startup time with mapped syntax"
+hyperfine \
+ "$(printf "%q" "$BAT") --no-config --color=always startup-time-src/Containerfile" \
+ --shell none \
+ --command-name 'bat … Containerfile' \
+ --warmup "$WARMUP_COUNT" \
+ --runs "$RUN_COUNT" \
+ --export-markdown "$RESULT_DIR/startup-time-with-mapped-syntax.md" \
+ --export-json "$RESULT_DIR/startup-time-with-mapped-syntax.json"
+cat "$RESULT_DIR/startup-time-with-mapped-syntax.md" >> "$REPORT"
+
+
heading "Plain-text speed"
hyperfine \
"$(printf "%q" "$BAT") --no-config --language=txt --style=plain highlighting-speed-src/numpy_test_multiarray.py" \
diff --git a/tests/benchmarks/startup-time-src/Containerfile b/tests/benchmarks/startup-time-src/Containerfile
new file mode 100644
index 00000000..a93ce851
--- /dev/null
+++ b/tests/benchmarks/startup-time-src/Containerfile
@@ -0,0 +1,3 @@
+FROM docker.io/alpine:latest
+COPY foo /root/bar
+RUN sleep 60
diff --git a/tests/benchmarks/startup-time-src/mystery-file b/tests/benchmarks/startup-time-src/mystery-file
new file mode 100644
index 00000000..a93ce851
--- /dev/null
+++ b/tests/benchmarks/startup-time-src/mystery-file
@@ -0,0 +1,3 @@
+FROM docker.io/alpine:latest
+COPY foo /root/bar
+RUN sleep 60
diff --git a/tests/examples/regression_tests/issue_2541.txt b/tests/examples/regression_tests/issue_2541.txt
new file mode 100644
index 00000000..1059b94e
--- /dev/null
+++ b/tests/examples/regression_tests/issue_2541.txt
@@ -0,0 +1 @@
+]8;;http://example.com\This is a link]8;;\n \ No newline at end of file
diff --git a/tests/examples/this-file-path-is-really-long-and-would-have-broken-the-layout-of-the-header.txt b/tests/examples/this-file-path-is-really-long-and-would-have-broken-the-layout-of-the-header.txt
new file mode 100644
index 00000000..4dac98dc
--- /dev/null
+++ b/tests/examples/this-file-path-is-really-long-and-would-have-broken-the-layout-of-the-header.txt
@@ -0,0 +1 @@
+The header is not broken \ No newline at end of file
diff --git a/tests/integration_tests.rs b/tests/integration_tests.rs
index f1a22d9d..3612654b 100644
--- a/tests/integration_tests.rs
+++ b/tests/integration_tests.rs
@@ -1175,6 +1175,20 @@ fn bom_stripped_when_no_color_and_not_loop_through() {
);
}
+// Regression test for https://github.com/sharkdp/bat/issues/2541
+#[test]
+fn no_broken_osc_emit_with_line_wrapping() {
+ bat()
+ .arg("--color=always")
+ .arg("--decorations=never")
+ .arg("--wrap=character")
+ .arg("--terminal-width=40")
+ .arg("regression_tests/issue_2541.txt")
+ .assert()
+ .success()
+ .stdout(predicate::function(|s: &str| s.lines().count() == 1));
+}
+
#[test]
fn can_print_file_named_cache() {
bat_with_config()
@@ -1394,6 +1408,61 @@ fn header_full_binary() {
}
#[test]
+#[cfg(not(feature = "git"))]
+fn header_narrow_terminal() {
+ bat()
+ .arg("--terminal-width=30")
+ .arg("--decorations=always")
+ .arg("this-file-path-is-really-long-and-would-have-broken-the-layout-of-the-header.txt")
+ .assert()
+ .success()
+ .stdout(
+ "\
+─────┬────────────────────────
+ │ File: this-file-path-is
+ │ -really-long-and-would-
+ │ have-broken-the-layout-
+ │ of-the-header.txt
+─────┼────────────────────────
+ 1 │ The header is not broke
+ │ n
+─────┴────────────────────────
+",
+ )
+ .stderr("");
+}
+
+#[test]
+fn header_very_narrow_terminal() {
+ bat()
+ .arg("--terminal-width=10")
+ .arg("--decorations=always")
+ .arg("this-file-path-is-really-long-and-would-have-broken-the-layout-of-the-header.txt")
+ .assert()
+ .success()
+ .stdout(
+ "\
+──────────
+File: this
+-file-path
+-is-really
+-long-and-
+would-have
+-broken-th
+e-layout-o
+f-the-head
+er.txt
+──────────
+The header
+ is not br
+oken
+──────────
+",
+ )
+ .stderr("");
+}
+
+#[test]
#[cfg(feature = "git")] // Expected output assumes git is enabled
fn header_default() {
bat()
@@ -1876,6 +1945,62 @@ fn ansi_passthrough_emit() {
}
}
+// Ensure that a simple ANSI sequence passthrough is emitted properly on wrapped lines.
+// This also helps ensure that escape sequences are counted as part of the visible characters when wrapping.
+#[test]
+fn ansi_sgr_emitted_when_wrapped() {
+ bat()
+ .arg("--paging=never")
+ .arg("--color=never")
+ .arg("--terminal-width=20")
+ .arg("--wrap=character")
+ .arg("--decorations=always")
+ .arg("--style=plain")
+ .write_stdin("\x1B[33mColor...............Also color.\n")
+ .assert()
+ .success()
+ .stdout("\x1B[33m\x1B[33mColor...............\n\x1B[33mAlso color.\n")
+ // FIXME: ~~~~~~~~ should not be emitted twice.
+ .stderr("");
+}
+
+// Ensure that a simple ANSI sequence passthrough is emitted properly on wrapped lines.
+// This also helps ensure that escape sequences are counted as part of the visible characters when wrapping.
+#[test]
+fn ansi_hyperlink_emitted_when_wrapped() {
+ bat()
+ .arg("--paging=never")
+ .arg("--color=never")
+ .arg("--terminal-width=20")
+ .arg("--wrap=character")
+ .arg("--decorations=always")
+ .arg("--style=plain")
+ .write_stdin("\x1B]8;;http://example.com/\x1B\\Hyperlinks..........Wrap across lines.\n")
+ .assert()
+ .success()
+ .stdout("\x1B]8;;http://example.com/\x1B\\\x1B]8;;http://example.com/\x1B\\Hyperlinks..........\x1B]8;;\x1B\\\n\x1B]8;;http://example.com/\x1B\\Wrap across lines.\n")
+ // FIXME: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ should not be emitted twice.
+ .stderr("");
+}
+
+// Ensure that multiple ANSI sequence SGR attributes are combined when emitted on wrapped lines.
+#[test]
+fn ansi_sgr_joins_attributes_when_wrapped() {
+ bat()
+ .arg("--paging=never")
+ .arg("--color=never")
+ .arg("--terminal-width=20")
+ .arg("--wrap=character")
+ .arg("--decorations=always")
+ .arg("--style=plain")
+ .write_stdin("\x1B[33mColor. \x1B[1mBold.........Also bold and color.\n")
+ .assert()
+ .success()
+ .stdout("\x1B[33m\x1B[33mColor. \x1B[1m\x1B[33m\x1B[1mBold.........\n\x1B[33m\x1B[1mAlso bold and color.\n")
+ // FIXME: ~~~~~~~~ ~~~~~~~~~~~~~~~ should not be emitted twice.
+ .stderr("");
+}
+
#[test]
fn ignored_suffix_arg() {
bat()
diff --git a/tests/syntax-tests/highlighted/JQ/sample.jq b/tests/syntax-tests/highlighted/JQ/sample.jq
index ba9c853f..057e9edd 100644
--- a/tests/syntax-tests/highlighted/JQ/sample.jq
+++ b/tests/syntax-tests/highlighted/JQ/sample.jq
@@ -1,31 +1,31 @@
import "../imported-file" ;
# With Comments !
-def weird($a; $b; $c):
- [ $a, $b, $c ] | transpose | reduce .[][] as $item (
- [];
- . + $item.property
- )
+def weird($a; $b; $c):
+ [ $a, $b, $c ] | transpose | reduce .[][] as $item (
+ [];
+ . + $item.property
+ )
;
-. | weird (.a; .b; .c) |
+. | weird (.a; .b; .c) |
(
-if (. | contains("never") ) then
+if (. | contains("never") ) then
 "Why yes"
else
 12.23
end
-) as $never |
+) as $never |
{
 hello,
 why: "because",
- hello: ( weird | ascii_upcase ),
- format_eg: ( . | @json "My json string \( . | this | part | just | white | ascii_upcase | transpose)" ),
- never: $never,
+ hello: ( weird | ascii_upcase ),
+ format_eg: ( . | @json "My json string \( . | this | part | just | white | ascii_upcase | transpose)" ),
+ never: $never,
 "literal_key": literal_value,
 "this": 12.1e12,
 "part": "almost"
@@ -38,8 +38,8 @@
 similar: "but not quite"
 }
 }
- ],
-} | (
+ ],
+} | (
 
 # And with very basic brace matching
 
@@ -47,13 +47,13 @@
 ] 
 
 # Other invalid ends
- ( [ } ] )
+ ( [ } ] )
 # A "valid" sequence
- ( [ { key: () , other_key:( [ [] [[]] ] ), gaga } ] )
+ ( [ { key: () , other_key:( [ [] [[]] ] ), gaga } ] )
 # A "invalid" sequence
- ( [ { key: () , other_key:( [ [] [[] ] ), gaga } ] )
+ ( [ { key: () , other_key:( [ [] [[] ] ), gaga } ] )
 "A string\n whith escaped characters \" because we can"
)