github.com/gagliardetto/golang-go@v0.0.0-20201020153340-53909ea70814/cmd/compile/internal/gc/testdata/closure_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  // closure.go tests closure operations.
     6  package main
     7  
     8  import "testing"
     9  
    10  //go:noinline
    11  func testCFunc_ssa() int {
    12  	a := 0
    13  	b := func() {
    14  		switch {
    15  		}
    16  		a++
    17  	}
    18  	b()
    19  	b()
    20  	return a
    21  }
    22  
    23  func testCFunc(t *testing.T) {
    24  	if want, got := 2, testCFunc_ssa(); got != want {
    25  		t.Errorf("expected %d, got %d", want, got)
    26  	}
    27  }
    28  
    29  // TestClosure tests closure related behavior.
    30  func TestClosure(t *testing.T) {
    31  	testCFunc(t)
    32  }