mirror of
https://github.com/go-sylixos/elvish.git
synced 2024-12-13 01:47:51 +08:00
e9b4035896
This will likely become a basic operation in future that can support more types than exceptions, so putting it in the builtin namespace is appropriate. Also remove the exc: module altogether as it contains nothing now. All the introspection features are now implemented as fields of the exception values and the reason values.
57 lines
1.9 KiB
Go
57 lines
1.9 KiB
Go
package eval
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/elves/elvish/pkg/eval/vals"
|
|
)
|
|
|
|
func TestBuiltinFnIO(t *testing.T) {
|
|
Test(t,
|
|
That(`put foo bar`).Puts("foo", "bar"),
|
|
That(`put $nil`).Puts(nil),
|
|
|
|
That("print abcd | read-upto c").Puts("abc"),
|
|
// read-upto does not consume more than needed
|
|
That("print abcd | { read-upto c; slurp }").Puts("abc", "d"),
|
|
// read-upto reads up to EOF
|
|
That("print abcd | read-upto z").Puts("abcd"),
|
|
|
|
That(`print eof-ending | read-line`).Puts("eof-ending"),
|
|
That(`print "lf-ending\n" | read-line`).Puts("lf-ending"),
|
|
That(`print "crlf-ending\r\n" | read-line`).Puts("crlf-ending"),
|
|
That(`print "extra-cr\r\r\n" | read-line`).Puts("extra-cr\r"),
|
|
|
|
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"),
|
|
|
|
// A sanity test that show writes something.
|
|
That(`show ?(fail foo) | !=s (slurp) ''`).Puts(true),
|
|
|
|
// 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"),
|
|
|
|
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"),
|
|
That(`echo '{"k": "v", "a": [1, 2]}' '"foo"' | from-json`).
|
|
Puts(vals.MakeMap("k", "v", "a", vals.MakeList(1.0, 2.0)),
|
|
"foo"),
|
|
That(`echo '[null, "foo"]' | from-json`).Puts(
|
|
vals.MakeList(nil, "foo")),
|
|
That(`echo 'invalid' | from-json`).ThrowsAny(),
|
|
|
|
That(`put "l\norem" ipsum | to-lines`).Prints("l\norem\nipsum\n"),
|
|
That(`put [&k=v &a=[1 2]] foo | to-json`).
|
|
Prints(`{"a":["1","2"],"k":"v"}
|
|
"foo"
|
|
`),
|
|
That(`put [$nil foo] | to-json`).Prints("[null,\"foo\"]\n"),
|
|
)
|
|
}
|