No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 

41 líneas
1.5 KiB

  1. // Copyright 2013 The Go Authors. All rights reserved.
  2. //
  3. // Use of this source code is governed by a BSD-style
  4. // license that can be found in the LICENSE file or at
  5. // https://developers.google.com/open-source/licenses/bsd.
  6. package main
  7. import (
  8. "testing"
  9. )
  10. var isBrowseURLTests = []struct {
  11. s string
  12. importPath string
  13. ok bool
  14. }{
  15. {"https://github.com/garyburd/gddo/blob/master/doc/code.go", "github.com/garyburd/gddo/doc", true},
  16. {"https://github.com/garyburd/go-oauth/blob/master/.gitignore", "github.com/garyburd/go-oauth", true},
  17. {"https://github.com/garyburd/gddo/issues/154", "github.com/garyburd/gddo", true},
  18. {"https://bitbucket.org/user/repo/src/bd0b661a263e/p1/p2?at=default", "bitbucket.org/user/repo/p1/p2", true},
  19. {"https://bitbucket.org/user/repo/src", "bitbucket.org/user/repo", true},
  20. {"https://bitbucket.org/user/repo", "bitbucket.org/user/repo", true},
  21. {"https://github.com/user/repo", "github.com/user/repo", true},
  22. {"https://github.com/user/repo/tree/master/p1", "github.com/user/repo/p1", true},
  23. {"http://code.google.com/p/project", "code.google.com/p/project", true},
  24. }
  25. func TestIsBrowseURL(t *testing.T) {
  26. for _, tt := range isBrowseURLTests {
  27. importPath, ok := isBrowseURL(tt.s)
  28. if tt.ok {
  29. if importPath != tt.importPath || ok != true {
  30. t.Errorf("IsBrowseURL(%q) = %q, %v; want %q %v", tt.s, importPath, ok, tt.importPath, true)
  31. }
  32. } else if ok {
  33. t.Errorf("IsBrowseURL(%q) = %q, %v; want _, false", tt.s, importPath, ok)
  34. }
  35. }
  36. }