mirror of
https://github.com/chylex/TweetDuck.git
synced 2025-04-14 03:15:49 +02:00
Move InjectedHTML unit tests to xUnit and rename Inject method
This commit is contained in:
parent
a117559063
commit
05d6c578b3
Core/Notification
Data
lib/TweetTest.Unit
tests
@ -263,7 +263,7 @@ protected override string GetTweetHTML(TweetNotification tweet){
|
||||
string html = base.GetTweetHTML(tweet);
|
||||
|
||||
foreach(InjectedHTML injection in plugins.NotificationInjections){
|
||||
html = injection.Inject(html);
|
||||
html = injection.InjectInto(html);
|
||||
}
|
||||
|
||||
return html;
|
||||
|
@ -47,7 +47,7 @@ protected override string GetTweetHTML(TweetNotification tweet){
|
||||
string html = tweet.GenerateHtml("td-screenshot");
|
||||
|
||||
foreach(InjectedHTML injection in plugins.NotificationInjections){
|
||||
html = injection.Inject(html);
|
||||
html = injection.InjectInto(html);
|
||||
}
|
||||
|
||||
return html;
|
||||
|
@ -16,7 +16,7 @@ public InjectedHTML(Position position, string search, string html){
|
||||
this.html = html;
|
||||
}
|
||||
|
||||
public string Inject(string targetHTML){
|
||||
public string InjectInto(string targetHTML){
|
||||
int index = targetHTML.IndexOf(search, StringComparison.Ordinal);
|
||||
|
||||
if (index == -1){
|
||||
|
49
lib/TweetTest.Unit/Data/TestInjectedHTML.fs
Normal file
49
lib/TweetTest.Unit/Data/TestInjectedHTML.fs
Normal file
@ -0,0 +1,49 @@
|
||||
namespace Unit.Data.InjectedHTML
|
||||
|
||||
open Xunit
|
||||
open TweetDuck.Data
|
||||
|
||||
|
||||
module Inject =
|
||||
let before = InjectedHTML.Position.Before
|
||||
let after = InjectedHTML.Position.After
|
||||
|
||||
[<Fact>]
|
||||
let ``injecting string before searched string works`` () =
|
||||
Assert.Equal("<p>source[left]<br>code</p>", InjectedHTML(before, "<br>", "[left]").InjectInto("<p>source<br>code</p>"))
|
||||
|
||||
[<Fact>]
|
||||
let ``injecting string after searched string works`` () =
|
||||
Assert.Equal("<p>source<br>[right]code</p>", InjectedHTML(after, "<br>", "[right]").InjectInto("<p>source<br>code</p>"))
|
||||
|
||||
[<Fact>]
|
||||
let ``injecting string at the beginning works`` () =
|
||||
Assert.Equal("[start]<p>source<br>code</p>", InjectedHTML(before, "<p>", "[start]").InjectInto("<p>source<br>code</p>"))
|
||||
|
||||
[<Fact>]
|
||||
let ``injecting string at the end works`` () =
|
||||
Assert.Equal("<p>source<br>code</p>[end]", InjectedHTML(after, "</p>", "[end]").InjectInto("<p>source<br>code</p>"))
|
||||
|
||||
[<Fact>]
|
||||
let ``injection only triggers for first occurrence of searched string`` () =
|
||||
Assert.Equal("<p>source[left]<br>code</p><br>", InjectedHTML(before, "<br>", "[left]").InjectInto("<p>source<br>code</p><br>"))
|
||||
Assert.Equal("<p>source<br>[right]code</p><br>", InjectedHTML(after, "<br>", "[right]").InjectInto("<p>source<br>code</p><br>"))
|
||||
|
||||
[<Fact>]
|
||||
let ``empty searched string injects at the beginning`` () =
|
||||
Assert.Equal("[start]<p>source<br>code</p>", InjectedHTML(before, "", "[start]").InjectInto("<p>source<br>code</p>"))
|
||||
Assert.Equal("[start]<p>source<br>code</p>", InjectedHTML(after, "", "[start]").InjectInto("<p>source<br>code</p>"))
|
||||
|
||||
[<Fact>]
|
||||
let ``injecting empty string does not modify source`` () =
|
||||
Assert.Equal("<p>source<br>code</p>", InjectedHTML(before, "<br>", "").InjectInto("<p>source<br>code</p>"))
|
||||
Assert.Equal("<p>source<br>code</p>", InjectedHTML(after, "<br>", "").InjectInto("<p>source<br>code</p>"))
|
||||
|
||||
[<Fact>]
|
||||
let ``failed match does not modify source`` () =
|
||||
Assert.Equal("<p>source<br>code</p>", InjectedHTML(before, "<wrong>", "[left]").InjectInto("<p>source<br>code</p>"))
|
||||
Assert.Equal("<p>source<br>code</p>", InjectedHTML(after, "<wrong>", "[right]").InjectInto("<p>source<br>code</p>"))
|
||||
|
||||
[<Fact>]
|
||||
let ``invalid position does not modify source`` () =
|
||||
Assert.Equal("<p>source<br>code</p>", InjectedHTML(enum<_>(1000), "<br>", "[somewhere]").InjectInto("<p>source<br>code</p>"))
|
@ -65,6 +65,7 @@
|
||||
<Compile Include="Core\TestBrowserUtils.fs" />
|
||||
<Compile Include="Core\TestStringUtils.fs" />
|
||||
<Compile Include="Core\TestTwitterUtils.fs" />
|
||||
<Compile Include="Data\TestInjectedHTML.fs" />
|
||||
<Compile Include="Data\TestResult.fs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
@ -1,64 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using TweetDuck.Data;
|
||||
|
||||
namespace UnitTests.Data{
|
||||
[TestClass]
|
||||
public class TestInjectedHTML{
|
||||
private static IEnumerable<InjectedHTML.Position> Positions => Enum.GetValues(typeof(InjectedHTML.Position)).Cast<InjectedHTML.Position>();
|
||||
|
||||
[TestMethod]
|
||||
public void TestFailedMatches(){
|
||||
foreach(var pos in Positions){
|
||||
Assert.AreEqual(string.Empty, new InjectedHTML(pos, "b", "b").Inject(string.Empty));
|
||||
Assert.AreEqual("aaaa", new InjectedHTML(pos, "b", "b").Inject("aaaa"));
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TestEmptySearch(){
|
||||
foreach(var pos in Positions){
|
||||
Assert.AreEqual("b", new InjectedHTML(pos, string.Empty, "b").Inject(string.Empty));
|
||||
Assert.AreEqual("baaaa", new InjectedHTML(pos, string.Empty, "b").Inject("aaaa"));
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TestEmptyHTML(){
|
||||
foreach(var pos in Positions){
|
||||
Assert.AreEqual(string.Empty, new InjectedHTML(pos, string.Empty, string.Empty).Inject(string.Empty));
|
||||
Assert.AreEqual("aaaa", new InjectedHTML(pos, string.Empty, string.Empty).Inject("aaaa"));
|
||||
Assert.AreEqual("aaaa", new InjectedHTML(pos, "a", string.Empty).Inject("aaaa"));
|
||||
Assert.AreEqual("aaaa", new InjectedHTML(pos, "b", string.Empty).Inject("aaaa"));
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TestInvalidPosition(){
|
||||
Assert.AreEqual("aaaa", new InjectedHTML((InjectedHTML.Position)(Positions.Count()+1), "a", "b").Inject("aaaa"));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TestPositions(){
|
||||
Assert.AreEqual("aaabcxaaa", new InjectedHTML(InjectedHTML.Position.Before, "x", "bc").Inject("aaaxaaa"));
|
||||
Assert.AreEqual("aaaxbcaaa", new InjectedHTML(InjectedHTML.Position.After, "x", "bc").Inject("aaaxaaa"));
|
||||
|
||||
Assert.AreEqual("bcxaaa", new InjectedHTML(InjectedHTML.Position.Before, "x", "bc").Inject("xaaa"));
|
||||
Assert.AreEqual("xbcaaa", new InjectedHTML(InjectedHTML.Position.After, "x", "bc").Inject("xaaa"));
|
||||
|
||||
Assert.AreEqual("aaabcx", new InjectedHTML(InjectedHTML.Position.Before, "x", "bc").Inject("aaax"));
|
||||
Assert.AreEqual("aaaxbc", new InjectedHTML(InjectedHTML.Position.After, "x", "bc").Inject("aaax"));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TestFirstOccurrence(){
|
||||
Assert.AreEqual("bcaaaa", new InjectedHTML(InjectedHTML.Position.Before, "a", "bc").Inject("aaaa"));
|
||||
Assert.AreEqual("abcaaa", new InjectedHTML(InjectedHTML.Position.After, "a", "bc").Inject("aaaa"));
|
||||
|
||||
Assert.AreEqual("bcaaaa", new InjectedHTML(InjectedHTML.Position.Before, "aa", "bc").Inject("aaaa"));
|
||||
Assert.AreEqual("aabcaa", new InjectedHTML(InjectedHTML.Position.After, "aa", "bc").Inject("aaaa"));
|
||||
}
|
||||
}
|
||||
}
|
@ -47,7 +47,6 @@
|
||||
<Compile Include="Data\TestCombinedFileStream.cs" />
|
||||
<Compile Include="Data\TestCommandLineArgs.cs" />
|
||||
<Compile Include="Data\TestFileSerializer.cs" />
|
||||
<Compile Include="Data\TestInjectedHTML.cs" />
|
||||
<Compile Include="Data\TestTwoKeyDictionary.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="UnitTestIO.cs" />
|
||||
|
Loading…
Reference in New Issue
Block a user