Source file
src/net/port_test.go
1
2
3
4
5 package net
6
7 import "testing"
8
9 var parsePortTests = []struct {
10 service string
11 port int
12 needsLookup bool
13 }{
14 {"", 0, false},
15
16
17 {"-1073741825", -1 << 30, false},
18 {"-1073741824", -1 << 30, false},
19 {"-1073741823", -(1<<30 - 1), false},
20 {"-123456789", -123456789, false},
21 {"-1", -1, false},
22 {"-0", 0, false},
23 {"0", 0, false},
24 {"+0", 0, false},
25 {"+1", 1, 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},
33
34
35 {"abc", 0, true},
36 {"9pfs", 0, true},
37 {"123badport", 0, true},
38 {"bad123port", 0, true},
39 {"badport123", 0, true},
40 {"123456789badport", 0, true},
41 {"-2147483649badport", 0, true},
42 {"2147483649badport", 0, true},
43 }
44
45 func TestParsePort(t *testing.T) {
46
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)
50 }
51 }
52 }
53
View as plain text