Greg Aker | 052b01d | 2011-04-21 14:38:03 -0500 | [diff] [blame] | 1 | <?php |
| 2 | |
Greg Aker | b4d93db | 2011-04-21 14:42:33 -0500 | [diff] [blame] | 3 | class Inflector_helper_test extends CI_TestCase { |
Andrey Andreev | 99b782d | 2012-06-09 22:24:46 +0300 | [diff] [blame] | 4 | |
Taufan Aditya | e1dc9ea | 2012-03-28 16:49:49 +0700 | [diff] [blame] | 5 | public function set_up() |
| 6 | { |
| 7 | $this->helper('inflector'); |
| 8 | } |
Andrey Andreev | 99b782d | 2012-06-09 22:24:46 +0300 | [diff] [blame] | 9 | |
Eric Barnes | 68286a4 | 2011-04-21 22:00:33 -0400 | [diff] [blame] | 10 | public function test_singular() |
Greg Aker | 052b01d | 2011-04-21 14:38:03 -0500 | [diff] [blame] | 11 | { |
| 12 | $strs = array( |
Andrey Andreev | 3ddd564 | 2014-02-17 17:31:23 +0200 | [diff] [blame] | 13 | 'tellies' => 'telly', |
| 14 | 'smellies' => 'smelly', |
| 15 | 'abjectnesses' => 'abjectness', |
| 16 | 'smells' => 'smell', |
| 17 | 'equipment' => 'equipment' |
Greg Aker | 052b01d | 2011-04-21 14:38:03 -0500 | [diff] [blame] | 18 | ); |
Andrey Andreev | 99b782d | 2012-06-09 22:24:46 +0300 | [diff] [blame] | 19 | |
Greg Aker | 052b01d | 2011-04-21 14:38:03 -0500 | [diff] [blame] | 20 | foreach ($strs as $str => $expect) |
| 21 | { |
| 22 | $this->assertEquals($expect, singular($str)); |
| 23 | } |
| 24 | } |
Andrey Andreev | 99b782d | 2012-06-09 22:24:46 +0300 | [diff] [blame] | 25 | |
Greg Aker | 052b01d | 2011-04-21 14:38:03 -0500 | [diff] [blame] | 26 | // -------------------------------------------------------------------- |
Andrey Andreev | 99b782d | 2012-06-09 22:24:46 +0300 | [diff] [blame] | 27 | |
Eric Barnes | 68286a4 | 2011-04-21 22:00:33 -0400 | [diff] [blame] | 28 | public function test_plural() |
Greg Aker | 052b01d | 2011-04-21 14:38:03 -0500 | [diff] [blame] | 29 | { |
| 30 | $strs = array( |
Andrey Andreev | 3ddd564 | 2014-02-17 17:31:23 +0200 | [diff] [blame] | 31 | 'telly' => 'tellies', |
| 32 | 'smelly' => 'smellies', |
| 33 | 'abjectness' => 'abjectnesses', // ref : http://en.wiktionary.org/wiki/abjectnesses |
| 34 | 'smell' => 'smells', |
| 35 | 'witch' => 'witches', |
| 36 | 'equipment' => 'equipment' |
Greg Aker | 052b01d | 2011-04-21 14:38:03 -0500 | [diff] [blame] | 37 | ); |
Andrey Andreev | 99b782d | 2012-06-09 22:24:46 +0300 | [diff] [blame] | 38 | |
Greg Aker | 052b01d | 2011-04-21 14:38:03 -0500 | [diff] [blame] | 39 | foreach ($strs as $str => $expect) |
| 40 | { |
| 41 | $this->assertEquals($expect, plural($str)); |
Andrey Andreev | 99b782d | 2012-06-09 22:24:46 +0300 | [diff] [blame] | 42 | } |
| 43 | } |
Greg Aker | 052b01d | 2011-04-21 14:38:03 -0500 | [diff] [blame] | 44 | |
| 45 | // -------------------------------------------------------------------- |
Andrey Andreev | 99b782d | 2012-06-09 22:24:46 +0300 | [diff] [blame] | 46 | |
Eric Barnes | 68286a4 | 2011-04-21 22:00:33 -0400 | [diff] [blame] | 47 | public function test_camelize() |
Greg Aker | 052b01d | 2011-04-21 14:38:03 -0500 | [diff] [blame] | 48 | { |
| 49 | $strs = array( |
| 50 | 'this is the string' => 'thisIsTheString', |
Andrey Andreev | 3ddd564 | 2014-02-17 17:31:23 +0200 | [diff] [blame] | 51 | 'this is another one' => 'thisIsAnotherOne', |
| 52 | 'i-am-playing-a-trick' => 'i-am-playing-a-trick', |
| 53 | 'what_do_you_think-yo?' => 'whatDoYouThink-yo?', |
Greg Aker | 052b01d | 2011-04-21 14:38:03 -0500 | [diff] [blame] | 54 | ); |
Andrey Andreev | 99b782d | 2012-06-09 22:24:46 +0300 | [diff] [blame] | 55 | |
Greg Aker | 052b01d | 2011-04-21 14:38:03 -0500 | [diff] [blame] | 56 | foreach ($strs as $str => $expect) |
| 57 | { |
| 58 | $this->assertEquals($expect, camelize($str)); |
| 59 | } |
Andrey Andreev | 99b782d | 2012-06-09 22:24:46 +0300 | [diff] [blame] | 60 | } |
Greg Aker | 052b01d | 2011-04-21 14:38:03 -0500 | [diff] [blame] | 61 | |
| 62 | // -------------------------------------------------------------------- |
Andrey Andreev | 99b782d | 2012-06-09 22:24:46 +0300 | [diff] [blame] | 63 | |
Eric Barnes | 68286a4 | 2011-04-21 22:00:33 -0400 | [diff] [blame] | 64 | public function test_underscore() |
Greg Aker | 052b01d | 2011-04-21 14:38:03 -0500 | [diff] [blame] | 65 | { |
| 66 | $strs = array( |
Andrey Andreev | 3ddd564 | 2014-02-17 17:31:23 +0200 | [diff] [blame] | 67 | 'this is the string' => 'this_is_the_string', |
| 68 | 'this is another one' => 'this_is_another_one', |
| 69 | 'i-am-playing-a-trick' => 'i-am-playing-a-trick', |
| 70 | 'what_do_you_think-yo?' => 'what_do_you_think-yo?', |
Greg Aker | 052b01d | 2011-04-21 14:38:03 -0500 | [diff] [blame] | 71 | ); |
Andrey Andreev | 99b782d | 2012-06-09 22:24:46 +0300 | [diff] [blame] | 72 | |
Greg Aker | 052b01d | 2011-04-21 14:38:03 -0500 | [diff] [blame] | 73 | foreach ($strs as $str => $expect) |
| 74 | { |
| 75 | $this->assertEquals($expect, underscore($str)); |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | // -------------------------------------------------------------------- |
Andrey Andreev | 99b782d | 2012-06-09 22:24:46 +0300 | [diff] [blame] | 80 | |
Eric Barnes | 68286a4 | 2011-04-21 22:00:33 -0400 | [diff] [blame] | 81 | public function test_humanize() |
Greg Aker | 052b01d | 2011-04-21 14:38:03 -0500 | [diff] [blame] | 82 | { |
| 83 | $strs = array( |
Andrey Andreev | 3ddd564 | 2014-02-17 17:31:23 +0200 | [diff] [blame] | 84 | 'this_is_the_string' => 'This Is The String', |
| 85 | 'this_is_another_one' => 'This Is Another One', |
| 86 | 'i-am-playing-a-trick' => 'I-am-playing-a-trick', |
| 87 | 'what_do_you_think-yo?' => 'What Do You Think-yo?', |
Greg Aker | 052b01d | 2011-04-21 14:38:03 -0500 | [diff] [blame] | 88 | ); |
Andrey Andreev | 99b782d | 2012-06-09 22:24:46 +0300 | [diff] [blame] | 89 | |
Greg Aker | 052b01d | 2011-04-21 14:38:03 -0500 | [diff] [blame] | 90 | foreach ($strs as $str => $expect) |
| 91 | { |
| 92 | $this->assertEquals($expect, humanize($str)); |
| 93 | } |
| 94 | } |
Andrey Andreev | 99b782d | 2012-06-09 22:24:46 +0300 | [diff] [blame] | 95 | |
Andrey Andreev | 12ee984 | 2018-06-01 18:07:34 +0300 | [diff] [blame^] | 96 | } |