2020-09-03 13:48:39 +08:00
|
|
|
package eval_test
|
2017-12-24 07:51:32 +08:00
|
|
|
|
2020-09-03 13:48:39 +08:00
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2021-01-27 09:28:38 +08:00
|
|
|
. "src.elv.sh/pkg/eval/evaltest"
|
2020-09-03 13:48:39 +08:00
|
|
|
)
|
2017-12-24 07:51:32 +08:00
|
|
|
|
|
|
|
func TestNs(t *testing.T) {
|
2018-05-22 08:08:11 +08:00
|
|
|
Test(t,
|
2018-03-03 13:06:03 +08:00
|
|
|
That("kind-of (ns [&])").Puts("ns"),
|
2017-12-24 07:51:32 +08:00
|
|
|
// A Ns is only equal to itself
|
2022-01-03 08:10:40 +08:00
|
|
|
That("var ns = (ns [&]); eq $ns $ns").Puts(true),
|
2018-03-03 13:06:03 +08:00
|
|
|
That("eq (ns [&]) (ns [&])").Puts(false),
|
|
|
|
That("eq (ns [&]) [&]").Puts(false),
|
2018-03-17 02:17:04 +08:00
|
|
|
|
2022-01-03 08:10:40 +08:00
|
|
|
That("var ns: = (ns [&a=b &x=y]); put $ns:a").Puts("b"),
|
|
|
|
That("var ns: = (ns [&a=b &x=y]); put $ns:[a]").Puts("b"),
|
2018-03-17 02:17:04 +08:00
|
|
|
// Test multi-key ns when sorting is possible
|
|
|
|
That(`keys (ns [&a=b])`).Puts("a"),
|
|
|
|
That(`has-key (ns [&a=b &x=y]) a`).Puts(true),
|
|
|
|
That(`has-key (ns [&a=b &x=y]) b`).Puts(false),
|
2018-05-22 08:08:11 +08:00
|
|
|
)
|
2017-12-24 07:51:32 +08:00
|
|
|
}
|
2021-01-09 08:41:42 +08:00
|
|
|
|
|
|
|
func TestBuiltinFunctionsReadOnly(t *testing.T) {
|
|
|
|
Test(t,
|
2022-10-02 12:01:39 +08:00
|
|
|
That("set return~ = { }").DoesNotCompile("variable $return~ is read-only"),
|
2021-01-09 08:41:42 +08:00
|
|
|
)
|
|
|
|
}
|