/// <summary>
 /// Creates a new formatSettings that will use the given Document to access the original source code,
 /// and will start indents from the given level.
 /// </summary>
 /// <param name="document"></param>
 /// <param name="formatSettings">The formatSettings settings to use when formatting this document.</param>
 /// <param name="controller"></param>
 public CSharpCodeFormatter(Document document, CSharpFormatSettings formatSettings, Controller controller)
 {
     if (document == null) throw new ArgumentNullException("document");
     this.document = document;
     this.formatSettings = formatSettings;
     this.controller = controller;
 }
        public void TestFile(string filename, bool stripText, CSharpFormatSettings settings)
        {
            string fileText = File.ReadAllText(filename);

            CSharpParser formatter = new CSharpParser();
            formatter.FormatSettings.SetFrom(settings);
            formatter.ParseCode(fileText);

            Assert.IsFalse(formatter.ErrorOccurred);

            string formattedText = formatter.CreatedCodeRoot.ToString();

            formattedText =
                Slyce.Common.Utility.StandardizeLineBreaks(formattedText, Slyce.Common.Utility.LineBreaks.Windows);

            string strippedFileText = Diff.StripWhitespace(new[] {fileText}, stripText)[0].Replace("\t", "    ");
            string strippedFormattedText = Diff.StripWhitespace(new[] { formattedText }, stripText)[0].Replace("\t", "    ");

            Assert.That(strippedFormattedText, Is.EqualTo(strippedFileText));
        }
        public void SetFormatSettings(CSharpFormatSettings settings)
        {
            if (settings == null) return;

            formatSettings.SetFrom(settings);
        }
 public void TestCommentOrdering()
 {
     CSharpFormatSettings settings = new CSharpFormatSettings();
     settings.ReorderBaseConstructs = true;
     TestFile("CSharpFormatter\\Test Files\\CommentOrdering.cs", true, settings);
 }
 public void As_Part_Of_A_Single_Line_Block_With_No_Braces()
 {
     const string methodBody = "if (true)\n// Comment\nActualStatement();";
     string expectedText = "{\n\tif (true) \n\t\t// Comment\n\t\tActualStatement();\n}\n".Replace("\n", Environment.NewLine);
     CSharpFormatSettings settings = new CSharpFormatSettings();
     settings.AddBracesToSingleLineBlocks = false;
     settings.SingleLineBlocksOnSameLineAsParent = false;
     TestBodyText(methodBody, expectedText, settings);
 }
 public void Comment_Blocks_Set_To_True()
 {
     const string methodBody = "// Comment \n /* Another Comment */ \n return 0xFFFFFFFF + 1;";
     string expectedText = "{\n\t/* Comment */\n\t/* Another Comment */\n\treturn 0xFFFFFFFF + 1;\n}\n".Replace("\n", Environment.NewLine);
     CSharpFormatSettings settings = new CSharpFormatSettings();
     settings.CommentLinesAsCommentBlock = true;
     TestBodyText(methodBody, expectedText, settings);
 }