PageRenderTime 45ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/vim/bundle/YouCompleteMe/third_party/ycmd/third_party/OmniSharpServer/NRefactory/ICSharpCode.NRefactory.Tests/CSharp/CodeIssues/RedundantEnumerableCastCallIssueTests.cs

https://bitbucket.org/tetonedge/linux
C# | 197 lines | 162 code | 10 blank | 25 comment | 0 complexity | ce6bff9ab8dd4d1729e9ca7be7556ef2 MD5 | raw file
Possible License(s): Apache-2.0, BSD-3-Clause, CC-BY-SA-3.0, MIT, WTFPL
  1. //
  2. // RedundantEnumerableCastCallIssueTests.cs
  3. //
  4. // Author:
  5. // Mike Krüger <mkrueger@xamarin.com>
  6. //
  7. // Copyright (c) 2013 Xamarin Inc. (http://xamarin.com)
  8. //
  9. // Permission is hereby granted, free of charge, to any person obtaining a copy
  10. // of this software and associated documentation files (the "Software"), to deal
  11. // in the Software without restriction, including without limitation the rights
  12. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  13. // copies of the Software, and to permit persons to whom the Software is
  14. // furnished to do so, subject to the following conditions:
  15. //
  16. // The above copyright notice and this permission notice shall be included in
  17. // all copies or substantial portions of the Software.
  18. //
  19. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  20. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  21. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  22. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  23. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  24. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  25. // THE SOFTWARE.
  26. using System;
  27. using NUnit.Framework;
  28. using ICSharpCode.NRefactory.CSharp.Refactoring;
  29. using ICSharpCode.NRefactory.CSharp.CodeActions;
  30. namespace ICSharpCode.NRefactory.CSharp.CodeIssues
  31. {
  32. [TestFixture]
  33. public class RedundantEnumerableCastCallIssueTests : InspectionActionTestBase
  34. {
  35. [Test]
  36. public void TestRedundantCast()
  37. {
  38. Test<RedundantEnumerableCastCallIssue>(@"
  39. using System;
  40. using System.Linq;
  41. using System.Collections.Generic;
  42. class Test
  43. {
  44. static void Main (IEnumerable<string> args)
  45. {
  46. var a = args.Cast<string> ();
  47. }
  48. }
  49. ", @"
  50. using System;
  51. using System.Linq;
  52. using System.Collections.Generic;
  53. class Test
  54. {
  55. static void Main (IEnumerable<string> args)
  56. {
  57. var a = args;
  58. }
  59. }
  60. ");
  61. }
  62. [Test]
  63. public void TestRedundantCastCase2()
  64. {
  65. Test<RedundantEnumerableCastCallIssue>(@"
  66. using System;
  67. using System.Linq;
  68. using System.Collections.Generic;
  69. class Test
  70. {
  71. static void Main (string[] args)
  72. {
  73. var a = args.Cast<string> ();
  74. }
  75. }
  76. ", @"
  77. using System;
  78. using System.Linq;
  79. using System.Collections.Generic;
  80. class Test
  81. {
  82. static void Main (string[] args)
  83. {
  84. var a = args;
  85. }
  86. }
  87. ");
  88. }
  89. [Test]
  90. public void TestRedundantOfType()
  91. {
  92. Test<RedundantEnumerableCastCallIssue>(@"
  93. using System;
  94. using System.Linq;
  95. using System.Collections.Generic;
  96. class Test
  97. {
  98. static void Main (IEnumerable<string> args)
  99. {
  100. var a = args.OfType<string> ();
  101. }
  102. }
  103. ", @"
  104. using System;
  105. using System.Linq;
  106. using System.Collections.Generic;
  107. class Test
  108. {
  109. static void Main (IEnumerable<string> args)
  110. {
  111. var a = args.Where (i => i != null);
  112. }
  113. }
  114. ");
  115. }
  116. [Test]
  117. public void TestRedundantOfTypeResolution2()
  118. {
  119. Test<RedundantEnumerableCastCallIssue>(@"
  120. using System;
  121. using System.Linq;
  122. using System.Collections.Generic;
  123. class Test
  124. {
  125. static void Main (IEnumerable<string> args)
  126. {
  127. var a = args.OfType<string> ();
  128. }
  129. }
  130. ", @"
  131. using System;
  132. using System.Linq;
  133. using System.Collections.Generic;
  134. class Test
  135. {
  136. static void Main (IEnumerable<string> args)
  137. {
  138. var a = args;
  139. }
  140. }
  141. ", 1);
  142. }
  143. [Test]
  144. public void TestInvalid()
  145. {
  146. TestWrongContext<RedundantEnumerableCastCallIssue>(@"
  147. using System;
  148. using System.Linq;
  149. using System.Collections.Generic;
  150. class Test
  151. {
  152. static void Main (IEnumerable<string> args)
  153. {
  154. var a = args.Cast<object> ();
  155. }
  156. }
  157. ");
  158. }
  159. [Test]
  160. public void TestDisable()
  161. {
  162. TestWrongContext<RedundantEnumerableCastCallIssue>(@"
  163. using System;
  164. using System.Linq;
  165. using System.Collections.Generic;
  166. class Test
  167. {
  168. static void Main (IEnumerable<string> args)
  169. {
  170. // ReSharper disable once RedundantEnumerableCastCall
  171. var a = args.Cast<string> ();
  172. }
  173. }
  174. ");
  175. }
  176. }
  177. }