aboutsummaryrefslogtreecommitdiff
path: root/internal/nametransform/nfc_test.go
blob: aad1d7d47823c07a71b75d7f68036b81072312fc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package nametransform

import (
	"strconv"
	"testing"

	"golang.org/x/text/unicode/norm"
)

func TestNFD2NFC(t *testing.T) {
	n := newLognamesTestInstance(NameMax)
	n.nfd2nfc = true
	iv := make([]byte, DirIVLen)
	srcNFC := "Österreich Café"
	srcNFD := norm.NFD.String(srcNFC)

	// cipherName should get normalized to NFC
	cipherName, _ := n.EncryptName(srcNFD, iv)
	// Decrypt without changing normalization
	decryptedRaw, _ := n.decryptName(cipherName, iv)
	if srcNFC != decryptedRaw {
		t.Errorf("want %s have %s", strconv.QuoteToASCII(srcNFC), strconv.QuoteToASCII(decryptedRaw))
	}
	// Decrypt with normalizing to NFD
	decrypted, _ := n.DecryptName(cipherName, iv)
	if srcNFD != decrypted {
		t.Errorf("want %s have %s", strconv.QuoteToASCII(srcNFD), strconv.QuoteToASCII(decrypted))
	}
}