public void Sorting_AngleBracketsFirst() { // With sort by type. string expectedFormatedCode_NoBlanks = @"#include <d_firstanyways> #include <e_secondanyways> #include <b.hpp> #include <c.hpp> #include ""filename.h"" #include ""a.h"""; string expectedFormatedCode_WithBlanks = @"#include <b_second> #include ""filename.h"" #include ""c_third"" // A comment #include ""z_first"""; var settings = new IncludeToolbox.FormatterOptionsPage(); settings.SortByType = IncludeToolbox.FormatterOptionsPage.TypeSorting.AngleBracketsFirst; settings.PrecedenceRegexes = new string[] { IncludeToolbox.RegexUtils.CurrentFileNameKey, ".+_.+" }; settings.BlankAfterRegexGroupMatch = false; settings.RemoveEmptyLines = false; string formatedCode = IncludeFormatter.FormatIncludes(sourceCode_NoBlanks, "filename.cpp", new string[] { }, settings); Assert.AreEqual(expectedFormatedCode_NoBlanks, formatedCode); formatedCode = IncludeFormatter.FormatIncludes(sourceCode_WithBlanks, "filename.cpp", new string[] { }, settings); Assert.AreEqual(expectedFormatedCode_WithBlanks, formatedCode); }
public void OtherPreprocessorDirectives() { string source = @"#pragma once // SomeComment #include ""z"" #include <b> #include ""filename.h"" #if test #include <d> // A comment #include ""a9"" #include <d> #include <c> #else #include <d> #include <a3> // comment //#endif #include <a2> #endif #include <b> #include <a1>"; string expectedFormatedCode = @"#pragma once // SomeComment #include <b> #include ""filename.h"" #include ""z"" #if test #include <c> // A comment #include <d> #include ""a9"" #else #include <a2> #include <a3> // comment //#endif #include <d> #endif #include <a1> #include <b>"; var settings = new IncludeToolbox.FormatterOptionsPage(); settings.SortByType = IncludeToolbox.FormatterOptionsPage.TypeSorting.AngleBracketsFirst; settings.PrecedenceRegexes = new string[] { IncludeToolbox.RegexUtils.CurrentFileNameKey }; settings.BlankAfterRegexGroupMatch = false; settings.RemoveEmptyLines = false; string formatedCode = IncludeFormatter.FormatIncludes(source, "filename.cpp", new string[] { }, settings); Assert.AreEqual(expectedFormatedCode, formatedCode); }