File: rename_test.go

package info (click to toggle)
golang-github-clbanning-mxj 2.7.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,200 kB
  • sloc: xml: 176; makefile: 4
file content (42 lines) | stat: -rw-r--r-- 867 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
package mxj

import (
	"fmt"
	"testing"
)

func TestRenameKey(t *testing.T) {
	fmt.Println("------------ rename_test.go")
	m := map[string]interface{}{
		"Div": map[string]interface{}{
			"Colour": "blue",
			"Width":  "100%",
		},
	}
	mv := Map(m)
	err := mv.RenameKey("Div.Colour", "Color")
	if err != nil {
		t.Fatal(err)
	}
	values, err := mv.ValuesForPath("Div.Color")
	if len(values) != 1 {
		t.Fatal("didn't add the new key")
	}
	if values[0] != "blue" {
		t.Fatal("value is changed")
	}
	values, err = mv.ValuesForPath("Div.Colour")
	if len(values) > 0 {
		t.Fatal("didn't removed the old key")
	}

	err = mv.RenameKey("not.existing.path", "newname")
	if err == nil {
		t.Fatal("should raise an error on a non existing path")
	}

	err = mv.RenameKey("Div.Color", "Width")
	if err == nil {
		t.Fatal("should raise an error if the newName already exists")
	}
}