From 162ce1dff827912a6afd115fe33e39af359d9922 Mon Sep 17 00:00:00 2001 From: Alex Kotov Date: Wed, 7 Sep 2022 18:03:35 +0400 Subject: [PATCH] Add Rust tests --- Makefile | 1 + src/lib.rs | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index fa26b47..c7a604c 100644 --- a/Makefile +++ b/Makefile @@ -82,6 +82,7 @@ target/debug/libpolytreewm.a: test: $(TEST_EXE) @echo "$(TEST_EXE)" | awk '{ OFS="\n"; $$1=$$1 } 1' | /bin/sh + $(CARGO) test clean: rm -f $(ALL_OBJ) $(ALL_EXE) diff --git a/src/lib.rs b/src/lib.rs index 9dc5ba6..eba48aa 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,11 +1,24 @@ use std::os::raw::*; -const MIN_BORDER_WIDTH: c_int = 0; const MAX_BORDER_WIDTH: c_int = 10000; #[no_mangle] pub extern "C" fn constraints_border_width(border_width: c_int) -> c_int { - if border_width < MIN_BORDER_WIDTH { return MIN_BORDER_WIDTH } if border_width > MAX_BORDER_WIDTH { return MAX_BORDER_WIDTH } border_width } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_constraints_border_width() { + assert_eq!(constraints_border_width(0), 0); + assert_eq!(constraints_border_width(10), 10); + assert_eq!(constraints_border_width(10_000), 10_000); + + assert_eq!(constraints_border_width(10_001), 10_000); + assert_eq!(constraints_border_width(20_000), 10_000); + } +}