PageRenderTime 61ms CodeModel.GetById 34ms RepoModel.GetById 1ms app.codeStats 0ms

/vim/bundle/YouCompleteMe/third_party/ycmd/third_party/OmniSharpServer/NRefactory/ICSharpCode.NRefactory.Tests/CSharp/CodeCompletion/CodeCompletionCSharp3Tests.cs

https://bitbucket.org/tetonedge/linux
C# | 474 lines | 393 code | 17 blank | 64 comment | 6 complexity | 05fc1bafd4c0cf7134478d917614efd6 MD5 | raw file
Possible License(s): Apache-2.0, BSD-3-Clause, CC-BY-SA-3.0, MIT, WTFPL
  1. //
  2. // CodeCompletionCSharp3Tests.cs
  3. //
  4. // Author:
  5. // Mike Krüger <mkrueger@novell.com>
  6. //
  7. // Copyright (C) 2008 Novell, Inc (http://www.novell.com)
  8. //
  9. // Permission is hereby granted, free of charge, to any person obtaining
  10. // a copy of this software and associated documentation files (the
  11. // "Software"), to deal in the Software without restriction, including
  12. // without limitation the rights to use, copy, modify, merge, publish,
  13. // distribute, sublicense, and/or sell copies of the Software, and to
  14. // permit persons to whom the Software is furnished to do so, subject to
  15. // the following conditions:
  16. //
  17. // The above copyright notice and this permission notice shall be
  18. // included in all copies or substantial portions of the Software.
  19. //
  20. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  21. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  22. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  23. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  24. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  25. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  26. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  27. //
  28. using System;
  29. using NUnit.Framework;
  30. namespace ICSharpCode.NRefactory.CSharp.CodeCompletion
  31. {
  32. [TestFixture()]
  33. public class CodeCompletionCSharp3Tests
  34. {
  35. /* Currently fails but works in monodevelop. Seems to be a bug in the unit test somewhere.
  36. [Test()]
  37. public void TestExtensionMethods ()
  38. {
  39. CompletionDataList provider = CodeCompletionBugTests.CreateProvider (
  40. @"using System;
  41. public static class EMClass
  42. {
  43. public static int ToInt32Ext (this Program s)
  44. {
  45. return Int32.Parse (s);
  46. }
  47. }
  48. class Program
  49. {
  50. static void Main (string[] args)
  51. {
  52. Program s;
  53. int i = s.$
  54. }
  55. }
  56. ");
  57. Assert.IsNotNull (provider, "provider == null");
  58. Assert.IsNotNull (provider.Find ("ToInt32Ext"), "extension method 'ToInt32Ext' not found.");
  59. }
  60. */
  61. [Test()]
  62. public void TestVarLocalVariables ()
  63. {
  64. CompletionDataList provider = CodeCompletionBugTests.CreateProvider (
  65. @"using System;
  66. class Test
  67. {
  68. public void TestMethod ()
  69. {
  70. }
  71. }
  72. class Program
  73. {
  74. static void Main (string[] args)
  75. {
  76. var t = new Test ();
  77. $t.$
  78. }
  79. }
  80. ");
  81. Assert.IsNotNull (provider, "provider == null");
  82. Assert.IsNotNull (provider.Find ("TestMethod"), "method 'TestMethod' not found.");
  83. }
  84. [Test()]
  85. public void TestVarLoopVariable ()
  86. {
  87. CompletionDataList provider = CodeCompletionBugTests.CreateProvider (
  88. @"using System;
  89. class Test
  90. {
  91. public void TestMethod ()
  92. {
  93. }
  94. }
  95. class Program
  96. {
  97. static void Main (string[] args)
  98. {
  99. var t = new Test[] {};
  100. foreach (var loopVar in t) {
  101. $loopVar.$
  102. }
  103. }
  104. }
  105. ");
  106. Assert.IsNotNull (provider, "provider == null");
  107. Assert.IsNotNull (provider.Find ("TestMethod"), "method 'TestMethod' not found.");
  108. }
  109. [Test()]
  110. public void TestAnonymousType ()
  111. {
  112. CompletionDataList provider = CodeCompletionBugTests.CreateProvider (
  113. @"
  114. class Program
  115. {
  116. static void Main (string[] args)
  117. {
  118. var t = new { TestInt = 6, TestChar='e', TestString =""Test""};
  119. $t.$
  120. }
  121. }
  122. ");
  123. Assert.IsNotNull (provider, "provider == null");
  124. Assert.IsNotNull (provider.Find ("TestInt"), "property 'TestInt' not found.");
  125. Assert.IsNotNull (provider.Find ("TestChar"), "property 'TestChar' not found.");
  126. Assert.IsNotNull (provider.Find ("TestString"), "property 'TestString' not found.");
  127. }
  128. [Test()]
  129. public void TestQueryExpression ()
  130. {
  131. CompletionDataList provider = CodeCompletionBugTests.CreateProvider (
  132. @"
  133. using System;
  134. using System.Collections.Generic;
  135. static class Linq
  136. {
  137. public static IEnumerable<T> Select<S, T> (this IEnumerable<S> collection, Func<S, T> func)
  138. {
  139. }
  140. }
  141. class Program
  142. {
  143. public void TestMethod ()
  144. {
  145. }
  146. static void Main (string[] args)
  147. {
  148. Program[] numbers;
  149. foreach (var x in from n in numbers select n) {
  150. $x.$
  151. }
  152. }
  153. }
  154. ");
  155. Assert.IsNotNull (provider, "provider == null");
  156. Assert.IsNotNull (provider.Find ("TestMethod"), "method 'TestMethod' not found.");
  157. }
  158. [Test()]
  159. public void TestLambdaExpressionCase1 ()
  160. {
  161. CompletionDataList provider = CodeCompletionBugTests.CreateCtrlSpaceProvider (
  162. @"
  163. using System;
  164. class Test
  165. {
  166. public void Foo ()
  167. {
  168. $Func<Test,int> x = s => s.$
  169. }
  170. }
  171. ");
  172. Assert.IsNotNull (provider, "provider == null");
  173. Assert.IsNotNull (provider.Find ("Foo"), "method 'Foo' not found.");
  174. }
  175. [Test()]
  176. public void TestLambdaExpressionCase2 ()
  177. {
  178. CompletionDataList provider = CodeCompletionBugTests.CreateProvider (
  179. @"
  180. namespace System {
  181. public class Array {
  182. public Test this[int i] {
  183. get {
  184. }
  185. set {
  186. }
  187. }
  188. }
  189. }
  190. static class ExtMethods
  191. {
  192. public static T Where<T>(this T[] t, Func<T, bool> pred)
  193. {
  194. return t;
  195. }
  196. }
  197. class Test
  198. {
  199. public void TestMethod ()
  200. {
  201. Test[] en = new Test[0];
  202. var x = en.Where (t => t != null);
  203. $x.$
  204. }
  205. }
  206. ");
  207. Assert.IsNotNull (provider, "provider == null");
  208. Assert.IsNotNull (provider.Find ("TestMethod"), "method 'TestMethod' not found.");
  209. }
  210. /// <summary>
  211. /// Bug 487237 - Broken lambda intellisense
  212. /// </summary>
  213. [Test()]
  214. public void TestBug487237 ()
  215. {
  216. CompletionDataList provider = CodeCompletionBugTests.CreateProvider (
  217. @"
  218. public interface IHelper
  219. {
  220. void DoIt ();
  221. }
  222. public class Program
  223. {
  224. delegate T MyDelegate <T> (T t);
  225. static int Main ()
  226. {
  227. $MyDelegate<IHelper> e = helper => helper.$
  228. return 0;
  229. }
  230. }
  231. ");
  232. Assert.IsNotNull (provider, "provider == null");
  233. Assert.IsNotNull (provider.Find ("DoIt"), "method 'DoIt' not found.");
  234. }
  235. /// <summary>
  236. /// Bug 491016 - No intellisense for lambdas inside linq query
  237. /// </summary>
  238. [Test()]
  239. public void TestBug491016 ()
  240. {
  241. CompletionDataList provider = CodeCompletionBugTests.CreateProvider (
  242. @"
  243. using System;
  244. using System.Collections.Generic;
  245. namespace System.Collections.Generic {
  246. public interface IEnumerable<T>
  247. {
  248. }
  249. }
  250. namespace Foo
  251. {
  252. class Data
  253. {
  254. public int Value = 5;
  255. }
  256. static class Ex
  257. {
  258. public static System.Collections.Generic.IEnumerable<TR> Foo<T, TR> (this System.Collections.Generic.IEnumerable<T> t, Func<T, TR> f)
  259. {
  260. yield return f (t.First ());
  261. }
  262. }
  263. public class C
  264. {
  265. public static void Main ()
  266. {
  267. System.Collections.Generic.IEnumerable<Data> i = new Data [0];
  268. $var prods = from pe in i.Foo (p2 => p2.$
  269. }
  270. }
  271. }
  272. ");
  273. Assert.IsNotNull (provider, "provider == null");
  274. Assert.IsNotNull (provider.Find ("Value"), "field 'Value' not found.");
  275. }
  276. /// <summary>
  277. /// Bug 491017 - No intellisense for static LINQ queries
  278. /// </summary>
  279. [Test()]
  280. public void TestBug491017 ()
  281. {
  282. CompletionDataList provider = CodeCompletionBugTests.CreateProvider (
  283. @"
  284. using System.Linq;
  285. using System.Linq.Expressions;
  286. class Test
  287. {
  288. $object e = from entity in ""olololcolc"" select entity.$
  289. }
  290. ");
  291. Assert.IsNotNull (provider, "provider == null");
  292. Assert.IsNotNull (provider.Find ("ToString"), "method 'ToString' not found.");
  293. Assert.IsNull (provider.Find ("Length"), "property 'Length' found, but shouldn't (indicates wrong return type).");
  294. }
  295. [Test()]
  296. public void TestDefaultParameterBug ()
  297. {
  298. CompletionDataList provider = CodeCompletionBugTests.CreateProvider (
  299. @"
  300. namespace Foo
  301. {
  302. class Data
  303. {
  304. public int Value = 5;
  305. }
  306. public class C
  307. {
  308. public void Foo (bool aBool = false)
  309. {
  310. Data data;
  311. $data.$
  312. }
  313. }
  314. }
  315. ");
  316. Assert.IsNotNull (provider, "provider == null");
  317. Assert.IsNotNull (provider.Find ("Value"), "field 'Value' not found.");
  318. }
  319. [Test()]
  320. public void TestLinqWhere() {
  321. CompletionDataList provider = CodeCompletionBugTests.CreateProvider(
  322. @"
  323. using System.Collections.Generic;
  324. using System.Linq;
  325. class A
  326. {
  327. public static void Method1()
  328. {
  329. int[] enumerable = new int[]{1,2,3};
  330. $IEnumerable<int> q = from i in enumerable where i.$
  331. }
  332. }
  333. ");
  334. Assert.IsNotNull(provider); // <--- here 0 item in the completion list
  335. Assert.IsNotNull(provider.Find("ToString"));
  336. }
  337. [Test()]
  338. public void TestLinqSelectContext ()
  339. {
  340. var provider = CodeCompletionBugTests.CreateProvider(
  341. @"
  342. using System.Collections.Generic;
  343. using System.Linq;
  344. class A
  345. {
  346. public static void Main (string[] args)
  347. {
  348. $from a in args select n$
  349. }
  350. }
  351. ");
  352. Assert.IsNotNull(provider); // <--- here 0 item in the completion list
  353. Assert.IsNotNull(provider.Find("new"), "'new' not found");
  354. Assert.IsNotNull(provider.Find("args"), "'args' not found");
  355. Assert.IsNotNull(provider.Find("a"), "'a' not found");
  356. }
  357. [Test()]
  358. public void TestLinqAnonymousTypeContext ()
  359. {
  360. var provider = CodeCompletionBugTests.CreateProvider(
  361. @"
  362. using System.Collections.Generic;
  363. using System.Linq;
  364. class A
  365. {
  366. public static void Main (string[] args)
  367. {
  368. Test($from a in args select new { t$);
  369. }
  370. }
  371. ");
  372. Assert.IsNotNull(provider);
  373. Assert.IsFalse (provider.AutoSelect );
  374. }
  375. [Test()]
  376. public void TestLinqAnonymousTypeContextCase2 ()
  377. {
  378. var provider = CodeCompletionBugTests.CreateProvider(
  379. @"
  380. using System.Collections.Generic;
  381. using System.Linq;
  382. class A
  383. {
  384. public static void Main (string[] args)
  385. {
  386. $from a in args select new { test = a$
  387. }
  388. }
  389. ");
  390. Assert.IsNotNull(provider); // <--- here 0 item in the completion list
  391. Assert.IsTrue (provider.AutoSelect );
  392. Assert.IsNotNull(provider.Find("a"), "'a' not found");
  393. Assert.IsNotNull(provider.Find("new"), "'new' not found");
  394. Assert.IsNotNull(provider.Find("args"), "'args' not found");
  395. }
  396. [Test()]
  397. public void TestLinqAnonymousTypeContextCase3 ()
  398. {
  399. var provider = CodeCompletionBugTests.CreateProvider(
  400. @"
  401. using System.Collections.Generic;
  402. using System.Linq;
  403. class A
  404. {
  405. public static void Main (string[] args)
  406. {
  407. $from a in args select new { test = a }$
  408. }
  409. }
  410. ");
  411. Assert.IsTrue(provider == null || provider.Count == 0); // <--- here 0 item in the completion list
  412. }
  413. [Test()]
  414. public void TestLinqExpressionContext ()
  415. {
  416. var provider = CodeCompletionBugTests.CreateProvider(
  417. @"
  418. using System.Collections.Generic;
  419. using System.Linq;
  420. class A
  421. {
  422. public static void Main (string[] args)
  423. {
  424. $from a in args where a !$
  425. }
  426. }
  427. ");
  428. Assert.IsTrue(provider == null || provider.Count == 0); // <--- here 0 item in the completion list
  429. }
  430. }
  431. }