(t *testing.T)
| 863 | } |
| 864 | |
| 865 | func TestNewAttachableMarkdown(t *testing.T) { |
| 866 | // Nothing has uploaded when this runs, so no argument carries a URL. |
| 867 | png := attachmentArg{Path: "./login.png", Alt: "login"} |
| 868 | mp4 := attachmentArg{Path: "./repro.mp4", Alt: "repro.mp4", RendersAsPlayer: true} |
| 869 | clip := attachmentArg{Path: "./clip.mov", Alt: "clip.mov", RendersAsPlayer: true} |
| 870 | |
| 871 | tests := []struct { |
| 872 | name string |
| 873 | markdown string |
| 874 | attachmentArgs []attachmentArg |
| 875 | wantErr string |
| 876 | }{ |
| 877 | { |
| 878 | name: "an image written as a reference-style image is fine", |
| 879 | markdown: "![the login screen][shot]\n\n[shot]: ./login.png", |
| 880 | attachmentArgs: []attachmentArg{png}, |
| 881 | }, |
| 882 | { |
| 883 | name: "an image written as a reference-style link is fine", |
| 884 | markdown: "See the [screenshot][shot].\n\n[shot]: ./login.png", |
| 885 | attachmentArgs: []attachmentArg{png}, |
| 886 | }, |
| 887 | { |
| 888 | name: "a video written as a reference-style link is fine", |
| 889 | markdown: "[the recording][clip]\n\n[clip]: ./repro.mp4", |
| 890 | attachmentArgs: []attachmentArg{mp4}, |
| 891 | }, |
| 892 | { |
| 893 | name: "a video written as a reference-style image is refused", |
| 894 | markdown: "![the recording][clip]\n\n[clip]: ./repro.mp4", |
| 895 | attachmentArgs: []attachmentArg{mp4}, |
| 896 | wantErr: "cannot embed a video as a reference-style image: ./repro.mp4", |
| 897 | }, |
| 898 | { |
| 899 | name: "every offending video is named", |
| 900 | markdown: "![one][a] and ![two][b]\n\n[a]: ./repro.mp4\n[b]: ./clip.mov", |
| 901 | attachmentArgs: []attachmentArg{mp4, clip}, |
| 902 | wantErr: "cannot embed a video as a reference-style image: ./repro.mp4, ./clip.mov", |
| 903 | }, |
| 904 | { |
| 905 | name: "a video named once is reported once", |
| 906 | markdown: "![one][a] and ![two][a]\n\n[a]: ./repro.mp4", |
| 907 | attachmentArgs: []attachmentArg{mp4}, |
| 908 | wantErr: "cannot embed a video as a reference-style image: ./repro.mp4", |
| 909 | }, |
| 910 | { |
| 911 | // Both orderings, because the reported videos are deduplicated by |
| 912 | // argument. A link is the allowed shape, so marking the argument |
| 913 | // seen while skipping it would swallow the embed that follows. |
| 914 | name: "a video used as both a link and an image is reported (image first)", |
| 915 | markdown: "![one][a] and [two][a]\n\n[a]: ./repro.mp4", |
| 916 | attachmentArgs: []attachmentArg{mp4}, |
| 917 | wantErr: "cannot embed a video as a reference-style image: ./repro.mp4", |
| 918 | }, |
| 919 | { |
| 920 | name: "a video used as both a link and an image is reported (link first)", |
| 921 | markdown: "[one][a] and ![two][a]\n\n[a]: ./repro.mp4", |
| 922 | attachmentArgs: []attachmentArg{mp4}, |
nothing calls this directly
no test coverage detected