File: map_private_test.go

package info (click to toggle)
golang-github-maxatome-go-testdeep 1.14.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,416 kB
  • sloc: perl: 1,012; yacc: 130; makefile: 2
file content (64 lines) | stat: -rw-r--r-- 1,336 bytes parent folder | download | duplicates (2)
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// Copyright (c) 2018, Maxime Soulé
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
// LICENSE file in the root directory of this source tree.

package tdutil

import (
	"reflect"
	"sort"
	"testing"
)

func TestKvSlice(t *testing.T) {
	t.Run("len=0", func(t *testing.T) {
		kvs := newKvSlice(0)
		if kvs.s != nil || kvs.v != nil {
			t.Errorf("newKvSlice failed: %v", *kvs)
		}
		sort.Sort(kvs)
	})

	t.Run("len=1", func(t *testing.T) {
		kvs := newKvSlice(1)
		if kvs.s == nil || kvs.v != nil {
			t.Errorf("newKvSlice failed: %v", *kvs)
		}
		kvs.s = append(kvs.s, kv{
			key:   reflect.ValueOf("a"),
			value: reflect.ValueOf(1),
		})
		sort.Sort(kvs)
	})

	t.Run("len>1", func(t *testing.T) {
		kvs := newKvSlice(3)
		if kvs.s == nil || kvs.v == nil {
			t.Errorf("newKvSlice failed: %v", *kvs)
		}
		kvs.s = append(kvs.s,
			kv{
				key:   reflect.ValueOf("b"),
				value: reflect.ValueOf(2),
			},
			kv{
				key:   reflect.ValueOf("c"),
				value: reflect.ValueOf(3),
			},
			kv{
				key:   reflect.ValueOf("a"),
				value: reflect.ValueOf(1),
			},
		)
		sort.Sort(kvs)

		if kvs.s[0].key.String() != "a" ||
			kvs.s[1].key.String() != "b" ||
			kvs.s[2].key.String() != "c" {
			t.Errorf("Sort failed: [%v, %v, %v]",
				kvs.s[0].key, kvs.s[1].key, kvs.s[2].key)
		}
	})
}