begin tests in core
This commit is contained in:
		
							parent
							
								
									5634ba6d97
								
							
						
					
					
						commit
						cdfc97d19b
					
				| @ -221,6 +221,8 @@ function parse_shorthand_int(string $limit): int { | |||||||
|  * @return string |  * @return string | ||||||
|  */ |  */ | ||||||
| function to_shorthand_int(int $int): string { | function to_shorthand_int(int $int): string { | ||||||
|  | 	assert($int >= 0); | ||||||
|  | 
 | ||||||
| 	if($int >= pow(1024, 3)) { | 	if($int >= pow(1024, 3)) { | ||||||
| 		return sprintf("%.1fGB", $int / pow(1024, 3)); | 		return sprintf("%.1fGB", $int / pow(1024, 3)); | ||||||
| 	} | 	} | ||||||
|  | |||||||
							
								
								
									
										43
									
								
								core/util.test.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										43
									
								
								core/util.test.php
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,43 @@ | |||||||
|  | <?php | ||||||
|  | require_once "util.inc.php"; | ||||||
|  | 
 | ||||||
|  | class CoreUtilIO extends \PHPUnit\Framework\TestCase { | ||||||
|  | 	public function test_html_escape() { | ||||||
|  | 		$this->assertEquals( | ||||||
|  | 			html_escape("Foo & <waffles>"), | ||||||
|  | 			"Foo & <waffles>" | ||||||
|  | 		); | ||||||
|  | 
 | ||||||
|  | 		$this->assertEquals( | ||||||
|  | 			html_unescape("Foo & <waffles>"), | ||||||
|  | 			"Foo & <waffles>" | ||||||
|  | 		); | ||||||
|  | 
 | ||||||
|  | 		$x = "Foo & <waffles>"; | ||||||
|  | 		$this->assertEquals(html_escape(html_unescape($x)), $x); | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	public function test_int_escape() { | ||||||
|  | 		$this->assertEquals(int_escape(""), 0); | ||||||
|  | 		$this->assertEquals(int_escape("1"), 1); | ||||||
|  | 		$this->assertEquals(int_escape("-1"), -1); | ||||||
|  | 		$this->assertEquals(int_escape("-1.5"), -1); | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	public function test_clamp() { | ||||||
|  | 		$this->assertEquals(clamp(0, 5, 10), 5); | ||||||
|  | 		$this->assertEquals(clamp(5, 5, 10), 5); | ||||||
|  | 		$this->assertEquals(clamp(7, 5, 10), 7); | ||||||
|  | 		$this->assertEquals(clamp(10, 5, 10), 10); | ||||||
|  | 		$this->assertEquals(clamp(15, 5, 10), 10); | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	public function test_shorthand_int() { | ||||||
|  | 		$this->assertEquals(to_shorthand_int(1231231231), "1.1GB"); | ||||||
|  | 
 | ||||||
|  | 		$this->assertEquals(parse_shorthand_int("foo"), -1); | ||||||
|  | 		$this->assertEquals(parse_shorthand_int("32M"), 33554432); | ||||||
|  | 		$this->assertEquals(parse_shorthand_int("43.4KB"), 44441); | ||||||
|  | 		$this->assertEquals(parse_shorthand_int("1231231231"), 1231231231); | ||||||
|  | 	} | ||||||
|  | } | ||||||
| @ -1,6 +1,9 @@ | |||||||
| <phpunit bootstrap="../tests/bootstrap.php" colors="true"> | <phpunit bootstrap="../tests/bootstrap.php" colors="true"> | ||||||
| 	<testsuites> | 	<testsuites> | ||||||
| 		<testsuite name="shimmie"> | 		<testsuite name="core"> | ||||||
|  | 			<directory suffix="test.php">../core/</directory> | ||||||
|  | 		</testsuite> | ||||||
|  | 		<testsuite name="ext"> | ||||||
| 			<directory suffix="test.php">../ext/</directory> | 			<directory suffix="test.php">../ext/</directory> | ||||||
| 		</testsuite> | 		</testsuite> | ||||||
| 	</testsuites> | 	</testsuites> | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user