File: alias_test.go

package info (click to toggle)
golang-github-gopherjs-gopherjs 0.0~git20170927.0.4152256-7
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 1,468 kB
  • sloc: cpp: 91; makefile: 7
file content (77 lines) | stat: -rw-r--r-- 933 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
72
73
74
75
76
77
package tests

import (
	"testing"
)

type foo struct {
	a int
}

func Test1(t *testing.T) {
	calls := 0
	bar := func() *foo {
		calls++
		return &foo{42}
	}
	q := &bar().a
	if calls != 1 {
		t.Error("Should've been a call")
	}
	*q = 40
	if calls != 1 {
		t.Error("Wrong number of calls: ", calls, ", should be 1")
	}
	if *q != 40 {
		t.Error("*q != 40")
	}
}

func Test2(t *testing.T) {
	f := foo{}
	p := &f.a
	f = foo{}
	f.a = 4
	if *p != 4 {
		t.Error("*p != 4")
	}
}

func Test3(t *testing.T) {
	f := foo{}
	p := &f
	f = foo{4}
	if p.a != 4 {
		t.Error("p.a != 4")
	}
}

func Test4(t *testing.T) {
	f := struct {
		a struct {
			b int
		}
	}{}
	p := &f.a
	q := &p.b
	r := &(*p).b
	*r = 4
	p = nil
	if *r != 4 {
		t.Error("*r != 4")
	}
	if *q != 4 {
		t.Error("*q != 4")
	}
}

func Test5(t *testing.T) {
	f := struct {
		a [3]int
	}{[3]int{6, 6, 6}}
	s := f.a[:]
	f.a = [3]int{4, 4, 4}
	if s[1] != 4 {
		t.Error("s[1] != 4")
	}
}