| 1 |
// Copyright (c) 2022 Tulir Asokan |
| 2 |
// |
| 3 |
// This Source Code Form is subject to the terms of the Mozilla Public |
| 4 |
// License, v. 2.0. If a copy of the MPL was not distributed with this |
| 5 |
// file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 6 |
|
| 7 |
package variationselector_test |
| 8 |
|
| 9 |
import ( |
| 10 |
"fmt" |
| 11 |
"strconv" |
| 12 |
"testing" |
| 13 |
|
| 14 |
"github.com/stretchr/testify/assert" |
| 15 |
|
| 16 |
"maunium.net/go/mautrix/util/variationselector" |
| 17 |
) |
| 18 |
|
| 19 |
func TestAdd(t *testing.T) { |
| 20 |
assert.Equal(t, "\U0001f44d\U0001F3FD", variationselector.Add("\U0001f44d\U0001F3FD")) |
| 21 |
assert.Equal(t, "\U0001f44d\ufe0f", variationselector.Add("\U0001f44d")) |
| 22 |
assert.Equal(t, "\U0001f44d\ufe0f", variationselector.Add("\U0001f44d\ufe0f")) |
| 23 |
assert.Equal(t, "4\ufe0f\u20e3", variationselector.Add("4\u20e3")) |
| 24 |
assert.Equal(t, "4\ufe0f\u20e3", variationselector.Add("4\ufe0f\u20e3")) |
| 25 |
assert.Equal(t, "\U0001f914", variationselector.Add("\U0001f914")) |
| 26 |
} |
| 27 |
|
| 28 |
func TestRemove(t *testing.T) { |
| 29 |
assert.Equal(t, "\U0001f44d", variationselector.Remove("\U0001f44d")) |
| 30 |
assert.Equal(t, "\U0001f44d", variationselector.Remove("\U0001f44d\ufe0f")) |
| 31 |
assert.Equal(t, "4\u20e3", variationselector.Remove("4\u20e3")) |
| 32 |
assert.Equal(t, "4\u20e3", variationselector.Remove("4\ufe0f\u20e3")) |
| 33 |
assert.Equal(t, "\U0001f914", variationselector.Remove("\U0001f914")) |
| 34 |
} |
| 35 |
|
| 36 |
func ExampleAdd() { |
| 37 |
fmt.Println(strconv.QuoteToASCII(variationselector.Add("\U0001f44d"))) // thumbs up (needs selector) |
| 38 |
fmt.Println(strconv.QuoteToASCII(variationselector.Add("\U0001f44d\ufe0f"))) // thumbs up with variation selector (stays as-is) |
| 39 |
fmt.Println(strconv.QuoteToASCII(variationselector.Add("\U0001f44d\U0001F3FD"))) // thumbs up with skin tone (shouldn't get selector) |
| 40 |
fmt.Println(strconv.QuoteToASCII(variationselector.Add("\U0001f914"))) // thinking face (shouldn't get selector) |
| 41 |
// Output: |
| 42 |
// "\U0001f44d\ufe0f" |
| 43 |
// "\U0001f44d\ufe0f" |
| 44 |
// "\U0001f44d\U0001f3fd" |
| 45 |
// "\U0001f914" |
| 46 |
} |
| 47 |
|
| 48 |
func ExampleRemove() { |
| 49 |
fmt.Println(strconv.QuoteToASCII(variationselector.Remove("\U0001f44d"))) |
| 50 |
fmt.Println(strconv.QuoteToASCII(variationselector.Remove("\U0001f44d\ufe0f"))) |
| 51 |
// Output: |
| 52 |
// "\U0001f44d" |
| 53 |
// "\U0001f44d" |
| 54 |
} |