2 // Copyright (c) 2004, Rodrigo B. de Oliveira (rbo@acm.org)
3 // All rights reserved.
5 // Redistribution and use in source and binary forms, with or without modification,
6 // are permitted provided that the following conditions are met:
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.
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.
29 namespace BooCompiler
.Tests
33 public class ObsoleteClass
36 public static int Bar
= 42;
38 [Obsolete("Indeed it is." )]
39 public static void Foo()
43 [Obsolete("We said so.")]
50 public class ConditionalClass
52 [System
.Diagnostics
.Conditional("BOO_COMPILER_TESTS_NOT_DEFINED_CONDITIONAL")]
53 public static void PrintNothing(int i
)
58 [System
.Diagnostics
.Conditional("BOO_COMPILER_TESTS_DEFINED_CONDITIONAL")]
59 public static void PrintSomething(string s
)
64 [System
.Diagnostics
.Conditional("BOO_COMPILER_TESTS_NOT_DEFINED_CONDITIONAL")]
65 public static void PrintNoT
<T
>(T s
)
70 [System
.Diagnostics
.Conditional("BOO_COMPILER_TESTS_DEFINED_CONDITIONAL")]
71 public static void PrintSomeT
<T
>(T s
)
77 public class ReturnDucks
79 public class DuckBase
{}
81 public class DuckFoo
: DuckBase
83 public string Foo() { return "foo"; }
86 public class DuckBar
: DuckBase
88 public string Bar() { return "bar"; }
91 [Boo
.Lang
.DuckTypedAttribute
]
92 public DuckBase
GetDuck(bool foo
)
94 if (foo
) return new DuckFoo();
105 public struct Rectangle
111 set { _top = value; }
115 public struct Vector3
117 public float x
, y
, z
;
120 public class Transform
124 public Vector3 position
126 get { return _position; }
127 set { _position = value; }
131 public class BOO313BaseClass
133 Transform _t
= new Transform();
134 public Transform transform
140 public class OutterClass
142 public class InnerClass
144 public static int X
= 3;
148 public class OverrideBoolOperator
150 public static implicit operator bool(OverrideBoolOperator instance
)
152 Console
.WriteLine("OverrideBoolOperator.operator bool");
157 public struct ValueTypeOverrideBoolOperator
159 public static implicit operator bool(ValueTypeOverrideBoolOperator instance
)
161 Console
.WriteLine("ValueTypeOverrideBoolOperator.operator bool");
166 public class ExtendsOverridenBoolOperator
: OverrideBoolOperator
168 [Boo
.Lang
.DuckTypedAttribute
]
169 public ExtendsOverridenBoolOperator
GetFoo()
171 return new ExtendsOverridenBoolOperator();
175 public class OverrideEqualityOperators
177 public static bool operator==(OverrideEqualityOperators lhs
, OverrideEqualityOperators rhs
)
179 if (Object
.Equals(null, lhs
))
181 Console
.WriteLine("lhs is null");
184 if (Object
.Equals(null, rhs
))
186 Console
.WriteLine("rhs is null");
191 public static bool operator!=(OverrideEqualityOperators lhs
, OverrideEqualityOperators rhs
)
193 if (Object
.Equals(null, lhs
))
195 Console
.WriteLine("lhs is null");
198 if (Object
.Equals(null, rhs
))
200 Console
.WriteLine("rhs is null");
205 // Just to remove the warnings; non-functional
206 public override bool Equals(object obj
)
208 throw new NotImplementedException("This override is for testing purposes only.");
211 // Just to remove the warnings; non-functional
212 public override int GetHashCode()
214 throw new NotImplementedException("This override is for testing purposes only.");
218 public class AmbiguousBase
220 public string Path(string empty
)
226 public class AmbiguousSub1
: AmbiguousBase
228 public new string Path
237 public class AmbiguousSub2
: AmbiguousSub1
249 public enum ByteEnum
: byte
256 public enum SByteEnum
: sbyte
286 public string FirstName
299 public string LastName
313 public class PersonCollection
: System
.Collections
.CollectionBase
315 public PersonCollection()
319 public Person
this[int index
]
323 return (Person
)InnerList
[index
];
328 InnerList
[index
] = value;
332 public Person
this[string fname
]
336 foreach (Person p
in InnerList
)
338 if (p
.FirstName
== fname
)
349 foreach (Person p
in InnerList
)
351 if (p
.FirstName
== fname
)
353 InnerList
[index
] = value;
361 public void Add(Person person
)
363 InnerList
.Add(person
);
367 public class Clickable
373 public event EventHandler Click
;
375 public static event EventHandler Idle
;
377 public void RaiseClick()
381 Click(this, EventArgs
.Empty
);
385 public static void RaiseIdle()
389 Idle(null, EventArgs
.Empty
);
394 public class BaseClass
396 protected BaseClass()
400 protected BaseClass(string message
)
402 Console
.WriteLine("BaseClass.constructor('{0}')", message
);
405 public virtual void Method0()
407 Console
.WriteLine("BaseClass.Method0");
410 public virtual void Method0(string text
)
412 Console
.WriteLine("BaseClass.Method0('{0}')", text
);
415 public virtual void Method1()
417 Console
.WriteLine("BaseClass.Method1");
420 //for BOO-632 regression test
421 protected int _protectedfield
= 0;
422 protected int ProtectedProperty
426 return _protectedfield
;
431 _protectedfield
= value;
436 public class DerivedClass
: BaseClass
438 public DerivedClass()
442 public void Method2()
449 public class ClassWithNewMethod
: DerivedClass
451 new public void Method2()
453 Console
.WriteLine("ClassWithNewMethod.Method2");
461 Console
.WriteLine("VarArgs.Method");
464 public void Method(params object[] args
)
466 Console
.WriteLine("VarArgs.Method({0})", Boo
.Lang
.Builtins
.join(args
, ", "));
470 public class Disposable
: System
.IDisposable
474 Console
.WriteLine("Disposable.constructor");
479 Console
.WriteLine("Disposable.foo");
482 void System
.IDisposable
.Dispose()
484 Console
.WriteLine("Disposable.Dispose");
488 public class Constants
490 public const string StringConstant
= "Foo";
492 public const int IntegerConstant
= 14;
494 public const uint UnsignedInt
= 255;
496 public const ulong UnsignedLong
= 297;
501 public static void SetValue(int value, ref int output
)
506 public static void SetRef(object value, ref object output
)
511 public static void ReturnValue(int value, out int output
)
516 public static void ReturnRef(object value, out object output
)
522 public class PointersBase
524 public void Foo(ref int bar
)
526 System
.Console
.WriteLine("PointersBase.Foo(int&)");
529 public unsafe void Foo(int* bar
)
531 System
.Console
.WriteLine("Pointers.Foo(int*)");
535 public class Pointers
: PointersBase
537 public new void Foo(ref int bar
)
539 System
.Console
.WriteLine("Pointers.Foo(int&)");
543 public class NoParameterlessConstructor
545 public NoParameterlessConstructor(object param
)
550 public abstract class AbstractClass
554 public abstract class AnotherAbstractClass
556 protected abstract string Foo();
558 public virtual string Bar()