...

Source file src/golang.org/x/text/internal/format/parser_test.go

Documentation: golang.org/x/text/internal/format

     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  
     5  package format
     6  
     7  import "testing"
     8  
     9  // TODO: most of Parser is tested in x/message. Move some tests here.
    10  
    11  func TestParsenum(t *testing.T) {
    12  	testCases := []struct {
    13  		s          string
    14  		start, end int
    15  		num        int
    16  		isnum      bool
    17  		newi       int
    18  	}{
    19  		{"a123", 0, 4, 0, false, 0},
    20  		{"1234", 1, 1, 0, false, 1},
    21  		{"123a", 0, 4, 123, true, 3},
    22  		{"12a3", 0, 4, 12, true, 2},
    23  		{"1234", 0, 4, 1234, true, 4},
    24  		{"1a234", 1, 3, 0, false, 1},
    25  	}
    26  	for _, tt := range testCases {
    27  		num, isnum, newi := parsenum(tt.s, tt.start, tt.end)
    28  		if num != tt.num || isnum != tt.isnum || newi != tt.newi {
    29  			t.Errorf("parsenum(%q, %d, %d) = %d, %v, %d, want %d, %v, %d", tt.s, tt.start, tt.end, num, isnum, newi, tt.num, tt.isnum, tt.newi)
    30  		}
    31  	}
    32  }
    33  

View as plain text