golang.org/x/build@v0.0.0-20240506185731-218518f32b70/devapp/gophercon_test.go (about)

     1  // Copyright 2017 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.
     4  package main
     5  
     6  import "testing"
     7  
     8  func TestIntFromStr(t *testing.T) {
     9  	testcases := []struct {
    10  		s string
    11  		i int
    12  	}{
    13  		{"123", 123},
    14  		{"User ID: 98403", 98403},
    15  		{"1234 User 5431 ID", 1234},
    16  		{"Stardate 153.2415", 153},
    17  	}
    18  	for _, tc := range testcases {
    19  		r, ok := intFromStr(tc.s)
    20  		if !ok {
    21  			t.Errorf("intFromStr(%q) = %v", tc.s, ok)
    22  		}
    23  		if r != tc.i {
    24  			t.Errorf("intFromStr(%q) = %d; want %d", tc.s, r, tc.i)
    25  		}
    26  	}
    27  	noInt := "hello there"
    28  	_, ok := intFromStr(noInt)
    29  	if ok {
    30  		t.Errorf("intFromStr(%q) = %v; want false", noInt, ok)
    31  	}
    32  }