summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMartin Nordholts <enselic@gmail.com>2021-01-10 11:56:03 +0100
committerMartin Nordholts <enselic@gmail.com>2021-01-10 11:56:03 +0100
commit02e6ff4183f6b24ff4fe297195287b65bc66eaee (patch)
tree4bc56d7a9cf30ba8f6d4f33f7a10bb2b89eb5c96 /tests
parentda1016662588cae98aeb96b2ec570b14f02f9c62 (diff)
parente3b114236452dc5a9084f623b3bd4b39100edd15 (diff)
Merge remote-tracking branch 'origin/master' into fix-1063
Diffstat (limited to 'tests')
-rw-r--r--tests/assets.rs2
-rw-r--r--tests/snapshot_tests.rs2
-rw-r--r--tests/syntax-tests/highlighted/gnuplot/test.gp19
-rw-r--r--tests/syntax-tests/source/gnuplot/test.gp19
-rw-r--r--tests/tester.rs36
5 files changed, 59 insertions, 19 deletions
diff --git a/tests/assets.rs b/tests/assets.rs
index d5de9015..fc01d9e8 100644
--- a/tests/assets.rs
+++ b/tests/assets.rs
@@ -8,7 +8,7 @@ fn all_themes_are_present() {
let assets = HighlightingAssets::from_binary();
let mut themes: Vec<_> = assets.themes().collect();
- themes.sort();
+ themes.sort_unstable();
assert_eq!(
themes,
diff --git a/tests/snapshot_tests.rs b/tests/snapshot_tests.rs
index 8abb8414..14c3eee1 100644
--- a/tests/snapshot_tests.rs
+++ b/tests/snapshot_tests.rs
@@ -7,7 +7,7 @@ macro_rules! snapshot_tests {
$(
#[test]
fn $test_name() {
- let bat_tester = BatTester::new();
+ let bat_tester = BatTester::default();
bat_tester.test_snapshot(stringify!($test_name), $style);
}
)*
diff --git a/tests/syntax-tests/highlighted/gnuplot/test.gp b/tests/syntax-tests/highlighted/gnuplot/test.gp
new file mode 100644
index 00000000..bb96f60d
--- /dev/null
+++ b/tests/syntax-tests/highlighted/gnuplot/test.gp
@@ -0,0 +1,19 @@
+set terminal pngcairo enhanced
+set output "/tmp/polynomial.png"
+
+set grid
+
+set xrange [-5:5]
+set yrange [-5:10]
+
+set samples 10000
+
+set key bottom right
+
+f(x) = 1.0 / 14.0 * ((x+4) * (x+1) * (x-1) * (x-3)) + 0.5
+
+plot \
+ f(x) title "polynomial of degree 4" \
+ with lines \
+ linewidth 2 \
+ linetype rgb '#0077ff'
diff --git a/tests/syntax-tests/source/gnuplot/test.gp b/tests/syntax-tests/source/gnuplot/test.gp
new file mode 100644
index 00000000..411cf134
--- /dev/null
+++ b/tests/syntax-tests/source/gnuplot/test.gp
@@ -0,0 +1,19 @@
+set terminal pngcairo enhanced
+set output "/tmp/polynomial.png"
+
+set grid
+
+set xrange [-5:5]
+set yrange [-5:10]
+
+set samples 10000
+
+set key bottom right
+
+f(x) = 1.0 / 14.0 * ((x+4) * (x+1) * (x-1) * (x-3)) + 0.5
+
+plot \
+ f(x) title "polynomial of degree 4" \
+ with lines \
+ linewidth 2 \
+ linetype rgb '#0077ff'
diff --git a/tests/tester.rs b/tests/tester.rs
index 9c52459f..8a1a0f3b 100644
--- a/tests/tester.rs
+++ b/tests/tester.rs
@@ -19,23 +19,6 @@ pub struct BatTester {
}
impl BatTester {
- pub fn new() -> Self {
- let temp_dir = create_sample_directory().expect("sample directory");
-
- let root = env::current_exe()
- .expect("tests executable")
- .parent()
- .expect("tests executable directory")
- .parent()
- .expect("bat executable directory")
- .to_path_buf();
-
- let exe_name = if cfg!(windows) { "bat.exe" } else { "bat" };
- let exe = root.join(exe_name);
-
- BatTester { temp_dir, exe }
- }
-
pub fn test_snapshot(&self, name: &str, style: &str) {
let output = Command::new(&self.exe)
.current_dir(self.temp_dir.path())
@@ -66,6 +49,25 @@ impl BatTester {
}
}
+impl Default for BatTester {
+ fn default() -> Self {
+ let temp_dir = create_sample_directory().expect("sample directory");
+
+ let root = env::current_exe()
+ .expect("tests executable")
+ .parent()
+ .expect("tests executable directory")
+ .parent()
+ .expect("bat executable directory")
+ .to_path_buf();
+
+ let exe_name = if cfg!(windows) { "bat.exe" } else { "bat" };
+ let exe = root.join(exe_name);
+
+ BatTester { temp_dir, exe }
+ }
+}
+
fn create_sample_directory() -> Result<TempDir, git2::Error> {
// Create temp directory and initialize repository
let temp_dir = TempDir::new("bat-tests").expect("Temp directory");