mirror of
https://github.com/mpv-player/mpv
synced 2024-12-26 17:12:36 +00:00
8708f4dc91
This enhancement makes it easier to create constant width property expansions, useful for the `--term-status-msg`. Additionally, it changes to `%f` printing with manual zero trimming, which is easier to control than `%g`. With this method, we can directly specify precision, not just significant numbers. This approach also avoids overly high precision for values less than 1, which is not necessary for a generic floating-point print function. A new print helper function is added, which can be used with adjusted precision for specific cases where a different default is needed. This also unifies the code slightly.
100 lines
7.6 KiB
C
100 lines
7.6 KiB
C
#include "test_utils.h"
|
|
#include "common/common.h"
|
|
|
|
int main(void)
|
|
{
|
|
void *ta_ctx = talloc_new(NULL);
|
|
|
|
assert_string_equal(mp_format_double(ta_ctx, 123.456, 0, false, false, false), "123");
|
|
assert_string_equal(mp_format_double(ta_ctx, 123.456, 0, false, false, true), "123");
|
|
assert_string_equal(mp_format_double(ta_ctx, 123.456, 0, false, true, false), "123%");
|
|
assert_string_equal(mp_format_double(ta_ctx, 123.456, 0, false, true, true), "123%");
|
|
assert_string_equal(mp_format_double(ta_ctx, 123.456, 0, true, false, false), "+123");
|
|
assert_string_equal(mp_format_double(ta_ctx, 123.456, 0, true, false, true), "+123");
|
|
assert_string_equal(mp_format_double(ta_ctx, 123.456, 0, true, true, false), "+123%");
|
|
assert_string_equal(mp_format_double(ta_ctx, 123.456, 0, true, true, true), "+123%");
|
|
|
|
assert_string_equal(mp_format_double(ta_ctx, -123.456, 0, false, false, false), "-123");
|
|
assert_string_equal(mp_format_double(ta_ctx, -123.456, 0, false, false, true), "-123");
|
|
assert_string_equal(mp_format_double(ta_ctx, -123.456, 0, false, true, false), "-123%");
|
|
assert_string_equal(mp_format_double(ta_ctx, -123.456, 0, false, true, true), "-123%");
|
|
assert_string_equal(mp_format_double(ta_ctx, -123.456, 0, true, false, false), "-123");
|
|
assert_string_equal(mp_format_double(ta_ctx, -123.456, 0, true, false, true), "-123");
|
|
assert_string_equal(mp_format_double(ta_ctx, -123.456, 0, true, true, false), "-123%");
|
|
assert_string_equal(mp_format_double(ta_ctx, -123.456, 0, true, true, true), "-123%");
|
|
|
|
assert_string_equal(mp_format_double(ta_ctx, 123.456, 2, false, false, false), "123.46");
|
|
assert_string_equal(mp_format_double(ta_ctx, 123.456, 2, false, false, true), "123.46");
|
|
assert_string_equal(mp_format_double(ta_ctx, 123.456, 2, false, true, false), "123.46%");
|
|
assert_string_equal(mp_format_double(ta_ctx, 123.456, 2, false, true, true), "123.46%");
|
|
assert_string_equal(mp_format_double(ta_ctx, 123.456, 2, true, false, false), "+123.46");
|
|
assert_string_equal(mp_format_double(ta_ctx, 123.456, 2, true, false, true), "+123.46");
|
|
assert_string_equal(mp_format_double(ta_ctx, 123.456, 2, true, true, false), "+123.46%");
|
|
assert_string_equal(mp_format_double(ta_ctx, 123.456, 2, true, true, true), "+123.46%");
|
|
|
|
assert_string_equal(mp_format_double(ta_ctx, -123.456, 2, false, false, false), "-123.46");
|
|
assert_string_equal(mp_format_double(ta_ctx, -123.456, 2, false, false, true), "-123.46");
|
|
assert_string_equal(mp_format_double(ta_ctx, -123.456, 2, false, true, false), "-123.46%");
|
|
assert_string_equal(mp_format_double(ta_ctx, -123.456, 2, false, true, true), "-123.46%");
|
|
assert_string_equal(mp_format_double(ta_ctx, -123.456, 2, true, false, false), "-123.46");
|
|
assert_string_equal(mp_format_double(ta_ctx, -123.456, 2, true, false, true), "-123.46");
|
|
assert_string_equal(mp_format_double(ta_ctx, -123.456, 2, true, true, false), "-123.46%");
|
|
assert_string_equal(mp_format_double(ta_ctx, -123.456, 2, true, true, true), "-123.46%");
|
|
|
|
assert_string_equal(mp_format_double(ta_ctx, 123.456, 6, false, false, false), "123.456000");
|
|
assert_string_equal(mp_format_double(ta_ctx, 123.456, 6, false, false, true), "123.456");
|
|
assert_string_equal(mp_format_double(ta_ctx, 123.456, 6, false, true, false), "123.456000%");
|
|
assert_string_equal(mp_format_double(ta_ctx, 123.456, 6, false, true, true), "123.456%");
|
|
assert_string_equal(mp_format_double(ta_ctx, 123.456, 6, true, false, false), "+123.456000");
|
|
assert_string_equal(mp_format_double(ta_ctx, 123.456, 6, true, false, true), "+123.456");
|
|
assert_string_equal(mp_format_double(ta_ctx, 123.456, 6, true, true, false), "+123.456000%");
|
|
assert_string_equal(mp_format_double(ta_ctx, 123.456, 6, true, true, true), "+123.456%");
|
|
|
|
assert_string_equal(mp_format_double(ta_ctx, -123.456, 6, false, false, false), "-123.456000");
|
|
assert_string_equal(mp_format_double(ta_ctx, -123.456, 6, false, false, true), "-123.456");
|
|
assert_string_equal(mp_format_double(ta_ctx, -123.456, 6, false, true, false), "-123.456000%");
|
|
assert_string_equal(mp_format_double(ta_ctx, -123.456, 6, false, true, true), "-123.456%");
|
|
assert_string_equal(mp_format_double(ta_ctx, -123.456, 6, true, false, false), "-123.456000");
|
|
assert_string_equal(mp_format_double(ta_ctx, -123.456, 6, true, false, true), "-123.456");
|
|
assert_string_equal(mp_format_double(ta_ctx, -123.456, 6, true, true, false), "-123.456000%");
|
|
assert_string_equal(mp_format_double(ta_ctx, -123.456, 6, true, true, true), "-123.456%");
|
|
|
|
assert_string_equal(mp_format_double(ta_ctx, 123, 6, false, false, false), "123.000000");
|
|
assert_string_equal(mp_format_double(ta_ctx, 123, 6, false, false, true), "123");
|
|
assert_string_equal(mp_format_double(ta_ctx, 123, 6, false, true, false), "123.000000%");
|
|
assert_string_equal(mp_format_double(ta_ctx, 123, 6, false, true, true), "123%");
|
|
assert_string_equal(mp_format_double(ta_ctx, 123, 6, true, false, false), "+123.000000");
|
|
assert_string_equal(mp_format_double(ta_ctx, 123, 6, true, false, true), "+123");
|
|
assert_string_equal(mp_format_double(ta_ctx, 123, 6, true, true, false), "+123.000000%");
|
|
assert_string_equal(mp_format_double(ta_ctx, 123, 6, true, true, true), "+123%");
|
|
|
|
assert_string_equal(mp_format_double(ta_ctx, -123, 6, false, false, false), "-123.000000");
|
|
assert_string_equal(mp_format_double(ta_ctx, -123, 6, false, false, true), "-123");
|
|
assert_string_equal(mp_format_double(ta_ctx, -123, 6, false, true, false), "-123.000000%");
|
|
assert_string_equal(mp_format_double(ta_ctx, -123, 6, false, true, true), "-123%");
|
|
assert_string_equal(mp_format_double(ta_ctx, -123, 6, true, false, false), "-123.000000");
|
|
assert_string_equal(mp_format_double(ta_ctx, -123, 6, true, false, true), "-123");
|
|
assert_string_equal(mp_format_double(ta_ctx, -123, 6, true, true, false), "-123.000000%");
|
|
assert_string_equal(mp_format_double(ta_ctx, -123, 6, true, true, true), "-123%");
|
|
|
|
assert_string_equal(mp_format_double(ta_ctx, INFINITY, 6, false, false, false), "inf");
|
|
assert_string_equal(mp_format_double(ta_ctx, INFINITY, 6, false, false, true), "inf");
|
|
assert_string_equal(mp_format_double(ta_ctx, INFINITY, 6, false, true, false), "inf%");
|
|
assert_string_equal(mp_format_double(ta_ctx, INFINITY, 6, false, true, true), "inf%");
|
|
assert_string_equal(mp_format_double(ta_ctx, INFINITY, 6, true, false, false), "+inf");
|
|
assert_string_equal(mp_format_double(ta_ctx, INFINITY, 6, true, false, true), "+inf");
|
|
assert_string_equal(mp_format_double(ta_ctx, INFINITY, 6, true, true, false), "+inf%");
|
|
assert_string_equal(mp_format_double(ta_ctx, INFINITY, 6, true, true, true), "+inf%");
|
|
|
|
assert_string_equal(mp_format_double(ta_ctx, -INFINITY, 6, false, false, false), "-inf");
|
|
assert_string_equal(mp_format_double(ta_ctx, -INFINITY, 6, false, false, true), "-inf");
|
|
assert_string_equal(mp_format_double(ta_ctx, -INFINITY, 6, false, true, false), "-inf%");
|
|
assert_string_equal(mp_format_double(ta_ctx, -INFINITY, 6, false, true, true), "-inf%");
|
|
assert_string_equal(mp_format_double(ta_ctx, -INFINITY, 6, true, false, false), "-inf");
|
|
assert_string_equal(mp_format_double(ta_ctx, -INFINITY, 6, true, false, true), "-inf");
|
|
assert_string_equal(mp_format_double(ta_ctx, -INFINITY, 6, true, true, false), "-inf%");
|
|
assert_string_equal(mp_format_double(ta_ctx, -INFINITY, 6, true, true, true), "-inf%");
|
|
|
|
talloc_free(ta_ctx);
|
|
}
|