Fix "PR c++/92804 ICE trying to use concept as a nested-name-specifier"
[official-gcc.git] / libgo / go / net / port_test.go
blobe0bdb4247d31f51485f65dc53e49101b4154e290
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.
5 package net
7 import "testing"
9 var parsePortTests = []struct {
10 service string
11 port int
12 needsLookup bool
14 {"", 0, false},
16 // Decimal number literals
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},
34 // Others
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},
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)