1 // Copyright 2016 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
9 var parsePortTests
= []struct {
16 // Decimal number literals
17 {"-1073741825", -1 << 30, false},
18 {"-1073741824", -1 << 30, false},
19 {"-1073741823", -(1<<30 - 1), false},
20 {"-123456789", -123456789, false},
26 {"65535", 65535, false},
27 {"65536", 65536, false},
28 {"123456789", 123456789, false},
29 {"1073741822", 1<<30 - 2, false},
30 {"1073741823", 1<<30 - 1, false},
31 {"1073741824", 1<<30 - 1, false},
32 {"1073741825", 1<<30 - 1, false},
37 {"123badport", 0, true},
38 {"bad123port", 0, true},
39 {"badport123", 0, true},
40 {"123456789badport", 0, true},
41 {"-2147483649badport", 0, true},
42 {"2147483649badport", 0, true},
45 func TestParsePort(t
*testing
.T
) {
46 // The following test cases are cribbed from the strconv
47 for _
, tt
:= range parsePortTests
{
48 if port
, needsLookup
:= parsePort(tt
.service
); port
!= tt
.port || needsLookup
!= tt
.needsLookup
{
49 t
.Errorf("parsePort(%q) = %d, %t; want %d, %t", tt
.service
, port
, needsLookup
, tt
.port
, tt
.needsLookup
)