fix buggy call to instr

main
Daniel Barlow 2023-01-03 21:18:29 +00:00
parent 24613ea424
commit c2c89b6dfd
3 changed files with 26 additions and 11 deletions

View File

@ -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)))

View File

@ -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))]

View File

@ -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"))))