New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make complex-candidate indexable #691

Merged
merged 2 commits into from Jun 6, 2018

Conversation

Projects
None yet
2 participants
@zzamboni
Contributor

zzamboni commented Jun 2, 2018

Makes it possible to access the fields of a complex-candidate object. Fixes #684.

Make complex-candidate indexable
Makes it possible to access the fields of a complex-candidate object.
@xiaq

This comment has been minimized.

Member

xiaq commented Jun 3, 2018

Awesome, thank you!

Can you add some tests as well? This can be a little bit involved, so here is some more guidance :)

In general with Go, you write test cases by writing functions named Test* in a file *_test.go, and those functions should accept one argument of type *testing.T. That is, the functions look like func TestSomething(t *testing.T) { ... } (the argument name t is convention).

To test the code you added does indeed implement indexing for complex candidates, you want to run some Elvish code and see if they behave as expected. For instance, you want to test that put (edit:complex-candidate lorem)[stem] puts the string lorem. Elvish has an internal mini-framework for testing Elvish code in eval/testutils.go:

// Framework for testing Elvish script. This file does not file a _test.go
// suffix so that it can be used from other packages that also want to test the
// modules they implement (e.g. edit: and re:).
//
// The entry point for the framework is the Test function, which accepts a
// *testing.T and a variadic number of test cases. Test cases are constructed
// using the That function followed by methods that add constraints on the test
// case. Overall, a test looks like:
//
// Test(t,
// That("put x").Puts("x"),
// That("echo x").Prints("x\n"))
//
// If some setup is needed, use the TestWithSetup function instead.

Since the edit module is not built-in, this will require some setup. One such example is

func TestRe(t *testing.T) {
setup := func(ev *eval.Evaler) { ev.Builtin.AddNs("re", Ns) }
That := eval.That
eval.TestWithSetup(t, setup,

Where the setup is simply adding an additional re namespace to the Evaler. In this case, it is easier to construct a namespace on the fly and add complex-candidate to it, so you would add something like this to candidate_test.go:

func TestComplexCandidate(t *testing.T) {
	setup := func(ev *eval.Evaler) {
		ev.Builtin.AddNs("edit", eval.NewNs().AddBuiltinFn(
			"edit:", "complex-candidate", makeComplexCandidate))
	}
	That := eval.That 
	eval.TestWithSetup(t, setup,
		That("put (edit:complex-candidate lorem)[stem]").Puts("lorem"),
		// Add more similar test cases here
	)
}

Good luck!

@zzamboni

This comment has been minimized.

Contributor

zzamboni commented Jun 6, 2018

@xiaq I've added some test cases - thanks for the pointers!

@xiaq xiaq merged commit 524b4b3 into elves:master Jun 6, 2018

2 checks passed

continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment