| 1 |
package testdata |
| 2 |
|
| 3 |
import ( |
| 4 |
"crypto/rand" |
| 5 |
mathrand "math/rand" |
| 6 |
"os" |
| 7 |
"path/filepath" |
| 8 |
"runtime" |
| 9 |
) |
| 10 |
|
| 11 |
func InvalidUTF8() ([]byte, error) { |
| 12 |
return load("UTF-8-test.txt") |
| 13 |
} |
| 14 |
|
| 15 |
func Sample() ([]byte, error) { |
| 16 |
return load("sample.txt") |
| 17 |
} |
| 18 |
|
| 19 |
func TestCases() ([]byte, error) { |
| 20 |
return load("test_cases.txt") |
| 21 |
} |
| 22 |
|
| 23 |
func RandomBytes() ([]byte, error) { |
| 24 |
length := mathrand.Intn(50) |
| 25 |
buf := make([]byte, length) |
| 26 |
_, err := rand.Read(buf) |
| 27 |
if err != nil { |
| 28 |
return nil, err |
| 29 |
} |
| 30 |
return buf, nil |
| 31 |
} |
| 32 |
|
| 33 |
func load(filename string) ([]byte, error) { |
| 34 |
|
| 35 |
_, currentFile, _, _ := runtime.Caller(0) |
| 36 |
dir := filepath.Dir(currentFile) |
| 37 |
path := filepath.Join(dir, filename) |
| 38 |
|
| 39 |
return os.ReadFile(path) |
| 40 |
} |