Giant blob of minor changes
[dotfiles/.git] / .config / coc / extensions / coc-go-data / tools / pkg / mod / github.com / google / go-cmp@v0.5.1 / cmp / internal / teststructs / project3.go
1 // Copyright 2017, 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.md file.
4
5 package teststructs
6
7 import (
8         "sync"
9
10         pb "github.com/google/go-cmp/cmp/internal/testprotos"
11 )
12
13 // This is an sanitized example of equality from a real use-case.
14 // The original equality function was as follows:
15 /*
16 func equalDirt(x, y *Dirt) bool {
17         if !reflect.DeepEqual(x.table, y.table) ||
18                 !reflect.DeepEqual(x.ts, y.ts) ||
19                 x.Discord != y.Discord ||
20                 !pb.Equal(&x.Proto, &y.Proto) ||
21                 len(x.wizard) != len(y.wizard) ||
22                 len(x.sadistic) != len(y.sadistic) ||
23                 x.lastTime != y.lastTime {
24                 return false
25         }
26         for k, vx := range x.wizard {
27                 vy, ok := y.wizard[k]
28                 if !ok || !pb.Equal(vx, vy) {
29                         return false
30                 }
31         }
32         for k, vx := range x.sadistic {
33                 vy, ok := y.sadistic[k]
34                 if !ok || !pb.Equal(vx, vy) {
35                         return false
36                 }
37         }
38         return true
39 }
40 */
41
42 type FakeMutex struct {
43         sync.Locker
44         x struct{}
45 }
46
47 type Dirt struct {
48         table    Table // Always concrete type of MockTable
49         ts       Timestamp
50         Discord  DiscordState
51         Proto    pb.Dirt
52         wizard   map[string]*pb.Wizard
53         sadistic map[string]*pb.Sadistic
54         lastTime int64
55         mu       FakeMutex
56 }
57
58 type DiscordState int
59
60 type Timestamp int64
61
62 func (d *Dirt) SetTable(t Table)                      { d.table = t }
63 func (d *Dirt) SetTimestamp(t Timestamp)              { d.ts = t }
64 func (d *Dirt) SetWizard(m map[string]*pb.Wizard)     { d.wizard = m }
65 func (d *Dirt) SetSadistic(m map[string]*pb.Sadistic) { d.sadistic = m }
66 func (d *Dirt) SetLastTime(t int64)                   { d.lastTime = t }
67
68 type Table interface {
69         Operation1() error
70         Operation2() error
71         Operation3() error
72 }
73
74 type MockTable struct {
75         state []string
76 }
77
78 func CreateMockTable(s []string) *MockTable { return &MockTable{s} }
79 func (mt *MockTable) Operation1() error     { return nil }
80 func (mt *MockTable) Operation2() error     { return nil }
81 func (mt *MockTable) Operation3() error     { return nil }
82 func (mt *MockTable) State() []string       { return mt.state }