chore: seperate large files
This commit is contained in:
parent
ebbf516689
commit
76e1298ded
44 changed files with 5745 additions and 4173 deletions
104
cmd/root_test.go
104
cmd/root_test.go
|
@ -149,6 +149,91 @@ func TestExecute_UnknownCommand(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
// TestExecute_SyncCommand tests the sync command through Execute
|
||||
func TestExecute_SyncCommand(t *testing.T) {
|
||||
// Save original args
|
||||
oldArgs := os.Args
|
||||
defer func() { os.Args = oldArgs }()
|
||||
|
||||
// Create temporary test directory
|
||||
tempDir := t.TempDir()
|
||||
|
||||
// Create source and target files
|
||||
sourceFile := filepath.Join(tempDir, "source.lrc")
|
||||
targetFile := filepath.Join(tempDir, "target.lrc")
|
||||
|
||||
if err := os.WriteFile(sourceFile, []byte("[00:01.00]Test line"), 0644); err != nil {
|
||||
t.Fatalf("Failed to create source file: %v", err)
|
||||
}
|
||||
|
||||
if err := os.WriteFile(targetFile, []byte("[00:10.00]Target line"), 0644); err != nil {
|
||||
t.Fatalf("Failed to create target file: %v", err)
|
||||
}
|
||||
|
||||
// Set up test environment
|
||||
outBuf, cleanup := setupTestEnv()
|
||||
|
||||
// Set args for sync command
|
||||
os.Args = []string{"sub-cli", "sync", sourceFile, targetFile}
|
||||
|
||||
// Execute command
|
||||
Execute()
|
||||
|
||||
// Get output
|
||||
cleanup()
|
||||
output := outBuf.String()
|
||||
|
||||
// Verify no error message or expected error format
|
||||
if strings.Contains(output, "Error:") && !strings.Contains(output, "Error: ") {
|
||||
t.Errorf("Expected formatted error or no error, got: %s", output)
|
||||
}
|
||||
}
|
||||
|
||||
// TestExecute_ConvertCommand tests the convert command through Execute
|
||||
func TestExecute_ConvertCommand(t *testing.T) {
|
||||
// Save original args
|
||||
oldArgs := os.Args
|
||||
defer func() { os.Args = oldArgs }()
|
||||
|
||||
// Create temporary test directory
|
||||
tempDir := t.TempDir()
|
||||
|
||||
// Create source file
|
||||
sourceContent := `1
|
||||
00:00:01,000 --> 00:00:04,000
|
||||
This is a test subtitle.`
|
||||
sourceFile := filepath.Join(tempDir, "source.srt")
|
||||
if err := os.WriteFile(sourceFile, []byte(sourceContent), 0644); err != nil {
|
||||
t.Fatalf("Failed to create source file: %v", err)
|
||||
}
|
||||
|
||||
// Define target file
|
||||
targetFile := filepath.Join(tempDir, "target.lrc")
|
||||
|
||||
// Set up test environment
|
||||
outBuf, cleanup := setupTestEnv()
|
||||
|
||||
// Set args for convert command
|
||||
os.Args = []string{"sub-cli", "convert", sourceFile, targetFile}
|
||||
|
||||
// Execute command
|
||||
Execute()
|
||||
|
||||
// Get output
|
||||
cleanup()
|
||||
output := outBuf.String()
|
||||
|
||||
// Verify no error message
|
||||
if strings.Contains(output, "Error:") {
|
||||
t.Errorf("Expected no error, but got: %s", output)
|
||||
}
|
||||
|
||||
// Verify target file exists
|
||||
if _, err := os.Stat(targetFile); os.IsNotExist(err) {
|
||||
t.Errorf("Target file was not created")
|
||||
}
|
||||
}
|
||||
|
||||
// TestHandleSync tests the sync command
|
||||
func TestHandleSync(t *testing.T) {
|
||||
// Create temporary test directory
|
||||
|
@ -381,3 +466,22 @@ func TestHandleFormat_NoArgs(t *testing.T) {
|
|||
t.Errorf("Expected fmt usage information when no args provided")
|
||||
}
|
||||
}
|
||||
|
||||
// TestHandleFormat_Error tests the error path in handleFormat
|
||||
func TestHandleFormat_Error(t *testing.T) {
|
||||
// Set up test environment
|
||||
outBuf, cleanup := setupTestEnv()
|
||||
|
||||
// Execute format command with non-existent file
|
||||
nonExistentFile := "/non/existent/path.srt"
|
||||
handleFormat([]string{nonExistentFile})
|
||||
|
||||
// Get output
|
||||
cleanup()
|
||||
output := outBuf.String()
|
||||
|
||||
// Verify error message is printed
|
||||
if !strings.Contains(output, "Error:") {
|
||||
t.Errorf("Expected error message for non-existent file, got: %s", output)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue