implemented after and before atoms w/ tests for them

This commit is contained in:
David Dworken
2022-04-08 18:23:17 -07:00
parent 1adcaeb6cf
commit 39b9b15d53
3 changed files with 93 additions and 2 deletions

View File

@@ -271,6 +271,15 @@ func TestAdvancedQuery(t *testing.T) {
t.Fatalf("hishtory query has the wrong number of lines=%d, out=%#v", strings.Count(out, "\n"), out)
}
// Query based on cwd without the slash
out = RunInteractiveBashCommands(t, `hishtory query cwd:tmp`)
if !strings.Contains(out, "echo querybydir") {
t.Fatalf("hishtory query doesn't contain result matching cwd:tmp, out=%#v", out)
}
if strings.Count(out, "\n") != 3 {
t.Fatalf("hishtory query has the wrong number of lines=%d, out=%#v", strings.Count(out, "\n"), out)
}
// Query based on cwd and another term
out = RunInteractiveBashCommands(t, `hishtory query cwd:/tmp querybydir`)
if !strings.Contains(out, "echo querybydir") {
@@ -298,5 +307,31 @@ func TestAdvancedQuery(t *testing.T) {
t.Fatalf("hishtory query has the wrong number of lines=%d, out=%#v", strings.Count(out, "\n"), out)
}
// Query based on before: and cwd:
out = RunInteractiveBashCommands(t, `hishtory query before:2025-07-02 cwd:/tmp`)
if strings.Count(out, "\n") != 3 {
t.Fatalf("hishtory query has the wrong number of lines=%d, out=%#v", strings.Count(out, "\n"), out)
}
out = RunInteractiveBashCommands(t, `hishtory query before:2025-07-02 cwd:tmp`)
if strings.Count(out, "\n") != 3 {
t.Fatalf("hishtory query has the wrong number of lines=%d, out=%#v", strings.Count(out, "\n"), out)
}
out = RunInteractiveBashCommands(t, `hishtory query before:2025-07-02 cwd:mp`)
if strings.Count(out, "\n") != 3 {
t.Fatalf("hishtory query has the wrong number of lines=%d, out=%#v", strings.Count(out, "\n"), out)
}
// Query based on after: and cwd:
out = RunInteractiveBashCommands(t, `hishtory query after:2020-07-02 cwd:/tmp`)
if strings.Count(out, "\n") != 3 {
t.Fatalf("hishtory query has the wrong number of lines=%d, out=%#v", strings.Count(out, "\n"), out)
}
// Query based on after: that returns no results
out = RunInteractiveBashCommands(t, `hishtory query after:2120-07-02 cwd:/tmp`)
if strings.Count(out, "\n") != 1 {
t.Fatalf("hishtory query has the wrong number of lines=%d, out=%#v", strings.Count(out, "\n"), out)
}
// TODO: test the username,hostname atoms
}