github.com/SagerNet/gvisor@v0.0.0-20210707092255-7731c139d75c/tools/go_generics/rules_tests/template_test.go (about)

     1  // Copyright 2018 The gVisor 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 template_test
    16  
    17  import (
    18  	"math"
    19  	"testing"
    20  )
    21  
    22  func TestMax(t *testing.T) {
    23  	var a int = max(10, 20)
    24  	if a != 20 {
    25  		t.Errorf("Bad result of max, got %v, want %v", a, 20)
    26  	}
    27  }
    28  
    29  func TestIntConst(t *testing.T) {
    30  	var a int = add(10)
    31  	if a != 30 {
    32  		t.Errorf("Bad result of add, got %v, want %v", a, 30)
    33  	}
    34  }
    35  
    36  func TestStrConst(t *testing.T) {
    37  	v := getName()
    38  	if v != "test" {
    39  		t.Errorf("Bad name, got %v, want %v", v, "test")
    40  	}
    41  }
    42  
    43  func TestImport(t *testing.T) {
    44  	v := getMax()
    45  	if v != math.MaxUint64 {
    46  		t.Errorf("Bad max value, got %v, want %v", v, uint64(math.MaxUint64))
    47  	}
    48  }