From dc7f7dc9685a99e16ffc60d22b06794519af0b99 Mon Sep 17 00:00:00 2001 From: n5m <72841454+n5m@users.noreply.github.com> Date: Fri, 4 Jun 2021 14:08:55 +0000 Subject: [PATCH] # This is a combination of 7 commits. # This is the 1st commit message: default last in strutils.find to -1 # This is the commit message #2: Revert "default last in strutils.find to -1" This reverts commit 3a995564a8b4c32096f7e6189312812523bf8fa2. # This is the commit message #3: add openArray variable of find with SkipTable # This is the commit message #4: add find method that accepts an openArray # This is the commit message #5: add tests # This is the commit message #6: Revert "add find method that accepts an openArray" This reverts commit 2ab5351b71fa6c736c355556791050c4d700706b. # This is the commit message #7: Revert "add openArray variable of find with SkipTable" This reverts commit 58159fc0b8a39c68b2c60116e953342dc2f9dfa9. --- tests/stdlib/tstrutils.nim | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/stdlib/tstrutils.nim b/tests/stdlib/tstrutils.nim index 234991bdbf96c..a7c643ca2f0ee 100644 --- a/tests/stdlib/tstrutils.nim +++ b/tests/stdlib/tstrutils.nim @@ -308,6 +308,22 @@ template main() = doAssert "abcd".find("bc", start=1, last=last) == -1 doAssert "abcd".find("bc", start=2, last=last) == -1 + # using openArray variant + block: + doAssert "abcde".toOpenArray(0, 4).find("") == 0 + doAssert "abcde".toOpenArray(1, 4).find("") == 0 + doAssert "abcde".toOpenArray(3, 4).find("") == 0 + doAssert "abcde".toOpenArray(4, 4).find("") == 0 + + doAssert "abcde".toOpenArray(0, 4).find("c") == 2 + doAssert "abcde".toOpenArray(1, 4).find("c") == 1 + doAssert "abcde".toOpenArray(2, 4).find("c") == 0 + doAssert "abcde".toOpenArray(3, 4).find("c") == -1 + + doAssert "abcde".toOpenArray(0, 4).find("cd") == 2 + doAssert "abcde".toOpenArray(1, 4).find("cd") == 1 + doAssert "abcde".toOpenArray(3, 4).find("cd") == -1 + block: # rfind doAssert "0123456789ABCDEFGAH".rfind('A') == 17 doAssert "0123456789ABCDEFGAH".rfind('A', last=13) == 10