#include #include TestResult test_no_format() { auto fmt = TRY(String::format("Hello, world!"_sv)); validate(fmt.view() == "Hello, world!"); test_success; } TestResult test_basic_string_format() { auto fmt = TRY(String::format("%s"_sv, "Hello, world!")); validate(fmt.view() == "Hello, world!"); test_success; } TestResult test_string_format_with_extra_chars() { auto fmt = TRY(String::format("Hello, %s!"_sv, "world")); validate(fmt.view() == "Hello, world!"); test_success; } TestResult test_string_format_with_width() { auto fmt = TRY(String::format("Hello,%6s!"_sv, "world")); validate(fmt.view() == "Hello, world!"); test_success; } TestResult test_string_format_left_align() { auto fmt = TRY(String::format("Hello, %-7s"_sv, "world!")); validate(fmt.view() == "Hello, world! "); test_success; } TestResult test_string_format_precision() { auto fmt = TRY(String::format("Hello, %.5s!"_sv, "world! this is some extra stuff we don't need")); validate(fmt.view() == "Hello, world!"); test_success; } TestResult test_basic_signed_integer_format() { auto fmt = TRY(String::format("%d"_sv, 42)); validate(fmt.view() == "42"); test_success; } TestResult test_negative_signed_integer_format() { auto fmt = TRY(String::format("%d"_sv, -653)); validate(fmt.view() == "-653"); test_success; } TestResult test_positive_signed_integer_format() { auto fmt = TRY(String::format("%+d"_sv, 653)); validate(fmt.view() == "+653"); test_success; } TestResult test_format_zero_with_explicit_zero_precision() { auto fmt = TRY(String::format("%.0d"_sv, 0)); validate(fmt.is_empty()); test_success; } TestResult test_octal_format() { auto fmt = TRY(String::format("%o"_sv, 34)); validate(fmt.view() == "42"); test_success; } TestResult test_hex_format() { auto fmt = TRY(String::format("%x"_sv, 43707)); validate(fmt.view() == "aabb"); test_success; } TestResult test_uppercase_hex_format() { auto fmt = TRY(String::format("%X"_sv, 43707)); validate(fmt.view() == "AABB"); test_success; } Result test_main() { test_prelude; run_test(test_no_format); run_test(test_basic_string_format); run_test(test_string_format_with_extra_chars); run_test(test_string_format_with_width); run_test(test_string_format_left_align); run_test(test_string_format_precision); run_test(test_basic_signed_integer_format); run_test(test_negative_signed_integer_format); run_test(test_positive_signed_integer_format); run_test(test_format_zero_with_explicit_zero_precision); run_test(test_octal_format); run_test(test_hex_format); run_test(test_uppercase_hex_format); return {}; }