| 222 | } |
| 223 | |
| 224 | func TestCapletEvalCommentAtStartOfLine(t *testing.T) { |
| 225 | tempFile, err := ioutil.TempFile("", "test-*.cap") |
| 226 | if err != nil { |
| 227 | t.Fatal(err) |
| 228 | } |
| 229 | defer os.Remove(tempFile.Name()) |
| 230 | tempFile.Close() |
| 231 | |
| 232 | cap := NewCaplet("test", tempFile.Name(), 100) |
| 233 | cap.Code = []string{ |
| 234 | "# comment", |
| 235 | " # not a comment (has space before #)", |
| 236 | " # not a comment (has tab before #)", |
| 237 | "command # inline comment", |
| 238 | } |
| 239 | |
| 240 | var gotLines []string |
| 241 | err = cap.Eval(nil, func(line string) error { |
| 242 | gotLines = append(gotLines, line) |
| 243 | return nil |
| 244 | }) |
| 245 | |
| 246 | if err != nil { |
| 247 | t.Errorf("unexpected error: %v", err) |
| 248 | } |
| 249 | |
| 250 | expectedLines := []string{ |
| 251 | " # not a comment (has space before #)", |
| 252 | " # not a comment (has tab before #)", |
| 253 | "command # inline comment", |
| 254 | } |
| 255 | |
| 256 | if len(gotLines) != len(expectedLines) { |
| 257 | t.Errorf("got %d lines, want %d", len(gotLines), len(expectedLines)) |
| 258 | return |
| 259 | } |
| 260 | |
| 261 | for i, line := range gotLines { |
| 262 | if line != expectedLines[i] { |
| 263 | t.Errorf("line %d: got %q, want %q", i, line, expectedLines[i]) |
| 264 | } |
| 265 | } |
| 266 | } |
| 267 | |
| 268 | func TestCapletEvalArgvSubstitutionEdgeCases(t *testing.T) { |
| 269 | tests := []struct { |