Add configurable sequence numbering command
This commit is contained in:
76
tests/contract/sequence_placement_test.go
Normal file
76
tests/contract/sequence_placement_test.go
Normal file
@@ -0,0 +1,76 @@
|
||||
package contract
|
||||
|
||||
import (
|
||||
"context"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/rogeecn/renamer/internal/sequence"
|
||||
)
|
||||
|
||||
func TestSequencePreviewWithPrefixPlacement(t *testing.T) {
|
||||
tmp := t.TempDir()
|
||||
|
||||
createFile(t, filepath.Join(tmp, "cover.png"))
|
||||
createFile(t, filepath.Join(tmp, "index.png"))
|
||||
|
||||
opts := sequence.DefaultOptions()
|
||||
opts.WorkingDir = tmp
|
||||
opts.Start = 10
|
||||
opts.Placement = sequence.PlacementPrefix
|
||||
opts.Separator = "-"
|
||||
|
||||
plan, err := sequence.Preview(context.Background(), opts, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("preview error: %v", err)
|
||||
}
|
||||
|
||||
expected := []string{"010-cover.png", "011-index.png"}
|
||||
if len(plan.Candidates) != len(expected) {
|
||||
t.Fatalf("expected %d candidates, got %d", len(expected), len(plan.Candidates))
|
||||
}
|
||||
for i, candidate := range plan.Candidates {
|
||||
if candidate.ProposedPath != expected[i] {
|
||||
t.Fatalf("candidate %d proposed %s, expected %s", i, candidate.ProposedPath, expected[i])
|
||||
}
|
||||
}
|
||||
|
||||
if plan.Config.Start != 10 {
|
||||
t.Fatalf("expected config start 10, got %d", plan.Config.Start)
|
||||
}
|
||||
if plan.Config.Placement != sequence.PlacementPrefix {
|
||||
t.Fatalf("expected prefix placement in config")
|
||||
}
|
||||
}
|
||||
|
||||
func TestSequencePreviewWithNumberPrefixLabel(t *testing.T) {
|
||||
tmp := t.TempDir()
|
||||
|
||||
createFile(t, filepath.Join(tmp, "cover.png"))
|
||||
createFile(t, filepath.Join(tmp, "index.png"))
|
||||
|
||||
ops := sequence.DefaultOptions()
|
||||
ops.WorkingDir = tmp
|
||||
ops.Placement = sequence.PlacementPrefix
|
||||
ops.Separator = "-"
|
||||
ops.NumberPrefix = "seq"
|
||||
|
||||
plan, err := sequence.Preview(context.Background(), ops, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("preview error: %v", err)
|
||||
}
|
||||
|
||||
expected := []string{"seq001-cover.png", "seq002-index.png"}
|
||||
if len(plan.Candidates) != len(expected) {
|
||||
t.Fatalf("expected %d candidates, got %d", len(expected), len(plan.Candidates))
|
||||
}
|
||||
for i, candidate := range plan.Candidates {
|
||||
if candidate.ProposedPath != expected[i] {
|
||||
t.Fatalf("candidate %d proposed %s, expected %s", i, candidate.ProposedPath, expected[i])
|
||||
}
|
||||
}
|
||||
|
||||
if warnings := plan.Summary.Warnings; len(warnings) != 0 {
|
||||
t.Fatalf("expected no warnings, got %#v", warnings)
|
||||
}
|
||||
}
|
||||
53
tests/contract/sequence_preview_test.go
Normal file
53
tests/contract/sequence_preview_test.go
Normal file
@@ -0,0 +1,53 @@
|
||||
package contract
|
||||
|
||||
import (
|
||||
"context"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/rogeecn/renamer/internal/sequence"
|
||||
)
|
||||
|
||||
func TestSequencePreviewDefaultNumbering(t *testing.T) {
|
||||
tmp := t.TempDir()
|
||||
|
||||
createFile(t, filepath.Join(tmp, "draft.txt"))
|
||||
createFile(t, filepath.Join(tmp, "notes.txt"))
|
||||
createFile(t, filepath.Join(tmp, "plan.txt"))
|
||||
|
||||
opts := sequence.DefaultOptions()
|
||||
opts.WorkingDir = tmp
|
||||
|
||||
plan, err := sequence.Preview(context.Background(), opts, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("preview error: %v", err)
|
||||
}
|
||||
|
||||
if plan.Summary.TotalCandidates != 3 {
|
||||
t.Fatalf("expected 3 candidates, got %d", plan.Summary.TotalCandidates)
|
||||
}
|
||||
if plan.Summary.RenamedCount != 3 {
|
||||
t.Fatalf("expected 3 renamed entries, got %d", plan.Summary.RenamedCount)
|
||||
}
|
||||
|
||||
expected := []string{"001_draft.txt", "002_notes.txt", "003_plan.txt"}
|
||||
if len(plan.Candidates) != 3 {
|
||||
t.Fatalf("expected 3 planned candidates, got %d", len(plan.Candidates))
|
||||
}
|
||||
for i, candidate := range plan.Candidates {
|
||||
if candidate.ProposedPath != expected[i] {
|
||||
t.Fatalf("candidate %d proposed %s, expected %s", i, candidate.ProposedPath, expected[i])
|
||||
}
|
||||
}
|
||||
|
||||
if plan.Summary.AppliedWidth != 3 {
|
||||
t.Fatalf("expected applied width 3, got %d", plan.Summary.AppliedWidth)
|
||||
}
|
||||
|
||||
if plan.Config.Start != 1 {
|
||||
t.Fatalf("expected start 1, got %d", plan.Config.Start)
|
||||
}
|
||||
if plan.Config.Placement != sequence.PlacementPrefix {
|
||||
t.Fatalf("expected prefix placement, got %s", plan.Config.Placement)
|
||||
}
|
||||
}
|
||||
39
tests/contract/sequence_width_test.go
Normal file
39
tests/contract/sequence_width_test.go
Normal file
@@ -0,0 +1,39 @@
|
||||
package contract
|
||||
|
||||
import (
|
||||
"context"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/rogeecn/renamer/internal/sequence"
|
||||
)
|
||||
|
||||
func TestSequencePreviewWithExplicitWidth(t *testing.T) {
|
||||
tmp := t.TempDir()
|
||||
|
||||
createFile(t, filepath.Join(tmp, "cutA.mov"))
|
||||
createFile(t, filepath.Join(tmp, "cutB.mov"))
|
||||
|
||||
opts := sequence.DefaultOptions()
|
||||
opts.WorkingDir = tmp
|
||||
opts.Width = 4
|
||||
|
||||
plan, err := sequence.Preview(context.Background(), opts, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("preview error: %v", err)
|
||||
}
|
||||
|
||||
expected := []string{"0001_cutA.mov", "0002_cutB.mov"}
|
||||
if len(plan.Candidates) != len(expected) {
|
||||
t.Fatalf("expected %d candidates, got %d", len(expected), len(plan.Candidates))
|
||||
}
|
||||
for i, candidate := range plan.Candidates {
|
||||
if candidate.ProposedPath != expected[i] {
|
||||
t.Fatalf("candidate %d proposed %s, expected %s", i, candidate.ProposedPath, expected[i])
|
||||
}
|
||||
}
|
||||
|
||||
if plan.Summary.AppliedWidth != 4 {
|
||||
t.Fatalf("expected applied width 4, got %d", plan.Summary.AppliedWidth)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user