Commit Graph

106 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
cf9ec15fa6 Implement os:chmod.
This supersedes #1730.
2024-01-03 22:02:57 +00:00
Qi Xiao
1c0cffbfed pkg/eval/vals/cmp.go: Use compareBuiltin for strings too. 2023-08-25 22:18:05 -04:00
Qi Xiao
a15f0f7d0a pkg/eval/vals: Test that structmaps are treated like maps by CmpTotal. 2023-08-22 22:07:26 -04:00
Qi Xiao
4ceb91901e pkg/eval/vals: Pretend structmaps are maps in typeOf too. 2023-08-22 21:56:02 -04:00
Qi Xiao
f240df4846 pkg/eval/vals: Add utils {Int64,Uint64}ToNum. 2023-08-13 22:46:22 -04:00
Qi Xiao
6992c0b693 Make pseudomaps print like [^tag &key=value].
Also make file:pipe output a struct map rather than a pseudomap.
2023-07-17 23:41:43 +01:00
Qi Xiao
96752afa4d Make struct maps indistinguishable from maps to Elvish code.
Struct map is a mechanism to let Go code expose simple structs to Elvish code.
The difference between struct maps and maps is convenience for Go code; they
also have different performance characteristics, but since struct maps are
always quite small, the difference is not meaningful for Elvish's use cases.

As a result, there is no good reason that Elvish code needs to be aware of the
difference between struct maps and normal maps. Making them indistinguishable to
Elvish code simplifies the language.

This commit does the following:

- Change Equal, Hash, Kind and Repr to treat struct maps like maps.

- Change Assoc and Dissoc to "promote" struct maps to maps.

- Remove the custom Repr method of parse.Source.

- Update documentation to reflect this change.
2023-07-14 23:57:38 +01:00
Qi Xiao
900cc52b05 Fix the hash code of maps. 2023-07-14 22:01:32 +01:00
Qi Xiao
2fe4512556 pkg/eval/vals: Make Repr sort map keys before printing.
This addresses #1495.
2023-05-20 10:52:52 +01:00
Qi Xiao
7c0c3eb82d pkg/eval/vals: Correct the godoc of Cmp. 2023-05-20 10:20:48 +01:00
Qi Xiao
3f4bbff9c5 pkg/eval: Add option for total order to the order and compare commands.
The same code will be used to sort map keys when printing maps.

This addresses #1495.
2023-05-18 23:21:18 +01:00
Qi Xiao
25e27d6bb6 pkg/eval/vals: Make Cmp(a, b) return CmpEqual if Equal(a, b).
Also match the order of branches in Cmp and Equal.
2023-05-18 10:45:42 +01:00
Qi Xiao
1e249ed7fb pkg/eval.cmp -> pkg/eval/vals.Cmp. 2023-05-18 10:31:31 +01:00
dunsany
9a26d6c645
Various has-key fixes (#1647)
* Correct slice indexing convention in code comment

A colon is not supported.

* Add more key slices tests

* Unify `has-key` tests with those from `pkg/eval/vals/has_key_test.go`

* Fix key slice format in documentation

Fixes #1646.

* Fix missing bracket

* Fix indexing

* Add more key slices `has-key` tests

* Fix `has-key` test expected value
2023-02-26 20:49:31 +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
306e2d7b8d
Issue 1570 order key option (#1616)
* Allow $nil for Callable options

Related #1570

* Add a `&key` option to the `order` command.

Resolves #1570

Co-authored-by: Qi Xiao <xiaq@users.noreply.github.com>
2022-11-20 19:10:19 +00:00
Kurtis Rader
c6e10f12a2 Some minor documentation fixes
Mostly elimination of duplicated words but also a few other fixes such
as the output of commands such as `%`.
2022-08-29 12:04:59 +01:00
Qi Xiao
2e788c846d Run gofmt.
https://tip.golang.org/doc/go1.19#go-doc
2022-08-07 22:30:11 +01:00
Qi Xiao
e0292dd298 Get coverage on IsStructMap methods with a hack. 2022-06-20 22:08:19 +01:00
Qi Xiao
4afbb71c07 Move pkg/testutil/must.go to a new pkg/must. 2022-06-20 20:29:14 +01:00
Qi Xiao
d48b6f1843 pkg/eval/vals: Replace MakeListFromStrings with a generic MakeListSlice. 2022-06-17 16:50:38 +01: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
Kurtis Rader
7bae8f2df7 Correctly handle [..=-1] list indexing
Fixes #1518
2022-05-22 20:38:16 +01:00
Qi Xiao
51e4d97568 interface{} -> any now that Elvish requires Go 1.18. 2022-03-20 16:17:19 +00:00
Qi Xiao
f7cb556d9b Require Go 1.18.
- Run "go fix" to remove legacy build tags

- Use staticcheck@master until it has a release that supports Go 1.18

- Turn off autocrlf for Windows tasks
2022-03-20 15:28:23 +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
59459793e3 pkg/persistent: Cons -> Conj.
Cons was a misnomer for the operation of adding an element at the end of a
vector. Follow Clojure's naming here and call this operation Conj.
2022-01-05 22:34:55 +00:00
Qi Xiao
ae91cf7b1c Fix build on Go 1.16. 2021-12-31 21:13:41 +00:00
Qi Xiao
097e32b375 pkg/eval/vals: Add ReprPlain, Repr without pretty-printing.
Also de-export NoPretty now that it is no longer needed.
2021-12-31 21:05:07 +00:00
Qi Xiao
de3ac3166d Add a new conversion utility vals.ScanMapToGo. 2021-12-31 18:00:36 +00:00
Qi Xiao
de5f0e0d32 Add new util vals.MakeListFromStrings. 2021-12-30 13:09:18 +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
Qi Xiao
046e02869d pkg/eval/vals: Document the use of 0 in UnifyNums. 2021-12-17 10:52:44 +00:00
Qi Xiao
82d92ad467 pkg/eval/vals: De-export the Eq util and move into a _test file. 2021-12-16 23:55:24 +00:00
Qi Xiao
089752147a Fixup for #1447. 2021-12-13 01:23:14 +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
fc66ad1d10 pkg/eval/vals: Remove support for the legacy a:b slice syntax.
This syntax was deprecated in 0.15.0 and no longer documented since then.
2021-10-22 17:41:09 +01:00
Qi Xiao
c07c26b4c7 pkg/eval/vals: Remove a duplicate test. 2021-09-11 13:57:53 +01:00
Qi Xiao
8c8a80ff52 Fix staticcheck error. 2021-09-11 02:58:54 +01:00
Qi Xiao
b36c9bf513 pkg/eval/vals: Improve coverage. 2021-09-11 02:54:34 +01:00
Shengjing Zhu
5724ec4c47 Fix typos and add codespell to CI 2021-08-22 23:07:34 +01:00
Qi Xiao
d15218f11e Fixup for #1354. 2021-07-07 23:25:01 +01:00
Kurtis Rader
85c499f110 Lint cleanups
This change addresses issues reported by the `staticcheck` tool and a
couple reported by the `golint` tool. It also adds missing issue links
to a couple of entries in the release notes. This change deliberately
does not address these warnings since it is unclear whether the project
owner would prefer to suppress or address them:

    pkg/store/cmd.go:8:2: should not use dot imports (ST1001)
    pkg/store/db_store.go:10:2: should not use dot imports (ST1001)
    pkg/store/dir.go:8:2: should not use dot imports (ST1001)
2021-07-07 23:21:02 +01:00
Qi Xiao
a12e1be189 Implement Hash for *big.Int and *big.Rat. 2021-06-27 17:01:12 +01:00
Qi Xiao
4afab8804b Fixup for #1342. 2021-06-27 16:41:07 +01:00
Kurtis Rader
3da541c719 Other float64 cases that should be generalized
While pondering issue #1340 I looked at the other `case float64:`
blocks. This change generalizes the few places that need it.

Fixes #1340
2021-06-27 16:32:38 +01:00
Qi Xiao
3b7c18c6c5 pkg/eval/vals: Improve test coverage of index.go and iterate_keys.go.
This addresses #1234.
2021-06-15 19:22:58 +01:00
Qi Xiao
2e9e0289cc Make the kind of int, *big.Int and *big.Rat "number". 2021-06-15 19:22:38 +01:00