1package stringprep
2
3import (
4	"fmt"
5	"reflect"
6	"testing"
7)
8
9func TestMapping(t *testing.T) {
10	mappingTests := []struct {
11		label  string
12		table  Mapping
13		in     rune
14		exists bool
15		out    []rune
16	}{
17		// Table B1
18		{label: "B1", table: TableB1, in: 0x00AD, exists: true, out: []rune{}},
19		{label: "B1", table: TableB1, in: 0x0040, exists: false, out: nil},
20		// Table B2
21		{label: "B2", table: TableB2, in: 0x0043, exists: true, out: []rune{0x0063}},
22		{label: "B2", table: TableB2, in: 0x00DF, exists: true, out: []rune{0x0073, 0x0073}},
23		{label: "B2", table: TableB2, in: 0x1F56, exists: true, out: []rune{0x03C5, 0x0313, 0x0342}},
24		{label: "B2", table: TableB2, in: 0x0040, exists: false, out: nil},
25		// Table B3
26		{label: "B3", table: TableB3, in: 0x1FF7, exists: true, out: []rune{0x03C9, 0x0342, 0x03B9}},
27		{label: "B3", table: TableB3, in: 0x0040, exists: false, out: nil},
28	}
29
30	for _, c := range mappingTests {
31		t.Run(fmt.Sprintf("%s 0x%04x", c.label, c.in), func(t *testing.T) {
32			got, ok := c.table.Map(c.in)
33			switch c.exists {
34			case true:
35				if !ok {
36					t.Errorf("input '0x%04x' was not found, but should have been", c.in)
37				}
38				if !reflect.DeepEqual(got, c.out) {
39					t.Errorf("input '0x%04x' was %v, expected %v", c.in, got, c.out)
40				}
41			case false:
42				if ok {
43					t.Errorf("input '0x%04x' was found, but should not have been", c.in)
44				}
45				if got != nil {
46					t.Errorf("input '0x%04x' was %v, expected %v", c.in, got, c.out)
47				}
48			}
49		})
50	}
51}
52