File: path_set_test.go

package info (click to toggle)
golang-github-zclconf-go-cty 1.12.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 1,464 kB
  • sloc: makefile: 2
file content (71 lines) | stat: -rw-r--r-- 2,052 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
65
66
67
68
69
70
71
package cty

import (
	"reflect"
	"testing"
)

func TestPathSet(t *testing.T) {
	helloWorld := Path{
		GetAttrStep{Name: "hello"},
		GetAttrStep{Name: "world"},
	}
	s := NewPathSet(helloWorld)

	if got, want := s.Has(helloWorld), true; got != want {
		t.Errorf("set does not have hello.world; should have it")
	}
	if got, want := s.Has(helloWorld[:1]), false; got != want {
		t.Errorf("set has hello; should not have it")
	}

	if got, want := s.List(), []Path{helloWorld}; !reflect.DeepEqual(got, want) {
		t.Errorf("wrong list result\ngot:  %#v\nwant: %#v", got, want)
	}

	fooBarBaz := Path{
		GetAttrStep{Name: "foo"},
		IndexStep{Key: StringVal("bar")},
		GetAttrStep{Name: "baz"},
	}
	s.AddAllSteps(fooBarBaz)
	if got, want := s.Has(helloWorld), true; got != want {
		t.Errorf("set does not have hello.world; should have it")
	}
	if got, want := s.Has(fooBarBaz), true; got != want {
		t.Errorf("set does not have foo['bar'].baz; should have it")
	}
	if got, want := s.Has(fooBarBaz[:2]), true; got != want {
		t.Errorf("set does not have foo['bar']; should have it")
	}
	if got, want := s.Has(fooBarBaz[:1]), true; got != want {
		t.Errorf("set does not have foo; should have it")
	}

	s.Remove(fooBarBaz[:2])
	if got, want := s.Has(fooBarBaz[:2]), false; got != want {
		t.Errorf("set has foo['bar']; should not have it")
	}
	if got, want := s.Has(fooBarBaz), true; got != want {
		t.Errorf("set does not have foo['bar'].baz; should have it")
	}
	if got, want := s.Has(fooBarBaz[:1]), true; got != want {
		t.Errorf("set does not have foo; should have it")
	}

	new := NewPathSet(s.List()...)
	if got, want := s.Equal(new), true; got != want {
		t.Errorf("new set does not equal original; want equal sets")
	}
	new.Remove(helloWorld)
	if got, want := s.Equal(new), false; got != want {
		t.Errorf("new set equals original; want non-equal sets")
	}
	new.Add(Path{
		GetAttrStep{Name: "goodbye"},
		GetAttrStep{Name: "world"},
	})
	if got, want := s.Equal(new), false; got != want {
		t.Errorf("new set equals original; want non-equal sets")
	}
}