| 1 | package tinyclient |
| 2 | |
| 3 | import ( |
| 4 | "encoding/json" |
| 5 | "os" |
| 6 | "testing" |
| 7 | ) |
| 8 | |
| 9 | func TestRoomParityFixture(t *testing.T) { |
| 10 | data, err := os.ReadFile("room_parity.json" ) |
| 11 | if err != nil { |
| 12 | t.Fatal(err) |
| 13 | } |
| 14 | var cases []struct { |
| 15 | Name string `json:"name"` |
| 16 | Content string `json:"content"` |
| 17 | Tags [][]string `json:"tags"` |
| 18 | Attachments []string `json:"attachments"` |
| 19 | Text string `json:"text"` |
| 20 | } |
| 21 | if err := json.Unmarshal(data, &cases); err != nil { |
| 22 | t.Fatal(err) |
| 23 | } |
| 24 | for _, tc := range cases { |
| 25 | t.Run(tc.Name, func(t *testing.T) { |
| 26 | row := map[string]any{"content" : tc.Content, "tags" : tc.Tags} |
| 27 | items := roomAttachments(row) |
| 28 | if len(items) != len(tc.Attachments) { |
| 29 | t.Fatalf("attachments: got %d, want %d" , len(items), len(tc.Attachments)) |
| 30 | } |
| 31 | for i, want := range tc.Attachments { |
| 32 | if items[i].URL != want { |
| 33 | t.Errorf("attachment %d: got %q, want %q" , i, items[i].URL, want) |
| 34 | } |
| 35 | } |
| 36 | rendered := string(renderChatMarkdown(tc.Content)) |
| 37 | if tc.Text != "" && rendered == "" { |
| 38 | t.Fatal("markdown renderer returned empty output" ) |
| 39 | } |
| 40 | }) |
| 41 | } |
| 42 | } |