Index: test/Format/check-coding-style-mozilla.cpp =================================================================== --- test/Format/check-coding-style-mozilla.cpp +++ test/Format/check-coding-style-mozilla.cpp @@ -0,0 +1,136 @@ +// RUN: clang-format -style=Mozilla %s > %T/foo.cpp 2>&1 +// RUN: diff -u %s %T/foo.cpp +// RUN: rm -rf %T/foo.cpp + +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +if (true) { +} else if (false) { +} else { +} + +while (true) { +} + +do { +} while (true); + +for (auto bar::in) { +} + +switch (var) { + case 1: { + // When you need to declare a variable in a switch, put the block in braces + int var; + break; + } + case 2: + foo(); + break; + default: + break; +} + +namespace mozilla { + +class MyClass : public A +{ + void Myclass(); +}; + +class MyClass : public X // When deriving from more than one class, put each on + // its own line. + , + public Y +{ +public: + MyClass(int aVar, int aVar2) + : mVar(aVar) + , mVar2(aVar2) + { + foo(); + } + + // Tiny constructors and destructors can be written on a single line. + MyClass() {} + + // Unless it's a copy or move constructor or you have a specific reason to + // allow implicit conversions, mark all single-argument constructors explicit. + explicit MyClass(OtherClass aArg) { bar(); } + + // This constructor can also take a single argument, so it also needs to be + // marked explicit. + explicit MyClass(OtherClass aArg, AnotherClass aArg2 = AnotherClass()) + { + foo(); + } + + int TinyFunction() + { + return mVar; + } // Tiny functions can be written in a single line. + + int LargerFunction() + { + bar(); + foo(); + } + +private: + int mVar; +}; + +} // namespace mozilla + +template // Templates on own line. +static int // Return type on own line for top-level functions. + MyFunction(int a) +{ + foo(); +} + +int +MyClass::Method(long b) +{ + bar(); +} + +T* p; // GOOD + +MOZ_ASSERT(!mChild && !(mBits & nsCachedStyleData::GetBitForSID(aSID)) && + !GetCachedStyleData(aSID), + "bar"); + +return (nextKeyframe < aTimeThreshold || + (mVideo.mTimeThreshold && + mVideo.mTimeThreshold.ref().EndTime() < aTimeThreshold)) && + nextKeyframe.ToMicroseconds() >= 0 && !nextKeyframe.IsInfinite(); + +LOGV("%d audio samples demuxed (sid:%d)", + aSamples->mSamples.Length(), + aSamples->mSamples[0]->mTrackInfo + ? aSamples->mSamples[0]->mTrackInfo->GetID() + : 0); + +return (aDecoder.HasPromise() || aDecoder.mTimeThreshold.isSome()) && + !aDecoder.HasPendingDrain() && !aDecoder.HasFatalError() && + !aDecoder.mDemuxRequest.Exists() && !aDecoder.mOutput.Length() && + !aDecoder.HasInternalSeekPending() && !aDecoder.mDecodeRequest.Exists(); + +if ((decoder.mWaitingForData && + (!decoder.mTimeThreshold || decoder.mTimeThreshold.ref().mWaiting)) || + (decoder.mWaitingForKey && decoder.mDecodeRequest.Exists())) { +} + +template +void +foo(); + +#define MACRO(V) \ + V(Rt2) /* one more char */ \ + V(Rs) /* than here */ \ +/* comment 3 */