forked from zamronypj/fano
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement explode() and improve unit test
- Loading branch information
Showing
12 changed files
with
267 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{*! | ||
* Fano Web Framework (https://fanoframework.github.io) | ||
* | ||
* @link https://github.com/fanoframework/fano | ||
* @copyright Copyright (c) 2018 - 2022 Zamrony P. Juhara | ||
* @license https://github.com/fanoframework/fano/blob/master/LICENSE (MIT) | ||
*} | ||
|
||
unit HelpersTest; | ||
|
||
interface | ||
|
||
{$MODE OBJFPC} | ||
{$H+} | ||
|
||
uses | ||
|
||
fpcunit, | ||
testregistry, | ||
StringUtilsTest; | ||
|
||
implementation | ||
end. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
{*! | ||
* Fano Web Framework (https://fanoframework.github.io) | ||
* | ||
* @link https://github.com/fanoframework/fano | ||
* @copyright Copyright (c) 2018 - 2022 Zamrony P. Juhara | ||
* @license https://github.com/fanoframework/fano/blob/master/LICENSE (MIT) | ||
*} | ||
|
||
unit StringUtilsTest; | ||
|
||
interface | ||
|
||
{$MODE OBJFPC} | ||
{$H+} | ||
|
||
uses | ||
|
||
fpcunit, | ||
testregistry, | ||
SysUtils, | ||
StringUtils; | ||
|
||
type | ||
|
||
(*!------------------------------------------------ | ||
* string utilities test case | ||
*-------------------------------------------------- | ||
* @author Zamrony P. Juhara <[email protected]> | ||
*-------------------------------------------------*) | ||
TStringUtilsTest = class(TTestCase) | ||
protected | ||
procedure Setup(); override; | ||
procedure TearDown(); override; | ||
published | ||
procedure TestJoinMultipleShouldPass(); | ||
procedure TestJoinSingleShouldPass(); | ||
procedure TestJoinEmptyShouldPass(); | ||
procedure TestExplodeEmptyShouldPass(); | ||
procedure TestExplodeSingleShouldPass(); | ||
procedure TestExplodeMultipleShouldPass(); | ||
procedure TestSlugShouldReturnCorrectSlug(); | ||
end; | ||
|
||
implementation | ||
|
||
|
||
procedure TStringUtilsTest.Setup(); | ||
begin | ||
end; | ||
|
||
procedure TStringUtilsTest.TearDown(); | ||
begin | ||
end; | ||
|
||
procedure TStringUtilsTest.TestJoinMultipleShouldPass(); | ||
var joinedStr : string; | ||
begin | ||
joinedStr := join('&', [ 'a=b', 'c=d', 'e=f']); | ||
AssertEquals('a=b&c=d&e=f', joinedStr); | ||
end; | ||
|
||
procedure TStringUtilsTest.TestJoinEmptyShouldPass(); | ||
var joinedStr : string; | ||
begin | ||
joinedStr := join('&', []); | ||
AssertEquals('', joinedStr); | ||
end; | ||
|
||
procedure TStringUtilsTest.TestJoinSingleShouldPass(); | ||
var joinedStr : string; | ||
begin | ||
joinedStr := join('&', [ 'a=b']); | ||
AssertEquals('a=b', joinedStr); | ||
end; | ||
|
||
procedure TStringUtilsTest.TestExplodeEmptyShouldPass(); | ||
var explodedStr : TStringArray; | ||
len : integer; | ||
begin | ||
explodedStr := explode('&', ''); | ||
len := length(explodedStr); | ||
AssertEquals(0, len); | ||
end; | ||
|
||
procedure TStringUtilsTest.TestExplodeSingleShouldPass(); | ||
var explodedStr : TStringArray; | ||
len : integer; | ||
begin | ||
explodedStr := explode('&', 'a=b'); | ||
len := length(explodedStr); | ||
AssertEquals(len, 1); | ||
AssertEquals('a=b', explodedStr[0]); | ||
end; | ||
|
||
procedure TStringUtilsTest.TestExplodeMultipleShouldPass(); | ||
var explodedStr : TStringArray; | ||
len : integer; | ||
begin | ||
explodedStr := explode('&', 'a=b&c=d&e=f'); | ||
len := length(explodedStr); | ||
AssertEquals(3, len); | ||
AssertEquals('a=b', explodedStr[0]); | ||
AssertEquals('c=d', explodedStr[1]); | ||
AssertEquals('e=f', explodedStr[2]); | ||
end; | ||
|
||
procedure TStringUtilsTest.TestSlugShouldReturnCorrectSlug(); | ||
begin | ||
AssertEquals('', slug('')); | ||
AssertEquals('', slug(' ')); | ||
AssertEquals('test-hei-slug-to-slug-10', slug('test hei$#@slug to Slug 10')); | ||
AssertEquals('test-hei-slug-to-slug-10', slug(' test hei$#@slug to Slug 10 ')); | ||
AssertEquals('test-hei-slug-to-slug-10', slug('@#@!test hei$#@slug to Slug 10#@@')); | ||
AssertEquals('test-hei-slug-to-slug-10', slug('@#@!test---hei$#@slug-to Slug 10#@@')); | ||
AssertEquals('test-hei-slug-to-slug-10', slug('@#@!test--^-hei$#@slug-to Slug 10#@@')); | ||
end; | ||
|
||
initialization | ||
RegisterTest(TStringUtilsTest); | ||
end. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.