Compare commits

..

No commits in common. "dc7e503342ab8b32ee21bb44ea5b4c26d9b0dba4" and "5911b052dc526898d4963680fe83c6e2dc67e55f" have entirely different histories.

2 changed files with 10 additions and 203 deletions

View File

@ -8,16 +8,16 @@
extern "C" usize strlen(const char*);
typedef int flags_t;
#define FLAG_ZERO_PAD (1 << 0)
#define FLAG_LEFT_ALIGN (1 << 1)
#define FLAG_BLANK_SIGNED (1 << 2)
#define FLAG_ALTERNATE (1 << 3)
#define FLAG_SIGN (1 << 4)
#define FLAG_USE_PRECISION (1 << 5)
#define FLAG_LONG (1 << 6)
#define FLAG_LONG_LONG (1 << 7)
#define FLAG_SHORT (1 << 8)
#define FLAG_CHAR (1 << 9)
#define FLAG_ZERO_PAD 1 << 0
#define FLAG_LEFT_ALIGN 1 << 1
#define FLAG_BLANK_SIGNED 1 << 2
#define FLAG_ALTERNATE 1 << 3
#define FLAG_SIGN 1 << 4
#define FLAG_USE_PRECISION 1 << 5
#define FLAG_LONG 1 << 6
#define FLAG_LONG_LONG 1 << 7
#define FLAG_SHORT 1 << 8
#define FLAG_CHAR 1 << 9
struct format_state
{
@ -139,10 +139,7 @@ static usize parse_precision(const char** format, flags_t& flags, va_list ap)
const int precision = va_arg(ap, int);
if (precision >= 0) result = (usize)precision;
else
{
result = 0;
flags &= ~FLAG_USE_PRECISION;
}
(*format)++;
}
}

View File

@ -82,15 +82,6 @@ TestResult test_positive_signed_integer_format()
test_success;
}
TestResult test_positive_signed_integer_format_with_empty_sign()
{
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));
@ -127,168 +118,6 @@ TestResult test_uppercase_hex_format()
test_success;
}
TestResult test_integer_format_with_width()
{
auto fmt = TRY(String::format("%6d"_sv, 42));
validate(fmt.view() == " 42");
test_success;
}
TestResult test_zero_padded_integer_format_with_width()
{
auto fmt = TRY(String::format("%06d"_sv, 42));
validate(fmt.view() == "000042");
test_success;
}
TestResult test_integer_format_with_precision()
{
auto fmt = TRY(String::format("%.6d"_sv, 42));
validate(fmt.view() == "000042");
test_success;
}
TestResult test_alternate_integer_format_with_width()
{
auto fmt = TRY(String::format("%#6x"_sv, 66));
validate(fmt.view() == " 0x42");
test_success;
}
TestResult test_zero_padded_alternate_integer_format_with_width()
{
auto fmt = TRY(String::format("%0#6x"_sv, 66));
validate(fmt.view() == "0x0042");
test_success;
}
TestResult test_alternate_integer_format_with_precision()
{
auto fmt = TRY(String::format("%#.6x"_sv, 66));
validate(fmt.view() == "0x000042");
test_success;
}
TestResult test_integer_format_left_align()
{
auto fmt = TRY(String::format("%-6d"_sv, 42));
validate(fmt.view() == "42 ");
test_success;
}
TestResult test_integer_format_left_align_override_zero_pad()
{
auto fmt = TRY(String::format("%-06d"_sv, 42));
validate(fmt.view() == "42 ");
test_success;
}
TestResult test_integer_format_left_align_with_alternate_format()
{
auto fmt = TRY(String::format("%#-6o"_sv, 0755));
validate(fmt.view() == "0755 ");
test_success;
}
TestResult test_integer_format_left_align_with_alternate_format_and_precision()
{
auto fmt = TRY(String::format("%#-8.5x"_sv, 0x44bb));
validate(fmt.view() == "0x044bb ");
test_success;
}
TestResult test_va_integer_width()
{
auto fmt = TRY(String::format("%0*d"_sv, 4, 42));
validate(fmt.view() == "0042");
test_success;
}
TestResult test_va_integer_precision()
{
auto fmt = TRY(String::format("%0.*d"_sv, 4, 42));
validate(fmt.view() == "0042");
test_success;
}
TestResult test_no_precision_assumed_as_zero()
{
auto fmt = TRY(String::format("%.d"_sv, 42));
validate(fmt.view() == "42");
test_success;
}
TestResult test_no_precision_assumed_as_explicit_zero()
{
auto fmt = TRY(String::format("%.d"_sv, 0));
validate(fmt.view() == "");
test_success;
}
TestResult test_negative_va_width()
{
auto fmt = TRY(String::format("%*d"_sv, -4, 42));
validate(fmt.view() == "42 ");
test_success;
}
TestResult test_negative_va_precision()
{
auto fmt = TRY(String::format("%.*d"_sv, -6, 0));
validate(fmt.view() == "0");
test_success;
}
TestResult test_verbatim_percent_format()
{
auto fmt = TRY(String::format("%%"_sv));
validate(fmt.view() == "%");
test_success;
}
TestResult test_format_character()
{
auto fmt = TRY(String::format("exampl%c"_sv, 'e'));
validate(fmt.view() == "example");
test_success;
}
Result<void> test_main()
{
test_prelude;
@ -302,29 +131,10 @@ Result<void> test_main()
run_test(test_basic_signed_integer_format);
run_test(test_negative_signed_integer_format);
run_test(test_positive_signed_integer_format);
run_test(test_positive_signed_integer_format_with_empty_sign);
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);
run_test(test_integer_format_with_width);
run_test(test_zero_padded_integer_format_with_width);
run_test(test_integer_format_with_precision);
run_test(test_alternate_integer_format_with_width);
run_test(test_zero_padded_alternate_integer_format_with_width);
run_test(test_alternate_integer_format_with_precision);
run_test(test_integer_format_left_align);
run_test(test_integer_format_left_align_override_zero_pad);
run_test(test_integer_format_left_align_with_alternate_format);
run_test(test_integer_format_left_align_with_alternate_format_and_precision);
run_test(test_va_integer_width);
run_test(test_va_integer_precision);
run_test(test_no_precision_assumed_as_zero);
run_test(test_no_precision_assumed_as_explicit_zero);
run_test(test_negative_va_width);
run_test(test_negative_va_precision);
run_test(test_verbatim_percent_format);
run_test(test_format_character);
return {};
}