-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[php] Add missing runmes for overload_* testcases
- Loading branch information
Showing
9 changed files
with
363 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
require "tests.php"; | ||
|
||
# Overloading bool, int, string | ||
check::equal(overloaded(true), "bool", "wrong!"); | ||
check::equal(overloaded(false), "bool", "wrong!"); | ||
|
||
check::equal(overloaded(0), "int", "wrong!"); | ||
check::equal(overloaded(1), "int", "wrong!"); | ||
check::equal(overloaded(2), "int", "wrong!"); | ||
|
||
check::equal(overloaded("1234"), "string", "wrong!"); | ||
|
||
# Test bool masquerading as int | ||
check::equal(intfunction(true), "int", "wrong!"); | ||
check::equal(intfunction(false), "int", "wrong!"); | ||
|
||
# Test int masquerading as bool | ||
check::equal(boolfunction(1), "true", "wrong!"); | ||
check::equal(boolfunction(0), "false", "wrong!"); | ||
|
||
############################################# | ||
|
||
# Overloading bool, int, string | ||
check::equal(overloaded_ref(true), "bool", "wrong!"); | ||
check::equal(overloaded_ref(false), "bool", "wrong!"); | ||
|
||
check::equal(overloaded_ref(0), "int", "wrong!"); | ||
check::equal(overloaded_ref(1), "int", "wrong!"); | ||
check::equal(overloaded_ref(2), "int", "wrong!"); | ||
|
||
check::equal(overloaded_ref("1234"), "string", "wrong!"); | ||
|
||
# Test bool masquerading as int | ||
check::equal(intfunction_ref(true), "int", "wrong!"); | ||
check::equal(intfunction_ref(false), "int", "wrong!"); | ||
|
||
# Test int masquerading as bool | ||
check::equal(boolfunction(1), "true", "wrong!"); | ||
check::equal(boolfunction(0), "false", "wrong!"); | ||
|
||
check::done(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
require "tests.php"; | ||
|
||
$pInt = NULL; | ||
|
||
# Check the correct constructors are available | ||
$p = new Pop($pInt); | ||
|
||
$p = new Pop($pInt, false); | ||
|
||
# Check overloaded in const only and pointers/references which target | ||
# languages cannot disambiguate | ||
check::equal($p->hip(false), 701, "Test 1 failed"); | ||
|
||
check::equal($p->hip($pInt), 702, "Test 2 failed"); | ||
|
||
# Reverse the order for the above | ||
check::equal($p->hop($pInt), 805, "Test 3 failed"); | ||
|
||
check::equal($p->hop(false), 801, "Test 4 failed"); | ||
|
||
# Few more variations and order shuffled | ||
check::equal($p->pop(false), 901, "Test 5 failed"); | ||
|
||
check::equal($p->pop($pInt), 904, "Test 6 failed"); | ||
|
||
check::equal($p->pop(), 905, "Test 7 failed"); | ||
|
||
# Overload on const only | ||
check::equal($p->bop($pInt), 1001, "Test 8 failed"); | ||
|
||
check::equal($p->bip($pInt), 2002, "Test 9 failed"); | ||
|
||
# Globals | ||
check::equal(muzak(false), 3001, "Test 10 failed"); | ||
|
||
check::equal(muzak($pInt), 3002, "Test 11 failed"); | ||
|
||
check::done(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
require "tests.php"; | ||
|
||
// No new functions | ||
check::functions(array()); | ||
check::classes(array('Foo')); | ||
// No new vars | ||
check::globals(array()); | ||
|
||
$f = new Foo(); | ||
$g = new Foo($f); | ||
|
||
check::done(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
require "tests.php"; | ||
|
||
$f = new Foo(); | ||
check::equal($f->test(3), 1, '$f->test(3)'); | ||
check::equal($f->test("hello"), 2, '$f->test("hello")'); | ||
check::equal($f->test(3.5, 2.5), 3, '$f->test(3.5, 2.5)'); | ||
check::equal($f->test("hello", 20), 1020, '$f->test("hello", 20)'); | ||
check::equal($f->test("hello", 20, 100), 120, '$f->test("hello", 20, 100)'); | ||
|
||
// C default args | ||
check::equal($f->test($f), 30, '$f->test(f)'); | ||
check::equal($f->test($f, 100), 120, '$f->test(f, 100)'); | ||
check::equal($f->test($f, 100, 200), 300, '$f->test(f, 100, 200)'); | ||
|
||
check::done(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
require "tests.php"; | ||
|
||
$f = new Foo(); | ||
check::equal($f->test(), 0, '$f->test()'); | ||
check::equal($f->test(3), 1, '$f->test(3)'); | ||
check::equal($f->test("hello"), 2, '$f->test("hello")'); | ||
check::equal($f->test(3.0, 2.0), 5.0, '$f->test(3, 2)'); | ||
check::equal($f->test(3.0), 1003.0, '$f->test(3.0)'); | ||
|
||
check::done(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
require "tests.php"; | ||
|
||
$f = new Foo(); | ||
check::equal($f->test(), 0, '$f->test()'); | ||
check::equal($f->test(3), 1, '$f->test(3)'); | ||
check::equal($f->test("hello"), 2, '$f->test("hello")'); | ||
check::equal($f->test(3.0, 2.0), 5.0, '$f->test(3.0, 2.0)'); | ||
check::equal($f->test(3.0), 1003.0, '$f->test(3.0)'); | ||
|
||
check::done(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
require "tests.php"; | ||
|
||
$f = new Foo(); | ||
$b = new Bar(); | ||
|
||
check::equal(spam($f), 1, "foo"); | ||
|
||
check::equal(spam($b), 2, "bar"); | ||
|
||
check::done(); |
110 changes: 110 additions & 0 deletions
110
Examples/test-suite/php/overload_template_fast_runme.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
<?php | ||
|
||
require "tests.php"; | ||
|
||
$f = foo(); | ||
|
||
$a = maximum(3, 4); | ||
$b = maximum(3.4, 5.2); | ||
|
||
# mix 1 | ||
check::equal(mix1("hi"), 101, "mix1(const char*)"); | ||
|
||
check::equal(mix1(1.0, 1.0), 102, "mix1(double, const double &)"); | ||
|
||
check::equal(mix1(1.0), 103, "mix1(double)"); | ||
|
||
# mix 2 | ||
check::equal(mix2("hi"), 101, "mix2(const char*)"); | ||
|
||
check::equal(mix2(1.0, 1.0), 102, "mix2(double, const double &)"); | ||
|
||
check::equal(mix2(1.0), 103, "mix2(double)"); | ||
|
||
# mix 3 | ||
check::equal(mix3("hi"), 101, "mix3(const char*)"); | ||
|
||
check::equal(mix3(1.0, 1.0), 102, "mix3(double, const double &)"); | ||
|
||
check::equal(mix3(1.0), 103, "mix3(double)"); | ||
|
||
# Combination 1 | ||
check::equal(overtparams1(100), 10, "overtparams1(int)"); | ||
|
||
check::equal(overtparams1(100.0, 100), 20, "overtparams1(double, int)"); | ||
|
||
# Combination 2 | ||
check::equal(overtparams2(100.0, 100), 40, "overtparams2(double, int)"); | ||
|
||
# Combination 3 | ||
check::equal(overloaded(), 60, "overloaded()"); | ||
|
||
check::equal(overloaded(100.0, 100), 70, "overloaded(double, int)"); | ||
|
||
# Combination 4 | ||
check::equal(overloadedagain("hello"), 80, "overloadedagain(const char *)"); | ||
|
||
check::equal(overloadedagain(), 90, "overloadedagain(double)"); | ||
|
||
# specializations | ||
check::equal(specialization(10), 202, "specialization(int)"); | ||
|
||
check::equal(specialization(10.0), 203, "specialization(double)"); | ||
|
||
check::equal(specialization(10, 10), 204, "specialization(int, int)"); | ||
|
||
check::equal(specialization(10.0, 10.0), 205, "specialization(double, double)"); | ||
|
||
check::equal(specialization("hi", "hi"), 201, "specialization(const char *, const char *)"); | ||
|
||
# simple specialization | ||
xyz(); | ||
xyz_int(); | ||
xyz_double(); | ||
|
||
# a bit of everything | ||
check::equal(overload("hi"), 0, "overload()"); | ||
|
||
check::equal(overload(1), 10, "overload(int t)"); | ||
|
||
check::equal(overload(1, 1), 20, "overload(int t, const int &)"); | ||
|
||
check::equal(overload(1, "hello"), 30, "overload(int t, const char *)"); | ||
|
||
$k = new Klass(); | ||
check::equal(overload($k), 10, "overload(Klass t)"); | ||
|
||
check::equal(overload($k, $k), 20, "overload(Klass t, const Klass &)"); | ||
|
||
check::equal(overload($k, "hello"), 30, "overload(Klass t, const char *)"); | ||
|
||
check::equal(overload(10.0, "hi"), 40, "overload(double t, const char *)"); | ||
|
||
check::equal(overload(), 50, "overload(const char *)"); | ||
|
||
# everything put in a namespace | ||
check::equal(nsoverload("hi"), 1000, "nsoverload()"); | ||
|
||
check::equal(nsoverload(1), 1010, "nsoverload(int t)"); | ||
|
||
check::equal(nsoverload(1, 1), 1020, "nsoverload(int t, const int &)"); | ||
|
||
check::equal(nsoverload(1, "hello"), 1030, "nsoverload(int t, const char *)"); | ||
|
||
check::equal(nsoverload($k), 1010, "nsoverload(Klass t)"); | ||
|
||
check::equal(nsoverload($k, $k), 1020, "nsoverload(Klass t, const Klass &)"); | ||
|
||
check::equal(nsoverload($k, "hello"), 1030, "nsoverload(Klass t, const char *)"); | ||
|
||
check::equal(nsoverload(10.0, "hi"), 1040, "nsoverload(double t, const char *)"); | ||
|
||
check::equal(nsoverload(), 1050, "nsoverload(const char *)"); | ||
|
||
|
||
A::foo(1); | ||
$b = new B(); | ||
$b->foo(1); | ||
|
||
|
||
check::done(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
<?php | ||
|
||
require "tests.php"; | ||
|
||
$f = foo(); | ||
|
||
$a = maximum(3, 4); | ||
$b = maximum(3.4, 5.2); | ||
|
||
# mix 1 | ||
check::equal(mix1("hi"), 101, "mix1(const char*)"); | ||
|
||
check::equal(mix1(1.0, 1.0), 102, "mix1(double, const double &)"); | ||
|
||
check::equal(mix1(1.0), 103, "mix1(double)"); | ||
|
||
# mix 2 | ||
check::equal(mix2("hi"), 101, "mix2(const char*)"); | ||
|
||
check::equal(mix2(1.0, 1.0), 102, "mix2(double, const double &)"); | ||
|
||
check::equal(mix2(1.0), 103, "mix2(double)"); | ||
|
||
# mix 3 | ||
check::equal(mix3("hi"), 101, "mix3(const char*)"); | ||
|
||
check::equal(mix3(1.0, 1.0), 102, "mix3(double, const double &)"); | ||
|
||
check::equal(mix3(1.0), 103, "mix3(double)"); | ||
|
||
# Combination 1 | ||
check::equal(overtparams1(100), 10, "overtparams1(int)"); | ||
|
||
check::equal(overtparams1(100.0, 100), 20, "overtparams1(double, int)"); | ||
|
||
# Combination 2 | ||
check::equal(overtparams2(100.0, 100), 40, "overtparams2(double, int)"); | ||
|
||
# Combination 3 | ||
check::equal(overloaded(), 60, "overloaded()"); | ||
|
||
check::equal(overloaded(100.0, 100), 70, "overloaded(double, int)"); | ||
|
||
# Combination 4 | ||
check::equal(overloadedagain("hello"), 80, "overloadedagain(const char *)"); | ||
|
||
check::equal(overloadedagain(), 90, "overloadedagain(double)"); | ||
|
||
# specializations | ||
check::equal(specialization(10), 202, "specialization(int)"); | ||
|
||
check::equal(specialization(10.0), 203, "specialization(double)"); | ||
|
||
check::equal(specialization(10, 10), 204, "specialization(int, int)"); | ||
|
||
check::equal(specialization(10.0, 10.0), 205, "specialization(double, double)"); | ||
|
||
check::equal(specialization("hi", "hi"), 201, "specialization(const char *, const char *)"); | ||
|
||
# simple specialization | ||
xyz(); | ||
xyz_int(); | ||
xyz_double(); | ||
|
||
# a bit of everything | ||
check::equal(overload("hi"), 0, "overload()"); | ||
|
||
check::equal(overload(1), 10, "overload(int t)"); | ||
|
||
check::equal(overload(1, 1), 20, "overload(int t, const int &)"); | ||
|
||
check::equal(overload(1, "hello"), 30, "overload(int t, const char *)"); | ||
|
||
$k = new Klass(); | ||
check::equal(overload($k), 10, "overload(Klass t)"); | ||
|
||
check::equal(overload($k, $k), 20, "overload(Klass t, const Klass &)"); | ||
|
||
check::equal(overload($k, "hello"), 30, "overload(Klass t, const char *)"); | ||
|
||
check::equal(overload(10.0, "hi"), 40, "overload(double t, const char *)"); | ||
|
||
check::equal(overload(), 50, "overload(const char *)"); | ||
|
||
# everything put in a namespace | ||
check::equal(nsoverload("hi"), 1000, "nsoverload()"); | ||
|
||
check::equal(nsoverload(1), 1010, "nsoverload(int t)"); | ||
|
||
check::equal(nsoverload(1, 1), 1020, "nsoverload(int t, const int &)"); | ||
|
||
check::equal(nsoverload(1, "hello"), 1030, "nsoverload(int t, const char *)"); | ||
|
||
check::equal(nsoverload($k), 1010, "nsoverload(Klass t)"); | ||
|
||
check::equal(nsoverload($k, $k), 1020, "nsoverload(Klass t, const Klass &)"); | ||
|
||
check::equal(nsoverload($k, "hello"), 1030, "nsoverload(Klass t, const char *)"); | ||
|
||
check::equal(nsoverload(10.0, "hi"), 1040, "nsoverload(double t, const char *)"); | ||
|
||
check::equal(nsoverload(), 1050, "nsoverload(const char *)"); | ||
|
||
|
||
A::foo(1); | ||
$b = new B(); | ||
$b->foo(1); | ||
|
||
|
||
check::done(); |