Add Rust tests
This commit is contained in:
parent
bd4b49c5e1
commit
162ce1dff8
2 changed files with 16 additions and 2 deletions
1
Makefile
1
Makefile
|
@ -82,6 +82,7 @@ target/debug/libpolytreewm.a:
|
||||||
|
|
||||||
test: $(TEST_EXE)
|
test: $(TEST_EXE)
|
||||||
@echo "$(TEST_EXE)" | awk '{ OFS="\n"; $$1=$$1 } 1' | /bin/sh
|
@echo "$(TEST_EXE)" | awk '{ OFS="\n"; $$1=$$1 } 1' | /bin/sh
|
||||||
|
$(CARGO) test
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f $(ALL_OBJ) $(ALL_EXE)
|
rm -f $(ALL_OBJ) $(ALL_EXE)
|
||||||
|
|
17
src/lib.rs
17
src/lib.rs
|
@ -1,11 +1,24 @@
|
||||||
use std::os::raw::*;
|
use std::os::raw::*;
|
||||||
|
|
||||||
const MIN_BORDER_WIDTH: c_int = 0;
|
|
||||||
const MAX_BORDER_WIDTH: c_int = 10000;
|
const MAX_BORDER_WIDTH: c_int = 10000;
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn constraints_border_width(border_width: c_int) -> c_int {
|
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 }
|
if border_width > MAX_BORDER_WIDTH { return MAX_BORDER_WIDTH }
|
||||||
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue