github.com/xyproto/u-root@v6.0.1-0.20200302025726-5528e0c77a3c+incompatible/cmds/core/elvish/eval/closure_test.go (about)

     1  package eval
     2  
     3  import "testing"
     4  
     5  func TestClosure(t *testing.T) {
     6  	runTests(t, []Test{
     7  		That("kind-of { }").Puts("fn"),
     8  		That("eq { } { }").Puts(false),
     9  		That("x = { }; put [&$x= foo][$x]").Puts("foo"),
    10  		That("[x]{ } a b").Errors(),
    11  		That("[x y]{ } a").Errors(),
    12  		That("[x y @rest]{ } a").Errors(),
    13  		That("[]{ } &k=v").Errors(),
    14  
    15  		That("explode [a b]{ }[arg-names]").Puts("a", "b"),
    16  		That("put [@r]{ }[rest-arg]").Puts("r"),
    17  		That("explode [&opt=def]{ }[opt-names]").Puts("opt"),
    18  		That("explode [&opt=def]{ }[opt-defaults]").Puts("def"),
    19  		That("put { body }[body]").Puts(" body "),
    20  		That("put [x @y]{ body }[def]").Puts("[x @y]{ body }"),
    21  		That("put { body }[src][code]").Puts(
    22  			"put { body }[src][code]"),
    23  	})
    24  }