diff options
author | Russell Belfer <rb@github.com> | 2014-01-27 14:57:03 -0800 |
---|---|---|
committer | Russell Belfer <rb@github.com> | 2014-01-27 14:57:03 -0800 |
commit | daebb598690c47600cf033be77acaad1ae8c4a70 (patch) | |
tree | c9d8a2124b4b47768d3e95defb1e5900db53bddf | |
parent | 082e82dba5b5174756b3a5fc2e385ccc59626164 (diff) | |
download | libgit2-daebb598690c47600cf033be77acaad1ae8c4a70.tar.gz |
Add PHP tests and fix bug in PHP builtin driver
14 files changed, 205 insertions, 4 deletions
diff --git a/src/userdiff.h b/src/userdiff.h index 2257035ac..9318b5476 100644 --- a/src/userdiff.h +++ b/src/userdiff.h @@ -186,7 +186,7 @@ PATTERNS("csharp", "|[-+*/<>%&^|=!]=|--|\\+\\+|<<=?|>>=?|&&|\\|\\||::|->"), PATTERNS("php", - "^[ \t]*((public|private|protected|static|final)[ \t]+)*((class|function)[ \t].*)$", + "^[ \t]*(((public|private|protected|static|final)[ \t]+)*((class|function)[ \t].*))$", /* -- */ "[a-zA-Z_][a-zA-Z0-9_]*" "|[-+0-9.e]+[fFlL]?|0[xX]?[0-9a-fA-F]+[lL]?" diff --git a/tests/resources/userdiff/.gitted/index b/tests/resources/userdiff/.gitted/index Binary files differindex df041cf72..b69d5cfb1 100644 --- a/tests/resources/userdiff/.gitted/index +++ b/tests/resources/userdiff/.gitted/index diff --git a/tests/resources/userdiff/.gitted/info/refs b/tests/resources/userdiff/.gitted/info/refs index 261695f80..b0743141d 100644 --- a/tests/resources/userdiff/.gitted/info/refs +++ b/tests/resources/userdiff/.gitted/info/refs @@ -1 +1 @@ -802734c801bffc466d69876bc4814f747aaac4fe refs/heads/master +60e3f7b244a5305e2c9fa4ef0e897f3b14f3b8dd refs/heads/master diff --git a/tests/resources/userdiff/.gitted/objects/info/packs b/tests/resources/userdiff/.gitted/objects/info/packs index 6970fd7b0..0c5fc2a30 100644 --- a/tests/resources/userdiff/.gitted/objects/info/packs +++ b/tests/resources/userdiff/.gitted/objects/info/packs @@ -1,2 +1,2 @@ -P pack-03f78c35e3ca74fffd9d6c2b6dcd60d6ab6a614a.pack +P pack-1652578900ac63564f2a24b9714529821276ceb9.pack diff --git a/tests/resources/userdiff/.gitted/objects/pack/pack-03f78c35e3ca74fffd9d6c2b6dcd60d6ab6a614a.idx b/tests/resources/userdiff/.gitted/objects/pack/pack-03f78c35e3ca74fffd9d6c2b6dcd60d6ab6a614a.idx Binary files differdeleted file mode 100644 index 6d723f525..000000000 --- a/tests/resources/userdiff/.gitted/objects/pack/pack-03f78c35e3ca74fffd9d6c2b6dcd60d6ab6a614a.idx +++ /dev/null diff --git a/tests/resources/userdiff/.gitted/objects/pack/pack-1652578900ac63564f2a24b9714529821276ceb9.idx b/tests/resources/userdiff/.gitted/objects/pack/pack-1652578900ac63564f2a24b9714529821276ceb9.idx Binary files differnew file mode 100644 index 000000000..6f4381cc7 --- /dev/null +++ b/tests/resources/userdiff/.gitted/objects/pack/pack-1652578900ac63564f2a24b9714529821276ceb9.idx diff --git a/tests/resources/userdiff/.gitted/objects/pack/pack-03f78c35e3ca74fffd9d6c2b6dcd60d6ab6a614a.pack b/tests/resources/userdiff/.gitted/objects/pack/pack-1652578900ac63564f2a24b9714529821276ceb9.pack Binary files differindex 5b263e27d..39bd1d8f0 100644 --- a/tests/resources/userdiff/.gitted/objects/pack/pack-03f78c35e3ca74fffd9d6c2b6dcd60d6ab6a614a.pack +++ b/tests/resources/userdiff/.gitted/objects/pack/pack-1652578900ac63564f2a24b9714529821276ceb9.pack diff --git a/tests/resources/userdiff/.gitted/packed-refs b/tests/resources/userdiff/.gitted/packed-refs index 6d24ee4ed..802f67ce0 100644 --- a/tests/resources/userdiff/.gitted/packed-refs +++ b/tests/resources/userdiff/.gitted/packed-refs @@ -1,2 +1,2 @@ # pack-refs with: peeled fully-peeled -802734c801bffc466d69876bc4814f747aaac4fe refs/heads/master +60e3f7b244a5305e2c9fa4ef0e897f3b14f3b8dd refs/heads/master diff --git a/tests/resources/userdiff/.gitted/refs/dummy-marker.txt b/tests/resources/userdiff/.gitted/refs/dummy-marker.txt new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/tests/resources/userdiff/.gitted/refs/dummy-marker.txt diff --git a/tests/resources/userdiff/after/file.php b/tests/resources/userdiff/after/file.php new file mode 100644 index 000000000..967d6466c --- /dev/null +++ b/tests/resources/userdiff/after/file.php @@ -0,0 +1,50 @@ +<?php + +namespace Faker; + +/** + * Proxy for other generators, to return only unique values. Works with + * Faker\Generator\Base->unique() + */ +class UniqueGenerator +{ + protected $generator; + protected $maxRetries; + protected $moreStuff; + protected $uniques = array(); + + public function __construct(Generator $generator, $maxRetries) + { + $this->generator = $generator; + $this->maxRetries = $maxRetries + 1; + } + + /** + * Catch and proxy all generator calls but return only unique values + */ + public function __get($attribute) + { + return $this->__call($attribute, array()); + } + + /** + * Catch and proxy all generator calls with arguments but return only unique values + */ + public function __call($name, $arguments) + { + $i = 0; + if (!isset($this->uniques[$name])) { + $this->uniques[$name] = array(); + } + do { + $res = call_user_func_array(array($this->generator, $name), $arguments); + $i++; + if ($i >= $this->maxRetries) { + throw new \OverflowException(sprintf('Maximum retries of %d reached without finding a unique value', $this->maxRetries)); + } + } while (in_array($res, $this->uniques[$name])); + $this->uniques[$name][]= $res; + + return $res; + } +} diff --git a/tests/resources/userdiff/before/file.php b/tests/resources/userdiff/before/file.php new file mode 100644 index 000000000..63250ad01 --- /dev/null +++ b/tests/resources/userdiff/before/file.php @@ -0,0 +1,49 @@ +<?php + +namespace Faker; + +/** + * Proxy for other generators, to return only unique values. Works with + * Faker\Generator\Base->unique() + */ +class UniqueGenerator +{ + protected $generator; + protected $maxRetries; + protected $uniques = array(); + + public function __construct(Generator $generator, $maxRetries) + { + $this->generator = $generator; + $this->maxRetries = $maxRetries; + } + + /** + * Catch and proxy all generator calls but return only unique values + */ + public function __get($attribute) + { + return $this->__call($attribute, array()); + } + + /** + * Catch and proxy all generator calls with arguments but return only unique values + */ + public function __call($name, $arguments) + { + if (!isset($this->uniques[$name])) { + $this->uniques[$name] = array(); + } + $i = 0; + do { + $res = call_user_func_array(array($this->generator, $name), $arguments); + $i++; + if ($i > $this->maxRetries) { + throw new \OverflowException(sprintf('Maximum retries of %d reached without finding a unique value', $this->maxRetries)); + } + } while (in_array($res, $this->uniques[$name])); + $this->uniques[$name][]= $res; + + return $res; + } +} diff --git a/tests/resources/userdiff/expected/driver/diff.php b/tests/resources/userdiff/expected/driver/diff.php new file mode 100644 index 000000000..9711b5b3e --- /dev/null +++ b/tests/resources/userdiff/expected/driver/diff.php @@ -0,0 +1,26 @@ +diff --git a/files/file.php b/files/file.php +index 63250ad..967d646 100644 +--- a/files/file.php ++++ b/files/file.php +@@ -12,2 +12,3 @@ class UniqueGenerator + protected $maxRetries; ++ protected $moreStuff; + protected $uniques = array(); +@@ -17,3 +18,3 @@ public function __construct(Generator $generator, $maxRetries) + $this->generator = $generator; +- $this->maxRetries = $maxRetries; ++ $this->maxRetries = $maxRetries + 1; + } +@@ -33,10 +34,10 @@ public function __call($name, $arguments) + { ++ $i = 0; + if (!isset($this->uniques[$name])) { + $this->uniques[$name] = array(); + } +- $i = 0; + do { + $res = call_user_func_array(array($this->generator, $name), $arguments); + $i++; +- if ($i > $this->maxRetries) { ++ if ($i >= $this->maxRetries) { + throw new \OverflowException(sprintf('Maximum retries of %d reached without finding a unique value', $this->maxRetries)); diff --git a/tests/resources/userdiff/expected/nodriver/diff.php b/tests/resources/userdiff/expected/nodriver/diff.php new file mode 100644 index 000000000..e77c094aa --- /dev/null +++ b/tests/resources/userdiff/expected/nodriver/diff.php @@ -0,0 +1,26 @@ +diff --git a/files/file.php b/files/file.php +index 63250ad..967d646 100644 +--- a/files/file.php ++++ b/files/file.php +@@ -12,2 +12,3 @@ class UniqueGenerator + protected $maxRetries; ++ protected $moreStuff; + protected $uniques = array(); +@@ -17,3 +18,3 @@ class UniqueGenerator + $this->generator = $generator; +- $this->maxRetries = $maxRetries; ++ $this->maxRetries = $maxRetries + 1; + } +@@ -33,10 +34,10 @@ class UniqueGenerator + { ++ $i = 0; + if (!isset($this->uniques[$name])) { + $this->uniques[$name] = array(); + } +- $i = 0; + do { + $res = call_user_func_array(array($this->generator, $name), $arguments); + $i++; +- if ($i > $this->maxRetries) { ++ if ($i >= $this->maxRetries) { + throw new \OverflowException(sprintf('Maximum retries of %d reached without finding a unique value', $this->maxRetries)); diff --git a/tests/resources/userdiff/files/file.php b/tests/resources/userdiff/files/file.php new file mode 100644 index 000000000..967d6466c --- /dev/null +++ b/tests/resources/userdiff/files/file.php @@ -0,0 +1,50 @@ +<?php + +namespace Faker; + +/** + * Proxy for other generators, to return only unique values. Works with + * Faker\Generator\Base->unique() + */ +class UniqueGenerator +{ + protected $generator; + protected $maxRetries; + protected $moreStuff; + protected $uniques = array(); + + public function __construct(Generator $generator, $maxRetries) + { + $this->generator = $generator; + $this->maxRetries = $maxRetries + 1; + } + + /** + * Catch and proxy all generator calls but return only unique values + */ + public function __get($attribute) + { + return $this->__call($attribute, array()); + } + + /** + * Catch and proxy all generator calls with arguments but return only unique values + */ + public function __call($name, $arguments) + { + $i = 0; + if (!isset($this->uniques[$name])) { + $this->uniques[$name] = array(); + } + do { + $res = call_user_func_array(array($this->generator, $name), $arguments); + $i++; + if ($i >= $this->maxRetries) { + throw new \OverflowException(sprintf('Maximum retries of %d reached without finding a unique value', $this->maxRetries)); + } + } while (in_array($res, $this->uniques[$name])); + $this->uniques[$name][]= $res; + + return $res; + } +} |