From c7e09a5b63cdd5cec40d190d446c4a35d5c22ca5 Mon Sep 17 00:00:00 2001 From: Stefan Majewsky Date: Thu, 20 Feb 2025 23:33:01 +0100 Subject: refined: demonstrate that Refined types are comparable, but not ordered --- refined/refined_test.go | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'refined') 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 +} -- cgit v1.2.3