commit c2c89b6dfd314a9d9c225306b82f41e6eb5482db
parent 24613ea424d6bc24187645b73184762673ac0be7
Author: Daniel Barlow <dan@telent.net>
Date: Tue, 3 Jan 2023 21:18:29 +0000
fix buggy call to instr
Diffstat:
3 files changed, 26 insertions(+), 11 deletions(-)
diff --git 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
@@ -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
@@ -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"))))