2014-06-30 23:55:16 -05:00
|
|
|
|
namespace Ficdown.Parser.Tests
|
|
|
|
|
{
|
2018-09-27 12:32:32 -05:00
|
|
|
|
using System.Collections.Generic;
|
2014-07-26 23:54:50 -05:00
|
|
|
|
using System.Linq;
|
2018-09-27 12:32:32 -05:00
|
|
|
|
using Model.Parser;
|
2014-07-02 23:11:36 -05:00
|
|
|
|
using Parser;
|
2014-06-30 23:55:16 -05:00
|
|
|
|
using Xunit;
|
|
|
|
|
|
|
|
|
|
public class UtilityTests
|
|
|
|
|
{
|
2018-09-27 12:32:32 -05:00
|
|
|
|
private List<FicdownException> Warnings = new List<FicdownException>();
|
|
|
|
|
|
2015-07-19 15:51:10 -05:00
|
|
|
|
private Utilities Utilities
|
|
|
|
|
{
|
2018-09-27 12:32:32 -05:00
|
|
|
|
get { return Utilities.GetInstance(Warnings, "none", 0); }
|
2015-07-19 15:51:10 -05:00
|
|
|
|
}
|
|
|
|
|
|
2014-07-02 23:11:36 -05:00
|
|
|
|
[Fact]
|
|
|
|
|
public void FullAnchorMatches()
|
|
|
|
|
{
|
|
|
|
|
var anchorStr = @"[Link text](/target-scene)";
|
2018-09-25 16:29:53 -05:00
|
|
|
|
var anchor = Utilities.ParseAnchor(anchorStr, 0, 0);
|
2014-07-26 23:54:50 -05:00
|
|
|
|
Assert.Equal(anchorStr, anchor.Original);
|
2014-07-02 23:11:36 -05:00
|
|
|
|
|
|
|
|
|
anchorStr = @"[Link text](?condition-state#toggle-state ""Title text"")";
|
2018-09-25 16:29:53 -05:00
|
|
|
|
anchor = Utilities.ParseAnchor(anchorStr, 0, 0);
|
2014-07-26 23:54:50 -05:00
|
|
|
|
Assert.Equal(anchorStr, anchor.Original);
|
2014-07-02 23:11:36 -05:00
|
|
|
|
|
|
|
|
|
anchorStr = @"[Link text](""Title text"")";
|
2018-09-25 16:29:53 -05:00
|
|
|
|
anchor = Utilities.ParseAnchor(anchorStr, 0, 0);
|
2014-07-26 23:54:50 -05:00
|
|
|
|
Assert.Equal(anchorStr, anchor.Original);
|
2014-07-02 23:11:36 -05:00
|
|
|
|
}
|
|
|
|
|
|
2014-06-30 23:55:16 -05:00
|
|
|
|
[Fact]
|
|
|
|
|
public void AnchorWithTargetMatches()
|
|
|
|
|
{
|
2018-09-25 16:29:53 -05:00
|
|
|
|
var anchor = Utilities.ParseAnchor(@"[Link text](/target-scene)", 0, 0);
|
2014-07-26 23:54:50 -05:00
|
|
|
|
Assert.Equal("Link text", anchor.Text);
|
|
|
|
|
Assert.Equal("target-scene", anchor.Href.Target);
|
2014-06-30 23:55:16 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void AnchorsWithConditionsMatch()
|
|
|
|
|
{
|
2018-09-25 16:29:53 -05:00
|
|
|
|
var anchor = Utilities.ParseAnchor(@"[Link text](?condition-state)", 0, 0);
|
2014-07-26 23:54:50 -05:00
|
|
|
|
Assert.Equal("Link text", anchor.Text);
|
|
|
|
|
Assert.True(anchor.Href.Conditions["condition-state"]);
|
|
|
|
|
|
2018-09-25 16:29:53 -05:00
|
|
|
|
anchor = Utilities.ParseAnchor(@"[Link text](?!condition-state)", 0, 0);
|
2014-07-26 23:54:50 -05:00
|
|
|
|
Assert.Equal("Link text", anchor.Text);
|
|
|
|
|
Assert.False(anchor.Href.Conditions["condition-state"]);
|
|
|
|
|
|
2018-09-25 16:29:53 -05:00
|
|
|
|
anchor = Utilities.ParseAnchor(@"[Link text](?condition-1&!condition-2)", 0, 0);
|
2014-07-26 23:54:50 -05:00
|
|
|
|
Assert.Equal("Link text", anchor.Text);
|
|
|
|
|
Assert.True(anchor.Href.Conditions["condition-1"]);
|
|
|
|
|
Assert.False(anchor.Href.Conditions["condition-2"]);
|
2014-06-30 23:55:16 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void AnchorsWithTogglesMatch()
|
|
|
|
|
{
|
2018-09-25 16:29:53 -05:00
|
|
|
|
var anchor = Utilities.ParseAnchor(@"[Link text](#toggle-state)", 0, 0);
|
2014-07-26 23:54:50 -05:00
|
|
|
|
Assert.Equal("Link text", anchor.Text);
|
|
|
|
|
Assert.Equal("#toggle-state", anchor.Href.Original);
|
|
|
|
|
|
2018-09-25 16:29:53 -05:00
|
|
|
|
anchor = Utilities.ParseAnchor(@"[Link text](#toggle-1+toggle-2)", 0, 0);
|
2014-07-26 23:54:50 -05:00
|
|
|
|
Assert.Equal("Link text", anchor.Text);
|
|
|
|
|
Assert.Equal("#toggle-1+toggle-2", anchor.Href.Original);
|
|
|
|
|
|
2018-09-25 16:29:53 -05:00
|
|
|
|
anchor = Utilities.ParseAnchor(@"[Link text](#toggle-1+toggle-2)", 0, 0);
|
2014-07-26 23:54:50 -05:00
|
|
|
|
Assert.Equal("Link text", anchor.Text);
|
|
|
|
|
Assert.Equal("#toggle-1+toggle-2", anchor.Href.Original);
|
2014-07-02 23:11:36 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void AnchorsWithTitlesMatch()
|
|
|
|
|
{
|
2018-09-25 16:29:53 -05:00
|
|
|
|
var anchor = Utilities.ParseAnchor(@"[Link text](""Title text"")", 0, 0);
|
2014-07-26 23:54:50 -05:00
|
|
|
|
Assert.Equal("Link text", anchor.Text);
|
|
|
|
|
Assert.Equal("Title text", anchor.Title);
|
|
|
|
|
|
2018-09-25 16:29:53 -05:00
|
|
|
|
anchor = Utilities.ParseAnchor(@"[Talking to Kid](""Lobby"")", 0, 0);
|
2014-07-26 23:54:50 -05:00
|
|
|
|
Assert.Equal("Talking to Kid", anchor.Text);
|
|
|
|
|
Assert.Equal("Lobby", anchor.Title);
|
2014-06-30 23:55:16 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void ComplexAnchorsMatch()
|
|
|
|
|
{
|
2018-09-25 16:29:53 -05:00
|
|
|
|
var anchor = Utilities.ParseAnchor(@"[Link text](/target-scene?condition-state#toggle-state ""Title text"")", 0, 0);
|
2014-07-26 23:54:50 -05:00
|
|
|
|
Assert.Equal("Link text", anchor.Text);
|
|
|
|
|
Assert.Equal("/target-scene?condition-state#toggle-state", anchor.Href.Original);
|
|
|
|
|
Assert.Equal("Title text", anchor.Title);
|
|
|
|
|
|
2018-09-25 16:29:53 -05:00
|
|
|
|
anchor = Utilities.ParseAnchor(@"[Link text](/target-scene#toggle-state)", 0, 0);
|
2014-07-26 23:54:50 -05:00
|
|
|
|
Assert.Equal("Link text", anchor.Text);
|
|
|
|
|
Assert.Equal("/target-scene#toggle-state", anchor.Href.Original);
|
|
|
|
|
|
2018-09-25 16:29:53 -05:00
|
|
|
|
anchor = Utilities.ParseAnchor(@"[Link text](/target-scene?condition-state)", 0, 0);
|
2014-07-26 23:54:50 -05:00
|
|
|
|
Assert.Equal("Link text", anchor.Text);
|
|
|
|
|
Assert.Equal("/target-scene?condition-state", anchor.Href.Original);
|
|
|
|
|
|
2018-09-25 16:29:53 -05:00
|
|
|
|
anchor = Utilities.ParseAnchor(@"[Link text](?condition-state#toggle-state)", 0, 0);
|
2014-07-26 23:54:50 -05:00
|
|
|
|
Assert.Equal("Link text", anchor.Text);
|
|
|
|
|
Assert.Equal("?condition-state#toggle-state", anchor.Href.Original);
|
2014-06-30 23:55:16 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void HrefWithTargetParses()
|
|
|
|
|
{
|
2014-07-02 23:11:36 -05:00
|
|
|
|
var anchors = Utilities.ParseAnchors("[Anchor](/target-scene)");
|
|
|
|
|
Assert.Equal("target-scene", anchors[0].Href.Target);
|
|
|
|
|
Assert.Null(anchors[0].Href.Conditions);
|
|
|
|
|
Assert.Null(anchors[0].Href.Toggles);
|
2014-06-30 23:55:16 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void HrefsWithConditionsParse()
|
|
|
|
|
{
|
2014-07-02 23:11:36 -05:00
|
|
|
|
var anchors = Utilities.ParseAnchors("[Anchor](?condition-state)");
|
|
|
|
|
Assert.Null(anchors[0].Href.Target);
|
|
|
|
|
Assert.Equal(1, anchors[0].Href.Conditions.Count);
|
|
|
|
|
Assert.True(anchors[0].Href.Conditions["condition-state"]);
|
|
|
|
|
Assert.Null(anchors[0].Href.Toggles);
|
|
|
|
|
|
|
|
|
|
anchors = Utilities.ParseAnchors("[Anchor](?condition-1&!condition-2)");
|
|
|
|
|
Assert.Null(anchors[0].Href.Target);
|
|
|
|
|
Assert.Equal(2, anchors[0].Href.Conditions.Count);
|
|
|
|
|
Assert.True(anchors[0].Href.Conditions["condition-1"]);
|
|
|
|
|
Assert.False(anchors[0].Href.Conditions["condition-2"]);
|
|
|
|
|
Assert.Null(anchors[0].Href.Toggles);
|
2014-06-30 23:55:16 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void HrefsWithTogglesParse()
|
|
|
|
|
{
|
2014-07-02 23:11:36 -05:00
|
|
|
|
var anchors = Utilities.ParseAnchors("[Anchor](#toggle-state)");
|
|
|
|
|
Assert.Null(anchors[0].Href.Target);
|
|
|
|
|
Assert.Null(anchors[0].Href.Conditions);
|
2014-07-26 23:54:50 -05:00
|
|
|
|
Assert.Equal(1, anchors[0].Href.Toggles.Count());
|
2014-07-02 23:11:36 -05:00
|
|
|
|
|
2014-07-26 23:54:50 -05:00
|
|
|
|
anchors = Utilities.ParseAnchors("[Anchor](#toggle-1+toggle-2)");
|
2014-07-02 23:11:36 -05:00
|
|
|
|
Assert.Null(anchors[0].Href.Target);
|
|
|
|
|
Assert.Null(anchors[0].Href.Conditions);
|
2014-07-26 23:54:50 -05:00
|
|
|
|
Assert.Equal(2, anchors[0].Href.Toggles.Count());
|
2014-06-30 23:55:16 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void ComplexHrefsParse()
|
|
|
|
|
{
|
2014-07-02 23:11:36 -05:00
|
|
|
|
var anchors = Utilities.ParseAnchors("[Anchor](/target-scene?condition-state#toggle-state)");
|
|
|
|
|
Assert.Equal("target-scene", anchors[0].Href.Target);
|
|
|
|
|
Assert.Equal(1, anchors[0].Href.Conditions.Count);
|
|
|
|
|
Assert.True(anchors[0].Href.Conditions["condition-state"]);
|
2014-07-26 23:54:50 -05:00
|
|
|
|
Assert.Equal(1, anchors[0].Href.Toggles.Count());
|
2014-07-02 23:11:36 -05:00
|
|
|
|
|
|
|
|
|
anchors = Utilities.ParseAnchors("[Anchor](/target-scene?condition-state)");
|
|
|
|
|
Assert.Equal("target-scene", anchors[0].Href.Target);
|
|
|
|
|
Assert.Equal(1, anchors[0].Href.Conditions.Count);
|
|
|
|
|
Assert.True(anchors[0].Href.Conditions["condition-state"]);
|
|
|
|
|
Assert.Null(anchors[0].Href.Toggles);
|
|
|
|
|
|
|
|
|
|
anchors = Utilities.ParseAnchors("[Anchor](/target-scene#toggle-state)");
|
|
|
|
|
Assert.Equal("target-scene", anchors[0].Href.Target);
|
|
|
|
|
Assert.Null(anchors[0].Href.Conditions);
|
2014-07-26 23:54:50 -05:00
|
|
|
|
Assert.Equal(1, anchors[0].Href.Toggles.Count());
|
2014-07-02 23:11:36 -05:00
|
|
|
|
|
2014-07-26 23:54:50 -05:00
|
|
|
|
anchors = Utilities.ParseAnchors("[Anchor](?condition-one&!condition-two#toggle-one+toggle-two)");
|
2014-07-02 23:11:36 -05:00
|
|
|
|
Assert.Null(anchors[0].Href.Target);
|
|
|
|
|
Assert.Equal(2, anchors[0].Href.Conditions.Count);
|
|
|
|
|
Assert.True(anchors[0].Href.Conditions["condition-one"]);
|
|
|
|
|
Assert.False(anchors[0].Href.Conditions["condition-two"]);
|
2014-07-26 23:54:50 -05:00
|
|
|
|
Assert.Equal(2, anchors[0].Href.Toggles.Count());
|
2014-06-30 23:55:16 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|