Skip to content

Commit

Permalink
Added Repository::format_list()
Browse files Browse the repository at this point in the history
  • Loading branch information
olvlvl committed Sep 19, 2016
1 parent 594cc43 commit acdd132
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
15 changes: 15 additions & 0 deletions lib/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,4 +150,19 @@ public function format_number($number, $pattern, array $symbols = [])
{
return $this->number_formatter->format($number, $pattern, $symbols);
}

/**
* Formats a variable-length lists of things.
*
* @param array $list The list to format.
* @param array $list_patterns A list patterns.
*
* @return string
*
* @see ListFormatter::format()
*/
public function format_list(array $list, array $list_patterns)
{
return $this->list_formatter->format($list, $list_patterns);
}
}
16 changes: 16 additions & 0 deletions tests/RepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,20 @@ public function test_format_number()
{
$this->assertSame("4,123.37", $this->repository->format_number(4123.37, "#,#00.#0"));
}

public function test_format_list()
{
$list = [ 'one', 'two', 'three' ];

$list_patterns = [

'start' => "{0}, {1}",
'middle' => "{0}, {1}",
'end' => "{0}, and {1}",
'2' => "{0} and {1}"

];

$this->assertSame("one, two, and three", $this->repository->format_list($list, $list_patterns));
}
}

0 comments on commit acdd132

Please sign in to comment.