Browse Source

- add LocationAssignmentCheckVisitor to ParseExpression-Tests

- use AcceptChildren to avoid check on CompilationUnit
pull/2/head
Siegfried Pammer 15 years ago
parent
commit
1ae2fed7b5
  1. 5
      src/Libraries/NRefactory/Test/Parser/ParseUtilCSharp.cs
  2. 5
      src/Libraries/NRefactory/Test/Parser/ParseUtilVBNet.cs

5
src/Libraries/NRefactory/Test/Parser/ParseUtilCSharp.cs

@ -40,7 +40,7 @@ namespace ICSharpCode.NRefactory.Tests.Ast @@ -40,7 +40,7 @@ namespace ICSharpCode.NRefactory.Tests.Ast
Type type = typeof(T);
Assert.IsTrue(type.IsAssignableFrom(parser.CompilationUnit.Children[0].GetType()), String.Format("Parsed expression was {0} instead of {1} ({2})", parser.CompilationUnit.Children[0].GetType(), type, parser.CompilationUnit.Children[0]));
parser.CompilationUnit.AcceptVisitor(new CheckParentVisitor(), null);
parser.CompilationUnit.AcceptVisitor(new LocationAssignmentCheckVisitor(), null);
parser.CompilationUnit.AcceptChildren(new LocationAssignmentCheckVisitor(), null);
return (T)parser.CompilationUnit.Children[0];
}
@ -76,11 +76,12 @@ namespace ICSharpCode.NRefactory.Tests.Ast @@ -76,11 +76,12 @@ namespace ICSharpCode.NRefactory.Tests.Ast
{
// SEMICOLON HACK : without a trailing semicolon, parsing expressions does not work correctly
IParser parser = ParserFactory.CreateParser(SupportedLanguage.CSharp, new StringReader(expr + ";"));
object parsedExpression = parser.ParseExpression();
INode parsedExpression = parser.ParseExpression();
if (expectErrors)
Assert.IsTrue(parser.Errors.ErrorOutput.Length > 0, "There were errors expected, but parser finished without errors.");
else
Assert.AreEqual("", parser.Errors.ErrorOutput);
parsedExpression.AcceptVisitor(new LocationAssignmentCheckVisitor(), null);
Type type = typeof(T);
Assert.IsTrue(type.IsAssignableFrom(parsedExpression.GetType()), String.Format("Parsed expression was {0} instead of {1} ({2})", parsedExpression.GetType(), type, parsedExpression));
return (T)parsedExpression;

5
src/Libraries/NRefactory/Test/Parser/ParseUtilVBNet.cs

@ -35,7 +35,7 @@ namespace ICSharpCode.NRefactory.Tests.Ast @@ -35,7 +35,7 @@ namespace ICSharpCode.NRefactory.Tests.Ast
Assert.IsTrue(type.IsAssignableFrom(parser.CompilationUnit.Children[0].GetType()), String.Format("Parsed expression was {0} instead of {1} ({2})", parser.CompilationUnit.Children[0].GetType(), type, parser.CompilationUnit.Children[0]));
parser.CompilationUnit.AcceptVisitor(new CheckParentVisitor(), null);
parser.CompilationUnit.AcceptVisitor(new LocationAssignmentCheckVisitor(), null);
parser.CompilationUnit.AcceptChildren(new LocationAssignmentCheckVisitor(), null);
return (T)parser.CompilationUnit.Children[0];
}
@ -76,11 +76,12 @@ namespace ICSharpCode.NRefactory.Tests.Ast @@ -76,11 +76,12 @@ namespace ICSharpCode.NRefactory.Tests.Ast
public static T ParseExpression<T>(string expr, bool expectErrors) where T : INode
{
IParser parser = ParserFactory.CreateParser(SupportedLanguage.VBNet, new StringReader(expr));
object parsedExpression = parser.ParseExpression();
INode parsedExpression = parser.ParseExpression();
if (expectErrors)
Assert.IsFalse(parser.Errors.ErrorOutput.Length == 0, "Expected errors, but operation completed successfully");
else
Assert.AreEqual("", parser.Errors.ErrorOutput);
parsedExpression.AcceptVisitor(new LocationAssignmentCheckVisitor(), null);
Type type = typeof(T);
Assert.IsTrue(type.IsAssignableFrom(parsedExpression.GetType()), String.Format("Parsed expression was {0} instead of {1} ({2})", parsedExpression.GetType(), type, parsedExpression));
return (T)parsedExpression;

Loading…
Cancel
Save