Example #1
0
        public void XmlComment_trims_common_leading_whitespace_over_all_lines()
        {
            string input = @"
            ## Test Heading
            
            Another line of text
            
              * list item 1
              * list item 2
            
            Third paragraph";

            string expected = @"## Test Heading

Another line of text

  * list item 1
  * list item 2

Third paragraph";

            string actual = XmlTextHelper.NormalizeIndentation(input);

            Assert.AreEqual(expected.Strip(), actual.Strip());
        }
Example #2
0
        public void NormalizeIndentation_empty()
        {
            string xmlText = "";
            string content = XmlTextHelper.NormalizeIndentation(xmlText);

            Assert.AreEqual(string.Empty, content);
        }
Example #3
0
        public void XmlComment_handles_code_on_the_first_line_poorly()
        {
            string input = @"
    POST /api/test
    
    {
      ""prop1"": {
        ""name"": ""value"",
        ...
      },
      ""prop2"": {
        ""name"": ""value"",
        ...
      }
    }
";

            string expectedButUndesired =
                @"POST /api/test

{
  ""prop1"": {
    ""name"": ""value"",
    ...
  },
  ""prop2"": {
    ""name"": ""value"",
    ...
  }
}";

            string actual = XmlTextHelper.NormalizeIndentation(input);

            Assert.AreEqual(expectedButUndesired.Strip(), actual.Strip());
        }
Example #4
0
        public void XmlComment_handles_mixed_indendation_using_space_tab()
        {
            string input = @"
    ## Test Heading
    
    Another line of text
    
        var object = {
            ""key1"": value,
            ""key2"": value
        }
";

            string expected =
                @"## Test Heading

Another line of text

	var object = {
		""key1"": value,
		""key2"": value
	}"    ;

            string actual = XmlTextHelper.NormalizeIndentation(input);

            Assert.AreEqual(expected.Strip(), actual.Strip());
        }
Example #5
0
        public void XmlComment_honours_code_blocks_when_finding_common_leading_whitespace()
        {
            string input = @"
            ## Test Heading
            
            Another line of text
            
                var object = {
                    ""key1"": value,
                    ""key2"": value
                }
            ";

            string expected =
                @"## Test Heading

Another line of text

	var object = {
		""key1"": value,
		""key2"": value
	}"    ;

            string actual = XmlTextHelper.NormalizeIndentation(input);

            Assert.AreEqual(expected.Strip(), actual.Strip());
        }
Example #6
0
        public void XmlComment_does_not_apply_trimming_if_no_common_sequence_found()
        {
            string input = @"
            ## Test Heading
            
I'm a line affecting the leading whitespace
            
              * list item 1
              * list item 2
            
            Third paragraph";

            string expected = @"            ## Test Heading
            
I'm a line affecting the leading whitespace
            
              * list item 1
              * list item 2
            
            Third paragraph";

            string actual = XmlTextHelper.NormalizeIndentation(input);

            Assert.AreEqual(expected.Strip(), actual.Strip());
        }
Example #7
0
        public void XmlComment_returns_verbatim_from_single_line_input()
        {
            string input    = @"My single line comment";
            string expected = @"My single line comment";
            string actual   = XmlTextHelper.NormalizeIndentation(input);

            Assert.AreEqual(expected.Strip(), actual.Strip());
        }
Example #8
0
        public void XmlComment_handles_mixed_complex_content()
        {
            string input = @"
            Some details about this
            method and why you'd like to use it.
            
            Here's an example of posting a new `TestModel` to the test endpoint.
            
                POST /api/test
                
                {
                  ""prop1"": {
                    ""name"": ""value"",
                    ...
                  },
                  ""prop2"": {
                    ""name"": ""value"",
                    ...
                  }
                }
";

            string expected = @"Some details about this
method and why you'd like to use it.

Here's an example of posting a new `TestModel` to the test endpoint.

    POST /api/test
    
    {
      ""prop1"": {
        ""name"": ""value"",
        ...
      },
      ""prop2"": {
        ""name"": ""value"",
        ...
      }
    }";

            string actual = XmlTextHelper.NormalizeIndentation(input);

            Assert.AreEqual(expected.Strip(), actual.Strip());
        }
Example #9
0
        public void XmlComment_detects_consistent_tab_indendation()
        {
            string input = @"
	Tab Indentation Line 1
	Tab Indentation Line 2
    Misplaced Space Indentation
	Tab Indentation Line 4
";

            string expected =
                @"	Tab Indentation Line 1
	Tab Indentation Line 2
    Misplaced Space Indentation
	Tab Indentation Line 4"    ;

            string actual = XmlTextHelper.NormalizeIndentation(input);

            Assert.AreEqual(expected.Strip(), actual.Strip());
        }
        public void XmlComment_detects_consistent_space_indendation()
        {
            string input = @"
    Space Indentation Line 1
    Space Indentation Line 2
	Misplaced Tab Indentation
    Space Indentation Line 4
";

            string expected =
                @"    Space Indentation Line 1
    Space Indentation Line 2
	Misplaced Tab Indentation
    Space Indentation Line 4";

            string actual = XmlTextHelper.NormalizeIndentation(input);

            Assert.AreEqual(expected, actual);
        }
Example #11
0
        public void XmlComment_handles_code_on_the_first_line_when_subsequent_non_code_lines_are_present()
        {
            string input = @"
    POST /api/test
    
    {
      ""prop1"": {
        ""name"": ""value"",
        ...
      },
      ""prop2"": {
        ""name"": ""value"",
        ...
      }
    }

The above is a sample code block
";

            string expectedButUndesired =
                @"    POST /api/test
    
    {
      ""prop1"": {
        ""name"": ""value"",
        ...
      },
      ""prop2"": {
        ""name"": ""value"",
        ...
      }
    }

The above is a sample code block";

            string actual = XmlTextHelper.NormalizeIndentation(input);

            Assert.AreEqual(expectedButUndesired.Strip(), actual.Strip());
        }
Example #12
0
 public void GetCommonLeadingWhitespace_empty()
 {
     string[] lines = { };
     Assert.IsNull(XmlTextHelper.GetCommonLeadingWhitespace(lines));
 }
Example #13
0
 public void GetCommonLeadingWhitespace_null()
 {
     Assert.Throws <ArgumentException>(() => XmlTextHelper.GetCommonLeadingWhitespace(null));
 }
Example #14
0
        public void NormalizeIndentation_null()
        {
            string xmlText = null;

            Assert.Throws <ArgumentNullException>(() => XmlTextHelper.NormalizeIndentation(xmlText));
        }