diff --git a/AK/Format.cpp b/AK/Format.cpp index 0f8398770fc..e157a494859 100644 --- a/AK/Format.cpp +++ b/AK/Format.cpp @@ -511,6 +511,8 @@ ErrorOr FormatBuilder::put_f64_with_precision( TRY(format_builder.put_u64(static_cast(value), base, false, upper_case, false, use_separator, Align::Right, 0, ' ', sign_mode, is_negative)); value -= static_cast(value); + bool did_emit_decimals = false; + if (precision > 0) { // FIXME: This is a terrible approximation but doing it properly would be a lot of work. If someone is up for that, a good // place to start would be the following video from CppCon 2019: @@ -535,6 +537,7 @@ ErrorOr FormatBuilder::put_f64_with_precision( TRY(string_builder.try_append('.')); TRY(string_builder.try_append('0' + (static_cast(value) % 10))); + did_emit_decimals = true; } } @@ -542,6 +545,22 @@ ErrorOr FormatBuilder::put_f64_with_precision( if (static_cast(value * 10.0) % 10 >= 5) TRY(round_up_digits(string_builder)); + if (did_emit_decimals && display_mode == RealNumberDisplayMode::Default) { + while (!string_builder.is_empty()) { + // Strip trailing zero decimals. + if (string_builder.string_view().ends_with('0')) { + string_builder.trim(1); + continue; + } + // Strip trailing decimal point. + if (string_builder.string_view().ends_with('.')) { + string_builder.trim(1); + break; + } + break; + } + } + return put_string(string_builder.string_view(), align, min_width, NumericLimits::max(), fill); } diff --git a/Tests/AK/TestFormat.cpp b/Tests/AK/TestFormat.cpp index 2a63259261f..215fa64ccfa 100644 --- a/Tests/AK/TestFormat.cpp +++ b/Tests/AK/TestFormat.cpp @@ -311,7 +311,8 @@ TEST_CASE(no_precision_no_trailing_number) TEST_CASE(precision_with_trailing_zeros) { - EXPECT_EQ(ByteString::formatted("{:0.3}", 1.12), "1.120"); + EXPECT_EQ(ByteString::formatted("{:0.3f}", 1.12), "1.120"); + EXPECT_EQ(ByteString::formatted("{:0.3}", 1.12), "1.12"); EXPECT_EQ(ByteString::formatted("{:0.1}", 1.12), "1.1"); } diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-fonts/parsing/font-valid.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-fonts/parsing/font-valid.txt index 9b71a9b50e4..fc1a1cd5e35 100644 --- a/Tests/LibWeb/Text/expected/wpt-import/css/css-fonts/parsing/font-valid.txt +++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-fonts/parsing/font-valid.txt @@ -2,8 +2,8 @@ Harness status: OK Found 315 tests -91 Pass -224 Fail +119 Pass +196 Fail Pass caption should be a supported system font. Pass icon should be a supported system font. Pass menu should be a supported system font. @@ -13,11 +13,11 @@ Pass status-bar should be a supported system font. Pass e.style['font'] = "xx-small serif" should set the property value Pass e.style['font'] = "normal medium/normal sans-serif" should set the property value Pass e.style['font'] = "normal normal xx-large/1.2 cursive" should set the property value -Fail e.style['font'] = "normal normal normal larger/calc(120% + 1.2em) fantasy" should set the property value +Pass e.style['font'] = "normal normal normal larger/calc(120% + 1.2em) fantasy" should set the property value Pass e.style['font'] = "normal normal normal normal smaller monospace" should set the property value Pass e.style['font'] = "normal normal normal italic 10px/normal Menu" should set the property value Fail e.style['font'] = "normal normal normal small-caps 20%/1.2 \"FB Armada\"" should set the property value -Fail e.style['font'] = "normal normal normal bold calc(30% - 40px)/calc(120% + 1.2em) serif" should set the property value +Pass e.style['font'] = "normal normal normal bold calc(30% - 40px)/calc(120% + 1.2em) serif" should set the property value Pass e.style['font'] = "normal normal normal ultra-condensed xx-small sans-serif" should set the property value Pass e.style['font'] = "normal normal oblique medium/normal cursive" should set the property value Pass e.style['font'] = "normal normal italic normal xx-large/1.2 fantasy" should set the property value @@ -29,7 +29,7 @@ Fail e.style['font'] = "normal normal small-caps normal calc(30% - 40px)/calc(12 Fail e.style['font'] = "normal normal small-caps italic xx-small cursive" should set the property value Fail e.style['font'] = "normal normal small-caps lighter medium/normal fantasy" should set the property value Fail e.style['font'] = "normal normal small-caps condensed xx-large/1.2 monospace" should set the property value -Fail e.style['font'] = "normal normal 100 larger/calc(120% + 1.2em) Menu" should set the property value +Pass e.style['font'] = "normal normal 100 larger/calc(120% + 1.2em) Menu" should set the property value Pass e.style['font'] = "normal normal 900 normal smaller \"FB Armada\"" should set the property value Pass e.style['font'] = "normal normal bold oblique 10px/normal serif" should set the property value Fail e.style['font'] = "normal normal bolder small-caps 20%/1.2 sans-serif" should set the property value @@ -41,7 +41,7 @@ Fail e.style['font'] = "normal normal ultra-expanded small-caps larger/calc(120% Pass e.style['font'] = "normal normal ultra-condensed 100 smaller serif" should set the property value Pass e.style['font'] = "normal oblique 10px/normal sans-serif" should set the property value Pass e.style['font'] = "normal italic normal 20%/1.2 cursive" should set the property value -Fail e.style['font'] = "normal oblique normal normal calc(30% - 40px)/calc(120% + 1.2em) fantasy" should set the property value +Pass e.style['font'] = "normal oblique normal normal calc(30% - 40px)/calc(120% + 1.2em) fantasy" should set the property value Fail e.style['font'] = "normal italic normal small-caps xx-small monospace" should set the property value Pass e.style['font'] = "normal oblique normal 900 medium/normal Menu" should set the property value Pass e.style['font'] = "normal italic normal extra-condensed xx-large/1.2 \"FB Armada\"" should set the property value @@ -49,11 +49,11 @@ Fail e.style['font'] = "normal oblique small-caps larger/calc(120% + 1.2em) seri Fail e.style['font'] = "normal italic small-caps normal smaller sans-serif" should set the property value Fail e.style['font'] = "normal oblique small-caps bold 10px/normal cursive" should set the property value Fail e.style['font'] = "normal italic small-caps condensed 20%/1.2 fantasy" should set the property value -Fail e.style['font'] = "normal oblique bolder calc(30% - 40px)/calc(120% + 1.2em) monospace" should set the property value +Pass e.style['font'] = "normal oblique bolder calc(30% - 40px)/calc(120% + 1.2em) monospace" should set the property value Fail e.style['font'] = "normal italic lighter normal xx-small Menu" should set the property value Fail e.style['font'] = "normal oblique 100 small-caps medium/normal \"FB Armada\"" should set the property value Pass e.style['font'] = "normal italic 900 semi-condensed xx-large/1.2 serif" should set the property value -Fail e.style['font'] = "normal oblique semi-expanded larger/calc(120% + 1.2em) sans-serif" should set the property value +Pass e.style['font'] = "normal oblique semi-expanded larger/calc(120% + 1.2em) sans-serif" should set the property value Pass e.style['font'] = "normal italic expanded normal smaller cursive" should set the property value Fail e.style['font'] = "normal oblique extra-expanded small-caps 10px/normal fantasy" should set the property value Pass e.style['font'] = "normal italic ultra-expanded bold 20%/1.2 monospace" should set the property value @@ -77,11 +77,11 @@ Fail e.style['font'] = "normal small-caps expanded oblique calc(30% - 40px)/calc Fail e.style['font'] = "normal small-caps extra-expanded lighter xx-small sans-serif" should set the property value Pass e.style['font'] = "normal 100 medium/normal cursive" should set the property value Pass e.style['font'] = "normal 900 normal xx-large/1.2 fantasy" should set the property value -Fail e.style['font'] = "normal bold normal normal larger/calc(120% + 1.2em) monospace" should set the property value +Pass e.style['font'] = "normal bold normal normal larger/calc(120% + 1.2em) monospace" should set the property value Pass e.style['font'] = "normal bolder normal italic smaller Menu" should set the property value Fail e.style['font'] = "normal lighter normal small-caps 10px/normal \"FB Armada\"" should set the property value Pass e.style['font'] = "normal 100 normal ultra-expanded 20%/1.2 serif" should set the property value -Fail e.style['font'] = "normal 900 oblique calc(30% - 40px)/calc(120% + 1.2em) sans-serif" should set the property value +Pass e.style['font'] = "normal 900 oblique calc(30% - 40px)/calc(120% + 1.2em) sans-serif" should set the property value Pass e.style['font'] = "normal bold italic normal xx-small cursive" should set the property value Fail e.style['font'] = "normal bolder oblique small-caps medium/normal fantasy" should set the property value Fail e.style['font'] = "normal lighter italic ultra-condensed xx-large/1.2 monospace" should set the property value @@ -93,7 +93,7 @@ Fail e.style['font'] = "normal lighter condensed calc(30% - 40px)/calc(120% + 1. Pass e.style['font'] = "normal 100 semi-condensed normal xx-small fantasy" should set the property value Pass e.style['font'] = "normal 900 semi-expanded italic medium/normal monospace" should set the property value Fail e.style['font'] = "normal bold expanded small-caps xx-large/1.2 Menu" should set the property value -Fail e.style['font'] = "normal extra-expanded larger/calc(120% + 1.2em) \"FB Armada\"" should set the property value +Pass e.style['font'] = "normal extra-expanded larger/calc(120% + 1.2em) \"FB Armada\"" should set the property value Pass e.style['font'] = "normal ultra-expanded normal smaller serif" should set the property value Pass e.style['font'] = "normal ultra-condensed normal normal 10px/normal sans-serif" should set the property value Pass e.style['font'] = "normal extra-condensed normal oblique 20%/1.2 cursive" should set the property value @@ -109,15 +109,15 @@ Fail e.style['font'] = "normal condensed small-caps italic calc(30% - 40px)/calc Fail e.style['font'] = "normal semi-condensed small-caps 100 xx-small Menu" should set the property value Pass e.style['font'] = "normal semi-expanded 900 medium/normal \"FB Armada\"" should set the property value Pass e.style['font'] = "normal expanded bold normal xx-large/1.2 serif" should set the property value -Fail e.style['font'] = "normal extra-expanded bolder oblique larger/calc(120% + 1.2em) sans-serif" should set the property value +Pass e.style['font'] = "normal extra-expanded bolder oblique larger/calc(120% + 1.2em) sans-serif" should set the property value Fail e.style['font'] = "normal ultra-expanded lighter small-caps smaller cursive" should set the property value Pass e.style['font'] = "italic 10px/normal fantasy" should set the property value Pass e.style['font'] = "oblique normal 20%/1.2 monospace" should set the property value -Fail e.style['font'] = "italic normal normal calc(30% - 40px)/calc(120% + 1.2em) Menu" should set the property value +Pass e.style['font'] = "italic normal normal calc(30% - 40px)/calc(120% + 1.2em) Menu" should set the property value Pass e.style['font'] = "oblique normal normal normal xx-small \"FB Armada\"" should set the property value Fail e.style['font'] = "italic normal normal small-caps medium/normal serif" should set the property value Pass e.style['font'] = "oblique normal normal 100 xx-large/1.2 sans-serif" should set the property value -Fail e.style['font'] = "italic normal normal ultra-condensed larger/calc(120% + 1.2em) cursive" should set the property value +Pass e.style['font'] = "italic normal normal ultra-condensed larger/calc(120% + 1.2em) cursive" should set the property value Fail e.style['font'] = "oblique normal small-caps smaller fantasy" should set the property value Fail e.style['font'] = "italic normal small-caps normal 10px/normal monospace" should set the property value Fail e.style['font'] = "oblique normal small-caps 900 20%/1.2 Menu" should set the property value @@ -125,11 +125,11 @@ Fail e.style['font'] = "italic normal small-caps extra-condensed calc(30% - 40px Pass e.style['font'] = "oblique normal bold xx-small serif" should set the property value Pass e.style['font'] = "italic normal bolder normal medium/normal sans-serif" should set the property value Fail e.style['font'] = "oblique normal lighter small-caps xx-large/1.2 cursive" should set the property value -Fail e.style['font'] = "italic normal 100 condensed larger/calc(120% + 1.2em) fantasy" should set the property value +Pass e.style['font'] = "italic normal 100 condensed larger/calc(120% + 1.2em) fantasy" should set the property value Pass e.style['font'] = "oblique normal semi-condensed smaller monospace" should set the property value Pass e.style['font'] = "italic normal semi-expanded normal 10px/normal Menu" should set the property value Fail e.style['font'] = "oblique normal expanded small-caps 20%/1.2 \"FB Armada\"" should set the property value -Fail e.style['font'] = "italic normal extra-expanded 900 calc(30% - 40px)/calc(120% + 1.2em) serif" should set the property value +Pass e.style['font'] = "italic normal extra-expanded 900 calc(30% - 40px)/calc(120% + 1.2em) serif" should set the property value Fail e.style['font'] = "oblique small-caps xx-small sans-serif" should set the property value Fail e.style['font'] = "italic small-caps normal medium/normal cursive" should set the property value Fail e.style['font'] = "oblique small-caps normal normal xx-large/1.2 fantasy" should set the property value @@ -141,19 +141,19 @@ Fail e.style['font'] = "italic small-caps 100 ultra-condensed calc(30% - 40px)/c Fail e.style['font'] = "oblique small-caps extra-condensed xx-small cursive" should set the property value Fail e.style['font'] = "italic small-caps condensed normal medium/normal fantasy" should set the property value Fail e.style['font'] = "oblique small-caps semi-condensed 900 xx-large/1.2 monospace" should set the property value -Fail e.style['font'] = "italic bold larger/calc(120% + 1.2em) Menu" should set the property value +Pass e.style['font'] = "italic bold larger/calc(120% + 1.2em) Menu" should set the property value Pass e.style['font'] = "oblique bolder normal smaller \"FB Armada\"" should set the property value Fail e.style['font'] = "italic lighter normal normal 10px/normal serif" should set the property value Fail e.style['font'] = "oblique 100 normal small-caps 20%/1.2 sans-serif" should set the property value -Fail e.style['font'] = "italic 900 normal semi-expanded calc(30% - 40px)/calc(120% + 1.2em) cursive" should set the property value +Pass e.style['font'] = "italic 900 normal semi-expanded calc(30% - 40px)/calc(120% + 1.2em) cursive" should set the property value Fail e.style['font'] = "oblique bold small-caps xx-small fantasy" should set the property value Fail e.style['font'] = "italic bolder small-caps normal medium/normal monospace" should set the property value Fail e.style['font'] = "oblique lighter small-caps expanded xx-large/1.2 Menu" should set the property value -Fail e.style['font'] = "italic 100 extra-expanded larger/calc(120% + 1.2em) \"FB Armada\"" should set the property value +Pass e.style['font'] = "italic 100 extra-expanded larger/calc(120% + 1.2em) \"FB Armada\"" should set the property value Pass e.style['font'] = "oblique 900 ultra-expanded normal smaller serif" should set the property value Fail e.style['font'] = "italic bold ultra-condensed small-caps 10px/normal sans-serif" should set the property value Pass e.style['font'] = "oblique extra-condensed 20%/1.2 cursive" should set the property value -Fail e.style['font'] = "italic condensed normal calc(30% - 40px)/calc(120% + 1.2em) fantasy" should set the property value +Pass e.style['font'] = "italic condensed normal calc(30% - 40px)/calc(120% + 1.2em) fantasy" should set the property value Pass e.style['font'] = "oblique semi-condensed normal normal xx-small monospace" should set the property value Fail e.style['font'] = "italic semi-expanded normal small-caps medium/normal Menu" should set the property value Pass e.style['font'] = "oblique expanded normal bolder xx-large/1.2 \"FB Armada\"" should set the property value @@ -161,7 +161,7 @@ Fail e.style['font'] = "italic extra-expanded small-caps larger/calc(120% + 1.2e Fail e.style['font'] = "oblique ultra-expanded small-caps normal smaller sans-serif" should set the property value Fail e.style['font'] = "italic ultra-condensed small-caps lighter 10px/normal cursive" should set the property value Pass e.style['font'] = "oblique extra-condensed 100 20%/1.2 fantasy" should set the property value -Fail e.style['font'] = "italic condensed 900 normal calc(30% - 40px)/calc(120% + 1.2em) monospace" should set the property value +Pass e.style['font'] = "italic condensed 900 normal calc(30% - 40px)/calc(120% + 1.2em) monospace" should set the property value Fail e.style['font'] = "oblique semi-condensed bold small-caps xx-small Menu" should set the property value Fail e.style['font'] = "small-caps medium/normal \"FB Armada\"" should set the property value Fail e.style['font'] = "small-caps normal xx-large/1.2 serif" should set the property value @@ -217,15 +217,15 @@ Fail e.style['font'] = "small-caps extra-expanded lighter normal larger/calc(120 Fail e.style['font'] = "small-caps ultra-expanded 100 oblique smaller sans-serif" should set the property value Pass e.style['font'] = "900 10px/normal cursive" should set the property value Pass e.style['font'] = "bold normal 20%/1.2 fantasy" should set the property value -Fail e.style['font'] = "bolder normal normal calc(30% - 40px)/calc(120% + 1.2em) monospace" should set the property value +Pass e.style['font'] = "bolder normal normal calc(30% - 40px)/calc(120% + 1.2em) monospace" should set the property value Fail e.style['font'] = "lighter normal normal normal xx-small Menu" should set the property value Pass e.style['font'] = "100 normal normal italic medium/normal \"FB Armada\"" should set the property value Fail e.style['font'] = "900 normal normal small-caps xx-large/1.2 serif" should set the property value -Fail e.style['font'] = "bold normal normal ultra-condensed larger/calc(120% + 1.2em) sans-serif" should set the property value +Pass e.style['font'] = "bold normal normal ultra-condensed larger/calc(120% + 1.2em) sans-serif" should set the property value Pass e.style['font'] = "bolder normal oblique smaller cursive" should set the property value Fail e.style['font'] = "lighter normal italic normal 10px/normal fantasy" should set the property value Fail e.style['font'] = "100 normal oblique small-caps 20%/1.2 monospace" should set the property value -Fail e.style['font'] = "900 normal italic extra-condensed calc(30% - 40px)/calc(120% + 1.2em) Menu" should set the property value +Pass e.style['font'] = "900 normal italic extra-condensed calc(30% - 40px)/calc(120% + 1.2em) Menu" should set the property value Fail e.style['font'] = "bold normal small-caps xx-small \"FB Armada\"" should set the property value Fail e.style['font'] = "bolder normal small-caps normal medium/normal serif" should set the property value Fail e.style['font'] = "lighter normal small-caps oblique xx-large/1.2 sans-serif" should set the property value @@ -257,11 +257,11 @@ Fail e.style['font'] = "lighter small-caps extra-expanded larger/calc(120% + 1.2 Fail e.style['font'] = "100 small-caps ultra-expanded normal smaller \"FB Armada\"" should set the property value Fail e.style['font'] = "900 small-caps ultra-condensed italic 10px/normal serif" should set the property value Pass e.style['font'] = "bold extra-condensed 20%/1.2 sans-serif" should set the property value -Fail e.style['font'] = "bolder condensed normal calc(30% - 40px)/calc(120% + 1.2em) cursive" should set the property value +Pass e.style['font'] = "bolder condensed normal calc(30% - 40px)/calc(120% + 1.2em) cursive" should set the property value Fail e.style['font'] = "lighter semi-condensed normal normal xx-small fantasy" should set the property value Pass e.style['font'] = "100 semi-expanded normal oblique medium/normal monospace" should set the property value Fail e.style['font'] = "900 expanded normal small-caps xx-large/1.2 Menu" should set the property value -Fail e.style['font'] = "bold extra-expanded italic larger/calc(120% + 1.2em) \"FB Armada\"" should set the property value +Pass e.style['font'] = "bold extra-expanded italic larger/calc(120% + 1.2em) \"FB Armada\"" should set the property value Pass e.style['font'] = "bolder ultra-expanded oblique normal smaller serif" should set the property value Fail e.style['font'] = "lighter ultra-condensed italic small-caps 10px/normal sans-serif" should set the property value Fail e.style['font'] = "100 extra-condensed small-caps 20%/1.2 cursive" should set the property value @@ -269,11 +269,11 @@ Fail e.style['font'] = "900 condensed small-caps normal calc(30% - 40px)/calc(12 Fail e.style['font'] = "bold semi-condensed small-caps oblique xx-small monospace" should set the property value Pass e.style['font'] = "semi-expanded medium/normal Menu" should set the property value Pass e.style['font'] = "expanded normal xx-large/1.2 \"FB Armada\"" should set the property value -Fail e.style['font'] = "extra-expanded normal normal larger/calc(120% + 1.2em) serif" should set the property value +Pass e.style['font'] = "extra-expanded normal normal larger/calc(120% + 1.2em) serif" should set the property value Pass e.style['font'] = "ultra-expanded normal normal normal smaller sans-serif" should set the property value Pass e.style['font'] = "ultra-condensed normal normal italic 10px/normal cursive" should set the property value Fail e.style['font'] = "extra-condensed normal normal small-caps 20%/1.2 fantasy" should set the property value -Fail e.style['font'] = "condensed normal normal bolder calc(30% - 40px)/calc(120% + 1.2em) monospace" should set the property value +Pass e.style['font'] = "condensed normal normal bolder calc(30% - 40px)/calc(120% + 1.2em) monospace" should set the property value Pass e.style['font'] = "semi-condensed normal oblique xx-small Menu" should set the property value Pass e.style['font'] = "semi-expanded normal italic normal medium/normal \"FB Armada\"" should set the property value Fail e.style['font'] = "expanded normal oblique small-caps xx-large/1.2 serif" should set the property value @@ -309,11 +309,11 @@ Fail e.style['font'] = "condensed small-caps bold calc(30% - 40px)/calc(120% + 1 Fail e.style['font'] = "semi-condensed small-caps bolder normal xx-small cursive" should set the property value Fail e.style['font'] = "semi-expanded small-caps lighter italic medium/normal fantasy" should set the property value Pass e.style['font'] = "expanded 100 xx-large/1.2 monospace" should set the property value -Fail e.style['font'] = "extra-expanded 900 normal larger/calc(120% + 1.2em) Menu" should set the property value +Pass e.style['font'] = "extra-expanded 900 normal larger/calc(120% + 1.2em) Menu" should set the property value Pass e.style['font'] = "ultra-expanded bold normal normal smaller \"FB Armada\"" should set the property value Pass e.style['font'] = "ultra-condensed bolder normal oblique 10px/normal serif" should set the property value Fail e.style['font'] = "extra-condensed lighter normal small-caps 20%/1.2 sans-serif" should set the property value -Fail e.style['font'] = "condensed 100 italic calc(30% - 40px)/calc(120% + 1.2em) cursive" should set the property value +Pass e.style['font'] = "condensed 100 italic calc(30% - 40px)/calc(120% + 1.2em) cursive" should set the property value Pass e.style['font'] = "semi-condensed 900 oblique normal xx-small fantasy" should set the property value Fail e.style['font'] = "semi-expanded bold italic small-caps medium/normal monospace" should set the property value Fail e.style['font'] = "expanded bolder small-caps xx-large/1.2 Menu" should set the property value