...

Source file src/cmd/compile/internal/test/testdata/map_test.go

Documentation: cmd/compile/internal/test/testdata

     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  }
    38  

View as plain text