summaryrefslogtreecommitdiff
path: root/test/Format
diff options
context:
space:
mode:
Diffstat (limited to 'test/Format')
-rw-r--r--test/Format/cursor.cpp6
-rw-r--r--test/Format/diagnostic.cpp4
-rw-r--r--test/Format/line-ranges.cpp11
-rw-r--r--test/Format/multiple-inputs-error.cpp6
-rw-r--r--test/Format/style-on-command-line.cpp29
5 files changed, 50 insertions, 6 deletions
diff --git a/test/Format/cursor.cpp b/test/Format/cursor.cpp
new file mode 100644
index 0000000000000..d9aab5acb6350
--- /dev/null
+++ b/test/Format/cursor.cpp
@@ -0,0 +1,6 @@
+// RUN: grep -Ev "// *[A-Z-]+:" %s > %t2.cpp
+// RUN: clang-format -style=LLVM %t2.cpp -cursor=6 > %t.cpp
+// RUN: FileCheck -strict-whitespace -input-file=%t.cpp %s
+// CHECK: {{^\{ "Cursor": 4 \}$}}
+// CHECK: {{^int\ \i;$}}
+ int i;
diff --git a/test/Format/diagnostic.cpp b/test/Format/diagnostic.cpp
deleted file mode 100644
index 2e930ee5b790a..0000000000000
--- a/test/Format/diagnostic.cpp
+++ /dev/null
@@ -1,4 +0,0 @@
-// RUN: clang-format 2>&1 >/dev/null %s |FileCheck %s
-
-}
-// CHECK: diagnostic.cpp:[[@LINE-1]]:1: error: unexpected '}'
diff --git a/test/Format/line-ranges.cpp b/test/Format/line-ranges.cpp
new file mode 100644
index 0000000000000..370445aed1e1d
--- /dev/null
+++ b/test/Format/line-ranges.cpp
@@ -0,0 +1,11 @@
+// RUN: grep -Ev "// *[A-Z-]+:" %s > %t.cpp
+// RUN: clang-format -style=LLVM -lines=1:1 -lines=5:5 -i %t.cpp
+// RUN: FileCheck -strict-whitespace -input-file=%t.cpp %s
+// CHECK: {{^int\ \*i;$}}
+ int*i;
+
+// CHECK: {{^\ \ int\ \ \*\ \ i;$}}
+ int * i;
+
+// CHECK: {{^\ \ int\ \*i;$}}
+ int * i;
diff --git a/test/Format/multiple-inputs-error.cpp b/test/Format/multiple-inputs-error.cpp
index 71f87e0b15b25..1aa9c9f3e2fad 100644
--- a/test/Format/multiple-inputs-error.cpp
+++ b/test/Format/multiple-inputs-error.cpp
@@ -1,6 +1,8 @@
// RUN: cp %s %t-1.cpp
// RUN: cp %s %t-2.cpp
-// RUN: clang-format 2>&1 >/dev/null -offset=1 -length=0 %t-1.cpp %t-2.cpp |FileCheck %s
-// CHECK: error: "-offset" and "-length" can only be used for single file.
+// RUN: not clang-format 2>&1 >/dev/null -offset=1 -length=0 %t-1.cpp %t-2.cpp |FileCheck %s
+// RUN: not clang-format 2>&1 >/dev/null -lines=1:1 %t-1.cpp %t-2.cpp |FileCheck %s -check-prefix=CHECK-LINE
+// CHECK: error: -offset, -length and -lines can only be used for single file.
+// CHECK-LINE: error: -offset, -length and -lines can only be used for single file.
int i ;
diff --git a/test/Format/style-on-command-line.cpp b/test/Format/style-on-command-line.cpp
new file mode 100644
index 0000000000000..22131a1ebe1bb
--- /dev/null
+++ b/test/Format/style-on-command-line.cpp
@@ -0,0 +1,29 @@
+// RUN: grep -Ev "// *[A-Z0-9_]+:" %s > %t.cpp
+// RUN: clang-format -style="{BasedOnStyle: Google, IndentWidth: 8}" %t.cpp | FileCheck -strict-whitespace -check-prefix=CHECK1 %s
+// RUN: clang-format -style="{BasedOnStyle: LLVM, IndentWidth: 7}" %t.cpp | FileCheck -strict-whitespace -check-prefix=CHECK2 %s
+// RUN: clang-format -style="{BasedOnStyle: invalid, IndentWidth: 7}" %t.cpp 2>&1 | FileCheck -strict-whitespace -check-prefix=CHECK3 %s
+// RUN: clang-format -style="{lsjd}" %t.cpp 2>&1 | FileCheck -strict-whitespace -check-prefix=CHECK4 %s
+// RUN: [ ! -e %T/.clang-format ] || rm %T/.clang-format
+// RUN: printf "BasedOnStyle: google\nIndentWidth: 5\n" > %T/.clang-format
+// RUN: clang-format -style=file %t.cpp 2>&1 | FileCheck -strict-whitespace -check-prefix=CHECK5 %s
+// RUN: printf "\n" > %T/.clang-format
+// RUN: clang-format -style=file %t.cpp 2>&1 | FileCheck -strict-whitespace -check-prefix=CHECK6 %s
+// RUN: [ ! -e %T/.clang-format ] || rm %T/.clang-format
+// RUN: [ ! -e %T/_clang-format ] || rm %T/_clang-format
+// RUN: printf "BasedOnStyle: google\nIndentWidth: 6\n" > %T/_clang-format
+// RUN: clang-format -style=file %t.cpp 2>&1 | FileCheck -strict-whitespace -check-prefix=CHECK7 %s
+void f() {
+// CHECK1: {{^ int\* i;$}}
+// CHECK2: {{^ int \*i;$}}
+// CHECK3: Unknown value for BasedOnStyle: invalid
+// CHECK3: Error parsing -style: Invalid argument, using LLVM style
+// CHECK3: {{^ int \*i;$}}
+// CHECK4: Error parsing -style: Invalid argument, using LLVM style
+// CHECK4: {{^ int \*i;$}}
+// CHECK5: {{^ int\* i;$}}
+// CHECK6: {{^Error reading .*\.clang-format: Invalid argument}}
+// XCHECK6X: {{^ int \*i;$}}
+// CHECK7: {{^ int\* i;$}}
+int*i;
+int j;
+}