From c2c89b6dfd314a9d9c225306b82f41e6eb5482db Mon Sep 17 00:00:00 2001 From: Daniel Barlow Date: Tue, 3 Jan 2023 21:18:29 +0000 Subject: [PATCH] fix buggy call to instr --- command.fnl | 4 +++- history.fnl | 4 ++-- test/history.fnl | 29 +++++++++++++++++++++-------- 3 files changed, 26 insertions(+), 11 deletions(-) diff --git a/command.fnl b/command.fnl index e3d0c85..05e66f0 100644 --- a/command.fnl +++ b/command.fnl @@ -36,7 +36,9 @@ [[:buffer Buffer.match #$1.buffer.name] - [:url #{$1 $1} #($1.buffer:location)] + [:url + (fn [term] (collect [v (_G.history:find term)] (values v.url v.url))) + #($1.buffer:location)] ] (fn [{:url url :buffer buffer}] (buffer:visit url))) diff --git a/history.fnl b/history.fnl index daac8d6..e152732 100644 --- a/history.fnl +++ b/history.fnl @@ -37,9 +37,9 @@ (s:reset))) (fn find [self term] - (let [s (self.db:prepare "select v.url,pt.title,v.timestamp from visits v left join page_titles pt on v.url = pt.url where instr(v.url, ?) is not null")] + (let [s (self.db:prepare "select v.url,pt.title,v.timestamp from visits v left join page_titles pt on v.url = pt.url where instr(v.url, ?) >0")] (assert (= 0 (s:bind_values term))) - (icollect [r (s:nrows)] r))) + (s:nrows))) (fn open [pathname] (let [db (if pathname (sqlite.open pathname) (sqlite.open_memory))] diff --git a/test/history.fnl b/test/history.fnl index 627b14b..862c335 100644 --- a/test/history.fnl +++ b/test/history.fnl @@ -11,15 +11,28 @@ (let [h (history.open)] (h:visit "http://example.com" (fake-time)) - (let [actual (h:find "example.com")] - (match actual - (where [{:url "http://example.com" :timestamp t}] (> t 0)) true - ?fail (assert false (view ?fail))))) + (assert + (accumulate [found false + r (h:find "example.com")] + (or + found + (match r + {:url "http://example.com" :timestamp t} true))))) (let [h (history.open)] (h:visit "http://example.com" (fake-time)) (h:title "http://example.com" "Page title") - (let [actual (h:find "example.com")] - (match actual - (where [{:url "http://example.com" :title "Page title" :timestamp t}] (> t 0)) true - ?fail (assert false (view ?fail))))) + (assert + (accumulate [found false + r (h:find "example.com")] + (or + found + (match r + {:url "http://example.com" :title "Page title" :timestamp t} true))))) + +(let [h (history.open "/tmp/foo.db")] + (h:visit "http://example.com" (fake-time)) + (h:visit "http://notsample.com" (+ 1 (fake-time))) + (each [r (h:find "example.com")] + (match r + {:url "http://notsample.com" } (assert false "unexpected row"))))