public void CustomGraphParseDGML() { string filenameTestOutput = "testdata/output.dgml"; string filenameComparision = "testdata/includegraph.dgml"; string[] noParseDirectories = new[] { Utils.GetExactPathName("testdata/subdir/subdir") }; IncludeGraph graph = new IncludeGraph(); graph.AddIncludesRecursively_ManualParsing(Utils.GetExactPathName("testdata/source0.cpp"), Enumerable.Empty <string>(), noParseDirectories); graph.AddIncludesRecursively_ManualParsing(Utils.GetExactPathName("testdata/source1.cpp"), Enumerable.Empty <string>(), noParseDirectories); // Formatting... var includeDirectories = new[] { Path.Combine(System.Environment.CurrentDirectory, "testdata") }; foreach (var item in graph.GraphItems) { item.FormattedName = IncludeFormatter.FormatPath(item.AbsoluteFilename, FormatterOptionsPage.PathMode.Shortest_AvoidUpSteps, includeDirectories); } // To DGML and save. // Since we don't want to have absolute paths in our compare/output dgml we hack the graph before writing it out. var dgml = RemoveAbsolutePathsFromDGML(graph.ToDGMLGraph(), new[] { System.Environment.CurrentDirectory }); dgml.Serialize(filenameTestOutput); string expectedFile = File.ReadAllText(filenameComparision); string writtenFile = File.ReadAllText(filenameTestOutput); Assert.AreEqual(expectedFile, writtenFile); // For a clean environment! File.Delete(filenameTestOutput); }
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); }
private void RemoveAbsolutePathsFromDGML(DGMLGraph dgml, IEnumerable <string> includeDirectories) { foreach (var item in dgml.Nodes) { item.Id = IncludeFormatter.FormatPath(item.Id, FormatterOptionsPage.PathMode.Shortest, includeDirectories); item.Label = IncludeFormatter.FormatPath(item.Label, FormatterOptionsPage.PathMode.Shortest, includeDirectories); } foreach (var link in dgml.Links) { link.Source = IncludeFormatter.FormatPath(link.Source, FormatterOptionsPage.PathMode.Shortest, includeDirectories); link.Target = IncludeFormatter.FormatPath(link.Target, FormatterOptionsPage.PathMode.Shortest, includeDirectories); } }
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); }
private DGMLGraph RemoveAbsolutePathsFromDGML(DGMLGraph dgml, IEnumerable <string> includeDirectories) { var dgml2 = new DGMLGraph(); foreach (var item in dgml.Nodes) { DGMLGraph.Node newNode = item; newNode.Id = IncludeFormatter.FormatPath(item.Id, FormatterOptionsPage.PathMode.Shortest_AvoidUpSteps, includeDirectories); dgml2.Nodes.Add(newNode); } foreach (var link in dgml.Links) { DGMLGraph.Link newLink = link; newLink.Source = IncludeFormatter.FormatPath(newLink.Source, FormatterOptionsPage.PathMode.Shortest_AvoidUpSteps, includeDirectories); newLink.Target = IncludeFormatter.FormatPath(newLink.Target, FormatterOptionsPage.PathMode.Shortest_AvoidUpSteps, includeDirectories); dgml2.Links.Add(newLink); } return(dgml2); }
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); }