forked from endel/js2php
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add simple testsuite asserting js input / php output
- Loading branch information
Showing
38 changed files
with
594 additions
and
2 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 |
---|---|---|
@@ -1 +1,2 @@ | ||
.DS_Store | ||
node_modules |
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
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 @@ | ||
var result = (((6 * 2) / 14) * 32 ) / 4; |
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
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,54 @@ | ||
class ClassExample { | ||
|
||
constructor(something) { | ||
this._something = something | ||
} | ||
|
||
toArray(model, array) { | ||
return array; | ||
} | ||
|
||
hello() { | ||
return "Hello world"; | ||
} | ||
|
||
get something() { | ||
return "Something: " + this._something; | ||
} | ||
|
||
set something(value) { | ||
this._something = value + 10; | ||
} | ||
|
||
creating(model) { | ||
Mail.send({ | ||
body: Module.template('signup-confirmation').compile({ | ||
base_url: AppConfig.get("retrieve.email.url") | ||
}), | ||
subject: "Sign-up confirmation", | ||
to: model.email, | ||
from: "somebody@example.com" | ||
}); | ||
} | ||
|
||
updating(model) { | ||
if (model.isDirty('status') && model.status == 1) { | ||
|
||
Mail.send({ | ||
body: Module.template('signup-approved').compile({ | ||
BASE_URL: AppConfig.get("retrieve.email.url") | ||
}), | ||
subject: "Approved!", | ||
to: model.email, | ||
from: "somebody@example.com" | ||
}); | ||
|
||
} | ||
} | ||
|
||
} | ||
|
||
// Instantiate class and call getter method | ||
example = new ClassExample("awesome"); | ||
var_dump(example.hello.apply()); | ||
var_dump(example.hello()); |
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,34 @@ | ||
<?php | ||
class ClassExample | ||
{ | ||
public function __construct($something) { | ||
$this->_something = $something; | ||
} | ||
public function toArray($model, $array) { | ||
return $array; | ||
} | ||
public function hello() { | ||
return "Hello world"; | ||
} | ||
public function creating($model) { | ||
Mail::send(array("body" => Module::template('signup-confirmation')->compile(array("base_url" => AppConfig::get("retrieve.email.url"))), "subject" => "Sign-up confirmation", "to" => $model->email, "from" => "somebody@example.com")); | ||
} | ||
public function updating($model) { | ||
if ($model->isDirty('status') && $model->status == 1) { | ||
Mail::send(array("body" => Module::template('signup-approved')->compile(array("BASE_URL" => AppConfig::get("retrieve.email.url"))), "subject" => "Approved!", "to" => $model->email, "from" => "somebody@example.com")); | ||
}} | ||
function __get($_property) { | ||
if ($_property === 'something') { | ||
return "Something: " + $this->_something; | ||
} | ||
} | ||
function __set($_property, $value) { | ||
if ($_property === 'something') { | ||
$this->_something = $value + 10; | ||
} | ||
} | ||
|
||
} | ||
$example = new ClassExample("awesome"); | ||
var_dump(call_user_func_array(array($example, 'hello'), array())); | ||
var_dump($example->hello()); |
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,10 @@ | ||
d = 10; | ||
var closure = function(a) { | ||
var c = 1; | ||
return function(b) { | ||
return a + b + c + d; | ||
} | ||
} | ||
|
||
calling = closure(5); | ||
var_dump(calling(4) == 20); |
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,12 @@ | ||
<?php | ||
$d = 10; | ||
$closure = function ($a) use (&$d) { | ||
$c = 1; | ||
return function ($b) use (&$a, &$c, &$d) { | ||
return $a + $b + $c + $d; | ||
} | ||
; | ||
} | ||
; | ||
$calling = $closure(5); | ||
var_dump($calling(4) == 20); |
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,24 @@ | ||
var x = 1, y = 50; | ||
var ternary = (x == 1) ? "Yes" : "No" | ||
|
||
var_dump(ternary); | ||
|
||
var_dump( x < y ) | ||
var_dump( x == 2 ) | ||
|
||
if (x < y) { | ||
echo("x < y"); | ||
} else if (x == 2) { | ||
echo("x==2"); | ||
} else { | ||
echo("else..."); | ||
} | ||
|
||
switch (x) { | ||
case 5: | ||
echo("Five!"); | ||
case 1: | ||
echo("One!"); | ||
default: | ||
echo("Default!"); | ||
} |
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,22 @@ | ||
<?php | ||
$x = 1; | ||
$y = 50; | ||
$ternary = ($x == 1) ? "Yes" : "No"; | ||
var_dump($ternary); | ||
var_dump($x < $y); | ||
var_dump($x == 2); | ||
if ($x < $y) { | ||
echo("x < y"); | ||
} else if ($x == 2) { | ||
echo("x==2"); | ||
} else {echo("else..."); | ||
}switch ($x){case 5: | ||
echo("Five!"); | ||
|
||
case 1: | ||
echo("One!"); | ||
|
||
default: | ||
echo("Default!"); | ||
|
||
} |
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 @@ | ||
var items = ["One", "Two", "Three"]; | ||
|
||
items.unshift("Zero"); | ||
items.shift(); | ||
items.push("Four"); | ||
|
||
var_dump(items); | ||
echo(items.join(", ")) | ||
|
||
echo(items.length) | ||
echo(items.indexOf({name: "Three"})) | ||
echo(items.join(", ")) | ||
|
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,10 @@ | ||
<?php | ||
$items = array("One", "Two", "Three"); | ||
array_unshift($items, "Zero"); | ||
array_shift($items); | ||
array_push($items, "Four"); | ||
var_dump($items); | ||
echo(join(", ", $items)); | ||
echo(count($items)); | ||
echo(array_search(array("name" => "Three"), $items)); | ||
echo(join(", ", $items)); |
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,23 @@ | ||
class Klass { | ||
without_params() { | ||
return "I'm a method without params." | ||
} | ||
|
||
with_default_params(param1="default") { | ||
return param1; | ||
} | ||
} | ||
|
||
function global_function() { | ||
return "I'm a global function"; | ||
} | ||
|
||
function global_function_with_params() { | ||
return "I'm a global function with params"; | ||
} | ||
|
||
klass = new Klass | ||
var_dump(klass.without_params.apply()) | ||
var_dump(klass.with_default_params.apply(null)) | ||
var_dump(klass.with_default_params.apply(null, ["Hey!"])) | ||
var_dump(klass.with_default_params.call(null, "Hey!")) |
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,22 @@ | ||
<?php | ||
class Klass | ||
{ | ||
public function without_params() { | ||
return "I'm a method without params."; | ||
} | ||
public function with_default_params($param1 = "default") { | ||
return $param1; | ||
} | ||
|
||
} | ||
function global_function() { | ||
return "I'm a global function"; | ||
} | ||
function global_function_with_params() { | ||
return "I'm a global function with params"; | ||
} | ||
$klass = new Klass(); | ||
var_dump(call_user_func_array(array($klass, 'without_params'), array())); | ||
var_dump(call_user_func_array(array($klass, 'with_default_params'), array())); | ||
var_dump(call_user_func_array(array($klass, 'with_default_params'), array("Hey!"))); | ||
var_dump(call_user_func(array($klass, 'with_default_params'), "Hey!")); |
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,12 @@ | ||
JSON.stringify({ | ||
integer: 5, | ||
string: "hey", | ||
nested: {objects:{here: "yey"}} | ||
}); | ||
|
||
var_dump(JSON.stringify({ | ||
integer: 5, | ||
string: "hey", | ||
nested: { objects: { here: "yey" } } | ||
})); | ||
|
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,3 @@ | ||
<?php | ||
json_encode(array("integer" => 5, "string" => "hey", "nested" => array("objects" => array("here" => "yey")))); | ||
var_dump(json_encode(array("integer" => 5, "string" => "hey", "nested" => array("objects" => array("here" => "yey"))))); |
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,4 @@ | ||
var_dump(Math.E); | ||
var_dump(Math.round(5.55557)); | ||
|
||
var_dump( Math.sin(5 + 8 * Math.sqrt(200)) * Math.PI ) |
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,4 @@ | ||
<?php | ||
var_dump(M_E); | ||
var_dump(round(5.55557)); | ||
var_dump(sin(5 + 8 * sqrt(200)) * M_PI); |
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,18 @@ | ||
var str = "Hello"; | ||
echo(" trimmed ".trim().trim().substr(1).trim().trim().trim()); | ||
|
||
var_dump("hello".replace("lo", "ium").toUpperCase()) | ||
|
||
var_dump("something".toUpperCase()) | ||
var_dump("something".indexOf("meth")) | ||
|
||
echo(" trimmed".trimLeft()); | ||
echo("trimmed ".trimRight()); | ||
|
||
echo(str.toUpperCase().substr(1)); | ||
echo(str.toLowerCase()); | ||
echo(str.substr(1)); | ||
|
||
if (str.match(/endel/)) { | ||
var_dump(str); | ||
} |
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,14 @@ | ||
<?php | ||
$str = "Hello"; | ||
echo(trim(trim(trim(substr(trim(trim(" trimmed ")), 1))))); | ||
var_dump(strtoupper(str_replace("lo", "ium", "hello"))); | ||
var_dump(strtoupper("something")); | ||
var_dump(strpos("something", "meth")); | ||
echo(ltrim(" trimmed")); | ||
echo(rtrim("trimmed ")); | ||
echo(substr(strtoupper($str), 1)); | ||
echo(strtolower($str)); | ||
echo(substr($str, 1)); | ||
if (preg_match('/endel/', $str)) { | ||
var_dump($str); | ||
} |
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 @@ | ||
var result = (((6 * 2) / 14) * 32 ) / 4; |
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,2 @@ | ||
<?php | ||
$result = 6 * 2 / 14 * 32 / 4; |
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,17 @@ | ||
|
||
function something(x, y = "something", z = 5) { | ||
var_dump(x, y, z); | ||
} | ||
|
||
function sum(a, b) { | ||
return a + b; | ||
} | ||
|
||
function hello(a, b) { | ||
return "hello!"; | ||
} | ||
|
||
var_dump(hello.apply(hello, [5,6])) | ||
var_dump(hello(5, 6)) | ||
|
||
// var_dump(something(5), sum(1,2)) |
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,12 @@ | ||
<?php | ||
function something($x, $y = "something", $z = 5) { | ||
var_dump($x, $y, $z); | ||
} | ||
function sum($a, $b) { | ||
return $a + $b; | ||
} | ||
function hello($a, $b) { | ||
return "hello!"; | ||
} | ||
var_dump(call_user_func_array('hello', array(5, 6))); | ||
var_dump(hello(5, 6)); |
Oops, something went wrong.