summaryrefslogtreecommitdiff
path: root/internal/draft/parser_test.go
diff options
from:
to:
context:
space:
mode:
Diffstat (limited to 'internal/draft/parser_test.go')
-rw-r--r--internal/draft/parser_test.go83
1 files changed, 83 insertions, 0 deletions
diff --git a/internal/draft/parser_test.go b/internal/draft/parser_test.go
new file mode 100644
index 0000000..c6d454d
--- /dev/null
+++ b/internal/draft/parser_test.go
@@ -0,0 +1,83 @@
+package draft
+
+import (
+ "os"
+ "strings"
+ "testing"
+)
+
+func TestParseDraftSevsk(t *testing.T) {
+ raw, err := os.ReadFile("../../.draft/sevsk.md.draft")
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ doc, err := ParseDraft("../../.draft/sevsk.md.draft", "sevsk", raw)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if doc.Metadata == nil || doc.Metadata.Title == "" {
+ t.Fatal("expected frontmatter metadata")
+ }
+
+ var galleries int
+ for _, section := range doc.Sections {
+ for _, block := range section.Blocks {
+ if block.Kind != GalleryBlock {
+ continue
+ }
+ galleries++
+ for _, p := range block.Gallery.Photos {
+ if !strings.HasPrefix(p.Key, "Sevsk/20241008-") {
+ t.Errorf("unexpected photo key %q", p.Key)
+ }
+ if strings.Contains(p.Caption, "2x") {
+ t.Errorf("layout token leaked into caption %q", p.Caption)
+ }
+ }
+ }
+ }
+ if galleries == 0 {
+ t.Fatal("expected at least one gallery")
+ }
+
+ // First gallery: 4 photos, captions on photos 1 and 3, none on 2; photo 4 had "2x |" => empty caption.
+ first := firstGallery(doc)
+ if first == nil || len(first.Photos) != 4 {
+ t.Fatalf("first gallery: want 4 photos, got %v", first)
+ }
+ if first.Timezone != "Europe/Moscow" {
+ t.Errorf("first gallery tz = %q", first.Timezone)
+ }
+ if first.Photos[0].Caption != "Никольская церковь. Действующая" {
+ t.Errorf("photo[0] caption = %q", first.Photos[0].Caption)
+ }
+ if first.Photos[1].Caption != "" {
+ t.Errorf("photo[1] caption = %q, want empty", first.Photos[1].Caption)
+ }
+ if first.Photos[3].Caption != "" {
+ t.Errorf("photo[3] caption = %q, want empty (only 2x token)", first.Photos[3].Caption)
+ }
+ if first.Photos[3].Key != "Sevsk/20241008-094036.jpg" {
+ t.Errorf("photo[3] key = %q", first.Photos[3].Key)
+ }
+}
+
+func firstGallery(doc *Document) *Gallery {
+ for _, section := range doc.Sections {
+ for _, block := range section.Blocks {
+ if block.Kind == GalleryBlock {
+ return block.Gallery
+ }
+ }
+ }
+ return nil
+}
+
+func TestSplitSectionsSeparator(t *testing.T) {
+ body := "intro\n...\nmiddle\n...\nend"
+ sections := splitSections(body)
+ if len(sections) != 3 {
+ t.Fatalf("want 3 sections, got %d", len(sections))
+ }
+}