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

     1  package eval
     2  
     3  import "testing"
     4  
     5  func TestBuiltinFnContainer(t *testing.T) {
     6  	Test(t,
     7  		That(`range 3`).Puts("0", "1", "2"),
     8  		That(`range 1 3`).Puts("1", "2"),
     9  		That(`range 0 10 &step=3`).Puts("0", "3", "6", "9"),
    10  		That(`repeat 4 foo`).Puts("foo", "foo", "foo", "foo"),
    11  		That(`explode [foo bar]`).Puts("foo", "bar"),
    12  
    13  		That(`put (assoc [0] 0 zero)[0]`).Puts("zero"),
    14  		That(`put (assoc [&] k v)[k]`).Puts("v"),
    15  		That(`put (assoc [&k=v] k v2)[k]`).Puts("v2"),
    16  		That(`has-key (dissoc [&k=v] k) k`).Puts(false),
    17  
    18  		That(`put foo bar | all`).Puts("foo", "bar"),
    19  		That(`echo foobar | all`).Prints("foobar\n"),
    20  		That(`{ put foo bar; echo foobar } | all`).Puts(
    21  			"foo", "bar").Prints("foobar\n"),
    22  		That(`range 100 | take 2`).Puts("0", "1"),
    23  		That(`range 100 | drop 98`).Puts("98", "99"),
    24  
    25  		That(`has-key [foo bar] 0`).Puts(true),
    26  		That(`has-key [foo bar] 0:1`).Puts(true),
    27  		That(`has-key [foo bar] 0:20`).Puts(false),
    28  		That(`has-key [&lorem=ipsum &foo=bar] lorem`).Puts(true),
    29  		That(`has-key [&lorem=ipsum &foo=bar] loremwsq`).Puts(false),
    30  		That(`has-value [&lorem=ipsum &foo=bar] lorem`).Puts(false),
    31  		That(`has-value [&lorem=ipsum &foo=bar] bar`).Puts(true),
    32  		That(`has-value [foo bar] bar`).Puts(true),
    33  		That(`has-value [foo bar] badehose`).Puts(false),
    34  		That(`has-value "foo" o`).Puts(true),
    35  		That(`has-value "foo" d`).Puts(false),
    36  
    37  		That(`range 100 | count`).Puts("100"),
    38  		That(`count [(range 100)]`).Puts("100"),
    39  		That(`count 1 2 3`).Errors(),
    40  
    41  		That(`keys [&]`).DoesNothing(),
    42  		That(`keys [&a=foo]`).Puts("a"),
    43  		// Windows does not have an external sort command. Disabled until we have a
    44  		// builtin sort command.
    45  		// That(`keys [&a=foo &b=bar] | each echo | sort | each $put~`).Puts("a", "b"),
    46  	)
    47  }