Skip to content

Commit f9b524e

Browse files
committed
add test case with mixed EOL
1 parent 4c47c7f commit f9b524e

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed

txtar/archive_test.go

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,39 @@ some content
7373
UseCRLF: true,
7474
},
7575
},
76+
{
77+
name: "mixed",
78+
text: "comment1\n" +
79+
"comment2\r\n" +
80+
"-- file1 --\r\n" +
81+
"File 1 text.\n" +
82+
"-- foo ---\r\n" +
83+
"More file 1 text.\r\n" +
84+
"-- file 2 --\r\n" +
85+
"File 2 text.\r\n" +
86+
"-- file 3 --\r\n" +
87+
"File 3 text.\r\n" +
88+
"-- foo ---\r\n" +
89+
"More file 3 text.\r\n" +
90+
"-- empty --\r\n" +
91+
"-- noNL --\r\n" +
92+
"hello world\r\n" +
93+
"-- empty filename line --\r\n" +
94+
"some content\n" +
95+
"-- --\n",
96+
parsed: &Archive{
97+
Comment: []byte("comment1\ncomment2\r\n"),
98+
Files: []File{
99+
{"file1", []byte("File 1 text.\n-- foo ---\r\nMore file 1 text.\r\n")},
100+
{"file 2", []byte("File 2 text.\r\n")},
101+
{"file 3", []byte("File 3 text.\r\n-- foo ---\r\nMore file 3 text.\r\n")},
102+
{"empty", []byte{}},
103+
{"noNL", []byte("hello world\r\n")},
104+
{"empty filename line", []byte("some content\n-- --\n\r\n")},
105+
},
106+
UseCRLF: true,
107+
},
108+
},
76109
}
77110
for _, tt := range tests {
78111
t.Run(tt.name, func(t *testing.T) {
@@ -144,6 +177,39 @@ hello world
144177
"-- noNL --\r\n" +
145178
"hello world\r\n",
146179
},
180+
{
181+
name: "mixed",
182+
input: &Archive{
183+
Comment: []byte("comment1\ncomment2\r\n"),
184+
Files: []File{
185+
{"file1", []byte("File 1 text.\n-- foo ---\r\nMore file 1 text.\r\n")},
186+
{"file 2", []byte("File 2 text.\r\n")},
187+
{"file 3", []byte("File 3 text.\r\n-- foo ---\r\nMore file 3 text.\r\n")},
188+
{"empty", []byte{}},
189+
{"noNL", []byte("hello world\r\n")},
190+
{"empty filename line", []byte("some content\r\n-- --\n")},
191+
},
192+
UseCRLF: true,
193+
},
194+
wanted: "comment1\n" +
195+
"comment2\r\n" +
196+
"-- file1 --\r\n" +
197+
"File 1 text.\n" +
198+
"-- foo ---\r\n" +
199+
"More file 1 text.\r\n" +
200+
"-- file 2 --\r\n" +
201+
"File 2 text.\r\n" +
202+
"-- file 3 --\r\n" +
203+
"File 3 text.\r\n" +
204+
"-- foo ---\r\n" +
205+
"More file 3 text.\r\n" +
206+
"-- empty --\r\n" +
207+
"-- noNL --\r\n" +
208+
"hello world\r\n" +
209+
"-- empty filename line --\r\n" +
210+
"some content\r\n" +
211+
"-- --\n\r\n",
212+
},
147213
}
148214
for _, tt := range tests {
149215
t.Run(tt.name, func(t *testing.T) {

0 commit comments

Comments
 (0)