1
0
Fork 0
mirror of https://github.com/tailix/libkernaux.git synced 2025-04-07 17:32:45 -04:00

Add original tests for printf

This commit is contained in:
Alex Kotov 2022-01-23 00:31:43 +05:00
parent fee4e7f76d
commit f9d4a37165
Signed by: kotovalexarian
GPG key ID: 553C0EBBEB5D5F08
2 changed files with 33 additions and 0 deletions

View file

@ -153,6 +153,21 @@ RSpec.describe KernAux, '.sprintf' do
[' 1234ABCD', ['%20X', 305_441_741]],
[' EDCB5433', ['%20X', 3_989_525_555]],
[' x', ['%20c', 'x']],
# width *20
[' Hello', ['%*s', 20, 'Hello']],
[' 1024', ['%*d', 20, 1024]],
[' -1024', ['%*d', 20, -1024]],
[' 1024', ['%*i', 20, 1024]],
[' -1024', ['%*i', 20, -1024]],
[' 1024', ['%*u', 20, 1024]],
[' 4294966272', ['%*u', 20, 4_294_966_272]],
[' 777', ['%*o', 20, 511]],
[' 37777777001', ['%*o', 20, 4_294_966_785]],
[' 1234abcd', ['%*x', 20, 305_441_741]],
[' edcb5433', ['%*x', 20, 3_989_525_555]],
[' 1234ABCD', ['%*X', 20, 305_441_741]],
[' EDCB5433', ['%*X', 20, 3_989_525_555]],
[' x', ['%*c', 20, 'x']],
].each do |expected, *args|
it "transforms #{args.inspect} to #{expected.inspect}" do
expect(described_class.sprintf(*args)).to eq expected

View file

@ -106,6 +106,8 @@ int main()
test("123.456789", "%f", 123.456789);
#endif
// - flag
// ...
test("42", "%0-d", 42);
test("-42", "%0-d", -42);
test("42 ", "%0-5d", 42);
@ -120,5 +122,21 @@ int main()
test("g", "%0-15.3g", -42.0);
#endif
// width *20
test(" Hello", "%*s", 20, "Hello");
test(" 1024", "%*d", 20, 1024);
test(" -1024", "%*d", 20, -1024);
test(" 1024", "%*i", 20, 1024);
test(" -1024", "%*i", 20, -1024);
test(" 1024", "%*u", 20, 1024);
test(" 4294966272", "%*u", 20, 4294966272);
test(" 777", "%*o", 20, 511);
test(" 37777777001", "%*o", 20, 4294966785);
test(" 1234abcd", "%*x", 20, 305441741);
test(" edcb5433", "%*x", 20, 3989525555);
test(" 1234ABCD", "%*X", 20, 305441741);
test(" EDCB5433", "%*X", 20, 3989525555);
test(" x", "%*c", 20, 'x');
return 0;
}