You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

33 line
902 B

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