package markup import ( "bytes" "testing" ) func TestAtExtension_Rendering(t *testing.T) { tests := []struct { name string markdown string expected string }{ { name: "renders simple at mention", markdown: "Hello @user.tngl.sh!", expected: `
Hello @user.tngl.sh!
`, }, { name: "renders multiple at mentions", markdown: "Hi @alice.tngl.sh and @bob.example.com", expected: `Hi @alice.tngl.sh and @bob.example.com
`, }, { name: "renders at mention in parentheses", markdown: "Check this out (@user.tngl.sh)", expected: `Check this out (@user.tngl.sh)
`, }, { name: "does not render email", markdown: "Contact me at test@example.com", expected: `Contact me at test@example.com
`, }, { name: "renders at mention with hyphen", markdown: "Follow @user-name.tngl.sh", expected: `Follow @user-name.tngl.sh
`, }, { name: "renders at mention with numbers", markdown: "@user123.test456.social", expected: ``, }, { name: "at mention at start of line", markdown: "@user.tngl.sh is cool", expected: `@user.tngl.sh is cool
`, }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { md := NewMarkdown() var buf bytes.Buffer if err := md.Convert([]byte(tt.markdown), &buf); err != nil { t.Fatalf("failed to convert markdown: %v", err) } result := buf.String() if result != tt.expected+"\n" { t.Errorf("expected:\n%s\ngot:\n%s", tt.expected, result) } }) } } func TestAtExtension_WithOtherMarkdown(t *testing.T) { tests := []struct { name string markdown string contains string }{ { name: "at mention with bold", markdown: "**Hello @user.tngl.sh**", contains: `Hello @user.tngl.sh`, }, { name: "at mention with italic", markdown: "*Check @user.tngl.sh*", contains: `Check @user.tngl.sh`, }, { name: "at mention in list", markdown: "- Item 1\n- @user.tngl.sh\n- Item 3", contains: `@user.tngl.sh`, }, { name: "at mention in link", markdown: "[@regnault.dev](https://regnault.dev)", contains: `@regnault.dev`, }, { name: "at mention in link again", markdown: "[check out @regnault.dev](https://regnault.dev)", contains: `check out @regnault.dev`, }, { name: "at mention in link again, multiline", markdown: "[\ncheck out @regnault.dev](https://regnault.dev)", contains: "\ncheck out @regnault.dev", }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { md := NewMarkdown() var buf bytes.Buffer if err := md.Convert([]byte(tt.markdown), &buf); err != nil { t.Fatalf("failed to convert markdown: %v", err) } result := buf.String() if !bytes.Contains([]byte(result), []byte(tt.contains)) { t.Errorf("expected output to contain:\n%s\ngot:\n%s", tt.contains, result) } }) } }