From 37e556b7a0490addeedb55ef8ffbf9613a0132b9 Mon Sep 17 00:00:00 2001 From: "P. Starsider" <132208486+starsiderfox@users.noreply.github.com> Date: Thu, 28 Sep 2023 00:22:31 +0200 Subject: [PATCH] Fix not working for ints and floats of sizes other than default --- elvis.nim | 4 ++-- tests.nim | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/elvis.nim b/elvis.nim index 743da01..d9a24d7 100644 --- a/elvis.nim +++ b/elvis.nim @@ -1,10 +1,10 @@ import options #true if float not 0 or NaN -template truthy*(val: float): bool = (val < 0 or val > 0) +template truthy*(val: SomeFloat): bool = (val < 0 or val > 0) #true if int not 0 -template truthy*(val: int): bool = (val != 0) +template truthy*(val: SomeInteger): bool = (val != 0) #try if char not \0 template truthy*(val: char): bool = (val != '\0') diff --git a/tests.nim b/tests.nim index d7e0d3b..11edc7d 100644 --- a/tests.nim +++ b/tests.nim @@ -36,15 +36,24 @@ suite "truthy": test "empty string": check(not(?"")) test "zero float": check(not ?0.0) test "NaN float": check(not ?NaN) + test "zero float32": check(not ?float32(0.0)) + test "NaN float32": check(not ?float32(NaN)) test "\0 char": check(not ?cha0) test "not \0 char": check(?'0') test "zero int": check(not ?0) + test "zero int32": check(not ?int32(0)) + test "zero uint32": check(not ?uint32(0)) test "empty array": check(not ?seq0) test "empty seq lit": check(?seq1) test "none option": check(not ?none(string)) test "not empty string": check(?"1") test "not zero float": check(?1.1) + test "not zero negative": check(?(-1.1)) + test "not zero float32": check(?float32(1.1)) test "not zero int": check(?1) + test "not zero int32": check(?int32(1)) + test "not zero uint32": check(?uint32(1)) + test "not zero uint8": check(?uint8(1)) test "not empty array": check(?[0]) test "not empty seq lit": check(?seq1)