From 6b7fd633b9866806a37beca1e9a099a0dc24d68d Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Sat, 25 Jun 2016 16:22:40 +0200 Subject: Add function to ellipsize text Signed-off-by: Florian Pritz --- application/test/tests/test_service_files.php | 32 +++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'application/test/tests') diff --git a/application/test/tests/test_service_files.php b/application/test/tests/test_service_files.php index 21688230f..401ddbe86 100644 --- a/application/test/tests/test_service_files.php +++ b/application/test/tests/test_service_files.php @@ -80,6 +80,38 @@ class test_service_files extends \test\Test { } } + public function test_ellipsize() + { + $a1 = "abc"; + $a2 = "abc\nabc"; + $a3 = "abc\nabc\nabc"; + $a4 = "abc\nabc\nabc\nabc"; + + $this->t->is(\service\files::ellipsize($a1, 1, strlen($a1)), + $a1, "Trim 1 line to 1, no change"); + + $this->t->is(\service\files::ellipsize($a3, 3, strlen($a3)), + $a3, "Trim 3 lines to 3, no change"); + + $this->t->is(\service\files::ellipsize($a3, 5, strlen($a3)), + $a3, "Trim 3 lines to 5, no change"); + + $this->t->is(\service\files::ellipsize($a2, 1, strlen($a2)), + "$a1\n...", "Trim 2 lines to 1, drop one line"); + + $this->t->is(\service\files::ellipsize($a3, 2, strlen($a3)), + "$a2\n...", "Trim 3 lines to 2, drop one line"); + + $this->t->is(\service\files::ellipsize($a4, 2, strlen($a4)), + "$a2\n...", "Trim 4 lines to 2, drop 2 lines"); + + $this->t->is(\service\files::ellipsize($a3, 3, strlen($a3) + 1), + "$a2\n...", "Last line incomplete, drop one line"); + + $this->t->is(\service\files::ellipsize($a1, 5, strlen($a1) + 1), + "$a1 ...", "Single line incomplete, only add dots"); + } + } -- cgit v1.2.3-24-g4f1b