about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2023-10-15 14:20:55 -0700
committerKartik K. Agaram <vc@akkartik.com>2023-10-15 14:20:55 -0700
commit6b723363b891a3a72b20718864cae780c823ebda (patch)
tree90239d38b539cb0188461d03ef25204cd847997c
parent69d86cae5ba5672e7020243d0f78f0ea6355fd8f (diff)
downloadlines.love-6b723363b891a3a72b20718864cae780c823ebda.tar.gz
add some tests for rfind
-rw-r--r--search.lua7
1 files changed, 7 insertions, 0 deletions
diff --git a/search.lua b/search.lua
index c9af187..dab7e1f 100644
--- a/search.lua
+++ b/search.lua
@@ -141,3 +141,10 @@ function rfind(s, pat, i, plain)
   assert (endpos >= #pat)
   return endpos-#pat+1
 end
+
+function test_rfind()
+  check_eq(rfind('abc', 'c'), 3, 'final char')
+  check_eq(rfind('acbc', 'c', 3), 2, 'previous char')
+  check_nil(rfind('abc', 'd'), 'missing char')
+  check_nil(rfind('abc', 'c', 2), 'no more char')
+end