Browse Source

Update roundtrip test.

newNRvisualizers
Daniel Grunwald 14 years ago
parent
commit
90c0758bb0
  1. 4
      ICSharpCode.NRefactory.ConsistencyCheck/Program.cs
  2. 2
      ICSharpCode.NRefactory.ConsistencyCheck/ResolverTest.cs
  3. 13
      ICSharpCode.NRefactory.ConsistencyCheck/RoundtripTest.cs
  4. 24
      ICSharpCode.NRefactory.Tests/CSharp/Parser/TypeMembers/MethodDeclarationTests.cs

4
ICSharpCode.NRefactory.ConsistencyCheck/Program.cs

@ -50,8 +50,8 @@ namespace ICSharpCode.NRefactory.ConsistencyCheck
solution.AllFiles.Count(), solution.AllFiles.Count(),
solution.Projects.Count); solution.Projects.Count);
//RunTestOnAllFiles("Roundtripping test", RoundtripTest.RunTest); RunTestOnAllFiles("Roundtripping test", RoundtripTest.RunTest);
RunTestOnAllFiles("Resolver test", ResolverTest.RunTest); //RunTestOnAllFiles("Resolver test", ResolverTest.RunTest);
Console.Write("Press any key to continue . . . "); Console.Write("Press any key to continue . . . ");
Console.ReadKey(true); Console.ReadKey(true);

2
ICSharpCode.NRefactory.ConsistencyCheck/ResolverTest.cs

@ -63,7 +63,7 @@ namespace ICSharpCode.NRefactory.ConsistencyCheck
{ {
if (!nodesWithConversions.Add(expression)) if (!nodesWithConversions.Add(expression))
throw new InvalidOperationException("Duplicate ProcessConversion() call"); throw new InvalidOperationException("Duplicate ProcessConversion() call");
if (conversion == Conversion.None) { if (!conversion.IsValid) {
Console.WriteLine("Compiler error at " + fileName + ":" + expression.StartLocation + ": Cannot convert from " + result + " to " + targetType); Console.WriteLine("Compiler error at " + fileName + ":" + expression.StartLocation + ": Cannot convert from " + result + " to " + targetType);
} }
} }

13
ICSharpCode.NRefactory.ConsistencyCheck/RoundtripTest.cs

@ -17,6 +17,7 @@
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
using System; using System;
using System.Diagnostics;
using System.IO; using System.IO;
using System.Text; using System.Text;
using ICSharpCode.NRefactory.CSharp; using ICSharpCode.NRefactory.CSharp;
@ -33,8 +34,8 @@ namespace ICSharpCode.NRefactory.ConsistencyCheck
{ {
public static void RunTest(CSharpFile file) public static void RunTest(CSharpFile file)
{ {
// TODO: also try Windows-style newlines once the parser bug with integer literals followed by \r is fixed
string code = file.Content.Text.Replace("\r\n", "\n"); string code = file.Content.Text.Replace("\r\n", "\n");
Debug.Assert(code.IndexOf('\r') < 0);
if (code.Contains("#pragma")) if (code.Contains("#pragma"))
return; // skip code with preprocessor directives return; // skip code with preprocessor directives
if (code.Contains("enum VarianceModifier") || file.FileName.EndsWith("ecore.cs") || file.FileName.EndsWith("method.cs")) if (code.Contains("enum VarianceModifier") || file.FileName.EndsWith("ecore.cs") || file.FileName.EndsWith("method.cs"))
@ -43,8 +44,6 @@ namespace ICSharpCode.NRefactory.ConsistencyCheck
return; // skip due to optional , at end of array initializer (see ArrayCreateExpressionTests.ArrayInitializerWithCommaAtEnd) return; // skip due to optional , at end of array initializer (see ArrayCreateExpressionTests.ArrayInitializerWithCommaAtEnd)
if (file.FileName.EndsWith("cs-parser.cs")) if (file.FileName.EndsWith("cs-parser.cs"))
return; // skip due to completely messed up comment locations return; // skip due to completely messed up comment locations
if (file.FileName.EndsWith("PrimitiveExpressionTests.cs"))
return; // skip due to PrimitiveExpressionTests.*WithLeadingDot
if (file.FileName.Contains("FormattingTests") || file.FileName.Contains("ContextAction") || file.FileName.Contains("CodeCompletion")) if (file.FileName.Contains("FormattingTests") || file.FileName.Contains("ContextAction") || file.FileName.Contains("CodeCompletion"))
return; // skip due to AttributeSectionTests.AttributeWithEmptyParenthesis return; // skip due to AttributeSectionTests.AttributeWithEmptyParenthesis
if (file.FileName.EndsWith("TypeSystemTests.TestCase.cs")) if (file.FileName.EndsWith("TypeSystemTests.TestCase.cs"))
@ -53,8 +52,12 @@ namespace ICSharpCode.NRefactory.ConsistencyCheck
return; // skip due to PreprocessorDirectiveTests.NestedInactiveIf return; // skip due to PreprocessorDirectiveTests.NestedInactiveIf
if (file.FileName.EndsWith("property.cs")) if (file.FileName.EndsWith("property.cs"))
return; // skip due to PreprocessorDirectiveTests.CommentOnEndOfIfDirective return; // skip due to PreprocessorDirectiveTests.CommentOnEndOfIfDirective
if (file.FileName.EndsWith("DefaultResolvedTypeDefinition.cs"))
return; // skip due to MethodDeclarationTests.GenericMethodWithMultipleConstraints
Roundtrip(file.Project.CreateParser(), file.FileName, code); Roundtrip(file.Project.CreateParser(), file.FileName, code);
// After trying unix-style newlines, also try windows-style newlines:
Roundtrip(file.Project.CreateParser(), file.FileName, code.Replace("\n", "\r\n"));
} }
public static void Roundtrip(CSharpParser parser, string fileName, string code) public static void Roundtrip(CSharpParser parser, string fileName, string code)
@ -86,6 +89,10 @@ namespace ICSharpCode.NRefactory.ConsistencyCheck
if (pos2 != generatedCode.Length) if (pos2 != generatedCode.Length)
throw new InvalidOperationException("Mismatch at end of file " + fileName); throw new InvalidOperationException("Mismatch at end of file " + fileName);
// 3b - validate that there are no lone \r
if (generatedCode.Replace(w.NewLine, "\n").IndexOf('\r') >= 0)
throw new InvalidOperationException(@"Got lone \r in " + fileName);
// 4. Parse generated output // 4. Parse generated output
CompilationUnit generatedCU; CompilationUnit generatedCU;
try { try {

24
ICSharpCode.NRefactory.Tests/CSharp/Parser/TypeMembers/MethodDeclarationTests.cs

@ -281,6 +281,30 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.TypeMembers
}); });
} }
[Test, Ignore("Parser bug: constraints added in wrong order")]
public void GenericMethodWithMultipleConstraints()
{
ParseUtilCSharp.AssertTypeMember(
"void MyMethod<A, B>() where A : IA where B : IB {} ",
new MethodDeclaration {
ReturnType = new PrimitiveType("void"),
Name = "MyMethod",
TypeParameters = {
new TypeParameterDeclaration { Name = "A" },
new TypeParameterDeclaration { Name = "B" }
},
Constraints = {
new Constraint {
TypeParameter = new SimpleType("A"),
BaseTypes = { new SimpleType("IA") }
},
new Constraint {
TypeParameter = new SimpleType("B"),
BaseTypes = { new SimpleType("IB") }
}
}});
}
[Test] [Test]
public void IncompleteConstraintsTest() public void IncompleteConstraintsTest()
{ {

Loading…
Cancel
Save