From ce04288d6492c36f5021198d9d7fe8a6932959e4 Mon Sep 17 00:00:00 2001 From: Viktor Marosvary Date: Tue, 24 Oct 2017 10:22:18 +0200 Subject: isAlphaNumberic and isDigit improvement + tests (#6579) if we encounter a character that does not satisfy the proc, we return immediately, without continuing to loop over the rest of the chars in the string. --- tests/stdlib/tstrutil.nim | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'tests') diff --git a/tests/stdlib/tstrutil.nim b/tests/stdlib/tstrutil.nim index fef1b38c2..57968df13 100644 --- a/tests/stdlib/tstrutil.nim +++ b/tests/stdlib/tstrutil.nim @@ -64,6 +64,25 @@ proc testDelete = delete(s, 0, 0) assert s == "1236789ABCDEFG" + +proc testIsAlphaNumeric = + assert isAlphaNumeric("abcdABC1234") == true + assert isAlphaNumeric("a") == true + assert isAlphaNumeric("abcABC?1234") == false + assert isAlphaNumeric("abcABC 1234") == false + assert isAlphaNumeric(".") == false + +testIsAlphaNumeric() + +proc testIsDigit = + assert isDigit("1") == true + assert isDigit("1234") == true + assert isDigit("abcABC?1234") == false + assert isDigit(".") == false + assert isDigit(":") == false + +testIsDigit() + proc testFind = assert "0123456789ABCDEFGH".find('A') == 10 assert "0123456789ABCDEFGH".find('A', 5) == 10 -- cgit 1.4.1-2-gfad0