Commit Graph

715 Commits

Author SHA1 Message Date
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
62795d907d Format the rule used by compare as an ordered list. 2023-08-22 21:20:46 -04:00
Qi Xiao
fbde7b1208 Fix name of &total option for the order command. 2023-08-22 21:12:52 -04:00
Qi Xiao
e5e26f1e51 Test and document NO_COLOR support. 2023-08-21 00:28:51 -04:00
Qi Xiao
607fa68aca Implement os:stat.
Time fields are omitted for now; they will be added when there's a proper Elvish
binding for time.Time.

This addresses #1659.
2023-08-21 00:05:05 -04:00
Qi Xiao
65bc9580cb pkg/eval/evaltest: Print value diffs by converting them with Repr first.
The options to go-cmp doesn't seem to actually transform lists and maps
properly, so use the string representation for diffs now.
2023-08-20 23:30:30 -04:00
Qi Xiao
95ba078ff6 pkg/eval/evaltest: Implement value matchers with interface. 2023-08-13 23:20:54 -04:00
Qi Xiao
f240df4846 pkg/eval/vals: Add utils {Int64,Uint64}ToNum. 2023-08-13 22:46:22 -04:00
Qi Xiao
e847e677fe Move a lot of symbols from path: to os:.
Most of the symbols moved originate from Go's os package. However,
eval-symlink, which is provided by Go's path/filepath package, is also moved to
the os: module since it requires actual filesystem access. The idea is that
Elvish's path: will only provide functionalities for lexically manipulating
file paths without referencing the actual filesystem, akin to Python's
pathlib.PurePath.

The old symbols in path: are not formally deprecated since the compiler can't
statically check symbols in modules yet.
2023-08-06 12:06:41 -04:00
Qi Xiao
a1b30deb86 pkg/eval/evaltest: Rename TestWithFullSetup -> TestWithSetup.
The old TestWithSetup is now more accurately called TestWithEvalerSetup.
2023-07-22 23:04:18 +01:00
Qi Xiao
981388d5c2 Add file:open-output. 2023-07-22 17:20:19 +01:00
Qi Xiao
cfc914e9ba New read-bytes builtin to read a fixed number of bytes. 2023-07-20 11:24:01 +01:00
Qi Xiao
93423d3244 Support (struct)map with 'r' or 'w' fields in redirections.
Now that pipe is a structmap and structmaps are considered indistinguishable to
normal maps, IO redirection should support arbitrary maps too.

Update the relevant section in the language spec and rewrite it a bit.
2023-07-18 17:52:06 +01:00
Qi Xiao
6481284f58
Merge pull request #1711 from mikelward/1245
Make Concat return a new globPattern.
2023-07-17 23:54:01 +01: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
Mikel Ward
8796233de4 Make Concat return a new globPattern.
I don't know if this is fully sufficient, but it seems to fix the specific test
case mentioned.

Fixes #1245
2023-07-16 18:28:32 +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
f0c5767ab6 pkg/eval: Use json.Number in from-json. 2023-05-22 07:35:17 +01:00
Qi Xiao
155ea5acb1 pkg/eval: Bump the sleep time in the test for peach more.
Another failure in the Linux ARM64 runner: https://cirrus-ci.com/task/6301954620522496
2023-05-20 11:55:31 +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
c71995ba9a pkg/eval: Add tests for "order &total". 2023-05-19 17:27:37 +01:00
Qi Xiao
058f9818ae pkg/eval: Fix the equality test in "has-value".
Previously Go's == was used to test for equality when the container is not a
map, which is more strict when Elvish's normal equality test. For example,
"has-value [[foo]] [foo]" used to output false, rather than the expected true.
2023-05-19 17:25:36 +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
Qi Xiao
19bd75db57 pkg/eval: Make the peach test cases print $best-run on failure. 2023-05-08 23:34:04 +01:00
Qi Xiao
0557e2a3be pkg/eval/evaltests: Make APIs of special matchers functions. 2023-05-08 23:27:53 +01:00
Qi Xiao
75ee4d0179 pkg/eval: Increase the base sleep time in peach's unit test to 2ms.
The previous value of 1ms caused some false positive on Cirrus's Linux ARM64 runner.
2023-05-07 22:38:22 +01:00
Qi Xiao
ae087dc1e4 pkg/eval: Don't use the new context.Cause API.
Elvish should still be buildable with Go 1.19.
2023-05-07 22:37:08 +01:00
Qi Xiao
f54fe608e8 Clean up some code from adding Context to Frame. 2023-05-07 21:49:27 +01:00
Qi Xiao
da576e221c pkg/eval: Use a Context inside Frame to pass interrupts. 2023-05-07 21:44:28 +01:00
Qi Xiao
6ecc2b306c Fixup for #1691. 2023-05-06 23:55:34 +01:00
Kurtis Rader
91c819d5d8 Add a &num-workers option to peach
Resolves #648
2023-04-16 20:34:55 -07:00
Qi Xiao
89bf04a802 pkg/eval: Construct ui.Text using the functions from the ui package.
This fixes #1668, because the crashing listbox rendering code uses "len(line) >
0" (where line is a ui.Text) to test whether it is non-empty. This test doesn't
work with the ui.Text constructed using "styled ''", which creates a ui.Text
with one empty segment.

The functions from the ui package are guaranteed to never return such ui.Text
instances, so switching the implementation of the styled builtin to functions
from the ui package fixes this.
2023-03-14 21:47:38 +00:00
Qi Xiao
0adf0ec147 Use the unix build tag.
The unix build tag is supported by Go 1.19.
2023-03-03 00:01:26 +00:00
Qi Xiao
67db2194c8 pkg/eval: Support slashes in relative command paths on Windows.
This fixes #1660.
2023-02-27 22:57:02 +00:00
Qi Xiao
34b115d7af Bump prog.DeprecationLevel to 19.
Remove use of float64 in tests, except for one that tests that it is deprecated.
2023-02-27 00:00:12 +00:00
Qi Xiao
5e1d0b6d3d Remove support for the "except" keyword.
It has been superseded by "catch" since the 0.18.0 release.
2023-02-26 23:55:48 +00:00
Qi Xiao
3845a2cf7f Expose stack traces in exceptions as opaque values.
Also document the correct way to compare the causes of exceptions.

This fixes #1632.
2023-02-26 23:52:26 +00: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
dunsany
4172348398 Fix exception capture example 2023-02-04 14:37:10 +00:00
Qi Xiao
97a73e2d95 evaltest.capturePort -> eval.CapturePort.
Also rename the original eval.CapturePort to ValueCapturePort.
2023-01-15 16:44:25 +00:00
Qi Xiao
c7ed16d3cb pkg/eval/evaltest: Print byte output diff with go-cmp. 2023-01-15 16:44:25 +00:00
Qi Xiao
6166c13409 Remove superfluous content from example for the deprecate builtin. 2023-01-13 00:21:33 +00:00
Qi Xiao
0b0f5ba867 Add a new "conj" command for appending values to a list. 2023-01-04 18:57:08 +00:00
Qi Xiao
24640d3241 pkg/eval: Move tests of builtin commands to match implementation files. 2023-01-04 18:37:47 +00:00