diff options
author | Alexander Kornienko <alexfh@google.com> | 2013-12-03 10:50:16 +0000 |
---|---|---|
committer | Alexander Kornienko <alexfh@google.com> | 2013-12-03 10:50:16 +0000 |
commit | a48a12cf81cb0804506ddeb4994f17008cf097b3 (patch) | |
tree | 00f58af46ff99f2706774862affea8019e248005 /clang/unittests/Format/FormatTestJS.cpp | |
parent | f54dcbc4e65a1d9d6a9c5731ed5ffd86a87c89ac (diff) | |
download | bcm5719-llvm-a48a12cf81cb0804506ddeb4994f17008cf097b3.tar.gz bcm5719-llvm-a48a12cf81cb0804506ddeb4994f17008cf097b3.zip |
Create a separate file for JS-specific unit tests.
Reviewers: djasper
Reviewed By: djasper
CC: cfe-commits, klimek
Differential Revision: http://llvm-reviews.chandlerc.com/D2307
llvm-svn: 196266
Diffstat (limited to 'clang/unittests/Format/FormatTestJS.cpp')
-rw-r--r-- | clang/unittests/Format/FormatTestJS.cpp | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/clang/unittests/Format/FormatTestJS.cpp b/clang/unittests/Format/FormatTestJS.cpp new file mode 100644 index 00000000000..1f8f139574a --- /dev/null +++ b/clang/unittests/Format/FormatTestJS.cpp @@ -0,0 +1,86 @@ +//===- unittest/Format/FormatTestJS.cpp - Formatting unit tests for JS ----===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#define DEBUG_TYPE "format-test" + +#include "FormatTestUtils.h" + +#include "clang/Format/Format.h" +#include "llvm/Support/Debug.h" +#include "gtest/gtest.h" + +namespace clang { +namespace format { + +class FormatTestJS : public ::testing::Test { +protected: + static std::string format(llvm::StringRef Code, unsigned Offset, + unsigned Length, const FormatStyle &Style) { + DEBUG(llvm::errs() << "---\n"); + DEBUG(llvm::errs() << Code << "\n\n"); + std::vector<tooling::Range> Ranges(1, tooling::Range(Offset, Length)); + tooling::Replacements Replaces = reformat(Style, Code, Ranges); + std::string Result = applyAllReplacements(Code, Replaces); + EXPECT_NE("", Result); + DEBUG(llvm::errs() << "\n" << Result << "\n\n"); + return Result; + } + + static std::string format(llvm::StringRef Code, + const FormatStyle &Style = getJSStyle()) { + return format(Code, 0, Code.size(), Style); + } + + static FormatStyle getJSStyle() { + FormatStyle Style = getLLVMStyle(); + Style.Language = FormatStyle::LK_JavaScript; + return Style; + } + + static FormatStyle getJSStyleWithColumns(unsigned ColumnLimit) { + FormatStyle Style = getJSStyle(); + Style.ColumnLimit = ColumnLimit; + return Style; + } + + static void verifyFormat(llvm::StringRef Code, + const FormatStyle &Style = getJSStyle()) { + EXPECT_EQ(Code.str(), format(test::messUp(Code), Style)); + } +}; + +TEST_F(FormatTestJS, UnderstandsJavaScriptOperators) { + verifyFormat("a == = b;"); + verifyFormat("a != = b;"); + + verifyFormat("a === b;"); + verifyFormat("aaaaaaa ===\n b;", getJSStyleWithColumns(10)); + verifyFormat("a !== b;"); + verifyFormat("aaaaaaa !==\n b;", getJSStyleWithColumns(10)); + verifyFormat("if (a + b + c +\n" + " d !==\n" + " e + f + g)\n" + " q();", + getJSStyleWithColumns(20)); + + verifyFormat("a >> >= b;"); + + verifyFormat("a >>> b;"); + verifyFormat("aaaaaaa >>>\n b;", getJSStyleWithColumns(10)); + verifyFormat("a >>>= b;"); + verifyFormat("aaaaaaa >>>=\n b;", getJSStyleWithColumns(10)); + verifyFormat("if (a + b + c +\n" + " d >>>\n" + " e + f + g)\n" + " q();", + getJSStyleWithColumns(20)); +} + +} // end namespace tooling +} // end namespace clang |