MCPcopy
hub / github.com/google/mangle / TestAddContainsRemove

Function TestAddContainsRemove

factstore/factstore_test.go:47–164  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

45}
46
47func TestAddContainsRemove(t *testing.T) {
48 for _, fs := range []FactStore{
49 NewSimpleInMemoryStore(),
50 NewIndexedInMemoryStore(),
51 NewMultiIndexedInMemoryStore(),
52 NewMultiIndexedArrayInMemoryStore(),
53 NewMergedStore([]FactStore{NewSimpleInMemoryStore()}, NewSimpleInMemoryStore()),
54 NewConcurrentFactStore(NewSimpleInMemoryStore())} {
55 t.Run(fmt.Sprintf("%T", fs), func(t *testing.T) {
56 tests := []ast.Atom{
57 atom("baz()"),
58 atom("foo(/bar)"),
59 atom("foo(/zzz)"),
60 atom("bar(/abc)"),
61 atom("bar(/bar,/baz)"),
62 atom("bar(/bar,/def)"),
63 atom("bar(/abc,/def)"),
64 evalAtom("bar([/abc],1,/def)"),
65 evalAtom("bar([/abc, /def],1,/def)"),
66 evalAtom("bar([/def, /abc],1,/def)"),
67 evalAtom("baz([/abc : 1, /def : 2], 1, /def)"),
68 evalAtom("baz({/abc : 1, /def : 2}, 1, /def)"),
69 evalAtom("baz({/abc : 1, /def : 3}, 1, /def)"),
70 }
71 for _, atom := range tests {
72 if got := fs.Add(atom); !got {
73 t.Errorf("Add(%v)=%v want %v", atom, got, true)
74 }
75 if !fs.Contains(atom) {
76 t.Errorf("Contains(%v)=true want false, store %v", atom, fs)
77 }
78 if got := fs.Add(atom); got {
79 t.Errorf("Add(%v)=%v want %v", atom, got, false)
80 }
81 if fsr, ok := fs.(FactStoreWithRemove); ok {
82 if got := fsr.Remove(atom); !got {
83 t.Errorf("Remove(%v)=false want true", atom)
84 }
85 if got := fsr.Remove(atom); got {
86 t.Errorf("2nd Remove(%v)=true want false", atom)
87 }
88 if fsr.Contains(atom) {
89 t.Errorf("Contains(%v)=true want false, store %v", atom, fs)
90 }
91 if got := fsr.Add(atom); !got {
92 t.Errorf("2nd Add(%v)=false want true", atom)
93 }
94 if !fsr.Contains(atom) {
95 t.Fatalf("after 2nd Add: Contains(%v)=false want true, store %v", atom, fs)
96 }
97 }
98 }
99 for _, tt := range []struct {
100 atom string
101 want stringset.Set
102 }{
103 {
104 atom: "baz()",

Callers

nothing calls this directly

Calls 15

AddMethod · 0.95
NewSimpleInMemoryStoreFunction · 0.85
NewIndexedInMemoryStoreFunction · 0.85
NewMergedStoreFunction · 0.85
NewConcurrentFactStoreFunction · 0.85
atomFunction · 0.70
evalAtomFunction · 0.70
AddMethod · 0.65
ContainsMethod · 0.65
RemoveMethod · 0.65

Tested by

no test coverage detected