github.com/FenixAra/go@v0.0.0-20170127160404-96ea0918e670/src/cmd/compile/internal/gc/testdata/map.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_ssa.go tests map operations. 6 package main 7 8 import "fmt" 9 10 var failed = false 11 12 //go:noinline 13 func lenMap_ssa(v map[int]int) int { 14 return len(v) 15 } 16 17 func testLenMap() { 18 19 v := make(map[int]int) 20 v[0] = 0 21 v[1] = 0 22 v[2] = 0 23 24 if want, got := 3, lenMap_ssa(v); got != want { 25 fmt.Printf("expected len(map) = %d, got %d", want, got) 26 failed = true 27 } 28 } 29 30 func testLenNilMap() { 31 32 var v map[int]int 33 if want, got := 0, lenMap_ssa(v); got != want { 34 fmt.Printf("expected len(nil) = %d, got %d", want, got) 35 failed = true 36 } 37 } 38 func main() { 39 testLenMap() 40 testLenNilMap() 41 42 if failed { 43 panic("failed") 44 } 45 }