[PATCH] D22146: clang-format: [JS] Sort imports case insensitive.

Martin Probst via cfe-commits cfe-commits at lists.llvm.org
Sat Jul 9 08:18:43 PDT 2016


This revision was automatically updated to reflect the committed changes.
Closed by commit rL274977: clang-format: [JS] Sort imports case insensitive. (authored by mprobst).

Changed prior to commit:
  http://reviews.llvm.org/D22146?vs=63271&id=63391#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D22146

Files:
  cfe/trunk/lib/Format/SortJavaScriptImports.cpp
  cfe/trunk/unittests/Format/SortImportsTestJS.cpp

Index: cfe/trunk/lib/Format/SortJavaScriptImports.cpp
===================================================================
--- cfe/trunk/lib/Format/SortJavaScriptImports.cpp
+++ cfe/trunk/lib/Format/SortJavaScriptImports.cpp
@@ -105,8 +105,8 @@
   // Empty URLs sort *last* (for export {...};).
   if (LHS.URL.empty() != RHS.URL.empty())
     return LHS.URL.empty() < RHS.URL.empty();
-  if (LHS.URL != RHS.URL)
-    return LHS.URL < RHS.URL;
+  if (int Res = LHS.URL.compare_lower(RHS.URL))
+    return Res < 0;
   // '*' imports (with prefix) sort before {a, b, ...} imports.
   if (LHS.Prefix.empty() != RHS.Prefix.empty())
     return LHS.Prefix.empty() < RHS.Prefix.empty();
@@ -245,7 +245,7 @@
     std::stable_sort(
         Symbols.begin(), Symbols.end(),
         [&](const JsImportedSymbol &LHS, const JsImportedSymbol &RHS) {
-          return LHS.Symbol < RHS.Symbol;
+          return LHS.Symbol.compare_lower(RHS.Symbol) < 0;
         });
     if (Symbols == Reference.Symbols) {
       // No change in symbol order.
Index: cfe/trunk/unittests/Format/SortImportsTestJS.cpp
===================================================================
--- cfe/trunk/unittests/Format/SortImportsTestJS.cpp
+++ cfe/trunk/unittests/Format/SortImportsTestJS.cpp
@@ -240,6 +240,27 @@
   verifySort("import {A, B,} from 'aa';\n", "import {B, A,} from 'aa';\n");
 }
 
+TEST_F(SortImportsTestJS, SortCaseInsensitive) {
+  verifySort("import {A} from 'aa';\n"
+             "import {A} from 'Ab';\n"
+             "import {A} from 'b';\n"
+             "import {A} from 'Bc';\n"
+             "\n"
+             "1;",
+             "import {A} from 'b';\n"
+             "import {A} from 'Bc';\n"
+             "import {A} from 'Ab';\n"
+             "import {A} from 'aa';\n"
+             "\n"
+             "1;");
+  verifySort("import {aa, Ab, b, Bc} from 'x';\n"
+             "\n"
+             "1;",
+             "import {b, Bc, Ab, aa} from 'x';\n"
+             "\n"
+             "1;");
+}
+
 } // end namespace
 } // end namespace format
 } // end namespace clang


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D22146.63391.patch
Type: text/x-patch
Size: 2069 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160709/2d529f8e/attachment.bin>


More information about the cfe-commits mailing list