Fix and expand rename_camel.i testcase
The regex pattern to upper-case things containing an `i` had incorrect escaping (`\\(`...`\\)` instead of `(`...`)`) so `import` didn't get renamed. This wasn't detected because there were no `_runme` files for this testcase, so add rename_camel_runme.php which uses reflection to check the wrapped PHP classes, functions and constants are all named as expected. Also expand coverage of converting to underscore case and add coverage for converting to lower-camel-case. Related to #1041.
This commit is contained in:
parent
e1bb265bf7
commit
cf7bdcf2df
3 changed files with 64 additions and 12 deletions
13
Examples/test-suite/php/rename_camel_runme.php
Normal file
13
Examples/test-suite/php/rename_camel_runme.php
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
<?php
|
||||
|
||||
require "tests.php";
|
||||
|
||||
// We want to fail if any extra classes/function/constants are defined.
|
||||
check::werror(true);
|
||||
|
||||
check::classes(array("rename_camel","GeometryFactory","ByteOrderValues"));
|
||||
check::functions(array("CamelCase","CamelCase1","CamelCase2","CamelCase3","lowerCamelCase","lowerCamelCase1","lowerCamelCase2","lowerCamelCase3","under_case","under_case1","under_case2","under_case3","IMPORT","foo","hello"));
|
||||
check::constants(array("Hello","Hi_there","Bye","See_you"));
|
||||
|
||||
|
||||
check::done();
|
||||
|
|
@ -7,6 +7,8 @@ class check {
|
|||
|
||||
private static $_extension = null;
|
||||
|
||||
private static $_werror = false;
|
||||
|
||||
// This is called automatically at the end of this file.
|
||||
static function init() {
|
||||
foreach(get_included_files() as $f) {
|
||||
|
|
@ -21,6 +23,10 @@ class check {
|
|||
self::$_extension = new ReflectionExtension($module_name);
|
||||
}
|
||||
|
||||
static function werror($v) {
|
||||
self::$_werror = $v;
|
||||
}
|
||||
|
||||
static function classname($string,$object) {
|
||||
if (!is_object($object))
|
||||
return check::fail("The second argument is a " . gettype($object) . ", not an object.");
|
||||
|
|
@ -139,6 +145,23 @@ class check {
|
|||
|
||||
}
|
||||
|
||||
static function constants($constants) {
|
||||
if (! is_array($constants)) $constants=array($constants);
|
||||
$message=array();
|
||||
$missing=array();
|
||||
$extra = self::$_extension->getConstants();
|
||||
unset($extra['swig_runtime_data_type_pointer']);
|
||||
foreach($constants as $constant) {
|
||||
if (! defined($constant)) $missing[]=$constant;
|
||||
else unset($extra[$constant]);
|
||||
}
|
||||
if ($missing) $message[]=sprintf("Constants missing: %s",join(",",$missing));
|
||||
if ($message) return check::fail(join("\n ",$message));
|
||||
if ($extra) $message[]=sprintf("These extra constants are defined: %s",join(",",array_keys($extra)));
|
||||
if ($message) return check::warn(join("\n ",$message));
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static function functionref($a,$type,$message) {
|
||||
if (! preg_match("/^_[a-f0-9]+$type$/i", $a))
|
||||
return check::fail($message);
|
||||
|
|
@ -167,6 +190,7 @@ class check {
|
|||
|
||||
static function warn($pattern) {
|
||||
$args=func_get_args();
|
||||
if (self::$_werror) self::fail($pattern);
|
||||
print("Warning on: ".call_user_func_array("sprintf",$args)."\n");
|
||||
return FALSE;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,47 +4,62 @@
|
|||
%rename("%(ctitle)s",%$isvariable,%$ismember) "";
|
||||
|
||||
%inline {
|
||||
struct GeometryFactory
|
||||
{
|
||||
struct GeometryFactory {
|
||||
void createPointFromInternalCoord(int);
|
||||
void BIG_METHOD(int);
|
||||
void BIG_METHOD(int) {}
|
||||
};
|
||||
|
||||
class ByteOrderValues {
|
||||
|
||||
public:
|
||||
void readHEX();
|
||||
void readHEX() {}
|
||||
static int ENDIAN_BIG;
|
||||
};
|
||||
|
||||
int ByteOrderValues::ENDIAN_BIG = 4321;
|
||||
}
|
||||
|
||||
|
||||
%rename(CamelCase1) camel_case_1;
|
||||
%rename("%(camelcase)s") camel_case_2;
|
||||
// ctitle is an alias for camelcase.
|
||||
%rename("%(ctitle)s") camel_case_3;
|
||||
|
||||
%rename(lowerCamelCase1) Lower_camel_case_1;
|
||||
%rename("%(lowercamelcase)s") Lower_camel_case_2;
|
||||
// lctitle is an alias for lowercamelcase.
|
||||
%rename("%(lctitle)s") Lower_camel_case_3;
|
||||
|
||||
%rename("%(utitle)s") CamelCase_5;
|
||||
%rename(under_case1) UnderCase1;
|
||||
%rename("%(undercase)s") UnderCase2;
|
||||
// utitle is an alias for undercase.
|
||||
%rename("%(utitle)s") UnderCase3;
|
||||
|
||||
%rename("%(regex:/\\(.*i.*\\)/\\U\\1/)s") "";
|
||||
// This should upper-case "import", but "hi_there" should be handled by the
|
||||
// rule below and become "Hi_there".
|
||||
%rename("%(regex:/(.*i.*)/\\U\\1/)s") "";
|
||||
|
||||
%rename("%(title)s",regexmatch$parentNode$type="enum .*") "";
|
||||
|
||||
%inline
|
||||
{
|
||||
int CamelCase(int);
|
||||
int camel_case_1(int);
|
||||
int camel_case_2(int);
|
||||
int camel_case_3(int);
|
||||
int camel_case_4(int);
|
||||
int camel_case(int);
|
||||
int CamelCase_5(int);
|
||||
int also_works_here(int);
|
||||
|
||||
int under_case(int);
|
||||
int UnderCase1(int);
|
||||
int UnderCase2(int);
|
||||
int UnderCase3(int);
|
||||
|
||||
int lowerCamelCase(int);
|
||||
int Lower_camel_case_1(int);
|
||||
int Lower_camel_case_2(int);
|
||||
int Lower_camel_case_3(int);
|
||||
|
||||
enum HelloEnum {
|
||||
hello, hi_there
|
||||
};
|
||||
|
||||
|
||||
enum ChaoEnum {
|
||||
bye, see_you
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue