summaryrefslogtreecommitdiff
path: root/src/cmd/fix/hashsum_test.go
blob: 241af2020d9a3d8f82f31ef32234a467b9d49106 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// Copyright 2011 The Go Authors.  All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package main

func init() {
	addTestCases(hashSumTests, hashSumFn)
}

var hashSumTests = []testCase{
	{
		Name: "hashsum.0",
		In: `package main

import "crypto/sha256"

func f() []byte {
	h := sha256.New()
	return h.Sum()
}
`,
		Out: `package main

import "crypto/sha256"

func f() []byte {
	h := sha256.New()
	return h.Sum(nil)
}
`,
	},

	{
		Name: "hashsum.1",
		In: `package main

func f(h hash.Hash) []byte {
	return h.Sum()
}
`,
		Out: `package main

func f(h hash.Hash) []byte {
	return h.Sum(nil)
}
`,
	},

	{
		Name: "hashsum.0",
		In: `package main

import "crypto/sha256"

func f() []byte {
	h := sha256.New()
	h.Write([]byte("foo"))
	digest := h.Sum()
}
`,
		Out: `package main

import "crypto/sha256"

func f() []byte {
	h := sha256.New()
	h.Write([]byte("foo"))
	digest := h.Sum(nil)
}
`,
	},

	{
		Name: "hashsum.0",
		In: `package main

import _ "crypto/sha256"
import "crypto"

func f() []byte {
	hashType := crypto.SHA256
	h := hashType.New()
	digest := h.Sum()
}
`,
		Out: `package main

import _ "crypto/sha256"
import "crypto"

func f() []byte {
	hashType := crypto.SHA256
	h := hashType.New()
	digest := h.Sum(nil)
}
`,
	},
}