blob: 472e28adbc685777d03643df1b523897d4257f55 [file] [log] [blame]
Greg Aker052b01d2011-04-21 14:38:03 -05001<?php
2
3require_once(BASEPATH.'helpers/inflector_helper.php');
4
Greg Akerb4d93db2011-04-21 14:42:33 -05005class Inflector_helper_test extends CI_TestCase {
Greg Aker052b01d2011-04-21 14:38:03 -05006
7
Eric Barnes68286a42011-04-21 22:00:33 -04008 public function test_singular()
Greg Aker052b01d2011-04-21 14:38:03 -05009 {
10 $strs = array(
11 'tellies' => 'telly',
12 'smellies' => 'smelly',
13 'abjectnesses' => 'abjectness',
Hamza Bhatti2a6a6162012-03-15 09:45:29 +040014 'smells' => 'smell',
15 'equipment' => 'equipment'
Greg Aker052b01d2011-04-21 14:38:03 -050016 );
17
18 foreach ($strs as $str => $expect)
19 {
20 $this->assertEquals($expect, singular($str));
21 }
22 }
23
24 // --------------------------------------------------------------------
25
Eric Barnes68286a42011-04-21 22:00:33 -040026 public function test_plural()
Greg Aker052b01d2011-04-21 14:38:03 -050027 {
28 $strs = array(
29 'telly' => 'tellies',
30 'smelly' => 'smellies',
Taufan Aditya8749bc72012-03-11 05:43:45 +070031 'abjectness' => 'abjectnesses', // ref : http://en.wiktionary.org/wiki/abjectnesses
Greg Aker052b01d2011-04-21 14:38:03 -050032 'smell' => 'smells',
Hamza Bhatti2a6a6162012-03-15 09:45:29 +040033 'witch' => 'witches',
34 'equipment' => 'equipment'
Greg Aker052b01d2011-04-21 14:38:03 -050035 );
36
37 foreach ($strs as $str => $expect)
38 {
39 $this->assertEquals($expect, plural($str));
40 }
41 }
42
43 // --------------------------------------------------------------------
44
Eric Barnes68286a42011-04-21 22:00:33 -040045 public function test_camelize()
Greg Aker052b01d2011-04-21 14:38:03 -050046 {
47 $strs = array(
48 'this is the string' => 'thisIsTheString',
49 'this is another one' => 'thisIsAnotherOne',
50 'i-am-playing-a-trick' => 'i-am-playing-a-trick',
51 'what_do_you_think-yo?' => 'whatDoYouThink-yo?',
52 );
53
54 foreach ($strs as $str => $expect)
55 {
56 $this->assertEquals($expect, camelize($str));
57 }
58 }
59
60 // --------------------------------------------------------------------
61
Eric Barnes68286a42011-04-21 22:00:33 -040062 public function test_underscore()
Greg Aker052b01d2011-04-21 14:38:03 -050063 {
64 $strs = array(
65 'this is the string' => 'this_is_the_string',
66 'this is another one' => 'this_is_another_one',
67 'i-am-playing-a-trick' => 'i-am-playing-a-trick',
68 'what_do_you_think-yo?' => 'what_do_you_think-yo?',
69 );
70
71 foreach ($strs as $str => $expect)
72 {
73 $this->assertEquals($expect, underscore($str));
74 }
75 }
76
77 // --------------------------------------------------------------------
78
Eric Barnes68286a42011-04-21 22:00:33 -040079 public function test_humanize()
Greg Aker052b01d2011-04-21 14:38:03 -050080 {
81 $strs = array(
82 'this_is_the_string' => 'This Is The String',
83 'this_is_another_one' => 'This Is Another One',
84 'i-am-playing-a-trick' => 'I-am-playing-a-trick',
85 'what_do_you_think-yo?' => 'What Do You Think-yo?',
86 );
87
88 foreach ($strs as $str => $expect)
89 {
90 $this->assertEquals($expect, humanize($str));
91 }
92 }
93}