Browse Source
git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@5287 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61pull/1/head
21 changed files with 333 additions and 51 deletions
@ -0,0 +1,21 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
using ICSharpCode.SharpDevelop; |
||||||
|
using ICSharpCode.SharpDevelop.Dom; |
||||||
|
|
||||||
|
namespace ICSharpCode.XmlEditor |
||||||
|
{ |
||||||
|
public class DefaultParserService : IParserService |
||||||
|
{ |
||||||
|
public ParseInformation GetExistingParseInformation(IProjectContent content, string fileName) |
||||||
|
{ |
||||||
|
return ParserService.GetExistingParseInformation(content, fileName); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,17 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
using ICSharpCode.SharpDevelop.Dom; |
||||||
|
|
||||||
|
namespace ICSharpCode.XmlEditor |
||||||
|
{ |
||||||
|
public interface IParserService |
||||||
|
{ |
||||||
|
ParseInformation GetExistingParseInformation(IProjectContent content, string fileName); |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,71 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.Collections.Generic; |
||||||
|
|
||||||
|
using ICSharpCode.Core; |
||||||
|
using ICSharpCode.SharpDevelop; |
||||||
|
using ICSharpCode.SharpDevelop.Dom; |
||||||
|
using ICSharpCode.SharpDevelop.Project; |
||||||
|
using ICSharpCode.XmlEditor; |
||||||
|
using NUnit.Framework; |
||||||
|
using XmlEditor.Tests.Utils; |
||||||
|
|
||||||
|
namespace XmlEditor.Tests.Folding |
||||||
|
{ |
||||||
|
[TestFixture] |
||||||
|
public class OldParseInfoFoldRegionsUsedForInvalidXmlTestFixture |
||||||
|
{ |
||||||
|
XmlFoldParser parser; |
||||||
|
ICompilationUnit unit; |
||||||
|
DefaultProjectContent projectContent; |
||||||
|
DomRegion previousCompilationUnitFoldRegion; |
||||||
|
MockParserService parserService; |
||||||
|
|
||||||
|
[SetUp] |
||||||
|
public void Init() |
||||||
|
{ |
||||||
|
string xml = |
||||||
|
"<root\r\n" + |
||||||
|
" <child>\r\n" + |
||||||
|
"</root>"; |
||||||
|
|
||||||
|
int line = 1; |
||||||
|
int column = 1; |
||||||
|
int endLine = 3; |
||||||
|
int endColumn = 8; |
||||||
|
previousCompilationUnitFoldRegion = new DomRegion(line, column, endLine, endColumn); |
||||||
|
|
||||||
|
projectContent = new DefaultProjectContent(); |
||||||
|
DefaultCompilationUnit existingUnit = new DefaultCompilationUnit(projectContent); |
||||||
|
existingUnit.FoldingRegions.Add(new FoldingRegion("<root>", previousCompilationUnitFoldRegion)); |
||||||
|
ParseInformation parseInfo = new ParseInformation(existingUnit); |
||||||
|
|
||||||
|
parserService = new MockParserService(); |
||||||
|
parserService.SetExistingParseInformation(@"d:\projects\test\a.xml", parseInfo); |
||||||
|
|
||||||
|
MockTextBuffer textBuffer = new MockTextBuffer(xml); |
||||||
|
DefaultXmlFileExtensions extensions = new DefaultXmlFileExtensions(null); |
||||||
|
XmlEditorOptions options = new XmlEditorOptions(new Properties()); |
||||||
|
parser = new XmlFoldParser(extensions, options, parserService); |
||||||
|
unit = parser.Parse(projectContent, @"d:\projects\test\a.xml", textBuffer); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void PreviouslyParsedFoldRegionUsedWhenXmlIsInvalid() |
||||||
|
{ |
||||||
|
Assert.AreEqual(previousCompilationUnitFoldRegion, unit.FoldingRegions[0].Region); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void ProjectContentPassedToParserServiceGetExistingParseInfoMethod() |
||||||
|
{ |
||||||
|
Assert.AreSame(projectContent, parserService.ProjectContentPassedToGetExistingParseInforMethod); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,44 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.Collections.Generic; |
||||||
|
using ICSharpCode.SharpDevelop.Dom; |
||||||
|
using ICSharpCode.XmlEditor; |
||||||
|
|
||||||
|
namespace XmlEditor.Tests.Utils |
||||||
|
{ |
||||||
|
public class MockParserService : IParserService |
||||||
|
{ |
||||||
|
IProjectContent projectContentPassedToGetExistingParseInfoMethod; |
||||||
|
Dictionary<string, ParseInformation> parseInfoDictionary = new Dictionary<string, ParseInformation>(); |
||||||
|
|
||||||
|
public MockParserService() |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
public ParseInformation GetExistingParseInformation(IProjectContent content, string fileName) |
||||||
|
{ |
||||||
|
projectContentPassedToGetExistingParseInfoMethod = content; |
||||||
|
|
||||||
|
ParseInformation parseInfo; |
||||||
|
if (parseInfoDictionary.TryGetValue(fileName, out parseInfo)) { |
||||||
|
return parseInfo; |
||||||
|
} |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
public void SetExistingParseInformation(string fileName, ParseInformation parseInfo) |
||||||
|
{ |
||||||
|
parseInfoDictionary.Add(fileName, parseInfo); |
||||||
|
} |
||||||
|
|
||||||
|
public IProjectContent ProjectContentPassedToGetExistingParseInforMethod { |
||||||
|
get { return projectContentPassedToGetExistingParseInfoMethod; } |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,53 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
using ICSharpCode.SharpDevelop.Dom; |
||||||
|
using ICSharpCode.XmlEditor; |
||||||
|
using NUnit.Framework; |
||||||
|
|
||||||
|
namespace XmlEditor.Tests.Utils.Tests |
||||||
|
{ |
||||||
|
[TestFixture] |
||||||
|
public class MockParserServiceTests |
||||||
|
{ |
||||||
|
MockParserService parserService; |
||||||
|
ParseInformation existingParseInfo; |
||||||
|
|
||||||
|
[SetUp] |
||||||
|
public void Init() |
||||||
|
{ |
||||||
|
|
||||||
|
DefaultProjectContent projectContent = new DefaultProjectContent(); |
||||||
|
DefaultCompilationUnit unit = new DefaultCompilationUnit(projectContent); |
||||||
|
existingParseInfo = new ParseInformation(unit); |
||||||
|
|
||||||
|
parserService = new MockParserService(); |
||||||
|
parserService.SetExistingParseInformation(@"d:\projects\test.xml", existingParseInfo); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void CanGetProjectContentPassedToGetExistingParseInfoMethod() |
||||||
|
{ |
||||||
|
DefaultProjectContent projectContent = new DefaultProjectContent(); |
||||||
|
parserService.GetExistingParseInformation(projectContent, "file.xml"); |
||||||
|
Assert.AreSame(projectContent, parserService.ProjectContentPassedToGetExistingParseInforMethod); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void GetExistingParseInfoReturnsParseInfoObjectForKnownFileName() |
||||||
|
{ |
||||||
|
Assert.AreSame(existingParseInfo, parserService.GetExistingParseInformation(null, @"d:\projects\test.xml")); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void GetExistingParseInfoReturnsNullForKnownFileName() |
||||||
|
{ |
||||||
|
Assert.IsNull(parserService.GetExistingParseInformation(null, @"d:\projects\unknown.xml")); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
Loading…
Reference in new issue