mirror of
https://github.com/v2fly/v2ray-core
synced 2024-02-27 03:18:06 +00:00
test cases for json config
This commit is contained in:
@@ -47,3 +47,7 @@ func (a *Assertion) Error(value error) *ErrorSubject {
|
||||
func (a *Assertion) Bool(value bool) *BoolSubject {
|
||||
return NewBoolSubject(NewSubject(a), value)
|
||||
}
|
||||
|
||||
func (a *Assertion) Pointer(value interface{}) *PointerSubject {
|
||||
return NewPointerSubject(NewSubject(a), value)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
package unit
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type PointerSubject struct {
|
||||
*Subject
|
||||
value interface{}
|
||||
}
|
||||
|
||||
func NewPointerSubject(base *Subject, value interface{}) *PointerSubject {
|
||||
return &PointerSubject{
|
||||
Subject: base,
|
||||
value: value,
|
||||
}
|
||||
}
|
||||
|
||||
func (subject *PointerSubject) Named(name string) *PointerSubject {
|
||||
subject.Subject.Named(name)
|
||||
return subject
|
||||
}
|
||||
|
||||
func (subject *PointerSubject) Fail(verb string, other interface{}) {
|
||||
subject.FailWithMessage(fmt.Sprintf("Not true that %s %s <%v>.", subject.DisplayString(), verb, other))
|
||||
}
|
||||
|
||||
func (subject *PointerSubject) DisplayString() string {
|
||||
return subject.Subject.DisplayString(fmt.Sprintf("%v", subject.value))
|
||||
}
|
||||
|
||||
func (subject *PointerSubject) Equals(expectation interface{}) {
|
||||
if subject.value != expectation {
|
||||
subject.Fail("is equal to", expectation)
|
||||
}
|
||||
}
|
||||
|
||||
func (subject *PointerSubject) IsNil() {
|
||||
if subject.value != nil {
|
||||
subject.FailWithMessage("Not true that " + subject.DisplayString() + " is nil.")
|
||||
}
|
||||
}
|
||||
|
||||
func (subject *PointerSubject) IsNotNil() {
|
||||
if subject.value == nil {
|
||||
subject.FailWithMessage("Not true that " + subject.DisplayString() + " is not nil.")
|
||||
}
|
||||
}
|
||||
@@ -46,3 +46,9 @@ func (subject *Uint16Subject) LessThan(expectation uint16) {
|
||||
subject.Fail("is less than", expectation)
|
||||
}
|
||||
}
|
||||
|
||||
func (subject *Uint16Subject) Positive() {
|
||||
if subject.value <= 0 {
|
||||
subject.FailWithMessage("Not true that " + subject.DisplayString() + " is positive.")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user