diff options
author | Olly Betts <olly@survex.com> | 2022-03-07 09:07:47 +1300 |
---|---|---|
committer | Olly Betts <olly@survex.com> | 2022-03-07 09:11:50 +1300 |
commit | cf7bdcf2df98f5f7200788caa902896bdcd1151a (patch) | |
tree | 8e17163971292853ce8e856b900ae159fae3008e | |
parent | e1bb265bf7e2543b8a50f93f188ee319785bf66e (diff) | |
download | swig-cf7bdcf2df98f5f7200788caa902896bdcd1151a.tar.gz |
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.
-rw-r--r-- | Examples/test-suite/php/rename_camel_runme.php | 13 | ||||
-rw-r--r-- | Examples/test-suite/php/tests.php | 24 | ||||
-rw-r--r-- | Examples/test-suite/rename_camel.i | 39 |
3 files changed, 64 insertions, 12 deletions
diff --git a/Examples/test-suite/php/rename_camel_runme.php b/Examples/test-suite/php/rename_camel_runme.php new file mode 100644 index 000000000..becd20d47 --- /dev/null +++ b/Examples/test-suite/php/rename_camel_runme.php @@ -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(); diff --git a/Examples/test-suite/php/tests.php b/Examples/test-suite/php/tests.php index aa27ea09b..d092b5317 100644 --- a/Examples/test-suite/php/tests.php +++ b/Examples/test-suite/php/tests.php @@ -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; } diff --git a/Examples/test-suite/rename_camel.i b/Examples/test-suite/rename_camel.i index 0f4ae11a1..76d44b8a8 100644 --- a/Examples/test-suite/rename_camel.i +++ b/Examples/test-suite/rename_camel.i @@ -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 |