From 8c98f433bffbfdece502a565e2e176a414939f87 Mon Sep 17 00:00:00 2001 From: Nicolas Boichat Date: Wed, 4 Jun 2025 09:54:44 +0200 Subject: [PATCH] test_sort: Add one more test checking arbitrary precision handling --- tests/by-util/test_sort.rs | 40 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/tests/by-util/test_sort.rs b/tests/by-util/test_sort.rs index 6ae2bb806..3fcd4e978 100644 --- a/tests/by-util/test_sort.rs +++ b/tests/by-util/test_sort.rs @@ -1527,3 +1527,43 @@ fn test_g_misc() { .succeeds() .stdout_is(output); } + +#[test] +// Test numbers with a large number of digits, where only the last digit is different. +// We use scientific notation to make sure string sorting does not correctly order them. +fn test_g_arbitrary() { + let input = [ + // GNU coreutils doesn't handle those correctly as they don't fit exactly in long double + "3", + "3.000000000000000000000000000000000000000000000000000000000000000004", + "0.3000000000000000000000000000000000000000000000000000000000000000002e1", + "0.03000000000000000000000000000000000000000000000000000000000000000003e2", + "0.003000000000000000000000000000000000000000000000000000000000000000001e3", + // GNU coreutils does handle those correctly though + "10", + "10.000000000000004", + "1.0000000000000002e1", + "0.10000000000000003e2", + "0.010000000000000001e3", + ] + .join("\n"); + let output = [ + "3", + "0.003000000000000000000000000000000000000000000000000000000000000000001e3", + "0.3000000000000000000000000000000000000000000000000000000000000000002e1", + "0.03000000000000000000000000000000000000000000000000000000000000000003e2", + "3.000000000000000000000000000000000000000000000000000000000000000004", + "10", + "0.010000000000000001e3", + "1.0000000000000002e1", + "0.10000000000000003e2", + "10.000000000000004", + ] + .join("\n") + + "\n"; + new_ucmd!() + .args(&["-g"]) + .pipe_in(input) + .succeeds() + .stdout_is(output); +}