github.com/sdboyer/gps@v0.16.3/selection_test.go (about) 1 package gps 2 3 import ( 4 "reflect" 5 "testing" 6 ) 7 8 // Regression test for https://github.com/sdboyer/gps/issues/174 9 func TestUnselectedRemoval(t *testing.T) { 10 // We don't need a comparison function for this test 11 bmi1 := bimodalIdentifier{ 12 id: mkPI("foo"), 13 pl: []string{"foo", "bar"}, 14 } 15 bmi2 := bimodalIdentifier{ 16 id: mkPI("foo"), 17 pl: []string{"foo", "bar", "baz"}, 18 } 19 bmi3 := bimodalIdentifier{ 20 id: mkPI("foo"), 21 pl: []string{"foo"}, 22 } 23 24 u := &unselected{ 25 sl: []bimodalIdentifier{bmi1, bmi2, bmi3}, 26 } 27 28 u.remove(bimodalIdentifier{ 29 id: mkPI("other"), 30 pl: []string{"other"}, 31 }) 32 33 if len(u.sl) != 3 { 34 t.Fatalf("len of unselected slice should have been 2 after no-op removal, got %v", len(u.sl)) 35 } 36 37 u.remove(bmi3) 38 want := []bimodalIdentifier{bmi1, bmi2} 39 if len(u.sl) != 2 { 40 t.Fatalf("removal of matching bmi did not work, slice should have 2 items but has %v", len(u.sl)) 41 } 42 if !reflect.DeepEqual(u.sl, want) { 43 t.Fatalf("wrong item removed from slice:\n\t(GOT): %v\n\t(WNT): %v", u.sl, want) 44 } 45 46 u.remove(bmi3) 47 if len(u.sl) != 2 { 48 t.Fatalf("removal of bmi w/non-matching packages should be a no-op but wasn't; slice should have 2 items but has %v", len(u.sl)) 49 } 50 51 u.remove(bmi2) 52 want = []bimodalIdentifier{bmi1} 53 if len(u.sl) != 1 { 54 t.Fatalf("removal of matching bmi did not work, slice should have 1 items but has %v", len(u.sl)) 55 } 56 if !reflect.DeepEqual(u.sl, want) { 57 t.Fatalf("wrong item removed from slice:\n\t(GOT): %v\n\t(WNT): %v", u.sl, want) 58 } 59 }