Subscribe and post RSS feeds to Bluesky
rss bluesky
at main 2.4 kB view raw
1package main 2 3import ( 4 "testing" 5) 6 7func TestSanitizeHandle(t *testing.T) { 8 tests := []struct { 9 name string 10 input string 11 expected string 12 }{ 13 { 14 name: "simple handle", 15 input: "user.bsky.social", 16 expected: "user_bsky_social", 17 }, 18 { 19 name: "handle with multiple dots", 20 input: "my.user.name.bsky.social", 21 expected: "my_user_name_bsky_social", 22 }, 23 { 24 name: "handle with @ prefix", 25 input: "@user.bsky.social", 26 expected: "user_bsky_social", 27 }, 28 { 29 name: "handle with multiple @ symbols", 30 input: "@@user.bsky.social", 31 expected: "user_bsky_social", 32 }, 33 { 34 name: "handle without dots", 35 input: "user", 36 expected: "user", 37 }, 38 { 39 name: "handle with dots and @", 40 input: "@test.user.example.com", 41 expected: "test_user_example_com", 42 }, 43 { 44 name: "empty string", 45 input: "", 46 expected: "", 47 }, 48 { 49 name: "only special characters", 50 input: "@.@.", 51 expected: "__", 52 }, 53 } 54 55 for _, tt := range tests { 56 t.Run(tt.name, func(t *testing.T) { 57 result := sanitizeHandle(tt.input) 58 if result != tt.expected { 59 t.Errorf("sanitizeHandle(%q) = %q, want %q", tt.input, result, tt.expected) 60 } 61 }) 62 } 63} 64 65func TestTruncateText(t *testing.T) { 66 tests := []struct { 67 name string 68 text string 69 maxLen int 70 expected string 71 }{ 72 { 73 name: "no truncation needed", 74 text: "short text", 75 maxLen: 20, 76 expected: "short text", 77 }, 78 { 79 name: "truncate at word boundary", 80 text: "this is a long text that needs truncation", 81 maxLen: 20, 82 expected: "this is a long text", 83 }, 84 { 85 name: "truncate without word boundary", 86 text: "verylongtextwithoutspaces", 87 maxLen: 10, 88 expected: "verylongte", 89 }, 90 { 91 name: "exact length", 92 text: "exactly ten", 93 maxLen: 11, 94 expected: "exactly ten", 95 }, 96 { 97 name: "empty string", 98 text: "", 99 maxLen: 10, 100 expected: "", 101 }, 102 { 103 name: "truncate with space at end", 104 text: "text with space ", 105 maxLen: 10, 106 expected: "text with", 107 }, 108 } 109 110 for _, tt := range tests { 111 t.Run(tt.name, func(t *testing.T) { 112 result := truncateText(tt.text, tt.maxLen) 113 if result != tt.expected { 114 t.Errorf("truncateText(%q, %d) = %q, want %q", tt.text, tt.maxLen, result, tt.expected) 115 } 116 }) 117 } 118}