Skip to content

Commit

Permalink
Fix for Issue #34
Browse files Browse the repository at this point in the history
  • Loading branch information
jamietre committed Aug 16, 2012
1 parent 33caa20 commit 354504d
Show file tree
Hide file tree
Showing 18 changed files with 10,693 additions and 10,515 deletions.
20,969 changes: 10,476 additions & 10,493 deletions distribution/CsQuery.XML

Large diffs are not rendered by default.

Binary file modified distribution/CsQuery.dll
Binary file not shown.
Binary file modified distribution/CsQuery.pdb
Binary file not shown.
4 changes: 4 additions & 0 deletions source/.nuget/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="NuGet.CommandLine" version="2.0.40000" />
</packages>
2 changes: 1 addition & 1 deletion source/CsQuery.Mvc/CsQuery.Mvc.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<ProjectExtensions>
<VisualStudio>
<UserProperties BuildVersion_BuildVersioningStyle="None.None.None.Increment" BuildVersion_AssemblyInfoFilename="Properties\AssemblyInfo.cs" BuildVersion_ConfigurationName="Release" BuildVersion_UpdateAssemblyVersion="True" />
<UserProperties BuildVersion_UseGlobalSettings="True" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_ConfigurationName="Release" BuildVersion_AssemblyInfoFilename="Properties\AssemblyInfo.cs" BuildVersion_BuildVersioningStyle="None.None.None.Increment" />
</VisualStudio>
</ProjectExtensions>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Expand Down
42 changes: 42 additions & 0 deletions source/CsQuery.Tests/Csharp/Methods/Before.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text;
using System.Reflection;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using NUnit.Framework;
using Assert = NUnit.Framework.Assert;
using Description = NUnit.Framework.DescriptionAttribute;
using TestContext = Microsoft.VisualStudio.TestTools.UnitTesting.TestContext;
using CsQuery;
using CsQuery.Utility;

namespace CsQuery.Tests.Csharp
{
/// <summary>
/// This method is largely covered by the jQuery tests
/// </summary>

public partial class Methods: CsQueryTest
{

[Test, TestMethod]
public void Before_MissingTarget()
{

var dom = TestDom("TestHtml");
var len = dom["*"].Length;

var target = dom["does-not-exist"];
var content = dom["<div id='content' />"];

target.Before(content);

// nothing was added
Assert.AreEqual(dom["*"].Length, len);
}


}
}
39 changes: 39 additions & 0 deletions source/CsQuery.Tests/Csharp/Methods/First.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text;
using System.Reflection;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using NUnit.Framework;
using Assert = NUnit.Framework.Assert;
using Description = NUnit.Framework.DescriptionAttribute;
using TestContext = Microsoft.VisualStudio.TestTools.UnitTesting.TestContext;
using CsQuery;
using CsQuery.Utility;

namespace CsQuery.Tests.Csharp
{
/// <summary>
/// This method is largely covered by the jQuery tests
/// </summary>

public partial class Methods: CsQueryTest
{

[Test, TestMethod]
public void First()
{

var dom = TestDom("TestHtml");

Assert.AreEqual(1, dom["span"].First().Length);
Assert.AreEqual("hlinks-user", dom["span"].First().Attr("id"));

Assert.AreEqual(0, dom["not-here"].First().Length);
}



}
}
38 changes: 38 additions & 0 deletions source/CsQuery.Tests/Csharp/Methods/Last.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text;
using System.Reflection;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using NUnit.Framework;
using Assert = NUnit.Framework.Assert;
using Description = NUnit.Framework.DescriptionAttribute;
using TestContext = Microsoft.VisualStudio.TestTools.UnitTesting.TestContext;
using CsQuery;
using CsQuery.Utility;

namespace CsQuery.Tests.Csharp
{
/// <summary>
/// This method is largely covered by the jQuery tests
/// </summary>

public partial class Methods: CsQueryTest
{

[Test, TestMethod]
public void Last()
{

var dom = TestDom("TestHtml");

Assert.AreEqual(1, dom["div"].Last().Length);
Assert.AreEqual("test-show-last", dom["div"].Last().Attr("id"));

Assert.AreEqual(0, dom["not-here"].Last().Length);
}


}
}
46 changes: 46 additions & 0 deletions source/CsQuery.Tests/Csharp/Methods/ReplaceWith.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text;
using System.Reflection;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using NUnit.Framework;
using Assert = NUnit.Framework.Assert;
using Description = NUnit.Framework.DescriptionAttribute;
using TestContext = Microsoft.VisualStudio.TestTools.UnitTesting.TestContext;
using CsQuery;
using CsQuery.Utility;

namespace CsQuery.Tests.Csharp
{
/// <summary>
/// This method is largely covered by the jQuery tests
/// </summary>

public partial class Methods: CsQueryTest
{
/// <summary>
/// Replace with: ensure that when content is moved between domains, a CsQuery object that was
/// the replacement content remains connected to the content in its new home.
/// </summary>

[Test, TestMethod]
public void ReplaceWith()
{

var dom = TestDom("TestHtml");

var target = dom["#test-show-last"];
var source = CQ.Create("<div id='new-content'><span /></div>");

Assert.AreEqual(2, target.Children().Length);
target.ReplaceWith(source);

Assert.AreEqual(1, source["#hlinks-user"].Length);
Assert.AreEqual(dom["#new-content"][0], source[0]);
}


}
}
4 changes: 4 additions & 0 deletions source/CsQuery.Tests/Csquery.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@
<Compile Include="Csharp\Dom\DomElement.cs" />
<Compile Include="Csharp\Dom\SpecialElements.cs" />
<Compile Include="Csharp\ExtensionMethods\Xml.cs" />
<Compile Include="Csharp\Methods\Before.cs" />
<Compile Include="Csharp\Methods\ReplaceWith.cs" />
<Compile Include="Csharp\Methods\Last.cs" />
<Compile Include="Csharp\Methods\First.cs" />
<Compile Include="Csharp\Methods\ParentsUntil.cs" />
<Compile Include="Csharp\Methods\Width.cs" />
<Compile Include="Csharp\Methods\Each.cs" />
Expand Down
4 changes: 2 additions & 2 deletions source/CsQuery.sln
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ Global
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
BuildVersion_BuildVersioningStyle = None.None.None.Increment
BuildVersion_UseGlobalSettings = False
BuildVersion_AssemblyInfoFilename =
BuildVersion_UseGlobalSettings = False
BuildVersion_BuildVersioningStyle = None.None.None.None
EndGlobalSection
EndGlobal
2 changes: 1 addition & 1 deletion source/CsQuery/CQ.cs
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ protected bool AddSelection(IDomObject element)

protected bool AddSelection(IEnumerable<IDomObject> elements)
{
bool result = false;
bool result = false;
foreach (IDomObject elm in elements)
{
result = true;
Expand Down
42 changes: 35 additions & 7 deletions source/CsQuery/CQ_jQuery/After.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public CQ After(IDomObject element)

public CQ After(IEnumerable<IDomObject> elements)
{
EnsureCsQuery(elements).InsertAtOffset(SelectionSet, 1);
EnsureCsQuery(elements).InsertAtOffset(this, 1);
return this;
}
#endregion
Expand Down Expand Up @@ -131,21 +131,39 @@ protected CQ InsertAtOffset(IEnumerable<IDomObject> target, int offset)

protected CQ InsertAtOffset(IEnumerable<IDomObject> target, int offset, out CQ insertedElements)
{
SelectionSet<IDomObject> sel = target as SelectionSet<IDomObject>;
bool isCsQuery = sel != null;
CQ cq = target as CQ;
SelectionSet<IDomObject> sel = null;

if (cq!=null) {
sel = cq.SelectionSet;
}

bool isTargetCsQuery = cq != null;

bool isFirst = true;

// Copy the target list: it could change otherwise
List<IDomObject> targets = new List<IDomObject>(target);

insertedElements = new CQ();
bool isEmptyTarget = sel.Count == 0;

// bind the source to the target's document if it was itself a CsQuery object, and update its selection set to reflect the
// current document.

if (isTargetCsQuery)
{
Document = cq.Document;
}

if (isCsQuery && sel.Count == 0)
if (isTargetCsQuery && isEmptyTarget)
{
// If appending items to an empty selection, just add them to the selection set
sel.AddRange(SelectionSet);
insertedElements.AddSelection(SelectionSet);

// selection set will be messed up if document was changed; rebuild it
SelectionSet.Clear();
SelectionSet.AddRange(insertedElements);
}
else
{
Expand All @@ -154,7 +172,7 @@ protected CQ InsertAtOffset(IEnumerable<IDomObject> target, int offset, out CQ i
if (el.IsDisconnected)
{
// Disconnected items are added to the selection set (if that's the target)
if (!isCsQuery)
if (!isTargetCsQuery)
{
throw new InvalidOperationException("You can't add elements to a disconnected element list, it must be in a selection set");
}
Expand All @@ -167,14 +185,21 @@ protected CQ InsertAtOffset(IEnumerable<IDomObject> target, int offset, out CQ i
sel.Insert(index + offset, item);
}
insertedElements.AddSelection(SelectionSet);

// selection set will be messed up if document was changed; rebuild it
SelectionSet.Clear();
SelectionSet.AddRange(insertedElements);
}
else
{
if (isFirst)
{
insertedElements.AddSelection(SelectionSet);
InsertAtOffset(el, offset);
isFirst = false;
insertedElements.AddSelection(SelectionSet);
// selection set will be messed up if document was changed; rebuild it
SelectionSet.Clear();
SelectionSet.AddRange(insertedElements);
}
else
{
Expand All @@ -185,6 +210,9 @@ protected CQ InsertAtOffset(IEnumerable<IDomObject> target, int offset, out CQ i
}
}
}



return this;
}
#endregion
Expand Down
2 changes: 1 addition & 1 deletion source/CsQuery/CQ_jQuery/Before.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public CQ Before(IDomObject element)

public CQ Before(IEnumerable<IDomObject> elements)
{
EnsureCsQuery(elements).InsertAtOffset(SelectionSet, 0);
EnsureCsQuery(elements).InsertAtOffset(this, 0);
return this;
}

Expand Down
2 changes: 1 addition & 1 deletion source/CsQuery/CsQuery.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ xcopy $(TargetDir)CsQuery.xml $(SolutionDir)..\Distribution /Y
</PropertyGroup>
<ProjectExtensions>
<VisualStudio>
<UserProperties BuildVersion_BuildVersioningStyle="None.None.None.Increment" BuildVersion_AssemblyInfoFilename="Properties\AssemblyInfo.cs" BuildVersion_ConfigurationName="Release" BuildVersion_UpdateAssemblyVersion="True" />
<UserProperties BuildVersion_UseGlobalSettings="True" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_ConfigurationName="Any" BuildVersion_AssemblyInfoFilename="Properties\AssemblyInfo.cs" BuildVersion_BuildVersioningStyle="None.None.None.Increment" />
</VisualStudio>
</ProjectExtensions>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Expand Down
2 changes: 1 addition & 1 deletion source/CsQuery/CsQuery.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package >
<metadata>
<id>CsQuery</id>
<version>1.2</version>
<version>1.2.0.8</version>
<title>CsQuery</title>
<authors>James Treworgy</authors>
<owners>James Treworgy</owners>
Expand Down
8 changes: 1 addition & 7 deletions source/CsQuery/Implementation/SelectionSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ public SelectionSet(IEnumerable<T> elements, SelectionSetOrder inputOrder, Selec
/// Cached count
/// </summary>

private int _Count=-1;
private bool _IsDirty;

private SelectionSetOrder OriginalOrder;
Expand Down Expand Up @@ -221,11 +220,7 @@ public int Count
{
return MutableList.Count;
} else {
if (_Count == -1)
{
_Count = OriginalList.Count();
}
return _Count;
return OriginalList.Count();
}
}
}
Expand Down Expand Up @@ -681,7 +676,6 @@ private IEnumerable<T> EmptyList()
private void Touch()
{
_IsDirty = true;

}

private void Clean()
Expand Down
2 changes: 1 addition & 1 deletion source/CsQuery/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.2.0.5")]
[assembly: AssemblyVersion("1.2.0.8")]

0 comments on commit 354504d

Please sign in to comment.