summaryrefslogtreecommitdiffstats
path: root/tests/snapshots
diff options
context:
space:
mode:
authorEzinwa Okpoechi <brainmaestro@outlook.com>2018-05-12 16:23:05 +0200
committerDavid Peter <sharkdp@users.noreply.github.com>2018-05-12 18:07:30 +0200
commit026a9ebae3d867e45e642969d988ca0473f5014a (patch)
tree0c4d9834adca895b62e927272ffb173ee8e3c496 /tests/snapshots
parentcb7b158172a8336778dc860795a1f2cdc0180356 (diff)
Add sample files and snapshot generator
Diffstat (limited to 'tests/snapshots')
-rwxr-xr-xtests/snapshots/generate_snapshots.py40
-rw-r--r--tests/snapshots/sample.modified.rs21
-rw-r--r--tests/snapshots/sample.rs18
3 files changed, 79 insertions, 0 deletions
diff --git a/tests/snapshots/generate_snapshots.py b/tests/snapshots/generate_snapshots.py
new file mode 100755
index 00000000..2859f27a
--- /dev/null
+++ b/tests/snapshots/generate_snapshots.py
@@ -0,0 +1,40 @@
+#!/usr/bin/env python3
+import itertools
+import subprocess
+import pathlib
+import shutil
+
+def generate_snapshots():
+ single_styles = ["changes", "grid", "header", "numbers"]
+ collective_styles = ["full", "plain"]
+
+ for num in range(len(single_styles)):
+ for grouped in itertools.combinations(single_styles, num + 1):
+ generate_snapshot(",".join(grouped))
+
+ for style in collective_styles:
+ generate_snapshot(style)
+
+def generate_snapshot(option):
+ command = "../../target/debug/bat --style={0} sample.rs > output/{0}.snapshot.txt".format(
+ option
+ )
+ print("generating snapshot for {}".format(option))
+ subprocess.call(command, shell=True)
+
+def prepare_output_dir():
+ shutil.rmtree("output", ignore_errors=True)
+ pathlib.Path("output").mkdir()
+
+def modify_sample_file():
+ print("modifying sample.rs to show changes")
+ shutil.copyfile("sample.modified.rs", "sample.rs")
+
+def undo_sample_file_modification():
+ print("undoing sample.rs modifications")
+ subprocess.call("git checkout -- sample.rs", shell=True)
+
+prepare_output_dir()
+modify_sample_file()
+generate_snapshots()
+undo_sample_file_modification()
diff --git a/tests/snapshots/sample.modified.rs b/tests/snapshots/sample.modified.rs
new file mode 100644
index 00000000..f1a030ce
--- /dev/null
+++ b/tests/snapshots/sample.modified.rs
@@ -0,0 +1,21 @@
+struct Rectangle {
+ width: u32,
+ height: u32,
+}
+
+fn main() {
+ let rect1 = Rectangle { width: 30, height: 50 };
+
+ println!(
+ "The perimeter of the rectangle is {} pixels.",
+ perimeter(&rect1)
+ );
+}
+
+fn area(rectangle: &Rectangle) -> u32 {
+ rectangle.width * rectangle.height
+}
+
+fn perimeter(rectangle: &Rectangle) -> u32 {
+ (rectangle.width + rectangle.height) * 2
+} \ No newline at end of file
diff --git a/tests/snapshots/sample.rs b/tests/snapshots/sample.rs
new file mode 100644
index 00000000..00ec0eb6
--- /dev/null
+++ b/tests/snapshots/sample.rs
@@ -0,0 +1,18 @@
+struct Rectangle {
+ width: u32,
+ height: u32,
+}
+
+fn main() {
+ // width and height of a rectangle can be different
+ let rect1 = Rectangle { width: 30, height: 50 };
+
+ println!(
+ "The area of the rectangle is {} square pixels.",
+ area(&rect1)
+ );
+}
+
+fn area(rectangle: &Rectangle) -> u32 {
+ rectangle.width * rectangle.height
+}