|
| 1 | +package text_test |
| 2 | + |
| 3 | +import ( |
| 4 | + "reflect" |
| 5 | + "testing" |
| 6 | + |
| 7 | + "github.com/72636c/hyperspaced/internal/text" |
| 8 | +) |
| 9 | + |
| 10 | +func Test_SplitString(t *testing.T) { |
| 11 | + testCases := []struct { |
| 12 | + description string |
| 13 | + input string |
| 14 | + expected []text.Char |
| 15 | + }{ |
| 16 | + { |
| 17 | + description: "Empty String", |
| 18 | + input: "", |
| 19 | + expected: []text.Char{}, |
| 20 | + }, |
| 21 | + { |
| 22 | + description: "One Letter", |
| 23 | + input: "f", |
| 24 | + expected: []text.Char{text.Char{'f'}}, |
| 25 | + }, |
| 26 | + { |
| 27 | + description: "Two Letters", |
| 28 | + input: "hi", |
| 29 | + expected: []text.Char{text.Char{'h'}, text.Char{'i'}}, |
| 30 | + }, |
| 31 | + { |
| 32 | + description: "Accent Normalisation", |
| 33 | + input: "e\u0301", |
| 34 | + expected: []text.Char{text.Char{'é'}}, |
| 35 | + }, |
| 36 | + { |
| 37 | + description: "Separate Emoji", |
| 38 | + input: "\U0001f30f\u2696", |
| 39 | + expected: []text.Char{text.Char{'🌏'}, text.Char{'⚖'}}, |
| 40 | + }, |
| 41 | + { |
| 42 | + // https://emojipedia.org/family-man-light-skin-tone-woman-light-skin-tone-girl-light-skin-tone-baby-light-skin-tone/ |
| 43 | + description: "Sequenced Emoji", |
| 44 | + input: "\U0001f468\U0001f3fb\u200d\U0001f469\U0001f3fb\u200d\U0001f467\U0001f3fb\u200d\U0001f476\U0001f3fb", |
| 45 | + expected: []text.Char{text.Char{'👨', '🏻', '\u200d', '👩', '🏻', '\u200d', '👧', '🏻', '\u200d', '👶', '🏻'}}, |
| 46 | + }, |
| 47 | + { |
| 48 | + // https://emojipedia.org/female-sleuth/ |
| 49 | + description: "Female Variant Selector", |
| 50 | + input: "\U0001f575\ufe0f\u200d\u2640\ufe0f", |
| 51 | + expected: []text.Char{text.Char{'🕵', '\ufe0f', '\u200d', '♀', '\ufe0f'}}, |
| 52 | + }, |
| 53 | + { |
| 54 | + // https://emojipedia.org/female-technologist/ |
| 55 | + description: "Join Control", |
| 56 | + input: "\U0001f469\u200d\U0001f4bb", |
| 57 | + expected: []text.Char{text.Char{'👩', '\u200d', '💻'}}, |
| 58 | + }, |
| 59 | + { |
| 60 | + // https://emojipedia.org/man-type-6/ |
| 61 | + description: "Skin Tone Modifier", |
| 62 | + input: "\U0001f468\U0001f3ff", |
| 63 | + expected: []text.Char{text.Char{'👨', '🏿'}}, |
| 64 | + }, |
| 65 | + } |
| 66 | + |
| 67 | + for _, testCase := range testCases { |
| 68 | + t.Run(testCase.description, func(t *testing.T) { |
| 69 | + actual := text.SplitString(testCase.input) |
| 70 | + if !reflect.DeepEqual(actual, testCase.expected) { |
| 71 | + t.Errorf("expected %+v, received %+v", testCase.expected, actual) |
| 72 | + } |
| 73 | + }) |
| 74 | + } |
| 75 | +} |
0 commit comments