Skip to content

Commit

Permalink
refactor: Minor code improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
qrichert committed Sep 23, 2024
1 parent a9d036f commit 564eeed
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 22 deletions.
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
default_install_hook_types: [pre-commit, pre-push]
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.5.3
rev: v0.9.6
hooks:
- id: ruff
args: [--fix]
- id: ruff-format
- repo: https://github.com/PyCQA/docformatter
rev: v1.7.5
rev: 06907d0
hooks:
- id: docformatter
- repo: https://github.com/RobertCraigie/pyright-python
rev: v1.1.372
rev: v1.1.394
hooks:
- id: pyright
- repo: https://github.com/adamchainz/blacken-docs
rev: 1.18.0
rev: 1.19.1
hooks:
- id: blacken-docs
additional_dependencies:
Expand Down
7 changes: 4 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ light-rust-test: ## Run light Rust unit tests

.PHONY: doc
doc: ## Build documentation
@cargo doc
@cargo doc --all-features
@echo file://$(shell pwd)/target/doc/$(shell basename $(shell pwd))/index.html

.PHONY: c
c: coverage
Expand All @@ -80,8 +81,8 @@ coverage: ## Unit tests coverage report
rc: rust-coverage
.PHONY: rust-coverage
rust-coverage: ## Unit tests coverage report
@cargo tarpaulin --engine Llvm --timeout 120 --out Html --output-dir target/
@open target/tarpaulin-report.html || xdg-open target/tarpaulin-report.html || :
@cargo tarpaulin --engine Llvm --timeout 120 --out Html --output-dir target/ --all-features
@echo file://$(shell pwd)/target/tarpaulin-report.html

.PHONY: rust-coverage-pct
rust-coverage-pct: ## Ensure code coverage of 100%
Expand Down
22 changes: 11 additions & 11 deletions src/textcanvas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1565,55 +1565,55 @@ mod tests {
#[test]
#[should_panic(expected = "TextCanvas' minimal size is 1×1.")]
fn size_zero_panics_for_width() {
let _ = TextCanvas::new(0, 1);
_ = TextCanvas::new(0, 1);
}

#[test]
#[should_panic(expected = "TextCanvas' minimal size is 1×1.")]
fn size_zero_panics_for_height() {
let _ = TextCanvas::new(1, 0);
_ = TextCanvas::new(1, 0);
}

#[test]
#[should_panic(expected = "TextCanvas' minimal size is 1×1.")]
fn size_zero_panics_for_width_and_height() {
let _ = TextCanvas::new(0, 0);
_ = TextCanvas::new(0, 0);
}

#[test]
#[should_panic(expected = "TextCanvas' minimal size is 1×1.")]
fn size_negative_panics_for_width() {
let _ = TextCanvas::new(-1, 1);
_ = TextCanvas::new(-1, 1);
}

#[test]
#[should_panic(expected = "TextCanvas' minimal size is 1×1.")]
fn size_negative_panics_for_height() {
let _ = TextCanvas::new(1, -1);
_ = TextCanvas::new(1, -1);
}

#[test]
#[should_panic(expected = "TextCanvas' minimal size is 1×1.")]
fn size_negative_panics_for_width_and_height() {
let _ = TextCanvas::new(-1, -1);
_ = TextCanvas::new(-1, -1);
}

#[test]
#[should_panic(expected = "TextCanvas' minimal size is 1×1.")]
fn size_too_big_panics_for_width() {
let _ = TextCanvas::new(100_000, 1);
_ = TextCanvas::new(100_000, 1);
}

#[test]
#[should_panic(expected = "TextCanvas' minimal size is 1×1.")]
fn size_too_big_panics_for_height() {
let _ = TextCanvas::new(1, 100_000);
_ = TextCanvas::new(1, 100_000);
}

#[test]
#[should_panic(expected = "TextCanvas' minimal size is 1×1.")]
fn size_too_big_panics_for_width_and_height() {
let _ = TextCanvas::new(100_000, 100_000);
_ = TextCanvas::new(100_000, 100_000);
}

#[test]
Expand All @@ -1627,7 +1627,7 @@ mod tests {
// multiply with overflow`. The solution is to divide instead:
//
// if width <= MAX_RESOLUTION / 2
let _ = TextCanvas::new(i32::MAX, 1);
_ = TextCanvas::new(i32::MAX, 1);
}

#[test]
Expand All @@ -1641,7 +1641,7 @@ mod tests {
// multiply with overflow`. The solution is to divide instead:
//
// if height <= MAX_RESOLUTION / 4
let _ = TextCanvas::new(1, i32::MAX);
_ = TextCanvas::new(1, i32::MAX);
}

#[test]
Expand Down
4 changes: 2 additions & 2 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ impl GameLoop<'_> {
print!("{string}");
return;
}
let _ = write!(self.stdout, "{string}");
_ = write!(self.stdout, "{string}");
}

/// Flush stdout.
Expand All @@ -270,7 +270,7 @@ impl GameLoop<'_> {
/// Flushing stdout forces the immediate display of what's in the
/// buffer, even if there is no `\n`.
pub fn flush(&mut self) {
let _ = self.stdout.flush();
_ = self.stdout.flush();
}

/// Sleep for some duration.
Expand Down
4 changes: 2 additions & 2 deletions tests/test_textcanvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -1209,7 +1209,7 @@ def test_draw_canvas_with_text(self) -> None:

# print(f"{canvas}")

self.assertEqual(canvas.to_string(), "⠀⠀⠀⠀⠀⠀⠀\n" "⠀a⠀⠀012\n" "⠀⠀⠀⠀⠀⠀⠀\n")
self.assertEqual(canvas.to_string(), "⠀⠀⠀⠀⠀⠀⠀\n⠀a⠀⠀012\n⠀⠀⠀⠀⠀⠀⠀\n")

def test_draw_canvas_with_colored_text(self) -> None:
canvas = TextCanvas(7, 3)
Expand Down Expand Up @@ -1381,7 +1381,7 @@ def test_merge_canvas_with_text(self) -> None:

# print(f"{canvas}")

self.assertEqual(canvas.to_string(), "⠀⠀⠀⠀⠀⠀⠀\n" "⠀a012e⠀\n" "⠀⠀⠀⠀⠀⠀⠀\n")
self.assertEqual(canvas.to_string(), "⠀⠀⠀⠀⠀⠀⠀\n⠀a012e⠀\n⠀⠀⠀⠀⠀⠀⠀\n")

def test_merge_canvas_with_colored_text(self) -> None:
canvas = TextCanvas(7, 3)
Expand Down

0 comments on commit 564eeed

Please # to comment.