2017-12-17 13:20:03 +08:00
|
|
|
package eval
|
|
|
|
|
2018-01-01 04:31:45 +08:00
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2018-02-15 17:14:05 +08:00
|
|
|
"github.com/elves/elvish/eval/vals"
|
2018-01-01 04:31:45 +08:00
|
|
|
)
|
2017-12-22 04:49:14 +08:00
|
|
|
|
|
|
|
func TestBuiltinFnIO(t *testing.T) {
|
2018-05-22 08:08:11 +08:00
|
|
|
Test(t,
|
2018-03-03 14:08:09 +08:00
|
|
|
That(`put foo bar`).Puts("foo", "bar"),
|
2019-04-10 05:47:48 +08:00
|
|
|
That(`put $nil`).Puts(nil),
|
2017-12-17 13:20:03 +08:00
|
|
|
|
2018-03-03 14:08:09 +08:00
|
|
|
That(`print [foo bar]`).Prints("[foo bar]"),
|
|
|
|
That(`print foo bar &sep=,`).Prints("foo,bar"),
|
|
|
|
That(`echo [foo bar]`).Prints("[foo bar]\n"),
|
|
|
|
That(`pprint [foo bar]`).Prints("[\n foo\n bar\n]\n"),
|
|
|
|
That(`repr foo bar ['foo bar']`).Prints("foo bar ['foo bar']\n"),
|
2017-12-17 13:20:03 +08:00
|
|
|
|
2018-12-16 18:40:10 +08:00
|
|
|
// Baseline for only-{bytes,values}
|
|
|
|
That(`{ print bytes; put values }`).Prints("bytes").Puts("values"),
|
|
|
|
That(`{ print bytes; put values } | only-bytes`).Prints("bytes").Puts(),
|
|
|
|
That(`{ print bytes; put values } | only-values`).Prints("").Puts("values"),
|
|
|
|
|
2018-03-03 14:08:09 +08:00
|
|
|
That(`print "a\nb" | slurp`).Puts("a\nb"),
|
|
|
|
That(`print "a\nb" | from-lines`).Puts("a", "b"),
|
|
|
|
That(`print "a\nb\n" | from-lines`).Puts("a", "b"),
|
2018-07-06 08:32:42 +08:00
|
|
|
That(`echo '{"k": "v", "a": [1, 2]}' '"foo"' | from-json`).
|
2019-04-20 01:26:27 +08:00
|
|
|
Puts(vals.MakeMap("k", "v", "a", vals.MakeList(1.0, 2.0)),
|
2018-07-06 08:32:42 +08:00
|
|
|
"foo"),
|
2019-04-08 05:54:28 +08:00
|
|
|
That(`echo '[null, "foo"]' | from-json`).Puts(
|
|
|
|
vals.MakeList(nil, "foo")),
|
2018-03-03 14:08:09 +08:00
|
|
|
That(`echo 'invalid' | from-json`).Errors(),
|
2017-12-17 13:20:03 +08:00
|
|
|
|
2018-03-03 14:08:09 +08:00
|
|
|
That(`put "l\norem" ipsum | to-lines`).Prints("l\norem\nipsum\n"),
|
2018-07-06 08:32:42 +08:00
|
|
|
That(`put [&k=v &a=[1 2]] foo | to-json`).
|
|
|
|
Prints(`{"a":["1","2"],"k":"v"}
|
2017-12-17 13:20:03 +08:00
|
|
|
"foo"
|
2018-03-03 14:08:09 +08:00
|
|
|
`),
|
2019-04-08 05:54:28 +08:00
|
|
|
That(`put [$nil foo] | to-json`).Prints("[null,\"foo\"]\n"),
|
2018-05-22 08:08:11 +08:00
|
|
|
)
|
2017-12-17 13:20:03 +08:00
|
|
|
}
|