Skip to content
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

Getting closer to an ideal syntax #1

Open
drusepth opened this issue Apr 13, 2021 · 0 comments
Open

Getting closer to an ideal syntax #1

drusepth opened this issue Apr 13, 2021 · 0 comments

Comments

@drusepth
Copy link
Owner

The syntax for inline tests right now technically works, but it's still pretty weird:

tested def integer_division(x, y)
  return Float::INFINITY if y.zero?
  x.to_i / y.to_i
end,
tests do |integer_division|
  assert integer_division(6, 3) == 2, "divides correctly"
  assert integer_division(5, 3) == 1, "uses integer division"
  assert integer_division(0, 3) == 0,  "0 / anything = 0"
  assert integer_division(3, 0) == Float::INFINITY
end

I think the ideal syntax would feel more native to Ruby and less hacky; something like:

def integer_division(x, y)
  return Float::INFINITY if y.zero?
  x.to_i / y.to_i
tests
  assert integer_division(6, 3) == 2, "divides correctly"
  assert integer_division(5, 3) == 1, "uses integer division"
  assert integer_division(0, 3) == 0,  "0 / anything = 0"
  assert integer_division(3, 0) == Float::INFINITY
end

However, I have no idea how we'd split a method definition like that syntax-wise without a bunch of gross boilerplate (which would probably look very similar to what we're already doing). If only Ruby had some kind of preprocessing step we could macro #DEFINE tests end, tests do |f| with...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant