on master help sign in
Add sample files and snapshot generator
commit026a9ebae3d867e45e642969d988ca0473f5014a authorEzinwa Okpoechi <brainmaestro@outlook.com> dateSat 12 May 2018, 16:23 (8 years ago) parentcb7b158
3 files changed+79
tests/snapshots/generate_snapshots.py+40 tests/snapshots/sample.modified.rs+21 tests/snapshots/sample.rs+18
tests/snapshots/generate_snapshots.pynew file+40
@@ -0,0 +1,40 @@
1+#!/usr/bin/env python3
2+import itertools
3+import subprocess
4+import pathlib
5+import shutil
6+
7+def generate_snapshots():
8+ single_styles = ["changes", "grid", "header", "numbers"]
9+ collective_styles = ["full", "plain"]
10+
11+ for num in range(len(single_styles)):
12+ for grouped in itertools.combinations(single_styles, num + 1):
13+ generate_snapshot(",".join(grouped))
14+
15+ for style in collective_styles:
16+ generate_snapshot(style)
17+
18+def generate_snapshot(option):
19+ command = "../../target/debug/bat --style={0} sample.rs > output/{0}.snapshot.txt".format(
20+ option
21+ )
22+ print("generating snapshot for {}".format(option))
23+ subprocess.call(command, shell=True)
24+
25+def prepare_output_dir():
26+ shutil.rmtree("output", ignore_errors=True)
27+ pathlib.Path("output").mkdir()
28+
29+def modify_sample_file():
30+ print("modifying sample.rs to show changes")
31+ shutil.copyfile("sample.modified.rs", "sample.rs")
32+
33+def undo_sample_file_modification():
34+ print("undoing sample.rs modifications")
35+ subprocess.call("git checkout -- sample.rs", shell=True)
36+
37+prepare_output_dir()
38+modify_sample_file()
39+generate_snapshots()
40+undo_sample_file_modification()
tests/snapshots/sample.modified.rsnew file+21
@@ -0,0 +1,21 @@
1+struct Rectangle {
2+ width: u32,
3+ height: u32,
4+}
5+
6+fn main() {
7+ let rect1 = Rectangle { width: 30, height: 50 };
8+
9+ println!(
10+ "The perimeter of the rectangle is {} pixels.",
11+ perimeter(&rect1)
12+ );
13+}
14+
15+fn area(rectangle: &Rectangle) -> u32 {
16+ rectangle.width * rectangle.height
17+}
18+
19+fn perimeter(rectangle: &Rectangle) -> u32 {
20+ (rectangle.width + rectangle.height) * 2
21+}
tests/snapshots/sample.rsnew file+18
@@ -0,0 +1,18 @@
1+struct Rectangle {
2+ width: u32,
3+ height: u32,
4+}
5+
6+fn main() {
7+ // width and height of a rectangle can be different
8+ let rect1 = Rectangle { width: 30, height: 50 };
9+
10+ println!(
11+ "The area of the rectangle is {} square pixels.",
12+ area(&rect1)
13+ );
14+}
15+
16+fn area(rectangle: &Rectangle) -> u32 {
17+ rectangle.width * rectangle.height
18+}