forked from v2ray/v2ray-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f3f1c09
commit e42510a
Showing
5 changed files
with
58 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package serial | ||
|
||
import ( | ||
"strconv" | ||
) | ||
|
||
type Uint16 interface { | ||
Value() uint16 | ||
} | ||
|
||
type Uint16Literal uint16 | ||
|
||
func (this Uint16Literal) String() string { | ||
return strconv.Itoa(int(this)) | ||
} | ||
|
||
func (this Uint16Literal) Value() uint16 { | ||
return uint16(this) | ||
} | ||
|
||
type Int interface { | ||
Value() int | ||
} | ||
|
||
type IntLiteral int | ||
|
||
func (this IntLiteral) String() string { | ||
return strconv.Itoa(int(this)) | ||
} | ||
|
||
func (this IntLiteral) Value() int { | ||
return int(this) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,41 @@ | ||
package assert | ||
|
||
import ( | ||
"strconv" | ||
"github.com/v2ray/v2ray-core/common/serial" | ||
) | ||
|
||
func Int(value int) *IntSubject { | ||
return &IntSubject{value: value} | ||
return &IntSubject{value: serial.IntLiteral(value)} | ||
} | ||
|
||
type IntSubject struct { | ||
Subject | ||
value int | ||
value serial.IntLiteral | ||
} | ||
|
||
func (subject *IntSubject) Named(name string) *IntSubject { | ||
subject.Subject.Named(name) | ||
return subject | ||
} | ||
|
||
func (subject *IntSubject) Fail(verb string, other int) { | ||
subject.FailWithMessage("Not true that " + subject.DisplayString() + " " + verb + " <" + strconv.Itoa(other) + ">.") | ||
} | ||
|
||
func (subject *IntSubject) DisplayString() string { | ||
return subject.Subject.DisplayString(strconv.Itoa(subject.value)) | ||
return subject.Subject.DisplayString(subject.value.String()) | ||
} | ||
|
||
func (subject *IntSubject) Equals(expectation int) { | ||
if subject.value != expectation { | ||
subject.Fail("is equal to", expectation) | ||
if subject.value.Value() != expectation { | ||
subject.Fail(subject.DisplayString(), "is equal to", serial.IntLiteral(expectation)) | ||
} | ||
} | ||
|
||
func (subject *IntSubject) GreaterThan(expectation int) { | ||
if subject.value <= expectation { | ||
subject.Fail("is greater than", expectation) | ||
if subject.value.Value() <= expectation { | ||
subject.Fail(subject.DisplayString(), "is greater than", serial.IntLiteral(expectation)) | ||
} | ||
} | ||
|
||
func (subject *IntSubject) LessThan(expectation int) { | ||
if subject.value >= expectation { | ||
subject.Fail("is less than", expectation) | ||
if subject.value.Value() >= expectation { | ||
subject.Fail(subject.DisplayString(), "is less than", serial.IntLiteral(expectation)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,47 @@ | ||
package assert | ||
|
||
import ( | ||
"strconv" | ||
"github.com/v2ray/v2ray-core/common/serial" | ||
) | ||
|
||
func Uint16(value uint16) *Uint16Subject { | ||
return &Uint16Subject{value: value} | ||
return &Uint16Subject{value: serial.Uint16Literal(value)} | ||
} | ||
|
||
type Uint16Subject struct { | ||
Subject | ||
value uint16 | ||
value serial.Uint16Literal | ||
} | ||
|
||
func (subject *Uint16Subject) Named(name string) *Uint16Subject { | ||
subject.Subject.Named(name) | ||
return subject | ||
} | ||
|
||
func (subject *Uint16Subject) Fail(verb string, other uint16) { | ||
subject.FailWithMessage("Not true that " + subject.DisplayString() + " " + verb + " <" + strconv.Itoa(int(other)) + ">.") | ||
} | ||
|
||
func (subject *Uint16Subject) DisplayString() string { | ||
return subject.Subject.DisplayString(strconv.Itoa(int(subject.value))) | ||
return subject.Subject.DisplayString(subject.value.String()) | ||
} | ||
|
||
func (subject *Uint16Subject) Equals(expectation uint16) { | ||
if subject.value != expectation { | ||
subject.Fail("is equal to", expectation) | ||
if subject.value.Value() != expectation { | ||
subject.Fail(subject.DisplayString(), "is equal to", serial.Uint16Literal(expectation)) | ||
} | ||
} | ||
|
||
func (subject *Uint16Subject) GreaterThan(expectation uint16) { | ||
if subject.value <= expectation { | ||
subject.Fail("is greater than", expectation) | ||
if subject.value.Value() <= expectation { | ||
subject.Fail(subject.DisplayString(), "is greater than", serial.Uint16Literal(expectation)) | ||
} | ||
} | ||
|
||
func (subject *Uint16Subject) LessThan(expectation uint16) { | ||
if subject.value >= expectation { | ||
subject.Fail("is less than", expectation) | ||
if subject.value.Value() >= expectation { | ||
subject.Fail(subject.DisplayString(), "is less than", serial.Uint16Literal(expectation)) | ||
} | ||
} | ||
|
||
func (subject *Uint16Subject) Positive() { | ||
if subject.value <= 0 { | ||
if subject.value.Value() <= 0 { | ||
subject.FailWithMessage("Not true that " + subject.DisplayString() + " is positive.") | ||
} | ||
} |