: Current.Previous->is(tok::identifier);
if (IsIdentifier ||
Current.Previous->isOneOf(
- tok::kw_namespace, tok::r_paren, tok::r_square, tok::r_brace,
- tok::kw_false, tok::kw_true, Keywords.kw_type, Keywords.kw_get,
- Keywords.kw_init, Keywords.kw_set) ||
+ tok::kw_default, tok::kw_namespace, tok::r_paren, tok::r_square,
+ tok::r_brace, tok::kw_false, tok::kw_true, Keywords.kw_type,
+ Keywords.kw_get, Keywords.kw_init, Keywords.kw_set) ||
Current.Previous->Tok.isLiteral()) {
Current.setType(TT_NonNullAssertion);
return;
MicrosoftStyle);
}
+TEST_F(FormatTestCSharp, DefaultLiteral) {
+ FormatStyle Style = getGoogleStyle(FormatStyle::LK_CSharp);
+
+ verifyFormat(
+ "T[] InitializeArray<T>(int length, T initialValue = default) {}", Style);
+ verifyFormat("System.Numerics.Complex fillValue = default;", Style);
+ verifyFormat("int Value { get } = default;", Style);
+ verifyFormat("int Value { get } = default!;", Style);
+ verifyFormat(R"(//
+public record Person {
+ public string GetInit { get; init; } = default!;
+};)",
+ Style);
+ verifyFormat(R"(//
+public record Person {
+ public string GetSet { get; set; } = default!;
+};)",
+ Style);
+}
+
TEST_F(FormatTestCSharp, CSharpSpaces) {
FormatStyle Style = getGoogleStyle(FormatStyle::LK_CSharp);
Style.SpaceBeforeSquareBrackets = false;