(t *testing.T)
| 785 | } |
| 786 | |
| 787 | func TestNewAttachableMarkdown(t *testing.T) { |
| 788 | // Nothing has uploaded when this runs, so no argument carries a URL. |
| 789 | png := attachmentArg{Path: "./login.png", Alt: "login"} |
| 790 | mp4 := attachmentArg{Path: "./repro.mp4", Alt: "repro.mp4", RendersAsPlayer: true} |
| 791 | clip := attachmentArg{Path: "./clip.mov", Alt: "clip.mov", RendersAsPlayer: true} |
| 792 | |
| 793 | tests := []struct { |
| 794 | name string |
| 795 | markdown string |
| 796 | attachmentArgs []attachmentArg |
| 797 | wantErr string |
| 798 | }{ |
| 799 | { |
| 800 | name: "an image written as a reference-style image is fine", |
| 801 | markdown: "![the login screen][shot]\n\n[shot]: ./login.png", |
| 802 | attachmentArgs: []attachmentArg{png}, |
| 803 | }, |
| 804 | { |
| 805 | name: "an image written as a reference-style link is fine", |
| 806 | markdown: "See the [screenshot][shot].\n\n[shot]: ./login.png", |
| 807 | attachmentArgs: []attachmentArg{png}, |
| 808 | }, |
| 809 | { |
| 810 | name: "a video written as a reference-style link is fine", |
| 811 | markdown: "[the recording][clip]\n\n[clip]: ./repro.mp4", |
| 812 | attachmentArgs: []attachmentArg{mp4}, |
| 813 | }, |
| 814 | { |
| 815 | name: "a video written as a reference-style image is refused", |
| 816 | markdown: "![the recording][clip]\n\n[clip]: ./repro.mp4", |
| 817 | attachmentArgs: []attachmentArg{mp4}, |
| 818 | wantErr: "cannot embed a video as a reference-style image: ./repro.mp4", |
| 819 | }, |
| 820 | { |
| 821 | name: "every offending video is named", |
| 822 | markdown: "![one][a] and ![two][b]\n\n[a]: ./repro.mp4\n[b]: ./clip.mov", |
| 823 | attachmentArgs: []attachmentArg{mp4, clip}, |
| 824 | wantErr: "cannot embed a video as a reference-style image: ./repro.mp4, ./clip.mov", |
| 825 | }, |
| 826 | { |
| 827 | name: "a video named once is reported once", |
| 828 | markdown: "![one][a] and ![two][a]\n\n[a]: ./repro.mp4", |
| 829 | attachmentArgs: []attachmentArg{mp4}, |
| 830 | wantErr: "cannot embed a video as a reference-style image: ./repro.mp4", |
| 831 | }, |
| 832 | { |
| 833 | // Both orderings, because the reported videos are deduplicated by |
| 834 | // argument. A link is the allowed shape, so marking the argument |
| 835 | // seen while skipping it would swallow the embed that follows. |
| 836 | name: "a video used as both a link and an image is reported (image first)", |
| 837 | markdown: "![one][a] and [two][a]\n\n[a]: ./repro.mp4", |
| 838 | attachmentArgs: []attachmentArg{mp4}, |
| 839 | wantErr: "cannot embed a video as a reference-style image: ./repro.mp4", |
| 840 | }, |
| 841 | { |
| 842 | name: "a video used as both a link and an image is reported (link first)", |
| 843 | markdown: "[one][a] and ![two][a]\n\n[a]: ./repro.mp4", |
| 844 | attachmentArgs: []attachmentArg{mp4}, |
nothing calls this directly
no test coverage detected