blob: 81ce5e394dab5e16049a135898b6845143bcf832 [file] [log] [blame]
Greg Aker052b01d2011-04-21 14:38:03 -05001<?php
2
Greg Akerb4d93db2011-04-21 14:42:33 -05003class Inflector_helper_test extends CI_TestCase {
Andrey Andreev99b782d2012-06-09 22:24:46 +03004
Taufan Adityae1dc9ea2012-03-28 16:49:49 +07005 public function set_up()
6 {
7 $this->helper('inflector');
8 }
Andrey Andreev99b782d2012-06-09 22:24:46 +03009
Eric Barnes68286a42011-04-21 22:00:33 -040010 public function test_singular()
Greg Aker052b01d2011-04-21 14:38:03 -050011 {
12 $strs = array(
Andrey Andreev3ddd5642014-02-17 17:31:23 +020013 'tellies' => 'telly',
14 'smellies' => 'smelly',
15 'abjectnesses' => 'abjectness',
16 'smells' => 'smell',
17 'equipment' => 'equipment'
Greg Aker052b01d2011-04-21 14:38:03 -050018 );
Andrey Andreev99b782d2012-06-09 22:24:46 +030019
Greg Aker052b01d2011-04-21 14:38:03 -050020 foreach ($strs as $str => $expect)
21 {
22 $this->assertEquals($expect, singular($str));
23 }
24 }
Andrey Andreev99b782d2012-06-09 22:24:46 +030025
Greg Aker052b01d2011-04-21 14:38:03 -050026 // --------------------------------------------------------------------
Andrey Andreev99b782d2012-06-09 22:24:46 +030027
Eric Barnes68286a42011-04-21 22:00:33 -040028 public function test_plural()
Greg Aker052b01d2011-04-21 14:38:03 -050029 {
30 $strs = array(
Andrey Andreev3ddd5642014-02-17 17:31:23 +020031 '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 Aker052b01d2011-04-21 14:38:03 -050037 );
Andrey Andreev99b782d2012-06-09 22:24:46 +030038
Greg Aker052b01d2011-04-21 14:38:03 -050039 foreach ($strs as $str => $expect)
40 {
41 $this->assertEquals($expect, plural($str));
Andrey Andreev99b782d2012-06-09 22:24:46 +030042 }
43 }
Greg Aker052b01d2011-04-21 14:38:03 -050044
45 // --------------------------------------------------------------------
Andrey Andreev99b782d2012-06-09 22:24:46 +030046
Eric Barnes68286a42011-04-21 22:00:33 -040047 public function test_camelize()
Greg Aker052b01d2011-04-21 14:38:03 -050048 {
49 $strs = array(
50 'this is the string' => 'thisIsTheString',
Andrey Andreev3ddd5642014-02-17 17:31:23 +020051 '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 Aker052b01d2011-04-21 14:38:03 -050054 );
Andrey Andreev99b782d2012-06-09 22:24:46 +030055
Greg Aker052b01d2011-04-21 14:38:03 -050056 foreach ($strs as $str => $expect)
57 {
58 $this->assertEquals($expect, camelize($str));
59 }
Andrey Andreev99b782d2012-06-09 22:24:46 +030060 }
Greg Aker052b01d2011-04-21 14:38:03 -050061
62 // --------------------------------------------------------------------
Andrey Andreev99b782d2012-06-09 22:24:46 +030063
Eric Barnes68286a42011-04-21 22:00:33 -040064 public function test_underscore()
Greg Aker052b01d2011-04-21 14:38:03 -050065 {
66 $strs = array(
Andrey Andreev3ddd5642014-02-17 17:31:23 +020067 '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 Aker052b01d2011-04-21 14:38:03 -050071 );
Andrey Andreev99b782d2012-06-09 22:24:46 +030072
Greg Aker052b01d2011-04-21 14:38:03 -050073 foreach ($strs as $str => $expect)
74 {
75 $this->assertEquals($expect, underscore($str));
76 }
77 }
78
79 // --------------------------------------------------------------------
Andrey Andreev99b782d2012-06-09 22:24:46 +030080
Eric Barnes68286a42011-04-21 22:00:33 -040081 public function test_humanize()
Greg Aker052b01d2011-04-21 14:38:03 -050082 {
83 $strs = array(
Andrey Andreev3ddd5642014-02-17 17:31:23 +020084 '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 Aker052b01d2011-04-21 14:38:03 -050088 );
Andrey Andreev99b782d2012-06-09 22:24:46 +030089
Greg Aker052b01d2011-04-21 14:38:03 -050090 foreach ($strs as $str => $expect)
91 {
92 $this->assertEquals($expect, humanize($str));
93 }
94 }
Andrey Andreev99b782d2012-06-09 22:24:46 +030095
Greg Aker052b01d2011-04-21 14:38:03 -050096}