Source file src/simd/_gen/unify/value_test.go

     1  // Copyright 2025 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 unify
     6  
     7  import (
     8  	"reflect"
     9  	"slices"
    10  	"testing"
    11  )
    12  
    13  func ExampleClosure_All_tuple() {
    14  	v := mustParse(`
    15  - !sum [1, 2]
    16  - !sum [3, 4]
    17  `)
    18  	printYaml(slices.Collect(v.All()))
    19  
    20  	// Output:
    21  	// - [1, 3]
    22  	// - [1, 4]
    23  	// - [2, 3]
    24  	// - [2, 4]
    25  }
    26  
    27  func ExampleClosure_All_def() {
    28  	v := mustParse(`
    29  a: !sum [1, 2]
    30  b: !sum [3, 4]
    31  c: 5
    32  `)
    33  	printYaml(slices.Collect(v.All()))
    34  
    35  	// Output:
    36  	// - {a: 1, b: 3, c: 5}
    37  	// - {a: 1, b: 4, c: 5}
    38  	// - {a: 2, b: 3, c: 5}
    39  	// - {a: 2, b: 4, c: 5}
    40  }
    41  
    42  func checkDecode[T any](t *testing.T, got *Value, want T) {
    43  	var gotT T
    44  	if err := got.Decode(&gotT); err != nil {
    45  		t.Fatalf("Decode failed: %v", err)
    46  	}
    47  	if !reflect.DeepEqual(&gotT, &want) {
    48  		t.Fatalf("got:\n%s\nwant:\n%s", prettyYaml(gotT), prettyYaml(want))
    49  	}
    50  }
    51  

View as plain text