using System;
using LeafWeb.Core.Utility;
using NUnit.Framework;

namespace LeafWeb.Core.Tests.Utility
{
	[TestFixture]
	public class StringExtensionsTests
	{
		[Test]
		public void FilterAlphaNumeric_AllGood()
		{
			var str = "thisIsFine123_";
			var result = str.FilterAlphaNumeric();
			Assert.That(result, Is.EqualTo(str));
		}

		[Test]
		public void FilterAlphaNumeric_NotAllowed()
		{
			var str = "notAllowed%";
			var result = str.FilterAlphaNumeric();
			Assert.That(result, Is.EqualTo("notAllowed"));
		}

		[Test]
		public void FilterAlphaNumeric_Space()
		{
			var str = "s p a c e s";
			var result = str.FilterAlphaNumeric();
			Assert.That(result, Is.EqualTo("spaces"));
		}

		[Test]
		public void FilterAlphaNumeric_NewLine()
		{
			var str = "new" + Environment.NewLine + "line";
			var result = str.FilterAlphaNumeric();
			Assert.That(result, Is.EqualTo("newline"));
		}

		[Test]
		public void FilterAlphaNumeric_Apostrophes()
		{
			var str = "apostrophe's";
			var result = str.FilterAlphaNumeric();
			Assert.That(result, Is.EqualTo("apostrophes"));
		}

		[Test]
		public void FilterAlphaNumeric_ValidFilename()
		{
			var str = "my apostrophe's.csv";
			var result = str.FilterValidFilename();
			Assert.That(result, Is.EqualTo("myapostrophes.csv"));
		}

		[Test]
		public void FilenameFromPath()
		{
			var str = "/full/path/to/file.ext";
			var result = str.FilenameFromPath();
			Assert.That(result, Is.EqualTo("file.ext"));
		}

		[Test]
		public void WhitespaceToUnderscoreTest()
		{
			var str = " w h i t e s p " + Environment.NewLine + " a c   e";
			var result = str.WhitespaceToUnderscore();
			Assert.That(result, Is.EqualTo("_w_h_i_t_e_s_p_a_c_e"));
		}
	}
}
