<?php
/**
 * @copyright  2009-2011 Roberto Perpuly
 *
 * This source may not be redistributed without prior consent.  Access to the 
 * source does not imply that you have consent to redistribute either this source
 * code or the generated binary. See LICENSE file for details.
 */

class StringTest extends PHPUnit_Framework_TestCase {

	function testEnsureEnds() {
		$this->assertEquals('/home/user/', \opstring\ensure_ends_with('/home/user', '/'));
		$this->assertEquals('/home/user/', \opstring\ensure_ends_with('/home/user/', '/'));
		$this->assertEquals('/home/user//', \opstring\ensure_ends_with('/home/user//', '/'));
	}
	
	function testBeginsWithShouldReturnTrue() {
		$this->assertEquals(TRUE, \opstring\begins_with('/home/users', '/home'));
		$this->assertEquals(TRUE, \opstring\begins_with('/home/users', '/'));
	}
	
	function testBeginsWithShouldReturnFalse() {
		$this->assertEquals(FALSE, \opstring\begins_with('/home/users', 'users'));
		$this->assertEquals(FALSE, \opstring\begins_with('/home/users', 'root'));
	}

	function testAfterShouldReturnText() {
		$this->assertEquals('gmail.com', \opstring\after('hello@gmail.com', '@'));
		$this->assertEquals('gmail.com', \opstring\after('hello@gmail.com', 'hello@'));
	}
	
	function testAfterShouldNotReturnText() {
		$this->assertEquals('', \opstring\after('hello@gmail.com', '.com'));
		$this->assertEquals(FALSE, \opstring\after('hello@gmail.com', 'csu.edu'));
	}
	
	function testBeforeShouldReturnText() {
		$this->assertEquals('hello', \opstring\before('hello@gmail.com', '@'));
		$this->assertEquals('hello', \opstring\before('hello@gmail.com', '@gmail.com'));
	}
	
	function testBeforeShouldNotReturnText() {
		$this->assertEquals('', \opstring\before('hello@gmail.com', 'hello'));
		$this->assertEquals(FALSE, \opstring\before('hello@gmail.com', 'csu.edu'));
	}
	
	function testReplaceShouldChangeAll() {
		$this->assertEquals('these ese a string', \opstring\replace('this is a string', 'is', 'ese'));
	}
	
	function testLength() {
		$this->assertEquals(5, \opstring\length('this '));
	}
	
	function testCompare() {
		$this->assertEquals(-1, \opstring\compare('that', 'this'));
		$this->assertEquals(0, \opstring\compare('this', 'this'));
		$this->assertEquals(1, \opstring\compare('this', 'that'));
		$this->assertEquals(1, \opstring\compare('this', 'thIS'));
	}
	
	function testCompareCase() {
		$this->assertEquals(-1, \opstring\compare_case('that', 'this'));
		$this->assertEquals(-1, \opstring\compare_case('that', 'thIS'));
		$this->assertEquals(0, \opstring\compare_case('this', 'this'));
		$this->assertEquals(0, \opstring\compare_case('this', 'thIS'));
		$this->assertEquals(1, \opstring\compare_case('this', 'that'));
		$this->assertEquals(1, \opstring\compare_case('this', 'thAT'));
		
	}
}