From a14af4a69feb036b1c2f332552495a3a2892595e Mon Sep 17 00:00:00 2001 From: Anton92nd Date: Sun, 9 Nov 2014 20:21:44 +0600 Subject: [PATCH] new class for converter testing created --- Converter.cs | 57 +-------------------------------------------- Converter_should.cs | 44 ++++++++++++++++++++++++++++++++++ Mark.csproj | 1 + 3 files changed, 46 insertions(+), 56 deletions(-) create mode 100644 Converter_should.cs diff --git a/Converter.cs b/Converter.cs index 98dc881..9bde22c 100644 --- a/Converter.cs +++ b/Converter.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.IO; using System.Linq; -using NUnit.Framework; namespace Mark { @@ -10,29 +9,9 @@ class Converter { static public readonly string[] LineEndings = { "\r\n", "\r", "\n" }; - private static string[] GetParagraphsFromText(string[] text) - { - var result = new List(); - while (text.Length > 0) - { - text = text.SkipWhile(x => x.Trim().Length == 0).ToArray(); - var paragraphLines = text.TakeWhile(x => x.Trim().Length > 0); - text = text.SkipWhile(x => x.Trim().Length > 0).ToArray(); - var paragraph = String.Join(" ", paragraphLines); - if (paragraph.Trim().Length > 0) - result.Add("

\n" + paragraph + "\n

"); - } - return result.ToArray(); - } - static public string ConvertString(string content) { - var paragraphs = GetParagraphsFromText(content.Split(LineEndings, StringSplitOptions.None)); - string result = ""; - foreach (var i in paragraphs) - { - result += '\n' + i; - } + string result = "\n" + content; return result + "\n\n"; } @@ -54,38 +33,4 @@ static void Main(string[] args) ConvertFile(fileName); } } - - [TestFixture] - class Converter_should - { - [Test] - public void throw_exception_if_no_such_file() - { - Assert.Throws(() => Converter.ConvertFile("no_such_file.txt")); - } - - [Test] - public void create_file_with_html_extension() - { - Converter.ConvertFile("sample.txt"); - Assert.True(File.Exists("sample.html")); - } - - [Test] - public void convert_empty_file_into_file_with_html_tag() - { - Converter.ConvertFile("empty.txt"); - var result = new StreamReader("empty.html").ReadToEnd().Split(Converter.LineEndings, StringSplitOptions.RemoveEmptyEntries); - var expected = new StreamReader("emptyResult.txt").ReadToEnd().Split(Converter.LineEndings, StringSplitOptions.RemoveEmptyEntries); - Assert.AreEqual(expected, result); - } - - [Test] - public void add_p_tags_around_paragraphs() - { - string text = "This\nis\nfirst paragraph\n \nThis is\nsecond\n"; - string result = Converter.ConvertString(text); - Assert.AreEqual("\n

\nThis is first paragraph\n

\n

\nThis is second\n

\n\n", result); - } - } } diff --git a/Converter_should.cs b/Converter_should.cs new file mode 100644 index 0000000..dd3d78c --- /dev/null +++ b/Converter_should.cs @@ -0,0 +1,44 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using NUnit.Framework; + +namespace Mark +{ + [TestFixture] + class Converter_should + { + [Test] + public void throw_exception_if_no_such_file() + { + Assert.Throws(() => Converter.ConvertFile("no_such_file.txt")); + } + + [Test] + public void create_file_with_html_extension() + { + Converter.ConvertFile("sample.txt"); + Assert.True(File.Exists("sample.html")); + } + + [Test] + public void convert_empty_file_into_file_with_html_tag() + { + Converter.ConvertFile("empty.txt"); + var result = new StreamReader("empty.html").ReadToEnd().Split(Converter.LineEndings, StringSplitOptions.RemoveEmptyEntries); + var expected = new StreamReader("emptyResult.txt").ReadToEnd().Split(Converter.LineEndings, StringSplitOptions.RemoveEmptyEntries); + Assert.AreEqual(expected, result); + } + + [Test] + public void add_p_tags_around_paragraphs() + { + string text = "This\nis\nfirst paragraph\n \nThis is\nsecond\n"; + string result = Converter.ConvertString(text); + Assert.AreEqual("\n

\nThis is first paragraph\n

\n

\nThis is second\n

\n\n", result); + } + } +} diff --git a/Mark.csproj b/Mark.csproj index 9567e40..3234e9b 100644 --- a/Mark.csproj +++ b/Mark.csproj @@ -45,6 +45,7 @@ +