golang.org/x/exp@v0.0.0-20240506185415-9bf2ced13842/mmap/mmap_test.go (about) 1 // Copyright 2015 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 mmap 6 7 import ( 8 "bytes" 9 "io" 10 "os" 11 "testing" 12 ) 13 14 func TestOpen(t *testing.T) { 15 const filename = "mmap_test.go" 16 r, err := Open(filename) 17 if err != nil { 18 t.Fatalf("Open: %v", err) 19 } 20 got := make([]byte, r.Len()) 21 if _, err := r.ReadAt(got, 0); err != nil && err != io.EOF { 22 t.Fatalf("ReadAt: %v", err) 23 } 24 want, err := os.ReadFile(filename) 25 if err != nil { 26 t.Fatalf("os.ReadFile: %v", err) 27 } 28 if len(got) != len(want) { 29 t.Fatalf("got %d bytes, want %d", len(got), len(want)) 30 } 31 if !bytes.Equal(got, want) { 32 t.Fatalf("\ngot %q\nwant %q", string(got), string(want)) 33 } 34 }