public void OtherPreprocessorDirectives() { string source = @"#pragma once // SomeComment #include ""z"" #include ""filename.h"" #if test #include <d> // A comment #include ""a9"" #else #include <d> #include <a3> // comment //#endif #include <a2> #endif #include <a1>"; string expectedFormatedCode = @"#pragma once // SomeComment #include ""filename.h"" #include ""z"" #if test #include <d> // A comment #include ""a9"" #else #include <a2> #include <a3> // comment //#endif #include <d> #endif #include <a1>"; 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); }
public void Sorting_BlanksAfterRegexGroup() { // Blanks after groups. string expectedFormatedCode_NoBlanks = @"#include ""filename.h"" #include <d_firstanyways> #include <e_secondanyways> #include ""a.h"" #include <b.hpp> #include <c.hpp> "; string expectedFormatedCode_WithBlanks = @"#include ""filename.h"" #include <b_second> #include ""c_third"" #include ""z_first"" // A comment "; var settings = new IncludeToolbox.FormatterOptionsPage(); settings.SortByType = IncludeToolbox.FormatterOptionsPage.TypeSorting.None; settings.PrecedenceRegexes = new string[] { IncludeToolbox.RegexUtils.CurrentFileNameKey, ".+_.+" }; settings.BlankAfterRegexGroupMatch = true; 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 Sorting() { string sourceCode = @"#include ""a.h"" #include <b.hpp> #include ""filename.h"" #include <d_firstanyways> #include <e_secondanyways> #include <c.hpp>"; string expectedFormatedCode0 = @"#include ""filename.h"" #include <d_firstanyways> #include <e_secondanyways> #include ""a.h"" #include <b.hpp> #include <c.hpp>"; var settings = new IncludeToolbox.FormatterOptionsPage(); settings.SortByType = IncludeToolbox.FormatterOptionsPage.TypeSorting.None; settings.PrecedenceRegexes = new string[] { IncludeFormatter.CurrentFileNameKey, ".+_.+" }; settings.BlankAfterRegexGroupMatch = true; string formatedCode = IncludeFormatter.FormatIncludes(sourceCode, "filename.cpp", new string[] { }, settings); Assert.AreEqual(expectedFormatedCode0, formatedCode); string expectedFormatedCode1 = @"#include <d_firstanyways> #include <e_secondanyways> #include <b.hpp> #include <c.hpp> #include ""filename.h"" #include ""a.h"""; settings.SortByType = IncludeToolbox.FormatterOptionsPage.TypeSorting.AngleBracketsFirst; settings.BlankAfterRegexGroupMatch = false; formatedCode = IncludeFormatter.FormatIncludes(sourceCode, "filename.cpp", new string[] { }, settings); Assert.AreEqual(expectedFormatedCode1, formatedCode); }
public void EmptySelection() { // Activate all features var settings = new IncludeToolbox.FormatterOptionsPage(); settings.SortByType = IncludeToolbox.FormatterOptionsPage.TypeSorting.AngleBracketsFirst; settings.PrecedenceRegexes = new string[] { IncludeToolbox.RegexUtils.CurrentFileNameKey }; settings.BlankAfterRegexGroupMatch = true; settings.RemoveEmptyLines = true; settings.DelimiterFormatting = IncludeToolbox.FormatterOptionsPage.DelimiterMode.AngleBrackets; settings.SlashFormatting = IncludeToolbox.FormatterOptionsPage.SlashMode.BackSlash; string formatedCode = IncludeFormatter.FormatIncludes("", "filename.cpp", new string[] { }, settings); Assert.AreEqual("", formatedCode); }
public void RemoveEmptyLines() { string expectedFormatedCode_WithBlanks = @"#include ""filename.h"" #include <b_second> #include ""c_third"" // A comment #include ""z_first"""; var settings = new IncludeToolbox.FormatterOptionsPage(); settings.SortByType = IncludeToolbox.FormatterOptionsPage.TypeSorting.None; settings.PrecedenceRegexes = new string[] { IncludeToolbox.RegexUtils.CurrentFileNameKey }; settings.BlankAfterRegexGroupMatch = false; settings.RemoveEmptyLines = true; string formatedCode = IncludeFormatter.FormatIncludes(sourceCode_WithBlanks, "filename.cpp", new string[] { }, settings); Assert.AreEqual(expectedFormatedCode_WithBlanks, formatedCode); }