Skip to content

Commit

Permalink
Add Script Builder Methods for Text & Integer
Browse files Browse the repository at this point in the history
  • Loading branch information
steeffeen-zz committed Jun 4, 2017
1 parent e880b21 commit 90d1edc
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
24 changes: 24 additions & 0 deletions FML/Script/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,30 @@ public static function getId(Identifiable $element)
return static::escapeText($element->getId(), false);
}

/**
* Get the 'Text' string representation of the given value
*
* @api
* @param string $value String value to convert to a ManiaScript 'Text'
* @return string
*/
public static function getText($value)
{
return '"' . (string)$value . '"';
}

/**
* Get the 'Integer' string representation of the given value
*
* @api
* @param int $value Int value to convert to a ManiaScript 'Integer'
* @return string
*/
public static function getInteger($value)
{
return (string)(int)$value;
}

/**
* Get the 'Real' string representation of the given value
*
Expand Down
14 changes: 14 additions & 0 deletions tests/Script/BuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,20 @@ public function testId()
$this->assertEquals("other\\\"id", Builder::getId(new Label("other\"id")));
}

public function testText()
{
$this->assertEquals('"Test Text"', Builder::getText("Test Text"));
$this->assertEquals('""', Builder::getText(null));
$this->assertEquals('"13"', Builder::getText(13));
}

public function testInteger()
{
$this->assertEquals("13", Builder::getInteger(13));
$this->assertEquals("0", Builder::getInteger(null));
$this->assertEquals("-42", Builder::getInteger(-42));
}

public function testReal()
{
$this->assertEquals("13.42", Builder::getReal(13.42));
Expand Down

0 comments on commit 90d1edc

Please sign in to comment.