github.com/mdempsky/go@v0.0.0-20151201204031-5dd372bd1e70/src/cmd/go/pkg_test.go (about) 1 // Copyright 2014 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 main 6 7 import ( 8 "reflect" 9 "strings" 10 "testing" 11 ) 12 13 var foldDupTests = []struct { 14 list []string 15 f1, f2 string 16 }{ 17 {stringList("math/rand", "math/big"), "", ""}, 18 {stringList("math", "strings"), "", ""}, 19 {stringList("strings"), "", ""}, 20 {stringList("strings", "strings"), "strings", "strings"}, 21 {stringList("Rand", "rand", "math", "math/rand", "math/Rand"), "Rand", "rand"}, 22 } 23 24 func TestFoldDup(t *testing.T) { 25 for _, tt := range foldDupTests { 26 f1, f2 := foldDup(tt.list) 27 if f1 != tt.f1 || f2 != tt.f2 { 28 t.Errorf("foldDup(%q) = %q, %q, want %q, %q", tt.list, f1, f2, tt.f1, tt.f2) 29 } 30 } 31 } 32 33 var parseMetaGoImportsTests = []struct { 34 in string 35 out []metaImport 36 }{ 37 { 38 `<meta name="go-import" content="foo/bar git https://github.com/rsc/foo/bar">`, 39 []metaImport{{"foo/bar", "git", "https://github.com/rsc/foo/bar"}}, 40 }, 41 { 42 `<meta name="go-import" content="foo/bar git https://github.com/rsc/foo/bar"> 43 <meta name="go-import" content="baz/quux git http://github.com/rsc/baz/quux">`, 44 []metaImport{ 45 {"foo/bar", "git", "https://github.com/rsc/foo/bar"}, 46 {"baz/quux", "git", "http://github.com/rsc/baz/quux"}, 47 }, 48 }, 49 { 50 `<head> 51 <meta name="go-import" content="foo/bar git https://github.com/rsc/foo/bar"> 52 </head>`, 53 []metaImport{{"foo/bar", "git", "https://github.com/rsc/foo/bar"}}, 54 }, 55 { 56 `<meta name="go-import" content="foo/bar git https://github.com/rsc/foo/bar"> 57 <body>`, 58 []metaImport{{"foo/bar", "git", "https://github.com/rsc/foo/bar"}}, 59 }, 60 } 61 62 func TestParseMetaGoImports(t *testing.T) { 63 for i, tt := range parseMetaGoImportsTests { 64 out, err := parseMetaGoImports(strings.NewReader(tt.in)) 65 if err != nil { 66 t.Errorf("test#%d: %v", i, err) 67 continue 68 } 69 if !reflect.DeepEqual(out, tt.out) { 70 t.Errorf("test#%d:\n\thave %q\n\twant %q", i, out, tt.out) 71 } 72 } 73 }