| 1 |
// Copyright 2021 The Go Authors. All rights reserved. |
| 2 |
// Use of this source code is governed by a BSD-style |
| 3 |
// license that can be found in the LICENSE file. |
| 4 |
|
| 5 |
package main |
| 6 |
|
| 7 |
import ( |
| 8 |
"./a" |
| 9 |
"fmt" |
| 10 |
) |
| 11 |
|
| 12 |
func main() { |
| 13 |
var v1 a.Value[int] |
| 14 |
|
| 15 |
a.Set(&v1, 1) |
| 16 |
if got, want := a.Get(&v1), 1; got != want { |
| 17 |
panic(fmt.Sprintf("Get() == %d, want %d", got, want)) |
| 18 |
} |
| 19 |
v1.Set(2) |
| 20 |
if got, want := v1.Get(), 2; got != want { |
| 21 |
panic(fmt.Sprintf("Get() == %d, want %d", got, want)) |
| 22 |
} |
| 23 |
v1p := new(a.Value[int]) |
| 24 |
a.Set(v1p, 3) |
| 25 |
if got, want := a.Get(v1p), 3; got != want { |
| 26 |
panic(fmt.Sprintf("Get() == %d, want %d", got, want)) |
| 27 |
} |
| 28 |
|
| 29 |
v1p.Set(4) |
| 30 |
if got, want := v1p.Get(), 4; got != want { |
| 31 |
panic(fmt.Sprintf("Get() == %d, want %d", got, want)) |
| 32 |
} |
| 33 |
|
| 34 |
var v2 a.Value[string] |
| 35 |
a.Set(&v2, "a") |
| 36 |
if got, want := a.Get(&v2), "a"; got != want { |
| 37 |
panic(fmt.Sprintf("Get() == %q, want %q", got, want)) |
| 38 |
} |
| 39 |
|
| 40 |
v2.Set("b") |
| 41 |
if got, want := a.Get(&v2), "b"; got != want { |
| 42 |
panic(fmt.Sprintf("Get() == %q, want %q", got, want)) |
| 43 |
} |
| 44 |
|
| 45 |
v2p := new(a.Value[string]) |
| 46 |
a.Set(v2p, "c") |
| 47 |
if got, want := a.Get(v2p), "c"; got != want { |
| 48 |
panic(fmt.Sprintf("Get() == %d, want %d", got, want)) |
| 49 |
} |
| 50 |
|
| 51 |
v2p.Set("d") |
| 52 |
if got, want := v2p.Get(), "d"; got != want { |
| 53 |
panic(fmt.Sprintf("Get() == %d, want %d", got, want)) |
| 54 |
} |
| 55 |
} |