ruby/ruby — pull request #717 by matthewd (2014-09-14 19:11:03+00:00)
Title: sprintf.c: improve rational 'f' format

The sprintf handling for Rational added in 1d196e0d2bd99590d03a73d7e59aa87f7266f8e3 was only working for a limited subset of values.

In addition to specific tests for the first examples I encountered, I've added a (rather ugly) set of nested loops, which together will test many combinations of formatting options: we know that float formatting works correctly, so we can just assert that matching Rational values produce the same strings.

Though [I have tangled with sprintf in a past life](https://github.com/rubinius/rubinius/commit/d6712a7fd110edcbe1b641e1f2a92c88473565d8), this is just a result of trial & error to get the added tests passing – it seems to behave much better, but I won't claim it's a complete implementation. The TODO on the non-`f` formats is untouched.

This should fix the consistent segfault we're seeing in the Rails (ActiveSupport) test suite.

/cc @nobu :heart: :green_heart: :blue_heart: