github.com/gagliardetto/golang-go@v0.0.0-20201020153340-53909ea70814/cmd/compile/internal/gc/testdata/map_test.go (about)

     1  // Copyright 2015 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  // map.go tests map operations.
     6  package main
     7  
     8  import "testing"
     9  
    10  //go:noinline
    11  func lenMap_ssa(v map[int]int) int {
    12  	return len(v)
    13  }
    14  
    15  func testLenMap(t *testing.T) {
    16  
    17  	v := make(map[int]int)
    18  	v[0] = 0
    19  	v[1] = 0
    20  	v[2] = 0
    21  
    22  	if want, got := 3, lenMap_ssa(v); got != want {
    23  		t.Errorf("expected len(map) = %d, got %d", want, got)
    24  	}
    25  }
    26  
    27  func testLenNilMap(t *testing.T) {
    28  
    29  	var v map[int]int
    30  	if want, got := 0, lenMap_ssa(v); got != want {
    31  		t.Errorf("expected len(nil) = %d, got %d", want, got)
    32  	}
    33  }
    34  func TestMap(t *testing.T) {
    35  	testLenMap(t)
    36  	testLenNilMap(t)
    37  }