diff options
| author | Stefan Majewsky <majewsky@gmx.net> | 2025-02-20 23:33:01 +0100 |
|---|---|---|
| committer | Stefan Majewsky <majewsky@gmx.net> | 2025-02-20 23:33:24 +0100 |
| commit | c7e09a5b63cdd5cec40d190d446c4a35d5c22ca5 (patch) | |
| tree | e8c30e3e0ff223239ec4e4da712b19f4857ff54e | |
| parent | d6c1edaa1b8176b49c1f776567a8b9b5e179dbf1 (diff) | |
| download | go-gg-c7e09a5b63cdd5cec40d190d446c4a35d5c22ca5.tar.gz | |
refined: demonstrate that Refined types are comparable, but not ordered
| -rw-r--r-- | refined/refined_test.go | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/refined/refined_test.go b/refined/refined_test.go index 118eef6..deda5ee 100644 --- a/refined/refined_test.go +++ b/refined/refined_test.go @@ -38,9 +38,6 @@ func (AccountName) Build(v refined.Prevalue[AccountName, string]) AccountName { return AccountName{refined.Build(v)} } -// Example for how to use Literal() to declare a pseudo-const value. -var reservedAccountName = refined.Literal[AccountName]("reserved") - // Example for how to access the contained value in computations. func (n AccountName) ContainerName() string { return fmt.Sprintf("container-for-%s", n.Raw()) @@ -59,3 +56,17 @@ func TestAccountName(t *testing.T) { err = json.Unmarshal(buf2, &d2) AssertEqual(t, err.Error(), "foo") } + +func TestRefinedMapKeys(t *testing.T) { + var ( + foo = refined.Literal[AccountName]("foo") + bar = refined.Literal[AccountName]("bar") + ) + m := map[AccountName]int{ + foo: 3, + bar: 1, + } + // TODO: AccountName is not an ordered type; we might need stuff like slices.Sorted() in package refined + // AssertEqual(slices.Sorted(maps.Keys(m)), []AccountName{bar, foo}) + _ = m +} |
