1 // Copyright 2018 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.
14 func TestParse(t *testing.T) {
15 var tests = []struct {
34 Comment: []byte("comment1\ncomment2\n"),
36 {"file1", []byte("File 1 text.\n-- foo ---\nMore file 1 text.\n")},
37 {"file 2", []byte("File 2 text.\n")},
39 {"noNL", []byte("hello world\n")},
44 for _, tt := range tests {
45 t.Run(tt.name, func(t *testing.T) {
46 a := Parse([]byte(tt.text))
47 if !reflect.DeepEqual(a, tt.parsed) {
48 t.Fatalf("Parse: wrong output:\nhave:\n%s\nwant:\n%s", shortArchive(a), shortArchive(tt.parsed))
52 if !reflect.DeepEqual(a, tt.parsed) {
53 t.Fatalf("Parse after Format: wrong output:\nhave:\n%s\nwant:\n%s", shortArchive(a), shortArchive(tt.parsed))
59 func TestFormat(t *testing.T) {
60 var tests = []struct {
68 Comment: []byte("comment1\ncomment2\n"),
70 {"file1", []byte("File 1 text.\n-- foo ---\nMore file 1 text.\n")},
71 {"file 2", []byte("File 2 text.\n")},
73 {"noNL", []byte("hello world")},
90 for _, tt := range tests {
91 t.Run(tt.name, func(t *testing.T) {
92 result := Format(tt.input)
93 if string(result) != tt.wanted {
94 t.Errorf("Wrong output. \nGot:\n%s\nWant:\n%s\n", string(result), tt.wanted)
100 func shortArchive(a *Archive) string {
102 fmt.Fprintf(&buf, "comment: %q\n", a.Comment)
103 for _, f := range a.Files {
104 fmt.Fprintf(&buf, "file %q: %q\n", f.Name, f.Data)