26 changed files with 714 additions and 186 deletions
@ -0,0 +1,17 @@ |
|||||||
|
// 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 CSharpRazorLanguageBinding : HtmlLanguageBinding |
||||||
|
{ |
||||||
|
public CSharpRazorLanguageBinding() |
||||||
|
: base( |
||||||
|
new TextEditorWithParseInformationFoldingFactory(), |
||||||
|
new RazorFoldGeneratorFactory("cshtml")) |
||||||
|
{ |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,77 @@ |
|||||||
|
// 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 System.Collections.Generic; |
||||||
|
using System.Linq; |
||||||
|
using ICSharpCode.AvalonEdit.Folding; |
||||||
|
|
||||||
|
namespace ICSharpCode.AspNet.Mvc.Folding |
||||||
|
{ |
||||||
|
public class HtmlFoldParser : IFoldParser |
||||||
|
{ |
||||||
|
List<HtmlElementFold> folds = new List<HtmlElementFold>(); |
||||||
|
Stack<HtmlElementFold> foldStack = new Stack<HtmlElementFold>(); |
||||||
|
HtmlReader htmlReader; |
||||||
|
IHtmlReaderFactory htmlReaderFactory; |
||||||
|
|
||||||
|
public HtmlFoldParser(IHtmlReaderFactory htmlReaderFactory) |
||||||
|
{ |
||||||
|
this.htmlReaderFactory = htmlReaderFactory; |
||||||
|
} |
||||||
|
|
||||||
|
public IEnumerable<NewFolding> GetFolds(string html) |
||||||
|
{ |
||||||
|
ClearPreviousFolds(); |
||||||
|
htmlReader = CreateHtmlReader(html); |
||||||
|
while (htmlReader.Read()) { |
||||||
|
if (htmlReader.IsEmptyElement) { |
||||||
|
// No folds for empty elements.
|
||||||
|
} else if (htmlReader.IsEndElement) { |
||||||
|
AddFoldForCompletedElement(); |
||||||
|
} else { |
||||||
|
SaveFoldStartOnStack(); |
||||||
|
} |
||||||
|
} |
||||||
|
SortFoldsByStartOffset(); |
||||||
|
return folds; |
||||||
|
} |
||||||
|
|
||||||
|
void ClearPreviousFolds() |
||||||
|
{ |
||||||
|
folds.Clear(); |
||||||
|
} |
||||||
|
|
||||||
|
HtmlReader CreateHtmlReader(string html) |
||||||
|
{ |
||||||
|
return htmlReaderFactory.CreateHtmlReader(html); |
||||||
|
} |
||||||
|
|
||||||
|
void SaveFoldStartOnStack() |
||||||
|
{ |
||||||
|
var fold = new HtmlElementFold() { |
||||||
|
ElementName = htmlReader.Value, |
||||||
|
StartOffset = htmlReader.Offset |
||||||
|
}; |
||||||
|
foldStack.Push(fold); |
||||||
|
} |
||||||
|
|
||||||
|
void AddFoldForCompletedElement() |
||||||
|
{ |
||||||
|
if (foldStack.Any()) { |
||||||
|
var fold = foldStack.Pop(); |
||||||
|
if (fold.ElementName == htmlReader.Value) { |
||||||
|
fold.EndOffset = htmlReader.EndOffset; |
||||||
|
folds.Add(fold); |
||||||
|
} else { |
||||||
|
AddFoldForCompletedElement(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
void SortFoldsByStartOffset() |
||||||
|
{ |
||||||
|
folds.Sort((fold1, fold2) => fold1.StartOffset.CompareTo(fold2.StartOffset)); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,48 @@ |
|||||||
|
// 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.SharpDevelop; |
||||||
|
using ICSharpCode.SharpDevelop.Dom; |
||||||
|
using ICSharpCode.SharpDevelop.Editor; |
||||||
|
|
||||||
|
namespace ICSharpCode.AspNet.Mvc.Folding |
||||||
|
{ |
||||||
|
public class HtmlLanguageBinding : DefaultLanguageBinding |
||||||
|
{ |
||||||
|
ITextEditorWithParseInformationFoldingFactory textEditorFactory; |
||||||
|
IFoldGeneratorFactory foldGeneratorFactory; |
||||||
|
IFoldGenerator foldGenerator; |
||||||
|
|
||||||
|
public HtmlLanguageBinding( |
||||||
|
ITextEditorWithParseInformationFoldingFactory textEditorFactory, |
||||||
|
IFoldGeneratorFactory foldGeneratorFactory) |
||||||
|
{ |
||||||
|
this.textEditorFactory = textEditorFactory; |
||||||
|
this.foldGeneratorFactory = foldGeneratorFactory; |
||||||
|
} |
||||||
|
|
||||||
|
public override IFormattingStrategy FormattingStrategy { |
||||||
|
get { return new DefaultFormattingStrategy(); } |
||||||
|
} |
||||||
|
|
||||||
|
public override LanguageProperties Properties { |
||||||
|
get { return LanguageProperties.None; } |
||||||
|
} |
||||||
|
|
||||||
|
public override void Attach(ITextEditor editor) |
||||||
|
{ |
||||||
|
Attach(textEditorFactory.CreateTextEditor(editor)); |
||||||
|
} |
||||||
|
|
||||||
|
void Attach(ITextEditorWithParseInformationFolding editor) |
||||||
|
{ |
||||||
|
foldGenerator = foldGeneratorFactory.CreateFoldGenerator(editor); |
||||||
|
} |
||||||
|
|
||||||
|
public override void Detach() |
||||||
|
{ |
||||||
|
foldGenerator.Dispose(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,117 @@ |
|||||||
|
// 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 System.IO; |
||||||
|
|
||||||
|
namespace ICSharpCode.AspNet.Mvc.Folding |
||||||
|
{ |
||||||
|
public class HtmlReader |
||||||
|
{ |
||||||
|
CharacterReader reader; |
||||||
|
HtmlNode currentNode = new HtmlNode(); |
||||||
|
|
||||||
|
public HtmlReader(string html) |
||||||
|
: this(new StringReader(html)) |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
public HtmlReader(TextReader reader) |
||||||
|
: this(new CharacterReader(reader)) |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
public HtmlReader(CharacterReader reader) |
||||||
|
{ |
||||||
|
this.reader = reader; |
||||||
|
} |
||||||
|
|
||||||
|
public string Value { |
||||||
|
get { return currentNode.Value; } |
||||||
|
} |
||||||
|
|
||||||
|
public int Offset { get; private set; } |
||||||
|
public int Length { get; private set; } |
||||||
|
|
||||||
|
public int EndOffset { |
||||||
|
get { return Offset + Length; } |
||||||
|
} |
||||||
|
|
||||||
|
public bool IsEmptyElement { get; private set; } |
||||||
|
public bool IsEndElement { get; private set; } |
||||||
|
|
||||||
|
public bool IsStartElement { |
||||||
|
get { return !IsEndElement; } |
||||||
|
} |
||||||
|
|
||||||
|
public bool Read() |
||||||
|
{ |
||||||
|
while (ReadNextCharacter()) { |
||||||
|
if (!IsHtml()) { |
||||||
|
// Skip character
|
||||||
|
} else if (IsElementStartCharacter()) { |
||||||
|
currentNode = new HtmlNode(); |
||||||
|
IsEndElement = reader.IsNextCharacterForwardSlash(); |
||||||
|
IsEmptyElement = false; |
||||||
|
Offset = reader.CurrentCharacterOffset; |
||||||
|
} else if (IsElementEndCharacter()) { |
||||||
|
Length = reader.NextCharacterOffset - Offset; |
||||||
|
return true; |
||||||
|
} else if (reader.IsForwardSlash()) { |
||||||
|
IsEmptyElement = !IsEndElement; |
||||||
|
} else if (IsElementNameCharacter()) { |
||||||
|
currentNode.Append(reader.CurrentCharacter); |
||||||
|
} else if (reader.IsDoubleQuote()) { |
||||||
|
ReadDoubleQuotedString(); |
||||||
|
} else if (reader.IsSingleQuote()) { |
||||||
|
ReadSingleQuotedString(); |
||||||
|
} |
||||||
|
} |
||||||
|
return false; |
||||||
|
} |
||||||
|
|
||||||
|
protected virtual bool IsHtml() |
||||||
|
{ |
||||||
|
return true; |
||||||
|
} |
||||||
|
|
||||||
|
bool ReadNextCharacter() |
||||||
|
{ |
||||||
|
return reader.Read(); |
||||||
|
} |
||||||
|
|
||||||
|
bool IsElementStartCharacter() |
||||||
|
{ |
||||||
|
return reader.IsLessThanSign(); |
||||||
|
} |
||||||
|
|
||||||
|
bool IsElementEndCharacter() |
||||||
|
{ |
||||||
|
return reader.IsGreaterThanSign(); |
||||||
|
} |
||||||
|
|
||||||
|
bool IsElementNameCharacter() |
||||||
|
{ |
||||||
|
return reader.IsLetterOrDigit() || reader.IsSpace(); |
||||||
|
} |
||||||
|
|
||||||
|
void ReadDoubleQuotedString() |
||||||
|
{ |
||||||
|
ReadUntil(() => reader.IsDoubleQuote()); |
||||||
|
} |
||||||
|
|
||||||
|
void ReadUntil(Func<bool> match) |
||||||
|
{ |
||||||
|
while (ReadNextCharacter()) { |
||||||
|
if (match()) { |
||||||
|
return; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
void ReadSingleQuotedString() |
||||||
|
{ |
||||||
|
ReadUntil(() => reader.IsSingleQuote()); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,12 @@ |
|||||||
|
// 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 interface IHtmlReaderFactory |
||||||
|
{ |
||||||
|
HtmlReader CreateHtmlReader(string html); |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,23 @@ |
|||||||
|
// 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 RazorFoldGeneratorFactory : IFoldGeneratorFactory |
||||||
|
{ |
||||||
|
public RazorFoldGeneratorFactory(string extension) |
||||||
|
{ |
||||||
|
this.Extension = extension; |
||||||
|
} |
||||||
|
|
||||||
|
string Extension { get; set; } |
||||||
|
|
||||||
|
public IFoldGenerator CreateFoldGenerator(ITextEditorWithParseInformationFolding textEditor) |
||||||
|
{ |
||||||
|
return new ScheduledFoldGenerator( |
||||||
|
new FoldGenerator(textEditor, new RazorHtmlFoldParser(Extension))); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,22 @@ |
|||||||
|
// 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 System.Collections.Generic; |
||||||
|
using ICSharpCode.AvalonEdit.Folding; |
||||||
|
|
||||||
|
namespace ICSharpCode.AspNet.Mvc.Folding |
||||||
|
{ |
||||||
|
public class RazorHtmlFoldParser : HtmlFoldParser |
||||||
|
{ |
||||||
|
public RazorHtmlFoldParser(string extension) |
||||||
|
: this(new RazorHtmlReaderFactory(extension)) |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
public RazorHtmlFoldParser(RazorHtmlReaderFactory htmlReaderFactory) |
||||||
|
: base(htmlReaderFactory) |
||||||
|
{ |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,29 @@ |
|||||||
|
// 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 System.IO; |
||||||
|
|
||||||
|
namespace ICSharpCode.AspNet.Mvc.Folding |
||||||
|
{ |
||||||
|
public class RazorHtmlReader : HtmlReader |
||||||
|
{ |
||||||
|
RazorMarkupCharacterReader reader; |
||||||
|
|
||||||
|
public RazorHtmlReader(string html) |
||||||
|
: this(new RazorMarkupCharacterReader(html)) |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
public RazorHtmlReader(RazorMarkupCharacterReader reader) |
||||||
|
: base(reader) |
||||||
|
{ |
||||||
|
this.reader = reader; |
||||||
|
} |
||||||
|
|
||||||
|
protected override bool IsHtml() |
||||||
|
{ |
||||||
|
return reader.IsHtml; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,19 @@ |
|||||||
|
// 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 RazorHtmlReaderFactory : IHtmlReaderFactory |
||||||
|
{ |
||||||
|
public RazorHtmlReaderFactory(string extension) |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
public HtmlReader CreateHtmlReader(string html) |
||||||
|
{ |
||||||
|
return new RazorHtmlReader(html); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,55 @@ |
|||||||
|
// 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 System.Collections.Generic; |
||||||
|
using System.IO; |
||||||
|
using System.Web.Razor; |
||||||
|
using System.Web.Razor.Parser.SyntaxTree; |
||||||
|
using System.Web.Razor.Text; |
||||||
|
|
||||||
|
namespace ICSharpCode.AspNet.Mvc.Folding |
||||||
|
{ |
||||||
|
public class RazorHtmlSpans |
||||||
|
{ |
||||||
|
List<Span> spans; |
||||||
|
|
||||||
|
public RazorHtmlSpans(string html) |
||||||
|
{ |
||||||
|
ReadHtmlSpans(html); |
||||||
|
} |
||||||
|
|
||||||
|
void ReadHtmlSpans(string html) |
||||||
|
{ |
||||||
|
RazorEngineHost razorEngineHost = new RazorEngineHost(RazorCodeLanguage.GetLanguageByExtension(".cshtml")); |
||||||
|
RazorTemplateEngine engine = new RazorTemplateEngine(razorEngineHost); |
||||||
|
ParserResults results = engine.ParseTemplate(new StringReader(html)); |
||||||
|
spans = new List<Span>(results.Document.Flatten()); |
||||||
|
spans.RemoveAll(span => span.Kind != SpanKind.Markup); |
||||||
|
} |
||||||
|
|
||||||
|
public bool IsHtml(int offset) |
||||||
|
{ |
||||||
|
if (offset >= 0) { |
||||||
|
return HtmlSpansContainOffset(offset); |
||||||
|
} |
||||||
|
return true; |
||||||
|
} |
||||||
|
|
||||||
|
bool HtmlSpansContainOffset(int offset) |
||||||
|
{ |
||||||
|
foreach (Span span in spans) { |
||||||
|
if (IsInSpan(span, offset)) { |
||||||
|
return true; |
||||||
|
} |
||||||
|
} |
||||||
|
return false; |
||||||
|
} |
||||||
|
|
||||||
|
bool IsInSpan(Span span, int offset) |
||||||
|
{ |
||||||
|
int spanOffset = span.Start.AbsoluteIndex; |
||||||
|
return (offset >= spanOffset) && (offset < spanOffset + span.Length); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,22 @@ |
|||||||
|
// 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 RazorMarkupCharacterReader : CharacterReader |
||||||
|
{ |
||||||
|
RazorHtmlSpans htmlSpans; |
||||||
|
|
||||||
|
public RazorMarkupCharacterReader(string html) |
||||||
|
: base(html) |
||||||
|
{ |
||||||
|
htmlSpans = new RazorHtmlSpans(html); |
||||||
|
} |
||||||
|
|
||||||
|
public bool IsHtml { |
||||||
|
get { return htmlSpans.IsHtml(CurrentCharacterOffset); } |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,15 @@ |
|||||||
|
// 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 WebFormsHtmlReaderFactory : IHtmlReaderFactory |
||||||
|
{ |
||||||
|
public HtmlReader CreateHtmlReader(string html) |
||||||
|
{ |
||||||
|
return new SimpleWebFormsHtmlReader(html); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,30 @@ |
|||||||
|
// 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 CharacterReaderTests |
||||||
|
{ |
||||||
|
CharacterReader reader; |
||||||
|
|
||||||
|
void CreateReader(string html) |
||||||
|
{ |
||||||
|
reader = new CharacterReader(html); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void ReadCharacters_ReadTwoCharacters_SecondCharacterIsCurrentCharacter() |
||||||
|
{ |
||||||
|
CreateReader("12345"); |
||||||
|
|
||||||
|
reader.ReadCharacters(2); |
||||||
|
|
||||||
|
Assert.AreEqual('2', reader.CurrentCharacter); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,76 @@ |
|||||||
|
// 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 System.Collections.Generic; |
||||||
|
using System.Linq; |
||||||
|
|
||||||
|
using ICSharpCode.AspNet.Mvc.Folding; |
||||||
|
using ICSharpCode.AvalonEdit.Folding; |
||||||
|
using NUnit.Framework; |
||||||
|
|
||||||
|
namespace AspNet.Mvc.Tests.Folding |
||||||
|
{ |
||||||
|
[TestFixture] |
||||||
|
public class RazorHtmlFoldParserTests |
||||||
|
{ |
||||||
|
RazorHtmlFoldParser parser; |
||||||
|
List<NewFolding> folds; |
||||||
|
|
||||||
|
void CreateCSharpParser() |
||||||
|
{ |
||||||
|
parser = new RazorHtmlFoldParser("cshtml"); |
||||||
|
} |
||||||
|
|
||||||
|
void GetFolds(string text) |
||||||
|
{ |
||||||
|
folds = parser.GetFolds(text).ToList(); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void GetFolds_ParagraphStartAndEndTag_ReturnsOneFoldForParagraphTag() |
||||||
|
{ |
||||||
|
CreateCSharpParser(); |
||||||
|
|
||||||
|
string text = |
||||||
|
"<p>\r\n" + |
||||||
|
"</p>"; |
||||||
|
|
||||||
|
GetFolds(text); |
||||||
|
|
||||||
|
var expectedFolds = new HtmlElementFold[] { |
||||||
|
new HtmlElementFold() { |
||||||
|
ElementName = "p", |
||||||
|
StartOffset = 0, |
||||||
|
EndOffset = 9 |
||||||
|
} |
||||||
|
}; |
||||||
|
|
||||||
|
CollectionAssert.AreEqual(expectedFolds, folds); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void GetFolds_EndAnchorTagInsideIfStatement_ReturnsOneFoldForParagraphTagAndNotAnchorTag() |
||||||
|
{ |
||||||
|
CreateCSharpParser(); |
||||||
|
|
||||||
|
string text = |
||||||
|
"@if (i<a || b>i) {\r\n" + |
||||||
|
" </a>\r\n" + |
||||||
|
" <p></p>\r\n" + |
||||||
|
"}\r\n"; |
||||||
|
|
||||||
|
GetFolds(text); |
||||||
|
|
||||||
|
var expectedFolds = new HtmlElementFold[] { |
||||||
|
new HtmlElementFold() { |
||||||
|
ElementName = "p", |
||||||
|
StartOffset = 34, |
||||||
|
EndOffset = 41 |
||||||
|
} |
||||||
|
}; |
||||||
|
|
||||||
|
CollectionAssert.AreEqual(expectedFolds, folds); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,38 @@ |
|||||||
|
// 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 RazorHtmlReaderTests |
||||||
|
{ |
||||||
|
RazorHtmlReader htmlReader; |
||||||
|
|
||||||
|
void CreateHtmlReader(string html) |
||||||
|
{ |
||||||
|
htmlReader = new RazorHtmlReader(html); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void Value_ReadFirstParagraphTagInsideIfStatementWithLessThanSign_ReturnsParagraphTagName() |
||||||
|
{ |
||||||
|
string html = |
||||||
|
"@if (i<a || b>i) {\r\n" + |
||||||
|
" <p></p>\r\n" + |
||||||
|
"}\r\n"; |
||||||
|
|
||||||
|
CreateHtmlReader(html); |
||||||
|
htmlReader.Read(); |
||||||
|
|
||||||
|
string value = htmlReader.Value; |
||||||
|
|
||||||
|
Assert.AreEqual("p", value); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,63 @@ |
|||||||
|
// 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 RazorMarkupCharacterReaderTests |
||||||
|
{ |
||||||
|
RazorMarkupCharacterReader reader; |
||||||
|
|
||||||
|
void CreateReader(string html) |
||||||
|
{ |
||||||
|
reader = new RazorMarkupCharacterReader(html); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void IsHtml_CurrentCharacterIsAtStartOfHtml_ReturnsTrue() |
||||||
|
{ |
||||||
|
CreateReader("<br/>"); |
||||||
|
|
||||||
|
bool htmlCharacterRead = reader.IsHtml; |
||||||
|
|
||||||
|
Assert.IsTrue(htmlCharacterRead); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void IsHtml_FirstCharacterReadIsRazorTransitionSymbol_ReturnsFalse() |
||||||
|
{ |
||||||
|
CreateReader("@model"); |
||||||
|
reader.Read(); |
||||||
|
|
||||||
|
bool result = reader.IsHtml; |
||||||
|
|
||||||
|
Assert.IsFalse(result); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void IsHtml_ReadFirstRazorTransitionSymbolAfterParagraphTag_ReturnsFalse() |
||||||
|
{ |
||||||
|
CreateReader("<p>@model.Message</p>"); |
||||||
|
reader.ReadCharacters(4); |
||||||
|
|
||||||
|
bool htmlCharacterRead = reader.IsHtml; |
||||||
|
|
||||||
|
Assert.IsFalse(htmlCharacterRead); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void IsHtml_ReadFirstCharacterAfterRazorTransitionSymbol_ReturnsFalse() |
||||||
|
{ |
||||||
|
CreateReader("<p>@model.Message</p>"); |
||||||
|
reader.ReadCharacters(5); |
||||||
|
|
||||||
|
bool htmlCharacterRead = reader.IsHtml; |
||||||
|
|
||||||
|
Assert.IsFalse(htmlCharacterRead); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
Loading…
Reference in new issue