mirror of
https://github.com/kjanat/articulate-parser.git
synced 2026-10-13 00:15:28 +02:00
- Add logger to all exporters for consistent error handling - Add Course.Validate() method with ValidationError type - Create shared test fixtures in internal/testdata - Refactor config passing: NewArticulateParser now takes *config.Config - Add NewLoggerFromConfig() factory for logger creation - Add context cancellation with signal handling (SIGINT/SIGTERM) - Add godoc examples for loggers and exporters - Add HTML exporter error path tests - Add fuzz tests for parser and HTMLCleaner - Fix markdown output: trim whitespace, collapse blank lines - Remove test output files from repo
105 lines
2.7 KiB
Go
105 lines
2.7 KiB
Go
package exporters
|
|
|
|
import (
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/kjanat/articulate-parser/internal/models"
|
|
"github.com/kjanat/articulate-parser/internal/services"
|
|
"github.com/kjanat/articulate-parser/internal/testdata"
|
|
)
|
|
|
|
// BenchmarkFactory_CreateExporter_Markdown benchmarks markdown exporter creation.
|
|
func BenchmarkFactory_CreateExporter_Markdown(b *testing.B) {
|
|
htmlCleaner := services.NewHTMLCleaner()
|
|
factory := NewFactory(htmlCleaner, nil)
|
|
|
|
b.ResetTimer()
|
|
for b.Loop() {
|
|
_, _ = factory.CreateExporter("markdown")
|
|
}
|
|
}
|
|
|
|
// BenchmarkFactory_CreateExporter_All benchmarks creating all exporter types.
|
|
func BenchmarkFactory_CreateExporter_All(b *testing.B) {
|
|
htmlCleaner := services.NewHTMLCleaner()
|
|
factory := NewFactory(htmlCleaner, nil)
|
|
formats := []string{"markdown", "docx", "html"}
|
|
|
|
b.ResetTimer()
|
|
for b.Loop() {
|
|
for _, format := range formats {
|
|
_, _ = factory.CreateExporter(format)
|
|
}
|
|
}
|
|
}
|
|
|
|
// BenchmarkAllExporters_Export benchmarks all exporters with the same course.
|
|
func BenchmarkAllExporters_Export(b *testing.B) {
|
|
htmlCleaner := services.NewHTMLCleaner()
|
|
course := testdata.BasicCourse()
|
|
|
|
exporters := map[string]struct {
|
|
exporter any
|
|
ext string
|
|
}{
|
|
"Markdown": {NewMarkdownExporter(htmlCleaner, nil), ".md"},
|
|
"Docx": {NewDocxExporter(htmlCleaner, nil), ".docx"},
|
|
"HTML": {NewHTMLExporter(htmlCleaner, nil), ".html"},
|
|
}
|
|
|
|
for name, exp := range exporters {
|
|
b.Run(name, func(b *testing.B) {
|
|
tempDir := b.TempDir()
|
|
exporter := exp.exporter.(interface {
|
|
Export(*models.Course, string) error
|
|
})
|
|
|
|
b.ResetTimer()
|
|
for b.Loop() {
|
|
outputPath := filepath.Join(tempDir, "benchmark"+exp.ext)
|
|
_ = exporter.Export(course, outputPath)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
// BenchmarkExporters_LargeCourse benchmarks exporters with large course data.
|
|
func BenchmarkExporters_LargeCourse(b *testing.B) {
|
|
htmlCleaner := services.NewHTMLCleaner()
|
|
course := testdata.LargeCourse(50)
|
|
|
|
b.Run("Markdown_Large", func(b *testing.B) {
|
|
exporter := NewMarkdownExporter(htmlCleaner, nil)
|
|
tempDir := b.TempDir()
|
|
|
|
b.ResetTimer()
|
|
for b.Loop() {
|
|
outputPath := filepath.Join(tempDir, "large.md")
|
|
_ = exporter.Export(course, outputPath)
|
|
}
|
|
})
|
|
|
|
b.Run("Docx_Large", func(b *testing.B) {
|
|
exporter := NewDocxExporter(htmlCleaner, nil)
|
|
tempDir := b.TempDir()
|
|
|
|
b.ResetTimer()
|
|
for b.Loop() {
|
|
outputPath := filepath.Join(tempDir, "large.docx")
|
|
_ = exporter.Export(course, outputPath)
|
|
}
|
|
})
|
|
|
|
b.Run("HTML_Large", func(b *testing.B) {
|
|
exporter := NewHTMLExporter(htmlCleaner, nil)
|
|
tempDir := b.TempDir()
|
|
|
|
b.ResetTimer()
|
|
for b.Loop() {
|
|
outputPath := filepath.Join(tempDir, "large.html")
|
|
_ = exporter.Export(course, outputPath)
|
|
}
|
|
})
|
|
}
|