summaryrefslogtreecommitdiff
path: root/unittests/Format
diff options
context:
space:
mode:
authorDaniel Jasper <djasper@google.com>2014-05-08 07:01:45 +0000
committerDaniel Jasper <djasper@google.com>2014-05-08 07:01:45 +0000
commit33a00075e1c1ec80650d190bd61f4bc9339de192 (patch)
tree142f48ba9edf345619f2538911e45331a35ebf36 /unittests/Format
parent603e37c3dd2933111c6e34c1c866a03c45d163b6 (diff)
downloadclang-33a00075e1c1ec80650d190bd61f4bc9339de192.tar.gz
clang-33a00075e1c1ec80650d190bd61f4bc9339de192.tar.bz2
clang-33a00075e1c1ec80650d190bd61f4bc9339de192.tar.xz
clang-format: [JS] Initial support for regex literals.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@208281 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests/Format')
-rw-r--r--unittests/Format/FormatTestJS.cpp70
1 files changed, 70 insertions, 0 deletions
diff --git a/unittests/Format/FormatTestJS.cpp b/unittests/Format/FormatTestJS.cpp
index a94ed4707d..52c85d3a9a 100644
--- a/unittests/Format/FormatTestJS.cpp
+++ b/unittests/Format/FormatTestJS.cpp
@@ -111,5 +111,75 @@ TEST_F(FormatTestJS, ClosureStyleComments) {
verifyFormat("var x = /** @type {foo} */ (bar);");
}
+TEST_F(FormatTestJS, RegexLiteralClassification) {
+ // Regex literals.
+ verifyFormat("var regex = /abc/;");
+ verifyFormat("f(/abc/);");
+ verifyFormat("f(abc, /abc/);");
+ verifyFormat("some_map[/abc/];");
+ verifyFormat("var x = a ? /abc/ : /abc/;");
+ verifyFormat("for (var i = 0; /abc/.test(s[i]); i++) {\n}");
+ verifyFormat("var x = !/abc/.test(y);");
+ verifyFormat("var x = a && /abc/.test(y);");
+ verifyFormat("var x = a || /abc/.test(y);");
+ verifyFormat("var x = a + /abc/.search(y);");
+
+ // Not regex literals.
+ verifyFormat("var a = a / 2 + b / 3;");
+}
+
+TEST_F(FormatTestJS, RegexLiteralSpecialCharacters) {
+ verifyFormat("var regex = /a*/;");
+ verifyFormat("var regex = /a+/;");
+ verifyFormat("var regex = /a?/;");
+ verifyFormat("var regex = /.a./;");
+ verifyFormat("var regex = /a\\*/;");
+ verifyFormat("var regex = /^a$/;");
+ verifyFormat("var regex = /\\/a/;");
+ verifyFormat("var regex = /(?:x)/;");
+ verifyFormat("var regex = /x(?=y)/;");
+ verifyFormat("var regex = /x(?!y)/;");
+ verifyFormat("var regex = /x|y/;");
+ verifyFormat("var regex = /a{2}/;");
+ verifyFormat("var regex = /a{1,3}/;");
+ verifyFormat("var regex = /[abc]/;");
+ verifyFormat("var regex = /[^abc]/;");
+ verifyFormat("var regex = /[\\b]/;");
+ verifyFormat("var regex = /\\b/;");
+ verifyFormat("var regex = /\\B/;");
+ verifyFormat("var regex = /\\d/;");
+ verifyFormat("var regex = /\\D/;");
+ verifyFormat("var regex = /\\f/;");
+ verifyFormat("var regex = /\\n/;");
+ verifyFormat("var regex = /\\r/;");
+ verifyFormat("var regex = /\\s/;");
+ verifyFormat("var regex = /\\S/;");
+ verifyFormat("var regex = /\\t/;");
+ verifyFormat("var regex = /\\v/;");
+ verifyFormat("var regex = /\\w/;");
+ verifyFormat("var regex = /\\W/;");
+ verifyFormat("var regex = /a(a)\\1/;");
+ verifyFormat("var regex = /\\0/;");
+}
+
+TEST_F(FormatTestJS, RegexLiteralModifiers) {
+ verifyFormat("var regex = /abc/g;");
+ verifyFormat("var regex = /abc/i;");
+ verifyFormat("var regex = /abc/m;");
+ verifyFormat("var regex = /abc/y;");
+}
+
+TEST_F(FormatTestJS, RegexLiteralLength) {
+ verifyFormat("var regex = /aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/;",
+ getGoogleJSStyleWithColumns(60));
+ verifyFormat("var regex =\n"
+ " /aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/;",
+ getGoogleJSStyleWithColumns(60));
+}
+
+TEST_F(FormatTestJS, RegexLiteralExamples) {
+ verifyFormat("var regex = search.match(/(?:\?|&)times=([^?&]+)/i);");
+}
+
} // end namespace tooling
} // end namespace clang