this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

internal/core/adt: implement BuiltinValidator equality

Two BuiltinValidator values are equal when they
wrap the same *Builtin (pointer identity, since
builtins are singletons) and have pairwise-equal
Args. Previously the case was empty, making all
BuiltinValidator comparisons return false.

Signed-off-by: Marcel van Lohuizen <mpvl@gmail.com>
Change-Id: Id1de9f19ebee699abed4c53f5e4f13bbc95d5324
Reviewed-on: https://cue.gerrithub.io/c/cue-lang/cue/+/1234638
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>

+101
+11
internal/core/adt/equality.go
··· 197 197 return true 198 198 199 199 case *BuiltinValidator: 200 + if y, ok := w.(*BuiltinValidator); ok { 201 + if x.Builtin != y.Builtin || len(x.Args) != len(y.Args) { 202 + return false 203 + } 204 + for i, xa := range x.Args { 205 + if !Equal(ctx, xa, y.Args[i], flags) { 206 + return false 207 + } 208 + } 209 + return true 210 + } 200 211 } 201 212 202 213 return false
+90
internal/core/adt/equality_test.go
··· 1 + // Copyright 2026 CUE 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 + package adt 16 + 17 + import ( 18 + "testing" 19 + ) 20 + 21 + // TestEqualTerminal_BuiltinValidator checks equality of BuiltinValidator values. 22 + func TestEqualTerminal_BuiltinValidator(t *testing.T) { 23 + b1 := &Builtin{Name: "MaxFields"} 24 + b2 := &Builtin{Name: "MinFields"} 25 + 26 + // Use BasicType values as stand-in args: BasicType equality is purely 27 + // structural (Kind comparison), so it exercises the recursive Equal call 28 + // without requiring a fully-wired OpContext. 29 + intArg := &BasicType{K: IntKind} 30 + strArg := &BasicType{K: StringKind} 31 + 32 + tests := []struct { 33 + name string 34 + v, w Value 35 + want bool 36 + }{ 37 + { 38 + name: "same builtin same args equal", 39 + v: &BuiltinValidator{Builtin: b1, Args: []Value{intArg}}, 40 + w: &BuiltinValidator{Builtin: b1, Args: []Value{intArg}}, 41 + want: true, 42 + }, 43 + { 44 + name: "same builtin different args not equal", 45 + v: &BuiltinValidator{Builtin: b1, Args: []Value{intArg}}, 46 + w: &BuiltinValidator{Builtin: b1, Args: []Value{strArg}}, 47 + want: false, 48 + }, 49 + { 50 + name: "different builtins same args not equal", 51 + v: &BuiltinValidator{Builtin: b1, Args: []Value{intArg}}, 52 + w: &BuiltinValidator{Builtin: b2, Args: []Value{intArg}}, 53 + want: false, 54 + }, 55 + { 56 + name: "different arg counts not equal", 57 + v: &BuiltinValidator{Builtin: b1, Args: []Value{intArg}}, 58 + w: &BuiltinValidator{Builtin: b1, Args: []Value{intArg, strArg}}, 59 + want: false, 60 + }, 61 + { 62 + name: "no-arg validators same builtin equal", 63 + v: &BuiltinValidator{Builtin: b1}, 64 + w: &BuiltinValidator{Builtin: b1}, 65 + want: true, 66 + }, 67 + { 68 + name: "no-arg validators different builtins not equal", 69 + v: &BuiltinValidator{Builtin: b1}, 70 + w: &BuiltinValidator{Builtin: b2}, 71 + want: false, 72 + }, 73 + { 74 + name: "validator vs non-validator not equal", 75 + v: &BuiltinValidator{Builtin: b1, Args: []Value{intArg}}, 76 + w: &BasicType{K: StructKind}, 77 + want: false, 78 + }, 79 + } 80 + 81 + ctx := &OpContext{} 82 + for _, tt := range tests { 83 + t.Run(tt.name, func(t *testing.T) { 84 + got := equalTerminal(ctx, tt.v, tt.w, 0) 85 + if got != tt.want { 86 + t.Errorf("equalTerminal(%T, %T) = %v, want %v", tt.v, tt.w, got, tt.want) 87 + } 88 + }) 89 + } 90 + }