mirror of
				https://github.com/fluffle/goirc
				synced 2025-11-03 19:48:04 +00:00 
			
		
		
		
	remove implementation-specific parts in tests
This commit is contained in:
		
							parent
							
								
									b294365fc1
								
							
						
					
					
						commit
						8f773c0c79
					
				
					 2 changed files with 3 additions and 86 deletions
				
			
		| 
						 | 
				
			
			@ -153,13 +153,6 @@ func TestClientAndStateTracking(t *testing.T) {
 | 
			
		|||
		t.Errorf("State tracker not disabled correctly.")
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// Finally, check state tracking handlers were all removed correctly
 | 
			
		||||
	for k, _ := range stHandlers {
 | 
			
		||||
		if _, ok := c.intHandlers.set[strings.ToLower(k)]; ok && k != "NICK" {
 | 
			
		||||
			// A bit leaky, because intHandlers adds a NICK handler.
 | 
			
		||||
			t.Errorf("State handler for '%s' not removed correctly.", k)
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	if len(c.stRemovers) != 0 {
 | 
			
		||||
		t.Errorf("stRemovers not zeroed correctly when removing state handlers.")
 | 
			
		||||
	}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -24,66 +24,28 @@ func TestHandlerSet(t *testing.T) {
 | 
			
		|||
 | 
			
		||||
	// Add one
 | 
			
		||||
	hn1 := hs.add("ONE", HandlerFunc(f)).(*hNode)
 | 
			
		||||
	hl, ok := hs.set["one"]
 | 
			
		||||
	_, ok := hs.set["one"]
 | 
			
		||||
	if len(hs.set) != 1 || !ok {
 | 
			
		||||
		t.Errorf("Set doesn't contain 'one' list after add().")
 | 
			
		||||
	}
 | 
			
		||||
	if hn1.set != hs || hn1.event != "one" || hn1.prev != nil || hn1.next != nil {
 | 
			
		||||
		t.Errorf("First node for 'one' not created correctly")
 | 
			
		||||
	}
 | 
			
		||||
	if hl.start != hn1 || hl.end != hn1 {
 | 
			
		||||
		t.Errorf("Node not added to empty 'one' list correctly.")
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// Add another one...
 | 
			
		||||
	hn2 := hs.add("one", HandlerFunc(f)).(*hNode)
 | 
			
		||||
	if len(hs.set) != 1 {
 | 
			
		||||
		t.Errorf("Set contains more than 'one' list after add().")
 | 
			
		||||
	}
 | 
			
		||||
	if hn2.set != hs || hn2.event != "one" {
 | 
			
		||||
		t.Errorf("Second node for 'one' not created correctly")
 | 
			
		||||
	}
 | 
			
		||||
	if hn1.prev != nil || hn1.next != hn2 || hn2.prev != hn1 || hn2.next != nil {
 | 
			
		||||
		t.Errorf("Nodes for 'one' not linked correctly.")
 | 
			
		||||
	}
 | 
			
		||||
	if hl.start != hn1 || hl.end != hn2 {
 | 
			
		||||
		t.Errorf("Node not appended to 'one' list correctly.")
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// Add a third one!
 | 
			
		||||
	hn3 := hs.add("one", HandlerFunc(f)).(*hNode)
 | 
			
		||||
	if len(hs.set) != 1 {
 | 
			
		||||
		t.Errorf("Set contains more than 'one' list after add().")
 | 
			
		||||
	}
 | 
			
		||||
	if hn3.set != hs || hn3.event != "one" {
 | 
			
		||||
		t.Errorf("Third node for 'one' not created correctly")
 | 
			
		||||
	}
 | 
			
		||||
	if hn1.prev != nil || hn1.next != hn2 ||
 | 
			
		||||
		hn2.prev != hn1 || hn2.next != hn3 ||
 | 
			
		||||
		hn3.prev != hn2 || hn3.next != nil {
 | 
			
		||||
		t.Errorf("Nodes for 'one' not linked correctly.")
 | 
			
		||||
	}
 | 
			
		||||
	if hl.start != hn1 || hl.end != hn3 {
 | 
			
		||||
		t.Errorf("Node not appended to 'one' list correctly.")
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// And finally a fourth one!
 | 
			
		||||
	hn4 := hs.add("one", HandlerFunc(f)).(*hNode)
 | 
			
		||||
	if len(hs.set) != 1 {
 | 
			
		||||
		t.Errorf("Set contains more than 'one' list after add().")
 | 
			
		||||
	}
 | 
			
		||||
	if hn4.set != hs || hn4.event != "one" {
 | 
			
		||||
		t.Errorf("Fourth node for 'one' not created correctly.")
 | 
			
		||||
	}
 | 
			
		||||
	if hn1.prev != nil || hn1.next != hn2 ||
 | 
			
		||||
		hn2.prev != hn1 || hn2.next != hn3 ||
 | 
			
		||||
		hn3.prev != hn2 || hn3.next != hn4 ||
 | 
			
		||||
		hn4.prev != hn3 || hn4.next != nil {
 | 
			
		||||
		t.Errorf("Nodes for 'one' not linked correctly.")
 | 
			
		||||
	}
 | 
			
		||||
	if hl.start != hn1 || hl.end != hn4 {
 | 
			
		||||
		t.Errorf("Node not appended to 'one' list correctly.")
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// Dispatch should result in 4 additions.
 | 
			
		||||
	if atomic.LoadInt32(callcount) != 0 {
 | 
			
		||||
| 
						 | 
				
			
			@ -100,17 +62,6 @@ func TestHandlerSet(t *testing.T) {
 | 
			
		|||
	if len(hs.set) != 1 {
 | 
			
		||||
		t.Errorf("Set list count changed after remove().")
 | 
			
		||||
	}
 | 
			
		||||
	if hn3.set != nil || hn3.prev != nil || hn3.next != nil {
 | 
			
		||||
		t.Errorf("Third node for 'one' not removed correctly.")
 | 
			
		||||
	}
 | 
			
		||||
	if hn1.prev != nil || hn1.next != hn2 ||
 | 
			
		||||
		hn2.prev != hn1 || hn2.next != hn4 ||
 | 
			
		||||
		hn4.prev != hn2 || hn4.next != nil {
 | 
			
		||||
		t.Errorf("Third node for 'one' not unlinked correctly.")
 | 
			
		||||
	}
 | 
			
		||||
	if hl.start != hn1 || hl.end != hn4 {
 | 
			
		||||
		t.Errorf("Third node for 'one' changed list pointers.")
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// Dispatch should result in 3 additions.
 | 
			
		||||
	hs.dispatch(c, &Line{Cmd: "One"})
 | 
			
		||||
| 
						 | 
				
			
			@ -120,19 +71,10 @@ func TestHandlerSet(t *testing.T) {
 | 
			
		|||
	}
 | 
			
		||||
 | 
			
		||||
	// Remove node 1.
 | 
			
		||||
	hs.remove(hn1)
 | 
			
		||||
	hn1.Remove()
 | 
			
		||||
	if len(hs.set) != 1 {
 | 
			
		||||
		t.Errorf("Set list count changed after remove().")
 | 
			
		||||
	}
 | 
			
		||||
	if hn1.set != nil || hn1.prev != nil || hn1.next != nil {
 | 
			
		||||
		t.Errorf("First node for 'one' not removed correctly.")
 | 
			
		||||
	}
 | 
			
		||||
	if hn2.prev != nil || hn2.next != hn4 || hn4.prev != hn2 || hn4.next != nil {
 | 
			
		||||
		t.Errorf("First node for 'one' not unlinked correctly.")
 | 
			
		||||
	}
 | 
			
		||||
	if hl.start != hn2 || hl.end != hn4 {
 | 
			
		||||
		t.Errorf("First node for 'one' didn't change list pointers.")
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// Dispatch should result in 2 additions.
 | 
			
		||||
	hs.dispatch(c, &Line{Cmd: "One"})
 | 
			
		||||
| 
						 | 
				
			
			@ -146,15 +88,6 @@ func TestHandlerSet(t *testing.T) {
 | 
			
		|||
	if len(hs.set) != 1 {
 | 
			
		||||
		t.Errorf("Set list count changed after remove().")
 | 
			
		||||
	}
 | 
			
		||||
	if hn4.set != nil || hn4.prev != nil || hn4.next != nil {
 | 
			
		||||
		t.Errorf("Fourth node for 'one' not removed correctly.")
 | 
			
		||||
	}
 | 
			
		||||
	if hn2.prev != nil || hn2.next != nil {
 | 
			
		||||
		t.Errorf("Fourth node for 'one' not unlinked correctly.")
 | 
			
		||||
	}
 | 
			
		||||
	if hl.start != hn2 || hl.end != hn2 {
 | 
			
		||||
		t.Errorf("Fourth node for 'one' didn't change list pointers.")
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// Dispatch should result in 1 addition.
 | 
			
		||||
	hs.dispatch(c, &Line{Cmd: "One"})
 | 
			
		||||
| 
						 | 
				
			
			@ -164,16 +97,7 @@ func TestHandlerSet(t *testing.T) {
 | 
			
		|||
	}
 | 
			
		||||
 | 
			
		||||
	// Remove node 2.
 | 
			
		||||
	hs.remove(hn2)
 | 
			
		||||
	if len(hs.set) != 0 {
 | 
			
		||||
		t.Errorf("Removing last node in 'one' didn't remove list.")
 | 
			
		||||
	}
 | 
			
		||||
	if hn2.set != nil || hn2.prev != nil || hn2.next != nil {
 | 
			
		||||
		t.Errorf("Second node for 'one' not removed correctly.")
 | 
			
		||||
	}
 | 
			
		||||
	if hl.start != nil || hl.end != nil {
 | 
			
		||||
		t.Errorf("Second node for 'one' didn't change list pointers.")
 | 
			
		||||
	}
 | 
			
		||||
	hn2.Remove()
 | 
			
		||||
 | 
			
		||||
	// Dispatch should result in NO additions.
 | 
			
		||||
	hs.dispatch(c, &Line{Cmd: "One"})
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue