Skip to content
This repository
Browse code

Added some unit tests.

  • Loading branch information...
commit 7bf1b4a850aff4be5cc7fa45b95405dbae716f75 1 parent d9113f3
Mike Krüger mkrueger authored
91 ICSharpCode.NRefactory.Tests/CSharp/CodeCompletion/ObjectInitializerTests.cs
@@ -475,8 +475,97 @@ public void Test ()
475 475 }
476 476 ", provider => {
477 477 Assert.IsNotNull(provider.Find("List<string>"), "class 'List<string>' not found.");
478   - });
  478 + }
  479 + );
  480 + }
  481 +
  482 + [Ignore ()]
  483 + [Test()]
  484 + public void TestArrayInitializerObjectCreationNarrowing()
  485 + {
  486 + CodeCompletionBugTests.CombinedProviderTest(
  487 +@"using System;
  488 +using System.Collections.Generic;
  489 +class MyList : List<IEnumerable<string>> {}
  490 +class MyTest
  491 +{
  492 + public void Test ()
  493 + {
  494 + $new MyList { new L$
  495 + }
  496 +}
  497 +", provider => {
  498 + Assert.IsNotNull(provider.Find("List<string>"), "class 'List<string>' not found.");
  499 + }
  500 + );
479 501 }
  502 +
  503 + [Ignore ()]
  504 + [Test()]
  505 + public void TestObjectCreationEnumerable()
  506 + {
  507 + CodeCompletionBugTests.CombinedProviderTest(
  508 +@"using System;
  509 +using System.Collections.Generic;
  510 +class MyList : List<IEnumerable<string>> { public bool MyProp {get;set; } }
  511 +class MyTest
  512 +{
  513 + public void Test ()
  514 + {
  515 + $new MyList { n$
480 516 }
481 517 }
  518 +", provider => {
  519 + Assert.IsNotNull(provider.Find("new"), "'new' not found.");
  520 + Assert.IsNotNull(provider.Find("MyProp"), "'MyProp' not found.");
  521 + }
  522 + );
  523 + }
  524 +
  525 + [Ignore ()]
  526 + [Test()]
  527 + public void TestObjectCreationForbiddenInArrayInitializers()
  528 + {
  529 + CodeCompletionBugTests.CombinedProviderTest(
  530 +@"using System;
  531 +using System.Collections.Generic;
  532 +class MyList : List<IEnumerable<string>> { public bool MyProp {get;set; } }
  533 +class MyTest
  534 +{
  535 + public void Test ()
  536 + {
  537 + $new MyList { new List<string> (), n$
  538 + }
  539 +}
  540 +", provider => {
  541 + Assert.IsNotNull(provider.Find("new"), "'new' not found.");
  542 + Assert.IsNull(provider.Find("MyProp"), "'MyProp' found.");
  543 + }
  544 + );
  545 + }
  546 +
  547 + [Ignore ()]
  548 + [Test()]
  549 + public void TestArrayInitializersForbiddenInObjectCreation()
  550 + {
  551 + CodeCompletionBugTests.CombinedProviderTest(
  552 +@"using System;
  553 +using System.Collections.Generic;
  554 +class MyList : List<IEnumerable<string>> { public bool MyProp {get;set; } public bool MyProp2 {get;set; } }
  555 +class MyTest
  556 +{
  557 + public void Test ()
  558 + {
  559 + $new MyList { MyProp = true, n$
  560 + }
  561 +}
  562 +", provider => {
  563 + Assert.IsNull(provider.Find("new"), "'new' found.");
  564 + Assert.IsNotNull(provider.Find("MyProp2"), "'MyProp2' not found.");
  565 + }
  566 + );
  567 + }
  568 + }
  569 +
  570 +}
482 571
30 ICSharpCode.NRefactory.Tests/CSharp/Parser/Bugs/ParserBugTests.cs
@@ -317,6 +317,36 @@ void Foo ()
317 317 }
318 318 Assert.IsTrue(passed);
319 319 }
  320 +
  321 + /// <summary>
  322 + /// Bug 4556 - AST broken for unclosed invocation
  323 + /// </summary>
  324 + [Ignore ()]
  325 + [Test]
  326 + public void TestBug4556()
  327 + {
  328 + string code =
  329 +@"using System;
  330 +
  331 +class Foo
  332 +{
  333 + public static void Main (string[] args)
  334 + {
  335 + Console.WriteLine (""foo"",
  336 + }
  337 +}
  338 +";
  339 + var unit = CompilationUnit.Parse(code);
  340 +
  341 + var type = unit.Members.First() as TypeDeclaration;
  342 + var method = type.Members.First() as MethodDeclaration;
  343 + bool passed = !method.Body.IsNull;
  344 + if (!passed) {
  345 + Console.WriteLine("Expected:" + code);
  346 + Console.WriteLine("Was:" + unit.GetText());
  347 + }
  348 + Assert.IsTrue(passed);
  349 + }
320 350
321 351 }
322 352 }

0 comments on commit 7bf1b4a

Please sign in to comment.
Something went wrong with that request. Please try again.