github.com/mem/u-root@v2.0.1-0.20181004165302-9b18b4636a33+incompatible/cmds/elvish/eval/builtin_fn_io_test.go (about) 1 package eval 2 3 import ( 4 "testing" 5 6 "github.com/u-root/u-root/cmds/elvish/eval/vals" 7 ) 8 9 func TestBuiltinFnIO(t *testing.T) { 10 runTests(t, []Test{ 11 That(`put foo bar`).Puts("foo", "bar"), 12 13 That(`print [foo bar]`).Prints("[foo bar]"), 14 That(`print foo bar &sep=,`).Prints("foo,bar"), 15 That(`echo [foo bar]`).Prints("[foo bar]\n"), 16 That(`pprint [foo bar]`).Prints("[\n foo\n bar\n]\n"), 17 That(`repr foo bar ['foo bar']`).Prints("foo bar ['foo bar']\n"), 18 19 That(`print "a\nb" | slurp`).Puts("a\nb"), 20 That(`print "a\nb" | from-lines`).Puts("a", "b"), 21 That(`print "a\nb\n" | from-lines`).Puts("a", "b"), 22 That(`echo '{"k": "v", "a": [1, 2]}' '"foo"' | from-json`).Puts( 23 vals.MakeMap(map[interface{}]interface{}{ 24 "k": "v", 25 "a": vals.MakeList("1", "2")}), 26 "foo"), 27 That(`echo 'invalid' | from-json`).Errors(), 28 29 That(`put "l\norem" ipsum | to-lines`).Prints("l\norem\nipsum\n"), 30 That(`put [&k=v &a=[1 2]] foo | to-json`).Prints( 31 `{"a":["1","2"],"k":"v"} 32 "foo" 33 `), 34 }) 35 }