1//===-- ClangFormatFuzzer.cpp - Fuzz the Clang format tool ----------------===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9///
10/// \file
11/// \brief This file implements a function that runs Clang format on a single
12///  input. This function is then linked into the Fuzzer library.
13///
14//===----------------------------------------------------------------------===//
15
16#include "clang/Format/Format.h"
17
18extern "C" void TestOneInput(uint8_t *data, size_t size) {
19  // FIXME: fuzz more things: different styles, different style features.
20  std::string s((const char *)data, size);
21  auto Style = getGoogleStyle(clang::format::FormatStyle::LK_Cpp);
22  Style.ColumnLimit = 60;
23  applyAllReplacements(s, clang::format::reformat(
24                              Style, s, {clang::tooling::Range(0, s.size())}));
25}
26