REMOVE unloved error handling inherited from Rust.

Also: Rename the test calls to match the final draft.
This commit is contained in:
Elf M. Sternberg 2018-01-10 14:30:46 -08:00
parent 73b0f90c16
commit 08dcb42897
2 changed files with 18 additions and 52 deletions

View File

@ -10,20 +10,6 @@ func is_unix_conventional(c byte) bool {
return (c >= '0' && c <= '9') || (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z')
}
var Rfc1288ErrorMsgs = []string {
"",
"Protocol prefix not recognized",
"Protocol request does not meet specifications",
}
type Rfc1288ErrorCode int
const (
Ok Rfc1288ErrorCode = 0
BadProtocol Rfc1288ErrorCode = 1
BadRequest Rfc1288ErrorCode = 2
)
type Rfc1288RequestType int
const (

View File

@ -36,101 +36,81 @@ func equals(tb testing.TB, exp, act interface{}) {
}
func TestGood_List(t *testing.T) {
res, req := parse_rfc1288_request("/W")
res, req := ParseRfc1288Request("/W")
assert(t, res == nil, "Expected result to be nil.")
assert(t, req.Type == UserList, "Expected type to be Userlist")
}
func TestGood_ListWSpaces(t *testing.T) {
res, req := parse_rfc1288_request("/W ");
res, req := ParseRfc1288Request("/W ");
assert(t, res == nil, "Expected result to be nil.")
assert(t, req.Type == UserList, "Expected type to be Userlist")
}
func TestBad_Start(t *testing.T) {
res, _ := parse_rfc1288_request("")
res, _ := ParseRfc1288Request("")
assert(t, res != nil, "Expected result to be BadProtocol.")
}
func TestBad_Start1(t *testing.T) {
res, _ := parse_rfc1288_request("/")
res, _ := ParseRfc1288Request("/")
assert(t, res != nil, "Expected result to be BadProtocol.")
}
func TestBad_Start2(t *testing.T) {
res, _ := parse_rfc1288_request("/X")
res, _ := ParseRfc1288Request("/X")
assert(t, res != nil, "Expected result to be BadProtocol.")
}
func TestGood_Name(t *testing.T) {
res, req := parse_rfc1288_request("/W foozle")
res, req := ParseRfc1288Request("/W foozle")
assert(t, res == nil, "Expected a good return")
assert(t, req.Type == User, "Expected User as a return type")
assert(t, *req.User == "foozle", "The user name did not match passed in value.")
}
func TestGood_NameLf(t *testing.T) {
res, req := parse_rfc1288_request("/W foozle\n")
res, req := ParseRfc1288Request("/W foozle\n")
assert(t, res == nil, "Expected a good return")
assert(t, req.Type == User, "Expected User as a return type")
assert(t, *req.User == "foozle", "The user name did not match passed in value.")
}
func TestGood_NameCr(t *testing.T) {
res, req := parse_rfc1288_request("/W foozle\r")
res, req := ParseRfc1288Request("/W foozle\r")
assert(t, res == nil, "Expected a good return")
assert(t, req.Type == User, "Expected User as a return type")
assert(t, *req.User == "foozle", "The user name did not match passed in value.")
}
func TestGood_NameCrLf(t *testing.T) {
res, req := parse_rfc1288_request("/W foozle\r\n")
res, req := ParseRfc1288Request("/W foozle\r\n")
assert(t, res == nil, "Expected a good return")
assert(t, req.Type == User, "Expected User as a return type")
assert(t, *req.User == "foozle", "The user name did not match passed in value.")
}
func TestGood_NameExtraSpace(t *testing.T) {
res, req := parse_rfc1288_request("/W foozle ")
res, req := ParseRfc1288Request("/W foozle ")
assert(t, res == nil, "Expected result to be nil.")
assert(t, req.Type == User, "Expected type to be User")
assert(t, *req.User == "foozle", "User name returned did not match")
}
func TestGood_NameWHost(t *testing.T) {
res, req := parse_rfc1288_request("/W foozle@localhost")
if res != nil {
t.Error("Expected a good return")
}
if req.Type != Remote {
t.Error("Expected Remote as a return type")
}
if *req.User != "foozle" {
t.Error("The user name did not match passed in value.")
}
if *req.Host != "localhost" {
t.Error("The host name did not match passed in value.")
}
res, req := ParseRfc1288Request("/W foozle@localhost")
assert(t, res == nil, "Expected a good return")
assert(t, req.Type == Remote, "Expected Remote as a return type")
}
func TestGood_NameWHostAndSpaces(t *testing.T) {
res, req := parse_rfc1288_request("/W foozle@localhost ")
if res != nil {
t.Error("Expected a good return")
}
if req.Type != Remote {
t.Error("Expected Remote as a return type")
}
if *req.User != "foozle" {
t.Error("The user name did not match passed in value.")
}
if *req.Host != "localhost" {
t.Error("The host name did not match passed in value.")
}
res, req := ParseRfc1288Request("/W foozle@localhost ")
assert(t, res == nil, "Expected a good return")
assert(t, req.Type == Remote, "Expected Remote as a return type")
}
func TestGood_NameWHostAndSpacesAndLowerW(t *testing.T) {
res, req := parse_rfc1288_request("/w foozle@localhost ")
res, req := ParseRfc1288Request("/w foozle@localhost ")
if res != nil {
t.Error("Expected a good return")
}
@ -146,7 +126,7 @@ func TestGood_NameWHostAndSpacesAndLowerW(t *testing.T) {
}
func TestBad_Name(t *testing.T) {
res, _ := parse_rfc1288_request("/W foozle.. ")
res, _ := ParseRfc1288Request("/W foozle.. ")
if res == nil {
t.Error("Expected BadRequest")
}