///
/// Copyright © 2003-2008 JetBrains s.r.o.
/// You may distribute under the terms of the GNU General Public License, as published by the Free Software Foundation, version 2 (see License.txt in the repository root folder).
///
using System;
using NUnit.Framework;
using JetBrains.Omea.HTML;
namespace OmniaMeaBaseTests
{
[TestFixture]
public class HTMLToolsTests
{
[Test]
public void TestFixingRelativeLinks()
{
string fixedHTML = HtmlTools.FixRelativeLinks(
"
", "http://www.jetbrains.com");
if( fixedHTML != "" )
{
Console.WriteLine( fixedHTML );
throw new Exception("Bad reference value quoted with ''");
}
fixedHTML = HtmlTools.FixRelativeLinks(
"", "http://www.jetbrains.com");
if( fixedHTML != "" )
{
Console.WriteLine( fixedHTML );
throw new Exception("Bad not quoted reference value");
}
fixedHTML = HtmlTools.FixRelativeLinks(
"", "ftp://www.jetbrains.com");
if( fixedHTML != "" )
{
Console.WriteLine( fixedHTML );
throw new Exception("Bad quoted reference value");
}
fixedHTML = HtmlTools.FixRelativeLinks(
"", "http://www.jetbrains.com");
if( fixedHTML != "" )
{
Console.WriteLine( fixedHTML );
throw new Exception("Bad trivial reference value");
}
fixedHTML = HtmlTools.FixRelativeLinks(
"",
"http://www.jetbrains.com" );
if( fixedHTML != "" )
{
Console.WriteLine( fixedHTML );
throw new Exception("Bad cascading style sheet reference value");
}
fixedHTML = HtmlTools.FixRelativeLinks(
"span { background-image: url(\"images/mybackground.gif\" }",
"http://www.jetbrains.com" );
if( fixedHTML != "span { background-image: url(\"http://www.jetbrains.com/images/mybackground.gif\" }" )
{
Console.WriteLine( fixedHTML );
throw new Exception("Bad cascading style sheet reference value");
}
fixedHTML = HtmlTools.FixRelativeLinks(
"", "ftp://www.jetbrains.com");
if( fixedHTML != "" )
{
Console.WriteLine( fixedHTML );
throw new Exception( "Bad absolute reference value" );
}
fixedHTML = HtmlTools.FixRelativeLinks(
"span { background-image: url(\"images/mybackground.gif\" }",
"http://www.jetbrains.com/omea/index.html" );
if( fixedHTML != "span { background-image: url(\"http://www.jetbrains.com/omea/images/mybackground.gif\" }" )
{
Console.WriteLine( fixedHTML );
throw new Exception( "Retreiving absolute path for regular page failed" );
}
}
[Test] public void TestConvertLinks()
{
Assert.AreEqual( "WWW).", HtmlTools.ConvertLinks( "WWW)." ) );
Assert.AreEqual( "WWW сервере", HtmlTools.ConvertLinks( "WWW сервере" ) );
Assert.AreEqual( "RSDN@home", HtmlTools.ConvertLinks( "RSDN@home" ) );
Assert.AreEqual( "news:3004312.1092753494993.JavaMail.itn@is.intellij.net...", HtmlTools.ConvertLinks( "news:3004312.1092753494993.JavaMail.itn@is.intellij.net..." ) );
Assert.AreEqual( "http://jetbrains.com.", HtmlTools.ConvertLinks( "http://jetbrains.com." ) );
Assert.AreEqual( "www.jetbrains.com.", HtmlTools.ConvertLinks( "www.jetbrains.com." ) );
Assert.AreEqual( "www.jetbrains.com. ", HtmlTools.ConvertLinks( "www.jetbrains.com. " ) );
Assert.AreEqual( "www.jetbrains.com/", HtmlTools.ConvertLinks( "www.jetbrains.com/" ) );
Assert.AreEqual( "http://www.jetbrains.com/", HtmlTools.ConvertLinks( "http://www.jetbrains.com/" ) );
Assert.AreEqual( "www.jetbrains.com a", HtmlTools.ConvertLinks( "www.jetbrains.com a" ) );
Assert.AreEqual( "news://news.intellij.net:119/a@b.com", HtmlTools.ConvertLinks( "news://news.intellij.net:119/a@b.com" ) );
}
}
}