| 26 | var linuxCkFixedNow = time.Unix(linuxCkLastModified+365*24*3600, 0) |
| 27 | |
| 28 | func TestSourceQueryBuilder(t *testing.T) { |
| 29 | // Cannot run in parallel: mutates text.NowFunc, a package-level var. |
| 30 | text.NowFunc = func() time.Time { return linuxCkFixedNow } |
| 31 | t.Cleanup(func() { text.NowFunc = time.Now }) |
| 32 | |
| 33 | type testCase struct { |
| 34 | desc string |
| 35 | search []string |
| 36 | bottomUp bool |
| 37 | separateSources bool |
| 38 | sortBy string |
| 39 | verbosity SearchVerbosity |
| 40 | targetMode parser.TargetMode |
| 41 | singleLineResults bool |
| 42 | searchBy string |
| 43 | wantResults []string |
| 44 | wantOutput []string |
| 45 | } |
| 46 | |
| 47 | testCases := []testCase{ |
| 48 | { |
| 49 | desc: "sort-by-metric bottomup separatesources", |
| 50 | search: []string{"linux"}, |
| 51 | bottomUp: true, |
| 52 | separateSources: true, |
| 53 | sortBy: "", |
| 54 | verbosity: Detailed, |
| 55 | wantResults: []string{"linux-ck", "linux-zen", "linux"}, |
| 56 | wantOutput: []string{ |
| 57 | "\x1b]8;;https://aur.archlinux.org/packages/linux-ck\x1b\\\x1b[1m\x1b[34maur\x1b[0m\x1b[0m/\x1b[1mlinux-ck\x1b[0m\x1b]8;;\x1b\\ \x1b[36m5.16.12-1\x1b[0m\x1b[1m (+450\x1b[0m \x1b[1m1.51) \x1b[0m\x1b[36m[365d]\x1b[0m \n The Linux-ck kernel and modules with ck's hrtimer patches\n", |
| 58 | "\x1b]8;;https://archlinux.org/packages/core/x86_64/linux-zen\x1b\\\x1b[1m\x1b[33mcore\x1b[0m\x1b[0m/\x1b[1mlinux-zen\x1b[0m\x1b]8;;\x1b\\ \x1b[36m5.16.0\x1b[0m\x1b[1m (1.0 B 1.0 B) \x1b[0m\n The Linux ZEN kernel and modules\n", |
| 59 | "\x1b]8;;https://archlinux.org/packages/core/x86_64/linux\x1b\\\x1b[1m\x1b[33mcore\x1b[0m\x1b[0m/\x1b[1mlinux\x1b[0m\x1b]8;;\x1b\\ \x1b[36m5.16.0\x1b[0m\x1b[1m (1.0 B 1.0 B) \x1b[0m\n The Linux kernel and modules\n", |
| 60 | }, |
| 61 | }, |
| 62 | { |
| 63 | desc: "sort-by-metric topdown separatesources", |
| 64 | search: []string{"linux"}, |
| 65 | bottomUp: false, |
| 66 | separateSources: true, |
| 67 | sortBy: "", |
| 68 | verbosity: Detailed, |
| 69 | wantResults: []string{"linux", "linux-zen", "linux-ck"}, |
| 70 | wantOutput: []string{ |
| 71 | "\x1b]8;;https://archlinux.org/packages/core/x86_64/linux\x1b\\\x1b[1m\x1b[33mcore\x1b[0m\x1b[0m/\x1b[1mlinux\x1b[0m\x1b]8;;\x1b\\ \x1b[36m5.16.0\x1b[0m\x1b[1m (1.0 B 1.0 B) \x1b[0m\n The Linux kernel and modules\n", |
| 72 | "\x1b]8;;https://archlinux.org/packages/core/x86_64/linux-zen\x1b\\\x1b[1m\x1b[33mcore\x1b[0m\x1b[0m/\x1b[1mlinux-zen\x1b[0m\x1b]8;;\x1b\\ \x1b[36m5.16.0\x1b[0m\x1b[1m (1.0 B 1.0 B) \x1b[0m\n The Linux ZEN kernel and modules\n", |
| 73 | "\x1b]8;;https://aur.archlinux.org/packages/linux-ck\x1b\\\x1b[1m\x1b[34maur\x1b[0m\x1b[0m/\x1b[1mlinux-ck\x1b[0m\x1b]8;;\x1b\\ \x1b[36m5.16.12-1\x1b[0m\x1b[1m (+450\x1b[0m \x1b[1m1.51) \x1b[0m\x1b[36m[365d]\x1b[0m \n The Linux-ck kernel and modules with ck's hrtimer patches\n", |
| 74 | }, |
| 75 | }, |
| 76 | { |
| 77 | desc: "sort-by-metric bottomup noseparatesources", |
| 78 | search: []string{"linux"}, |
| 79 | bottomUp: true, |
| 80 | separateSources: false, |
| 81 | sortBy: "", |
| 82 | verbosity: Detailed, |
| 83 | wantResults: []string{"linux-ck", "linux-zen", "linux"}, |
| 84 | wantOutput: []string{ |
| 85 | "\x1b]8;;https://aur.archlinux.org/packages/linux-ck\x1b\\\x1b[1m\x1b[34maur\x1b[0m\x1b[0m/\x1b[1mlinux-ck\x1b[0m\x1b]8;;\x1b\\ \x1b[36m5.16.12-1\x1b[0m\x1b[1m (+450\x1b[0m \x1b[1m1.51) \x1b[0m\x1b[36m[365d]\x1b[0m \n The Linux-ck kernel and modules with ck's hrtimer patches\n", |