diff options
| author | Paul Buetow <paul@buetow.org> | 2025-07-20 21:20:40 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2025-07-20 21:20:40 +0300 |
| commit | 9e3328a6aaefe4bd1aa0ec3e8bf6e93d6033180b (patch) | |
| tree | f70a6b53facc81a8bddbe5eeee76708e474e3298 /internal/audio/validate_test.go | |
| parent | 1afd19206720af695625dd46ff0ded0dedeef329 (diff) | |
test: add comprehensive test suite for audio and anki packages
- Add tests for audio package (62.8% coverage)
- OpenAI provider tests with mocking
- Provider interface and fallback mechanism tests
- Bulgarian text validation tests
- Audio caching functionality tests
- Add tests for anki package (84.8% coverage)
- CSV generation tests
- APKG package generation tests
- Card management and formatting tests
- Directory scanning and media handling tests
- Add test utilities and mocks
- Mock implementations for external dependencies
- Test helpers for common operations
- Utilities for creating test directories and files
- Update Taskfile.yaml with comprehensive test targets
- test: Run all tests
- test-verbose: Run with verbose output
- test-coverage: Run with coverage report
- test-coverage-html: Generate HTML coverage report
- test-race: Run with race detector
- test-short: Run only short tests
- test-all: Comprehensive suite with coverage and race detection
- clean: Remove build artifacts and test files
- Fix existing image package tests
- Remove tests for non-existent methods
- Update tests to match actual implementation
- Skip tests requiring live OpenAI API
This provides a solid foundation for ensuring code quality and catching regressions.
π€ Generated with [opencode](https://opencode.ai)
Co-Authored-By: opencode <noreply@opencode.ai>
Diffstat (limited to 'internal/audio/validate_test.go')
| -rw-r--r-- | internal/audio/validate_test.go | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/internal/audio/validate_test.go b/internal/audio/validate_test.go new file mode 100644 index 0000000..7bc3c9e --- /dev/null +++ b/internal/audio/validate_test.go @@ -0,0 +1,64 @@ +package audio + +import ( + "strings" + "testing" +) + +func TestValidateBulgarianText(t *testing.T) { + tests := []struct { + name string + text string + wantErr bool + errMsg string + }{ + { + name: "valid Bulgarian word", + text: "ΡΠ±ΡΠ»ΠΊΠ°", + wantErr: false, + }, + { + name: "valid Bulgarian sentence", + text: "ΠΠ΄ΡΠ°Π²Π΅ΠΉ, ΠΊΠ°ΠΊ ΡΠΈ?", + wantErr: false, + }, + { + name: "empty text", + text: "", + wantErr: true, + errMsg: "text cannot be empty", + }, + { + name: "whitespace only", + text: " \t\n", + wantErr: true, + errMsg: "text cannot be empty", + }, + { + name: "English text", + text: "Hello world", + wantErr: true, + errMsg: "text must contain Cyrillic characters", + }, + { + name: "numbers only", + text: "12345", + wantErr: true, + errMsg: "text must contain Cyrillic characters", + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + err := ValidateBulgarianText(tt.text) + if (err != nil) != tt.wantErr { + t.Errorf("ValidateBulgarianText() error = %v, wantErr %v", err, tt.wantErr) + } + if tt.wantErr && err != nil { + if !strings.Contains(err.Error(), tt.errMsg) { + t.Errorf("ValidateBulgarianText() error = %v, want error containing %v", err.Error(), tt.errMsg) + } + } + }) + } +} |
