[clang-format] Rename CSharpNullConditionalSq and add missing test
authorJonathan Coe <jbcoe@google.com>
Mon, 2 Mar 2020 15:46:33 +0000 (15:46 +0000)
committerJonathan Coe <jbcoe@google.com>
Mon, 2 Mar 2020 15:46:33 +0000 (15:46 +0000)
Summary:
Rename CSharpNullConditionalSq to CSharpNullConditionalLSquare.

Add test for spaces inside [] with C# Null conditionals.

Address comments missed from https://reviews.llvm.org/D75368.

Reviewers: krasimir

Reviewed By: krasimir

Subscribers: cfe-commits

Tags: #clang-format, #clang

Differential Revision: https://reviews.llvm.org/D75456

clang/lib/Format/FormatToken.h
clang/lib/Format/FormatTokenLexer.cpp
clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/FormatTestCSharp.cpp

index ac117840ea33582af5dbb4a70a305aa7462ca905..d0d08e470e6c19b5186af7d250afa1a12f661a57 100644 (file)
@@ -106,7 +106,7 @@ namespace format {
   TYPE(CSharpNullable)                                                         \
   TYPE(CSharpNullCoalescing)                                                   \
   TYPE(CSharpNullConditional)                                                  \
-  TYPE(CSharpNullConditionalSq)                                                \
+  TYPE(CSharpNullConditionalLSquare)                                           \
   TYPE(Unknown)
 
 enum TokenType {
index da73361ee3d5b8f7914d2244b6265ea51c44982e..8fa78b773e5eb820b249e045afff2d61b94ddcf2 100644 (file)
@@ -345,7 +345,7 @@ bool FormatTokenLexer::tryMergeCSharpNullConditional() {
 
   if (PeriodOrLSquare->is(tok::l_square)) {
     Question->Tok.setKind(tok::question); // no '?[' in clang tokens.
-    Question->Type = TT_CSharpNullConditionalSq;
+    Question->Type = TT_CSharpNullConditionalLSquare;
   } else {
     Question->Tok.setKind(tok::question); // no '?.' in clang tokens.
     Question->Type = TT_CSharpNullConditional;
index e1e08686ac44e80c955e491ab6befd87ab8fa948..35e0b423cfc4922a92506463645db5bc63ef6884 100644 (file)
@@ -972,7 +972,7 @@ private:
       }
       break;
     case tok::question:
-      if (Tok->is(TT_CSharpNullConditionalSq)) {
+      if (Tok->is(TT_CSharpNullConditionalLSquare)) {
         if (!parseSquare())
           return false;
         break;
@@ -1456,7 +1456,7 @@ private:
         return;
       }
       if (CurrentToken->TokenText == "?[") {
-        Current.Type = TT_CSharpNullConditionalSq;
+        Current.Type = TT_CSharpNullConditionalLSquare;
         return;
       }
     }
@@ -2947,11 +2947,11 @@ bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line,
       return true;
 
     // No space before '?['.
-    if (Right.is(TT_CSharpNullConditionalSq))
+    if (Right.is(TT_CSharpNullConditionalLSquare))
       return false;
 
     // Possible space inside `?[ 0 ]`.
-    if (Left.is(TT_CSharpNullConditionalSq))
+    if (Left.is(TT_CSharpNullConditionalLSquare))
       return Style.SpacesInSquareBrackets;
 
     // space between keywords and paren e.g. "using ("
index 0bc49856375b00305d8391e54d28a79c63ffc69c..d22e0da82321ecdc914c15d8e4a18eb7b105f0c0 100644 (file)
@@ -607,6 +607,7 @@ TEST_F(FormatTestCSharp, CSharpSpaces) {
 
   Style.SpacesInSquareBrackets = true;
   verifyFormat(R"(private float[ , ] Values;)", Style);
+  verifyFormat(R"(string dirPath = args?[ 0 ];)", Style);
 }
 
 TEST_F(FormatTestCSharp, CSharpNullableTypes) {