PageRenderTime 49ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/BooCompiler.Tests/SupportingClasses.cs

https://github.com/boo/boo-lang
C# | 569 lines | 456 code | 85 blank | 28 comment | 13 complexity | 0276bf2e8fadf56346155a721b0e4477 MD5 | raw file
Possible License(s): GPL-2.0
  1. #region license
  2. // Copyright (c) 2004, Rodrigo B. de Oliveira (rbo@acm.org)
  3. // All rights reserved.
  4. //
  5. // Redistribution and use in source and binary forms, with or without modification,
  6. // are permitted provided that the following conditions are met:
  7. //
  8. // * Redistributions of source code must retain the above copyright notice,
  9. // this list of conditions and the following disclaimer.
  10. // * Redistributions in binary form must reproduce the above copyright notice,
  11. // this list of conditions and the following disclaimer in the documentation
  12. // and/or other materials provided with the distribution.
  13. // * Neither the name of Rodrigo B. de Oliveira nor the names of its
  14. // contributors may be used to endorse or promote products derived from this
  15. // software without specific prior written permission.
  16. //
  17. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  18. // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  19. // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  20. // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
  21. // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  22. // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  23. // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  24. // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  25. // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  26. // THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27. #endregion
  28. namespace BooCompiler.Tests
  29. {
  30. using System;
  31. public class ObsoleteClass
  32. {
  33. [Obsolete("It is." )]
  34. public static int Bar = 42;
  35. [Obsolete("Indeed it is." )]
  36. public static void Foo()
  37. {
  38. }
  39. [Obsolete("We said so.")]
  40. public static int Baz
  41. {
  42. get { return 42; }
  43. }
  44. }
  45. public class ConditionalClass
  46. {
  47. [System.Diagnostics.Conditional("BOO_COMPILER_TESTS_NOT_DEFINED_CONDITIONAL")]
  48. public static void PrintNothing(int i)
  49. {
  50. Console.WriteLine(i);
  51. }
  52. [System.Diagnostics.Conditional("BOO_COMPILER_TESTS_DEFINED_CONDITIONAL")]
  53. public static void PrintSomething(string s)
  54. {
  55. Console.WriteLine(s);
  56. }
  57. [System.Diagnostics.Conditional("BOO_COMPILER_TESTS_NOT_DEFINED_CONDITIONAL")]
  58. public static void PrintNoT<T>(T s)
  59. {
  60. Console.WriteLine(s);
  61. }
  62. [System.Diagnostics.Conditional("BOO_COMPILER_TESTS_DEFINED_CONDITIONAL")]
  63. public static void PrintSomeT<T>(T s)
  64. {
  65. Console.WriteLine(s);
  66. }
  67. }
  68. public class ReturnDucks
  69. {
  70. public class DuckBase {}
  71. public class DuckFoo : DuckBase
  72. {
  73. public string Foo() { return "foo"; }
  74. }
  75. public class DuckBar : DuckBase
  76. {
  77. public string Bar() { return "bar"; }
  78. }
  79. [Boo.Lang.DuckTypedAttribute]
  80. public DuckBase GetDuck(bool foo)
  81. {
  82. if (foo) return new DuckFoo();
  83. return new DuckBar();
  84. }
  85. }
  86. public struct Point
  87. {
  88. public int x;
  89. public int y;
  90. }
  91. public struct Rectangle
  92. {
  93. Point _top;
  94. public Point topLeft
  95. {
  96. get { return _top; }
  97. set { _top = value; }
  98. }
  99. }
  100. public struct Vector3
  101. {
  102. public float x, y, z;
  103. }
  104. public class Transform
  105. {
  106. Vector3 _position;
  107. public Vector3 position
  108. {
  109. get { return _position; }
  110. set { _position = value; }
  111. }
  112. }
  113. public class BOO313BaseClass
  114. {
  115. Transform _t = new Transform();
  116. public Transform transform
  117. {
  118. get { return _t; }
  119. }
  120. }
  121. public class OutterClass
  122. {
  123. public class InnerClass
  124. {
  125. public static int X = 3;
  126. }
  127. }
  128. public class OverrideBoolOperator
  129. {
  130. public static implicit operator bool(OverrideBoolOperator instance)
  131. {
  132. Console.WriteLine("OverrideBoolOperator.operator bool");
  133. return false;
  134. }
  135. }
  136. public struct ValueTypeOverrideBoolOperator
  137. {
  138. public static implicit operator bool(ValueTypeOverrideBoolOperator instance)
  139. {
  140. Console.WriteLine("ValueTypeOverrideBoolOperator.operator bool");
  141. return false;
  142. }
  143. }
  144. public class ExtendsOverridenBoolOperator : OverrideBoolOperator
  145. {
  146. [Boo.Lang.DuckTypedAttribute]
  147. public ExtendsOverridenBoolOperator GetFoo()
  148. {
  149. return new ExtendsOverridenBoolOperator();
  150. }
  151. }
  152. public class OverrideEqualityOperators
  153. {
  154. public static bool operator==(OverrideEqualityOperators lhs, OverrideEqualityOperators rhs)
  155. {
  156. if (Object.Equals(null, lhs))
  157. {
  158. Console.WriteLine("lhs is null");
  159. }
  160. if (Object.Equals(null, rhs))
  161. {
  162. Console.WriteLine("rhs is null");
  163. }
  164. return true;
  165. }
  166. public static bool operator!=(OverrideEqualityOperators lhs, OverrideEqualityOperators rhs)
  167. {
  168. if (Object.Equals(null, lhs))
  169. {
  170. Console.WriteLine("lhs is null");
  171. }
  172. if (Object.Equals(null, rhs))
  173. {
  174. Console.WriteLine("rhs is null");
  175. }
  176. return false;
  177. }
  178. // Just to remove the warnings; non-functional
  179. public override bool Equals(object obj)
  180. {
  181. throw new NotImplementedException("This override is for testing purposes only.");
  182. }
  183. // Just to remove the warnings; non-functional
  184. public override int GetHashCode()
  185. {
  186. throw new NotImplementedException("This override is for testing purposes only.");
  187. }
  188. }
  189. public class AmbiguousBase
  190. {
  191. public string Path(string empty)
  192. {
  193. return "Base";
  194. }
  195. }
  196. public class AmbiguousSub1 : AmbiguousBase
  197. {
  198. public new string Path
  199. {
  200. get
  201. {
  202. return "Sub1";
  203. }
  204. }
  205. }
  206. public class AmbiguousSub2 : AmbiguousSub1
  207. {
  208. }
  209. [Flags]
  210. public enum TestEnum
  211. {
  212. Foo = 1,
  213. Bar = 2,
  214. Baz = 4
  215. }
  216. public enum ByteEnum : byte
  217. {
  218. Foo = 1,
  219. Bar = 2,
  220. Baz = 4
  221. }
  222. public enum SByteEnum : sbyte
  223. {
  224. Foo = -1,
  225. Bar = -2,
  226. Baz = -4
  227. }
  228. public class Person
  229. {
  230. string _fname;
  231. string _lname;
  232. uint _age;
  233. public Person()
  234. {
  235. }
  236. public uint Age
  237. {
  238. get
  239. {
  240. return _age;
  241. }
  242. set
  243. {
  244. _age = value;
  245. }
  246. }
  247. public string FirstName
  248. {
  249. get
  250. {
  251. return _fname;
  252. }
  253. set
  254. {
  255. _fname = value;
  256. }
  257. }
  258. public string LastName
  259. {
  260. get
  261. {
  262. return _lname;
  263. }
  264. set
  265. {
  266. _lname = value;
  267. }
  268. }
  269. }
  270. public class PersonCollection : System.Collections.CollectionBase
  271. {
  272. public PersonCollection()
  273. {
  274. }
  275. public Person this[int index]
  276. {
  277. get
  278. {
  279. return (Person)InnerList[index];
  280. }
  281. set
  282. {
  283. InnerList[index] = value;
  284. }
  285. }
  286. public Person this[string fname]
  287. {
  288. get
  289. {
  290. foreach (Person p in InnerList)
  291. {
  292. if (p.FirstName == fname)
  293. {
  294. return p;
  295. }
  296. }
  297. return null;
  298. }
  299. set
  300. {
  301. int index = 0;
  302. foreach (Person p in InnerList)
  303. {
  304. if (p.FirstName == fname)
  305. {
  306. InnerList[index] = value;
  307. break;
  308. }
  309. ++index;
  310. }
  311. }
  312. }
  313. public void Add(Person person)
  314. {
  315. InnerList.Add(person);
  316. }
  317. }
  318. public class Clickable
  319. {
  320. public Clickable()
  321. {
  322. }
  323. public event EventHandler Click;
  324. public static event EventHandler Idle;
  325. public void RaiseClick()
  326. {
  327. if (null != Click)
  328. {
  329. Click(this, EventArgs.Empty);
  330. }
  331. }
  332. public static void RaiseIdle()
  333. {
  334. if (null != Idle)
  335. {
  336. Idle(null, EventArgs.Empty);
  337. }
  338. }
  339. }
  340. public class BaseClass
  341. {
  342. protected BaseClass()
  343. {
  344. }
  345. protected BaseClass(string message)
  346. {
  347. Console.WriteLine("BaseClass.constructor('{0}')", message);
  348. }
  349. public virtual void Method0()
  350. {
  351. Console.WriteLine("BaseClass.Method0");
  352. }
  353. public virtual void Method0(string text)
  354. {
  355. Console.WriteLine("BaseClass.Method0('{0}')", text);
  356. }
  357. public virtual void Method1()
  358. {
  359. Console.WriteLine("BaseClass.Method1");
  360. }
  361. //for BOO-632 regression test
  362. protected int _protectedfield = 0;
  363. protected int ProtectedProperty
  364. {
  365. get
  366. {
  367. return _protectedfield;
  368. }
  369. set
  370. {
  371. _protectedfield = value;
  372. }
  373. }
  374. }
  375. public class DerivedClass : BaseClass
  376. {
  377. public DerivedClass()
  378. {
  379. }
  380. public void Method2()
  381. {
  382. Method0();
  383. Method1();
  384. }
  385. }
  386. public class ClassWithNewMethod : DerivedClass
  387. {
  388. new public void Method2()
  389. {
  390. Console.WriteLine("ClassWithNewMethod.Method2");
  391. }
  392. }
  393. public class VarArgs
  394. {
  395. public void Method()
  396. {
  397. Console.WriteLine("VarArgs.Method");
  398. }
  399. public void Method(params object[] args)
  400. {
  401. Console.WriteLine("VarArgs.Method({0})", Boo.Lang.Builtins.join(args, ", "));
  402. }
  403. }
  404. public class Disposable : System.IDisposable
  405. {
  406. public Disposable()
  407. {
  408. Console.WriteLine("Disposable.constructor");
  409. }
  410. public void foo()
  411. {
  412. Console.WriteLine("Disposable.foo");
  413. }
  414. void System.IDisposable.Dispose()
  415. {
  416. Console.WriteLine("Disposable.Dispose");
  417. }
  418. }
  419. public class Constants
  420. {
  421. public const string StringConstant = "Foo";
  422. public const int IntegerConstant = 14;
  423. public const uint UnsignedInt = 255;
  424. public const ulong UnsignedLong = 297;
  425. }
  426. public class ByRef
  427. {
  428. public static void SetValue(int value, ref int output)
  429. {
  430. output = value;
  431. }
  432. public static void SetRef(object value, ref object output)
  433. {
  434. output = value;
  435. }
  436. public static void ReturnValue(int value, out int output)
  437. {
  438. output = value;
  439. }
  440. public static void ReturnRef(object value, out object output)
  441. {
  442. output = value;
  443. }
  444. }
  445. public class PointersBase
  446. {
  447. public void Foo(ref int bar)
  448. {
  449. System.Console.WriteLine("PointersBase.Foo(int&)");
  450. }
  451. public unsafe void Foo(int* bar)
  452. {
  453. System.Console.WriteLine("Pointers.Foo(int*)");
  454. }
  455. }
  456. public class Pointers : PointersBase
  457. {
  458. public new void Foo(ref int bar)
  459. {
  460. System.Console.WriteLine("Pointers.Foo(int&)");
  461. }
  462. }
  463. public class NoParameterlessConstructor
  464. {
  465. public NoParameterlessConstructor(object param)
  466. {
  467. }
  468. }
  469. public abstract class AbstractClass
  470. {
  471. }
  472. public abstract class AnotherAbstractClass
  473. {
  474. protected abstract string Foo();
  475. public virtual string Bar()
  476. {
  477. return "Bar";
  478. }
  479. }
  480. public abstract class AbstractFoo
  481. {
  482. public abstract T Bar<T>(T x);
  483. }
  484. }