Guest User

Giorgio Sironi

a guest
Oct 20th, 2009
327
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. class RegexTest extends PHPUnit_Framework_TestCase
  4. {
  5.     public function testSimpleRegex()
  6.     {
  7.         $this->assertEquals(1, preg_match('/foo/', 'foo'));
  8.         $this->assertEquals(1, preg_match('/foo/', 'my fooooo'));
  9.         $this->assertEquals(1, preg_match('/f.o/', 'my foo'));
  10.         $this->assertEquals(1, preg_match('/[foym ]/', 'my foo'));
  11.         $this->assertEquals(0, preg_match('/[fom ]{6}/', 'my foo'));
  12.     }
  13.  
  14.     public function testMailAddresses()
  15.     {
  16.         $this->assertEquals(1, preg_match('/[a-z]{1,}@gmail.com/', 'address@gmail.com'));
  17.         $this->assertEquals(0, preg_match('/[a-z]{1,}@gmail.com/', '@gmail.com'));
  18.         $this->assertEquals(1, preg_match('/[a-z]{1,}@[a-z.]{3,}/', 'address@gmail.com'));
  19.         $this->assertEquals(0, preg_match('/[a-z]{1,}@[a-z]{1,}\.[a-z.]{2,}/', 'address@gmail'));
  20.         $this->assertEquals(1, preg_match('/[a-z]{1,}@[a-z]{1,}\.[a-z.]{2,}/', 'address@gmail.com'));
  21.     }
  22.  
  23.     public function testBackReferences()
  24.     {
  25.         $matches = array();
  26.         $this->assertEquals(1, preg_match('/([a-z]{1,})@[a-z.]{1,}/', 'address@gmail.com', $matches));
  27.         $this->assertEquals('address', $matches[1]);
  28.  
  29.         $matches = array();
  30.         $this->assertEquals(1, preg_match('/([a-z]{1,})@([a-z.]{1,}\.([a-z]{1,}))/', 'address@gmail.com', $matches));
  31.         $this->assertEquals('address', $matches[1]);
  32.         $this->assertEquals('gmail.com', $matches[2]);
  33.         $this->assertEquals('com', $matches[3]);
  34.     }
  35. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×