| 
									
										
										
										
											2016-05-24 21:55:46 +02:00
										 |  |  | package assert | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import ( | 
					
						
							|  |  |  | 	"bytes" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-06 23:25:52 +01:00
										 |  |  | 	"fmt" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-20 20:55:45 +02:00
										 |  |  | 	"v2ray.com/core/common/serial" | 
					
						
							| 
									
										
										
										
											2016-05-24 21:55:46 +02:00
										 |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-27 21:39:09 +01:00
										 |  |  | func (v *Assert) Bytes(value []byte) *BytesSubject { | 
					
						
							| 
									
										
										
										
											2016-05-24 21:55:46 +02:00
										 |  |  | 	return &BytesSubject{ | 
					
						
							|  |  |  | 		Subject: Subject{ | 
					
						
							|  |  |  | 			disp: serial.BytesToHexString(value), | 
					
						
							| 
									
										
										
										
											2016-11-27 21:39:09 +01:00
										 |  |  | 			a:    v, | 
					
						
							| 
									
										
										
										
											2016-05-24 21:55:46 +02:00
										 |  |  | 		}, | 
					
						
							|  |  |  | 		value: value, | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | type BytesSubject struct { | 
					
						
							|  |  |  | 	Subject | 
					
						
							|  |  |  | 	value []byte | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (subject *BytesSubject) Equals(expectation []byte) { | 
					
						
							| 
									
										
										
										
											2017-02-06 23:25:52 +01:00
										 |  |  | 	if len(subject.value) != len(expectation) { | 
					
						
							| 
									
										
										
										
											2017-02-07 23:33:02 +01:00
										 |  |  | 		subject.FailWithMessage(fmt.Sprint("Bytes arrays have differen size: expected ", len(expectation), ", actual ", len(subject.value))) | 
					
						
							|  |  |  | 		return | 
					
						
							| 
									
										
										
										
											2017-02-06 23:25:52 +01:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	for idx, b := range expectation { | 
					
						
							|  |  |  | 		if subject.value[idx] != b { | 
					
						
							| 
									
										
										
										
											2017-04-27 13:31:09 +02:00
										 |  |  | 			subject.FailWithMessage(fmt.Sprint("Bytes are different: ", b, " vs ", subject.value[idx], " at pos ", idx)) | 
					
						
							| 
									
										
										
										
											2017-02-06 23:25:52 +01:00
										 |  |  | 			return | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2016-05-24 21:55:46 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (subject *BytesSubject) NotEquals(expectation []byte) { | 
					
						
							|  |  |  | 	if bytes.Equal(subject.value, expectation) { | 
					
						
							|  |  |  | 		subject.Fail("is not equal to", serial.BytesToHexString(expectation)) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } |