Пример #1
0
TEST_F(FormatTestJS, SpacesInContainerLiterals) {
  verifyFormat("var arr = [1, 2, 3];");
  verifyFormat("var obj = {a: 1, b: 2, c: 3};");

  verifyFormat("var obj = {a: 1, b: 2, c: 3};",
               getChromiumStyle(FormatStyle::LK_JavaScript));
  verifyFormat("someVariable = {'a': [{}]};");
}
Пример #2
0
static FormatStyle getStyle() {
  FormatStyle TheStyle = getGoogleStyle();
  if (Style == "LLVM")
    TheStyle = getLLVMStyle();
  if (Style == "Chromium")
    TheStyle = getChromiumStyle();
  return TheStyle;
}
Пример #3
0
TEST_F(FormatTestJS, SpacesInContainerLiterals) {
  verifyFormat("var arr = [1, 2, 3];");
  verifyFormat("f({a: 1, b: 2, c: 3});");

  verifyFormat("var object_literal_with_long_name = {\n"
               "  a: 'aaaaaaaaaaaaaaaaaa',\n"
               "  b: 'bbbbbbbbbbbbbbbbbb'\n"
               "};");

  verifyFormat("f({a: 1, b: 2, c: 3});",
               getChromiumStyle(FormatStyle::LK_JavaScript));
  verifyFormat("f({'a': [{}]});");
}
Пример #4
0
TEST_F(FormatTestJava, Chromium) {
  verifyFormat("class SomeClass {\n"
               "    void f() {}\n"
               "    int g() {\n"
               "        return 0;\n"
               "    }\n"
               "    void h() {\n"
               "        while (true) f();\n"
               "        for (;;) f();\n"
               "        if (true) f();\n"
               "    }\n"
               "}",
               getChromiumStyle(FormatStyle::LK_Java));
}
Пример #5
0
TEST_F(FormatTestJava, Annotations) {
  verifyFormat("@Override\n"
               "public String toString() {}");
  verifyFormat("@Override\n"
               "@Nullable\n"
               "public String getNameIfPresent() {}");
  verifyFormat("@Override // comment\n"
               "@Nullable\n"
               "public String getNameIfPresent() {}");
  verifyFormat("@java.lang.Override // comment\n"
               "@Nullable\n"
               "public String getNameIfPresent() {}");

  verifyFormat("@SuppressWarnings(value = \"unchecked\")\n"
               "public void doSomething() {}");
  verifyFormat("@SuppressWarnings(value = \"unchecked\")\n"
               "@Author(name = \"abc\")\n"
               "public void doSomething() {}");

  verifyFormat("DoSomething(new A() {\n"
               "  @Override\n"
               "  public String toString() {}\n"
               "});");

  verifyFormat("void SomeFunction(@Nullable String something) {}");
  verifyFormat("void SomeFunction(@org.llvm.Nullable String something) {}");

  verifyFormat("@Partial @Mock DataLoader loader;");
  verifyFormat("@Partial\n"
               "@Mock\n"
               "DataLoader loader;",
               getChromiumStyle(FormatStyle::LK_Java));
  verifyFormat("@SuppressWarnings(value = \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\")\n"
               "public static int iiiiiiiiiiiiiiiiiiiiiiii;");

  verifyFormat("@SomeAnnotation(\"With some really looooooooooooooong text\")\n"
               "private static final long something = 0L;");
  verifyFormat("@org.llvm.Qualified(\"With some really looooooooooong text\")\n"
               "private static final long something = 0L;");
  verifyFormat("@Mock\n"
               "DataLoader loooooooooooooooooooooooader =\n"
               "    aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa;",
               getStyleWithColumns(60));
  verifyFormat("@org.llvm.QualifiedMock\n"
               "DataLoader loooooooooooooooooooooooader =\n"
               "    aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa;",
               getStyleWithColumns(60));
  verifyFormat("@Test(a)\n"
               "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa =\n"
               "    aaaaaaaaaaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaa);");
  verifyFormat("@SomeAnnotation(\n"
               "    aaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaa)\n"
               "int i;",
               getStyleWithColumns(50));
  verifyFormat("@Test\n"
               "ReturnType doSomething(\n"
               "    String aaaaaaaaaaaaa, String bbbbbbbbbbbbbbb) {}",
               getStyleWithColumns(60));
  verifyFormat("{\n"
               "  boolean someFunction(\n"
               "      @Param(aaaaaaaaaaaaaaaa) String aaaaa,\n"
               "      String bbbbbbbbbbbbbbb) {}\n"
               "}",
               getStyleWithColumns(60));
}