google / starlark-go

Starlark in Go: the Starlark configuration language, implemented in Go
BSD 3-Clause "New" or "Revised" License
2.26k stars 204 forks source link

Added a ParamDefault() method to Function that returns parameter default values. #452

Closed vtsao closed 1 year ago

vtsao commented 1 year ago

450

vtsao commented 1 year ago

@adonovan not sure where the best place is to add a test for this? It doesn't look like any of the other starlark.Function methods have tests.

adonovan commented 1 year ago

@adonovan not sure where the best place is to add a test for this? It doesn't look like any of the other starlark.Function methods have tests.

Yeah, there isn't much there yet. See the TODO in testdata/function.star:

# TODO(adonovan):
# - add some introspection functions for looking at function values
#   and test that functions have correct position, free vars, names of locals, etc.

If you're feeling diligent, you could add a built-in function following the paradigm of hasFields or struct that returns a dict of function attributes (e.g. name, pos, defaults) and then write assertions in Starlark. But if you don't feel like it that's fine too.

vtsao commented 1 year ago

If you're feeling diligent, you could add a built-in function following the paradigm of hasFields or struct that returns a dict of function attributes (e.g. name, pos, defaults) and then write assertions in Starlark. But if you don't feel like it that's fine too.

I added a test in value_test.go for this that I think is more direct as it tests ParamDefault() directly. Hope this is okay, even though it's a bit different than the other tests.

vtsao commented 1 year ago

@adonovan friendly ping - how does this all look?

vtsao commented 1 year ago

Hey @adonovan, following up again - any chance we can get this merged? Let me know if you'd like to see anything else in this PR. Thanks!