(t *testing.T)
| 397 | } |
| 398 | |
| 399 | func TestSplitFileArg(t *testing.T) { |
| 400 | tests := []struct { |
| 401 | name string |
| 402 | arg string |
| 403 | wantPath string |
| 404 | wantText string |
| 405 | }{ |
| 406 | { |
| 407 | name: "no hash", |
| 408 | arg: "./shot.png", |
| 409 | wantPath: "./shot.png", |
| 410 | }, |
| 411 | { |
| 412 | name: "text after a hash", |
| 413 | arg: "./shot.png#The login error state", |
| 414 | wantPath: "./shot.png", |
| 415 | wantText: "The login error state", |
| 416 | }, |
| 417 | { |
| 418 | name: "an existing path containing a hash stays whole", |
| 419 | arg: "./shot#dark.png", |
| 420 | wantPath: "./shot#dark.png", |
| 421 | }, |
| 422 | { |
| 423 | name: "the text can contain a hash", |
| 424 | arg: "./shot.png#first#second", |
| 425 | wantPath: "./shot.png", |
| 426 | wantText: "first#second", |
| 427 | }, |
| 428 | { |
| 429 | name: "the longest existing path wins", |
| 430 | arg: "./shot#dark.png#first.png#second", |
| 431 | wantPath: "./shot#dark.png#first.png", |
| 432 | wantText: "second", |
| 433 | }, |
| 434 | { |
| 435 | name: "a hash with nothing after it", |
| 436 | arg: "./shot.png#", |
| 437 | wantPath: "./shot.png", |
| 438 | }, |
| 439 | { |
| 440 | name: "a missing path splits at the last hash", |
| 441 | arg: "./gone.png#first#second", |
| 442 | wantPath: "./gone.png#first", |
| 443 | wantText: "second", |
| 444 | }, |
| 445 | { |
| 446 | name: "a hash at the start isn't a split", |
| 447 | arg: "#second", |
| 448 | wantPath: "#second", |
| 449 | }, |
| 450 | } |
| 451 | |
| 452 | for _, tt := range tests { |
| 453 | t.Run(tt.name, func(t *testing.T) { |
| 454 | t.Chdir(t.TempDir()) |
| 455 | for _, name := range []string{"shot.png", "shot#dark.png", "shot#dark.png#first.png"} { |
| 456 | require.NoError(t, os.WriteFile(name, []byte("the bytes"), 0o600)) |
nothing calls this directly
no test coverage detected