github.com/elves/Elvish@v0.12.0/eval/closure_test.go (about)

     1  package eval
     2  
     3  import "testing"
     4  
     5  func TestClosure(t *testing.T) {
     6  	Test(t,
     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]").
    22  			Puts("put { body }[src][code]"),
    23  	)
    24  }