Download this file
| 1 | package copydesk |
| 2 | |
| 3 | import "testing" |
| 4 | |
| 5 | func TestCopyFileScopeRejectsExtraFiles(t *testing.T) { |
| 6 | before := map[string][]byte{"app.go": []byte(`var title="Old words"`), "app_test.go": []byte(`want:="Old words"; check(ok)`)} |
| 7 | after := map[string][]byte{"app.go": []byte(`var title="New words"`), "app_test.go": []byte(`want:="New words"; check(ok)`)} |
| 8 | ex := []Literal{{Key: "title", Path: "app.go", Start: 11, End: 20, Text: "Old words"}} |
| 9 | r := Review{Version: 1, Strings: []Wording{{Key: "title", Text: "New words", Action: "accept"}}} |
| 10 | if err := ValidateFiles(before, after, ex, r, []string{}, true); err != nil { |
| 11 | t.Fatal(err) |
| 12 | } |
| 13 | after["app_test.go"] = []byte(`want:="New words"; check(true)`) |
| 14 | if ValidateFiles(before, after, ex, r, nil, true) == nil { |
| 15 | t.Fatal("test logic edit accepted") |
| 16 | } |
| 17 | after["app_test.go"] = before["app_test.go"] |
| 18 | after["evil.go"] = []byte("bad") |
| 19 | if ValidateFiles(before, after, ex, r, nil, true) == nil { |
| 20 | t.Fatal("new file accepted") |
| 21 | } |
| 22 | } |
| 23 | |