| 1 | // Copyright 2016 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 buildutil_testscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/buildutil_test`/ |
| 6 | |
| 7 | import ( |
| 8 | "go/buildscip-go gomod github.com/golang/go/src go1.25.0 `go/build`/" |
| 9 | "ioscip-go gomod github.com/golang/go/src go1.25.0 io/" |
| 10 | "reflectscip-go gomod github.com/golang/go/src go1.25.0 reflect/" |
| 11 | "stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/" |
| 12 | "testingscip-go gomod github.com/golang/go/src go1.25.0 testing/" |
| 13 | |
| 14 | "golang.org/x/tools/go/buildutilscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/buildutil`/" |
| 15 | ) |
| 16 | |
| 17 | func TestParseOverlayArchivescip-go gomod golang.org/x/tools . `golang.org/x/tools/go/buildutil_test`/TestParseOverlayArchive().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 18 | var tt = []struct { |
| 19 | in string |
| 20 | out map[string][]byte |
| 21 | hasErr bool |
| 22 | }{ |
| 23 | { |
| 24 | "a.go\n5\n12345", |
| 25 | map[string][]byte{"a.go": []byte("12345")}, |
| 26 | false, |
| 27 | }, |
| 28 | { |
| 29 | "a.go\n5\n1234", |
| 30 | nil, |
| 31 | true, |
| 32 | }, |
| 33 | { |
| 34 | "a.go\n5\n12345b.go\n4\n1234", |
| 35 | map[string][]byte{"a.go": []byte("12345"), "b.go": []byte("1234")}, |
| 36 | false, |
| 37 | }, |
| 38 | } |
| 39 | |
| 40 | for _, test := range tt { |
| 41 | got, err := buildutilscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/buildutil`/.ParseOverlayArchivescip-go gomod golang.org/x/tools . `golang.org/x/tools/go/buildutil`/ParseOverlayArchive().(stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.NewReaderscip-go gomod github.com/golang/go/src go1.25.0 strings/NewReader().(test.in)) |
| 42 | if err == nil && test.hasErr { |
| 43 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("expected error for %q", test.in) |
| 44 | } |
| 45 | if err != nil && !test.hasErr { |
| 46 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("unexpected error %v for %q", err, test.in) |
| 47 | } |
| 48 | if !reflectscip-go gomod github.com/golang/go/src go1.25.0 reflect/.DeepEqualscip-go gomod github.com/golang/go/src go1.25.0 reflect/DeepEqual().(got, test.out) { |
| 49 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("got %#v, want %#v", got, test.out) |
| 50 | } |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | func TestOverlayscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/buildutil_test`/TestOverlay().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 55 | ctx := &buildscip-go gomod github.com/golang/go/src go1.25.0 `go/build`/.Defaultscip-go gomod github.com/golang/go/src go1.25.0 `go/build`/Default. |
| 56 | ov := map[string][]byte{ |
| 57 | "/somewhere/a.go": []byte("file contents"), |
| 58 | } |
| 59 | names := []string{"/somewhere/a.go", "/somewhere//a.go"} |
| 60 | ctx = buildutilscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/buildutil`/.OverlayContextscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/buildutil`/OverlayContext().(ctx, ov) |
| 61 | for _, name := range names { |
| 62 | f, err := buildutilscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/buildutil`/.OpenFilescip-go gomod golang.org/x/tools . `golang.org/x/tools/go/buildutil`/OpenFile().(ctx, name) |
| 63 | if err != nil { |
| 64 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("unexpected error %v", err) |
| 65 | } |
| 66 | b, err := ioscip-go gomod github.com/golang/go/src go1.25.0 io/.ReadAllscip-go gomod github.com/golang/go/src go1.25.0 io/ReadAll().(f) |
| 67 | if err != nil { |
| 68 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("unexpected error %v", err) |
| 69 | } |
| 70 | if got, expected := string(b), string(ov["/somewhere/a.go"]); got != expected { |
| 71 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("read %q, expected %q", got, expected) |
| 72 | } |
| 73 | } |
| 74 | } |