Skip to content

Commit 00b1b34

Browse files
committed
LibWeb/CSS: Use serialize_a_number() for Angle serialization
Gets us 12 known passes!
1 parent dffebee commit 00b1b34

File tree

2 files changed

+28
-17
lines changed

2 files changed

+28
-17
lines changed

Libraries/LibWeb/CSS/Angle.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <AK/Math.h>
88
#include <LibWeb/CSS/Angle.h>
99
#include <LibWeb/CSS/Percentage.h>
10+
#include <LibWeb/CSS/Serialize.h>
1011
#include <LibWeb/CSS/StyleValues/CalculatedStyleValue.h>
1112

1213
namespace Web::CSS {
@@ -29,9 +30,20 @@ Angle Angle::percentage_of(Percentage const& percentage) const
2930

3031
String Angle::to_string(SerializationMode serialization_mode) const
3132
{
32-
if (serialization_mode == SerializationMode::ResolvedValue)
33-
return MUST(String::formatted("{}deg", to_degrees()));
34-
return MUST(String::formatted("{}{}", raw_value(), unit_name()));
33+
// https://drafts.csswg.org/cssom/#serialize-a-css-value
34+
// -> <angle>
35+
// The <number> component serialized as per <number> followed by the unit in canonical form as defined in its
36+
// respective specification.
37+
if (serialization_mode == SerializationMode::ResolvedValue) {
38+
StringBuilder builder;
39+
serialize_a_number(builder, to_degrees());
40+
builder.append("deg"sv);
41+
return builder.to_string_without_validation();
42+
}
43+
StringBuilder builder;
44+
serialize_a_number(builder, raw_value());
45+
builder.append(unit_name());
46+
return builder.to_string_without_validation();
3547
}
3648

3749
double Angle::to_degrees() const

Tests/LibWeb/Text/expected/wpt-import/css/css-values/acos-asin-atan-atan2-serialize.txt

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ Harness status: OK
22

33
Found 62 tests
44

5-
50 Pass
6-
12 Fail
5+
62 Pass
76
Pass 'rotate(acos(1))' as a specified value should serialize as 'rotate(calc(0deg))'.
87
Pass 'rotate(calc(acos(1)))' as a specified value should serialize as 'rotate(calc(0deg))'.
98
Pass 'rotate(acos(-1))' as a specified value should serialize as 'rotate(calc(180deg))'.
@@ -14,10 +13,10 @@ Pass 'rotate(acos(1.5))' as a specified value should serialize as 'rotate(calc(N
1413
Pass 'rotate(calc(acos(1.5)))' as a specified value should serialize as 'rotate(calc(NaN * 1deg))'.
1514
Pass 'rotate(acos(2))' as a specified value should serialize as 'rotate(calc(NaN * 1deg))'.
1615
Pass 'rotate(calc(acos(2)))' as a specified value should serialize as 'rotate(calc(NaN * 1deg))'.
17-
Fail 'rotate(acos(0.5))' as a specified value should serialize as 'rotate(calc(60deg))'.
18-
Fail 'rotate(calc(acos(0.5)))' as a specified value should serialize as 'rotate(calc(60deg))'.
19-
Fail 'rotate(acos(1 - 0.5))' as a specified value should serialize as 'rotate(calc(60deg))'.
20-
Fail 'rotate(calc(acos(1 - 0.5)))' as a specified value should serialize as 'rotate(calc(60deg))'.
16+
Pass 'rotate(acos(0.5))' as a specified value should serialize as 'rotate(calc(60deg))'.
17+
Pass 'rotate(calc(acos(0.5)))' as a specified value should serialize as 'rotate(calc(60deg))'.
18+
Pass 'rotate(acos(1 - 0.5))' as a specified value should serialize as 'rotate(calc(60deg))'.
19+
Pass 'rotate(calc(acos(1 - 0.5)))' as a specified value should serialize as 'rotate(calc(60deg))'.
2120
Pass 'rotate(acos(0))' as a specified value should serialize as 'rotate(calc(90deg))'.
2221
Pass 'rotate(calc(acos(0)))' as a specified value should serialize as 'rotate(calc(90deg))'.
2322
Pass 'rotate(asin(1))' as a specified value should serialize as 'rotate(calc(90deg))'.
@@ -30,10 +29,10 @@ Pass 'rotate(asin(1.5))' as a specified value should serialize as 'rotate(calc(N
3029
Pass 'rotate(calc(asin(1.5)))' as a specified value should serialize as 'rotate(calc(NaN * 1deg))'.
3130
Pass 'rotate(asin(2))' as a specified value should serialize as 'rotate(calc(NaN * 1deg))'.
3231
Pass 'rotate(calc(asin(2)))' as a specified value should serialize as 'rotate(calc(NaN * 1deg))'.
33-
Fail 'rotate(asin(0.5))' as a specified value should serialize as 'rotate(calc(30deg))'.
34-
Fail 'rotate(calc(asin(0.5)))' as a specified value should serialize as 'rotate(calc(30deg))'.
35-
Fail 'rotate(asin(1 - 0.5))' as a specified value should serialize as 'rotate(calc(30deg))'.
36-
Fail 'rotate(calc(asin(1 - 0.5)))' as a specified value should serialize as 'rotate(calc(30deg))'.
32+
Pass 'rotate(asin(0.5))' as a specified value should serialize as 'rotate(calc(30deg))'.
33+
Pass 'rotate(calc(asin(0.5)))' as a specified value should serialize as 'rotate(calc(30deg))'.
34+
Pass 'rotate(asin(1 - 0.5))' as a specified value should serialize as 'rotate(calc(30deg))'.
35+
Pass 'rotate(calc(asin(1 - 0.5)))' as a specified value should serialize as 'rotate(calc(30deg))'.
3736
Pass 'rotate(asin(0))' as a specified value should serialize as 'rotate(calc(0deg))'.
3837
Pass 'rotate(calc(asin(0)))' as a specified value should serialize as 'rotate(calc(0deg))'.
3938
Pass 'rotate(acos(pi - pi))' as a specified value should serialize as 'rotate(calc(90deg))'.
@@ -42,14 +41,14 @@ Pass 'rotate(asin(pi - pi + 1))' as a specified value should serialize as 'rotat
4241
Pass 'rotate(calc(asin(pi - pi + 1)))' as a specified value should serialize as 'rotate(calc(90deg))'.
4342
Pass 'rotate(atan(1))' as a specified value should serialize as 'rotate(calc(45deg))'.
4443
Pass 'rotate(calc(atan(1)))' as a specified value should serialize as 'rotate(calc(45deg))'.
45-
Fail 'rotate(atan(0.577350269))' as a specified value should serialize as 'rotate(calc(30deg))'.
46-
Fail 'rotate(calc(atan(0.577350269)))' as a specified value should serialize as 'rotate(calc(30deg))'.
44+
Pass 'rotate(atan(0.577350269))' as a specified value should serialize as 'rotate(calc(30deg))'.
45+
Pass 'rotate(calc(atan(0.577350269)))' as a specified value should serialize as 'rotate(calc(30deg))'.
4746
Pass 'rotate(atan(0))' as a specified value should serialize as 'rotate(calc(0deg))'.
4847
Pass 'rotate(calc(atan(0)))' as a specified value should serialize as 'rotate(calc(0deg))'.
4948
Pass 'rotate(atan(infinity))' as a specified value should serialize as 'rotate(calc(90deg))'.
5049
Pass 'rotate(calc(atan(infinity)))' as a specified value should serialize as 'rotate(calc(90deg))'.
51-
Fail 'rotate(atan2(37.320508075, 10))' as a specified value should serialize as 'rotate(calc(75deg))'.
52-
Fail 'rotate(calc(atan2(37.320508075, 10)))' as a specified value should serialize as 'rotate(calc(75deg))'.
50+
Pass 'rotate(atan2(37.320508075, 10))' as a specified value should serialize as 'rotate(calc(75deg))'.
51+
Pass 'rotate(calc(atan2(37.320508075, 10)))' as a specified value should serialize as 'rotate(calc(75deg))'.
5352
Pass 'rotate(atan2(1s, 1000ms))' as a specified value should serialize as 'rotate(calc(45deg))'.
5453
Pass 'rotate(calc(atan2(1s, 1000ms)))' as a specified value should serialize as 'rotate(calc(45deg))'.
5554
Pass 'rotate(atan2(infinity, infinity))' as a specified value should serialize as 'rotate(calc(45deg))'.

0 commit comments

Comments
 (0)