Main.hx 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. @:nativeGen
  2. class Main {
  3. static var voidResult:String;
  4. static function testVoid(a:Int, b:String = 'hello', ?c:String):Void {
  5. voidResult = '$a $b $c';
  6. }
  7. static function test(a:Int, b:String = 'hello', ?c:String):String {
  8. return '$a $b $c';
  9. }
  10. public static function main() {
  11. untyped __cs__('global::Main.testVoid(1, "foo")');
  12. var expected = '1 foo null';
  13. if(voidResult != expected) {
  14. throw 'Invalid result of testVoid(1, "foo"). Expected: $expected. Got: $voidResult';
  15. }
  16. untyped __cs__('global::Main.testVoid(2)');
  17. var expected = '2 hello null';
  18. if(voidResult != expected) {
  19. throw 'Invalid result of testVoid(2). Expected: $expected. Got: $voidResult';
  20. }
  21. var expected = '3 bar null';
  22. var result = untyped __cs__('global::Main.test(3, "bar")');
  23. if(expected != result) {
  24. throw 'Invalid result of test(3, "bar"). Expected: $expected. Got: $result';
  25. }
  26. var expected = '4 hello null';
  27. var result = untyped __cs__('global::Main.test(4)');
  28. if(expected != result) {
  29. throw 'Invalid result of test(4). Expected: $expected. Got: $result';
  30. }
  31. var n:CtorTest = untyped __cs__('new global::CtorTest(20);') ;
  32. if(n.a != 20 || n.b != 'hello') {
  33. throw 'Invalid result of new CtorTest(20)';
  34. }
  35. var n:CtorTest = untyped __cs__('new global::CtorTest();') ;
  36. if(n.a != 10 || n.b != 'hello') {
  37. throw 'Invalid result of new CtorTest()';
  38. }
  39. }
  40. }
  41. @:nativeGen
  42. class CtorTest {
  43. public var a:Int;
  44. public var b:String;
  45. public function new(a:Int = 10, b:String = 'hello') {
  46. this.a = a;
  47. this.b = b;
  48. }
  49. }