GoPLS Viewer

Home|gopls/internal/bug/bug_test.go
1// Copyright 2022 The Go Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
5package bug
6
7import (
8    "fmt"
9    "testing"
10)
11
12func resetForTesting() {
13    exemplars = nil
14    waiters = nil
15}
16
17func TestListBugs(t *testing.T) {
18    defer resetForTesting()
19
20    Report("bad"nil)
21
22    wantBugs(t"bad")
23
24    for i := 0i < 3i++ {
25        Report(fmt.Sprintf("index:%d"i), nil)
26    }
27
28    wantBugs(t"bad""index:0")
29}
30
31func wantBugs(t *testing.Twant ...string) {
32    t.Helper()
33
34    bugs := List()
35    if gotwant := len(bugs), len(want); got != want {
36        t.Errorf("List(): got %d bugs, want %d"gotwant)
37        return
38    }
39
40    for ib := range bugs {
41        if gotwant := b.Descriptionwant[i]; got != want {
42            t.Errorf("bug.List()[%d] = %q, want %q"igotwant)
43        }
44    }
45}
46
47func TestBugNotification(t *testing.T) {
48    defer resetForTesting()
49
50    Report("unseen"nil)
51
52    notify1 := Notify()
53    notify2 := Notify()
54
55    Report("seen"Data{"answer"42})
56
57    for _got := range []Bug{<-notify1, <-notify2} {
58        if gotwant := got.Description"seen"got != want {
59            t.Errorf("Saw bug %q, want %q"gotwant)
60        }
61        if gotwant := got.Data["answer"], 42got != want {
62            t.Errorf(`bug.Data["answer"] = %v, want %v`gotwant)
63        }
64    }
65}
66
MembersX
resetForTesting
wantBugs.t
wantBugs.bugs
TestBugNotification.RangeStmt_989.BlockStmt.got
TestListBugs
wantBugs.got
TestBugNotification.t
TestBugNotification.notify2
TestBugNotification.RangeStmt_989.got
TestBugNotification.RangeStmt_989.BlockStmt.want
TestListBugs.t
wantBugs
wantBugs.want
wantBugs.RangeStmt_668.i
wantBugs.RangeStmt_668.BlockStmt.got
TestBugNotification
testing
TestListBugs.i
wantBugs.RangeStmt_668.b
TestBugNotification.notify1
Members
X