8 changed files with 192 additions and 3 deletions
@ -0,0 +1,64 @@
@@ -0,0 +1,64 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
|
||||
namespace ICSharpCode.AspNet.Mvc.Folding |
||||
{ |
||||
public class WebFormsMarkupCharacterReader : CharacterReader |
||||
{ |
||||
bool isInAspxMarkup; |
||||
bool isAtEndAspxMarkup; |
||||
int previousCharacter = EndOfCharacters; |
||||
|
||||
public WebFormsMarkupCharacterReader(string html) |
||||
: base(html) |
||||
{ |
||||
} |
||||
|
||||
protected override void OnCharacterRead() |
||||
{ |
||||
if (isInAspxMarkup) { |
||||
CheckForAspxEndTag(); |
||||
} else { |
||||
CheckForAspxMarkupStartTag(); |
||||
} |
||||
} |
||||
|
||||
void CheckForAspxEndTag() |
||||
{ |
||||
if (isAtEndAspxMarkup) { |
||||
OutsideOfMarkup(); |
||||
} |
||||
if (IsGreaterThanSign() && IsPreviousCharacterPercentSign()) { |
||||
isAtEndAspxMarkup = true; |
||||
} |
||||
previousCharacter = CurrentCharacter; |
||||
} |
||||
|
||||
void OutsideOfMarkup() |
||||
{ |
||||
isAtEndAspxMarkup = false; |
||||
isInAspxMarkup = false; |
||||
} |
||||
|
||||
bool IsPreviousCharacterPercentSign() |
||||
{ |
||||
return previousCharacter == '%'; |
||||
} |
||||
|
||||
void CheckForAspxMarkupStartTag() |
||||
{ |
||||
isInAspxMarkup = IsAspxMarkupStartTag(); |
||||
} |
||||
|
||||
public bool IsHtml { |
||||
get { return !isInAspxMarkup; } |
||||
} |
||||
|
||||
bool IsAspxMarkupStartTag() |
||||
{ |
||||
return IsLessThanSign() && IsNextCharacterPercentSign(); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,75 @@
@@ -0,0 +1,75 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using ICSharpCode.AspNet.Mvc.Folding; |
||||
using NUnit.Framework; |
||||
|
||||
namespace AspNet.Mvc.Tests.Folding |
||||
{ |
||||
[TestFixture] |
||||
public class WebFormsMarkupCharacterReaderTests |
||||
{ |
||||
WebFormsMarkupCharacterReader reader; |
||||
|
||||
void CreateReader(string html) |
||||
{ |
||||
reader = new WebFormsMarkupCharacterReader(html); |
||||
} |
||||
|
||||
[Test] |
||||
public void IsHtml_CurrentCharacterIsAtStartOfHtml_ReturnsTrue() |
||||
{ |
||||
CreateReader("<br/>"); |
||||
|
||||
bool htmlCharacterRead = reader.IsHtml; |
||||
|
||||
Assert.IsTrue(htmlCharacterRead); |
||||
} |
||||
|
||||
[Test] |
||||
public void IsHtml_FirstCharacterReadIsPartOfAspxMarkup_ReturnsFalse() |
||||
{ |
||||
CreateReader("<%@ Page Language=\"VB\" %>"); |
||||
reader.Read(); |
||||
|
||||
bool result = reader.IsHtml; |
||||
|
||||
Assert.IsFalse(result); |
||||
} |
||||
|
||||
[Test] |
||||
public void IsHtml_FirstCharacterReadIsPartOfBreakTag_ReturnsTrue() |
||||
{ |
||||
CreateReader("<br/>"); |
||||
reader.Read(); |
||||
|
||||
bool readHtmlCharacter = reader.IsHtml; |
||||
|
||||
Assert.IsTrue(readHtmlCharacter); |
||||
} |
||||
|
||||
[Test] |
||||
public void IsHtml_FirstCharacterReadAfterAspxMarkupStartOpenBracketTag_ReturnsFalse() |
||||
{ |
||||
CreateReader("<%= model.Message %>"); |
||||
reader.Read(); |
||||
reader.Read(); |
||||
|
||||
bool readHtmlCharacter = reader.IsHtml; |
||||
|
||||
Assert.IsFalse(readHtmlCharacter); |
||||
} |
||||
|
||||
[Test] |
||||
public void IsHtml_ReadFirstCharacterAfterAspxEndMarkupTag_ReturnsTrue() |
||||
{ |
||||
CreateReader("<%= %><br/>"); |
||||
reader.ReadCharacters(7); |
||||
|
||||
bool readHtmlCharacter = reader.IsHtml; |
||||
|
||||
Assert.IsTrue(readHtmlCharacter); |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue