Add Rust tests

This commit is contained in:
Alex Kotov 2022-09-07 18:03:35 +04:00
parent bd4b49c5e1
commit 162ce1dff8
Signed by: kotovalexarian
GPG key ID: 553C0EBBEB5D5F08
2 changed files with 16 additions and 2 deletions

View file

@ -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)

View file

@ -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);
}
}