ical_test.go
⎇
Raw
1package ical
2
3import (
4 "strings"
5 "testing"
6 "time"
7)
8
9func TestEscape(t *testing.T) {
10 if got := Escape("a,b;c\\d\ne"); got != `a\,b\;c\\d\ne` {
11 t.Errorf("Escape: %q", got)
12 }
13}
14
15func TestFoldKeepsUTF8AndLength(t *testing.T) {
16 line := "DESCRIPTION:" + strings.Repeat("Übungsprogramm für die Kniestreckung – ", 6)
17 out := fold(line)
18 for _, l := range strings.Split(strings.TrimSuffix(out, "\r\n"), "\r\n") {
19 if len(l) > 75 {
20 t.Errorf("Zeile länger als 75 Bytes: %d", len(l))
21 }
22 if !strings.HasPrefix(l, "DESCRIPTION") && !strings.HasPrefix(l, " ") {
23 t.Errorf("Folgezeile ohne Leerzeichen: %q", l)
24 }
25 }
26 // Entfalten ergibt wieder das Original
27 if unfolded := strings.ReplaceAll(strings.TrimSuffix(out, "\r\n"), "\r\n ", ""); unfolded != line {
28 t.Error("Faltung nicht verlustfrei")
29 }
30}
31
32func TestCalendar(t *testing.T) {
33 berlin, _ := time.LoadLocation("Europe/Berlin")
34 start := time.Date(2026, 11, 12, 9, 30, 0, 0, berlin)
35 c := Calendar{Name: "Physiotherapie, Praxis", ProdID: "-//PhysioBase//DE", Events: []Event{
36 {UID: "abc@x", Start: start, End: start.Add(30 * time.Minute), Stamp: start, Summary: "Physiotherapie", Location: "Musterstr. 1, Köln", Sequence: 2},
37 {UID: "def@x", Start: start, End: start, Stamp: start, Summary: "Abgesagt", Cancelled: true},
38 }}
39 s := string(c.Bytes())
40 for _, want := range []string{
41 "BEGIN:VCALENDAR\r\n", "X-WR-CALNAME:Physiotherapie\\, Praxis\r\n", "DTSTART:20261112T083000Z\r\n",
42 "DTEND:20261112T090000Z\r\n", "SEQUENCE:2\r\n", "LOCATION:Musterstr. 1\\, Köln\r\n", "STATUS:CANCELLED\r\n", "END:VCALENDAR\r\n",
43 } {
44 if !strings.Contains(s, want) {
45 t.Errorf("fehlt: %q", want)
46 }
47 }
48 if strings.Contains(strings.ReplaceAll(s, "\r\n", ""), "\n") {
49 t.Error("nackte LF-Zeilenenden")
50 }
51}
52