|
| 1 | +// Copyright 2025 The Skycfg Authors. |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | +// |
| 15 | +// SPDX-License-Identifier: Apache-2.0 |
| 16 | + |
| 17 | +//go:build go1.23 |
| 18 | + |
| 19 | +package protomodule |
| 20 | + |
| 21 | +import ( |
| 22 | + "maps" |
| 23 | + "reflect" |
| 24 | + "slices" |
| 25 | + "testing" |
| 26 | + |
| 27 | + "go.starlark.net/starlark" |
| 28 | + |
| 29 | + pb "github.com/stripe/skycfg/internal/test_proto" |
| 30 | +) |
| 31 | + |
| 32 | +func TestListType_Elements(t *testing.T) { |
| 33 | + msg := (&pb.MessageV3{}).ProtoReflect().Descriptor() |
| 34 | + listFieldDesc := msg.Fields().ByName("r_string") |
| 35 | + |
| 36 | + rep := newProtoRepeated(listFieldDesc) |
| 37 | + rep.Append(starlark.String("a")) |
| 38 | + rep.Append(starlark.String("b")) |
| 39 | + |
| 40 | + got := slices.Collect(rep.Elements()) |
| 41 | + want := []starlark.Value{starlark.String("a"), starlark.String("b")} |
| 42 | + if !reflect.DeepEqual(want, got) { |
| 43 | + t.Fatalf("wanted: %v\ngot : %v", want, got) |
| 44 | + } |
| 45 | +} |
| 46 | + |
| 47 | +func TestMapType_Entries(t *testing.T) { |
| 48 | + msg := (&pb.MessageV3{}).ProtoReflect().Descriptor() |
| 49 | + mapFieldDesc := msg.Fields().ByName("map_string") |
| 50 | + |
| 51 | + pmap := newProtoMap(mapFieldDesc.MapKey(), mapFieldDesc.MapValue()) |
| 52 | + pmap.SetKey(starlark.String("a"), starlark.String("1")) |
| 53 | + pmap.SetKey(starlark.String("b"), starlark.String("2")) |
| 54 | + |
| 55 | + got := maps.Collect(pmap.Entries()) |
| 56 | + want := map[starlark.Value]starlark.Value{ |
| 57 | + starlark.String("a"): starlark.String("1"), |
| 58 | + starlark.String("b"): starlark.String("2"), |
| 59 | + } |
| 60 | + if !reflect.DeepEqual(want, got) { |
| 61 | + t.Fatalf("wanted: %v\ngot : %v", want, got) |
| 62 | + } |
| 63 | +} |
0 commit comments