Commit Graph

19 Commits

Author SHA1 Message Date
Qi Xiao
6e36058d0a pkg/tt: Improve API.
- Use reflection to derive function name.

- Take test cases as variadic arguments, instead of requiring them to be wrapped
  in a Table.

- Support naming test cases.

- Run test cases as subtests with t.Run.
2024-01-11 15:42:43 +00:00
Qi Xiao
973e8e76e2 pkg/eval/vals: Avoid the .Name hack for allowing using $nil for callable.
Also add a test.
2022-11-20 19:31:07 +00:00
Kurtis Rader
71cd3835bc Don't dot import pkg/tt
Qualified imports of pkg/tt outnumber unqualified (27 to 24). Improve
consistency, and clarity, by changing the dot (unqualified) imports of
that package symbols to qualified.
2022-06-04 23:39:19 +01:00
Qi Xiao
51e4d97568 interface{} -> any now that Elvish requires Go 1.18. 2022-03-20 16:17:19 +00:00
Qi Xiao
5f1673c6c4 Use go-cmp to report unexpected test results.
cmp.Diff panics when comparing a struct that has unexported fields and no String
or Equal method, so change some structs to either export all their fields or
have an Equal method.

This fixes #1136.
2022-03-11 22:49:32 +00:00
Qi Xiao
de3ac3166d Add a new conversion utility vals.ScanMapToGo. 2021-12-31 18:00:36 +00:00
Qi Xiao
7da15f48fb pkg/eval/vals: Add more conversion helpers.
Also update the comment in conversion.go.
2021-12-29 22:32:25 +00:00
Kurtis Rader
87656c99fa Replace AnyError in tests with a specific error
The `AnyError` placeholder error can cause tests to succeed for errors
other than what was expected. That is, the use of `AnyError` can mask
bugs in a unit test. So replace it with the specific error, or error type,
the test expects to be raised.

This does not remove the anyError structure because it is used in
the TestCase.DoesNotCompile() method. To keep the size of this change
as small as possible I want to defer updating that use to a separate
change. However, remove the public AnyError var so future test writers
don't attempt to use it.
2021-12-13 01:08:24 +00:00
Qi Xiao
ab88de7c15 Fix ScanToGo's error message when ptr points to an interface.
When the destination to scan into is an interface, its zero value is simply a
nil interface, losing the information of the original type and resulting in
error messages like "need nil, got $actual-type".

ScanToGo now handles this case specifically, and uses the string representation
of the interface type in the error message.

Before:

~> ns []
Exception: wrong type of argument 0: wrong type: need nil, got list
~> var x~ = x
Exception: wrong type: need nil, got string

After:

~> ns []
Exception: wrong type of argument 0: wrong type: need !!hashmap.Map, got list
~> var x~ = x
Exception: wrong type: need !!eval.Callable, got string

This is still not ideal, since the "need" type is not given as an Elvish "kind",
but it's much less confusing than than old "need nil" messages.

This fixes #715.
2021-12-05 23:49:49 +00:00
Qi Xiao
b36c9bf513 pkg/eval/vals: Improve coverage. 2021-09-11 02:54:34 +01:00
Qi Xiao
320b77ea1b pkg/eval/vals: Convert any number type to float64.
This addresses #1300.
2021-05-09 14:32:50 +01:00
Qi Xiao
5c643181a4 Cleanup, docs and tests. 2021-04-05 20:48:22 +01:00
Qi Xiao
da67ba8a4a Use machine word (int) instead of int64 for fixnum. 2021-04-04 13:37:38 +01:00
Qi Xiao
4612b58759 Support exact integer and rational numbers. 2021-04-04 00:58:53 +01:00
Qi Xiao
196eea21d4 Change module import path to src.elv.sh 2021-01-27 01:30:25 +00:00
Qi Xiao
b8513f75b3 pkg/eval/vals: Move the "any" matcher to pkg/tt. 2020-01-06 23:19:00 +00:00
Qi Xiao
843e7f3d99 pkg/eval/vals: Do dot-imports from pkg/tt. 2020-01-06 23:14:51 +00:00
Qi Xiao
a8950535eb pkg/eval/vals: Always return structured errors.
Also match errors accurately in tests.
2020-01-06 23:02:26 +00:00
Qi Xiao
e45fdf7228 Move all libraries to new pkg/. 2019-12-23 20:00:59 +00:00