hasValidValues() + tests started
This commit is contained in:
		
							parent
							
								
									a4d40a90d5
								
							
						
					
					
						commit
						28bf282924
					
				
							
								
								
									
										14
									
								
								irc.go
									
									
									
									
									
								
							
							
						
						
									
										14
									
								
								irc.go
									
									
									
									
									
								
							| @ -388,3 +388,17 @@ func IRC(nick, user string) *Connection { | |||||||
| 	irc.setupCallbacks() | 	irc.setupCallbacks() | ||||||
| 	return irc | 	return irc | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | // Returns true if all values in struct make 
 | ||||||
|  | // somewhat sense.
 | ||||||
|  | func (irc *Connection) hasValidValues() bool { | ||||||
|  | 	if 0 == len(irc.nick) { | ||||||
|  | 		return false | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	if 0 == len(irc.Version) { | ||||||
|  | 		return false | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	return true | ||||||
|  | } | ||||||
|  | |||||||
							
								
								
									
										37
									
								
								irc_test.go
									
									
									
									
									
								
							
							
						
						
									
										37
									
								
								irc_test.go
									
									
									
									
									
								
							| @ -157,8 +157,43 @@ func TestIRCemptyNick(t *testing.T) { | |||||||
|   |   | ||||||
| func TestIRCemptyUser(t *testing.T) { | func TestIRCemptyUser(t *testing.T) { | ||||||
| 	irccon := IRC("go-eventirc", "") | 	irccon := IRC("go-eventirc", "") | ||||||
| 	irccon = nil |  | ||||||
| 	if nil != irccon { | 	if nil != irccon { | ||||||
| 		t.Error("empty user didn't result in error") | 		t.Error("empty user didn't result in error") | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | func TestHasValidValues0(t *testing.T) { | ||||||
|  | 	irccon := IRC("go-eventirc", "go-eventirc") | ||||||
|  | 	if nil == irccon { | ||||||
|  | 		t.Error("creating IRC struct failed") | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	if false == irccon.hasValidValues() { | ||||||
|  | 		t.Error("valid struct not detected as such") | ||||||
|  | 	} | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | func TestHasValidValues1(t *testing.T) { | ||||||
|  | 	irccon := IRC("go-eventirc", "go-eventirc") | ||||||
|  | 	if nil == irccon { | ||||||
|  | 		t.Error("creating IRC struct failed") | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	irccon.Version = "" | ||||||
|  | 	if irccon.hasValidValues() { | ||||||
|  | 		t.Error("empty 'Version' not detected") | ||||||
|  | 	} | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | func TestHasValidValues2(t *testing.T) { | ||||||
|  | 	irccon := IRC("go-eventirc", "go-eventirc") | ||||||
|  | 	if nil == irccon { | ||||||
|  | 		t.Error("creating IRC struct failed") | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	irccon.nick = "" | ||||||
|  | 	if irccon.hasValidValues() { | ||||||
|  | 		t.Error("empty 'nick' not detected") | ||||||
|  | 	} | ||||||
|  | } | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user