Skip to content

Commit 5f77567

Browse files
committed
added ExistsParam overload #135
1 parent e2b2dcd commit 5f77567

4 files changed

Lines changed: 170 additions & 3 deletions

File tree

Quick.Parameters.pas

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{ ***************************************************************************
22
3-
Copyright (c) 2016-2021 Kike Pérez
3+
Copyright (c) 2016-2021 Kike P�rez
44
55
Unit : Quick.Parameters
66
Description : Map comandline to class
7-
Author : Kike Pérez
7+
Author : Kike P�rez
88
Version : 1.4
99
Created : 12/07/2020
10-
Modified : 01/08/2021
10+
Modified : 01/03/2026
1111
1212
This file is part of QuickLib: https://github.com/exilon/QuickLib
1313
@@ -188,6 +188,7 @@ TParam = class
188188
function GetHelp : TStringList;
189189
property Help : Boolean read fHelp write fHelp;
190190
function ExistsParam(const aParam : string): Boolean; overload;
191+
function ExistsParam(const aParam, aValueSeparator : string): Boolean; overload;
191192
end;
192193
{$M-}
193194

@@ -329,6 +330,21 @@ function TParameters.ExistsParam(const aParam : string): Boolean;
329330
end;
330331
end;
331332

333+
function TParameters.ExistsParam(const aParam, aValueSeparator : string): Boolean;
334+
var
335+
param : TParam;
336+
begin
337+
param := TParam.Create;
338+
param.Name := aParam;
339+
param.Alias := '';
340+
param.ValueSeparator := aValueSeparator;
341+
try
342+
Result := ExistParam(param,param.Name);
343+
finally
344+
param.Free;
345+
end;
346+
end;
347+
332348
procedure TParameters.ParseParams;
333349
var
334350
param : TParam;

test/Quick.Parameters.Tests.pas

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
{ ***************************************************************************
2+
3+
Copyright (c) 2016-2026 Kike Pérez
4+
5+
Unit : Quick.Parameters.Tests
6+
Description : Tests for Quick.Parameters
7+
Author : Kike Pérez
8+
Version : 1.0
9+
Created : 01/03/2026
10+
Modified : 01/03/2026
11+
12+
This file is part of QuickLib: https://github.com/exilon/QuickLib
13+
14+
***************************************************************************
15+
16+
Licensed under the Apache License, Version 2.0 (the "License");
17+
you may not use this file except in compliance with the License.
18+
You may obtain a copy of the License at
19+
20+
http://www.apache.org/licenses/LICENSE-2.0
21+
22+
Unless required by applicable law or agreed to in writing, software
23+
distributed under the License is distributed on an "AS IS" BASIS,
24+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
25+
See the License for the specific language governing permissions and
26+
limitations under the License.
27+
28+
*************************************************************************** }
29+
30+
unit Quick.Parameters.Tests;
31+
32+
{$i QuickLib.inc}
33+
34+
interface
35+
36+
uses
37+
DUnitX.TestFramework,
38+
Quick.Parameters;
39+
40+
type
41+
// Minimal TParameters subclass with no published properties,
42+
// so ParseParams does not raise ERequiredParameterNotFound.
43+
TTestParameters = class(TParameters)
44+
published
45+
end;
46+
47+
[TestFixture]
48+
TQuickParametersTests = class
49+
private
50+
fParams : TTestParameters;
51+
public
52+
[Setup]
53+
procedure SetUp;
54+
[TearDown]
55+
procedure TearDown;
56+
57+
// ExistsParam single-arg overload (default '=' separator)
58+
[Test]
59+
procedure Test_ExistsParam_NonExistentParam_ReturnsFalse;
60+
[Test]
61+
procedure Test_ExistsParam_EmptyParam_ReturnsFalse;
62+
[Test]
63+
procedure Test_ExistsParam_DoesNotRaise;
64+
65+
// ExistsParam two-arg overload (custom separator — issue #135)
66+
[Test]
67+
procedure Test_ExistsParam_WithCustomSeparator_NonExistentParam_ReturnsFalse;
68+
[Test]
69+
procedure Test_ExistsParam_WithColonSeparator_DoesNotRaise;
70+
[Test]
71+
procedure Test_ExistsParam_WithSpaceSeparator_DoesNotRaise;
72+
[Test]
73+
procedure Test_ExistsParam_DefaultAndCustomSeparator_SameResultForAbsentParam;
74+
end;
75+
76+
implementation
77+
78+
procedure TQuickParametersTests.SetUp;
79+
begin
80+
fParams := TTestParameters.Create(False);
81+
end;
82+
83+
procedure TQuickParametersTests.TearDown;
84+
begin
85+
fParams.Free;
86+
end;
87+
88+
procedure TQuickParametersTests.Test_ExistsParam_NonExistentParam_ReturnsFalse;
89+
begin
90+
Assert.IsFalse(fParams.ExistsParam('__nonexistent_param_xyz__'),
91+
'A param that is not on the command line must return False');
92+
end;
93+
94+
procedure TQuickParametersTests.Test_ExistsParam_EmptyParam_ReturnsFalse;
95+
begin
96+
Assert.IsFalse(fParams.ExistsParam(''),
97+
'An empty param name must return False');
98+
end;
99+
100+
procedure TQuickParametersTests.Test_ExistsParam_DoesNotRaise;
101+
begin
102+
Assert.WillNotRaise(
103+
procedure begin fParams.ExistsParam('someParam'); end,
104+
nil,
105+
'ExistsParam with a valid param name must not raise an exception');
106+
end;
107+
108+
procedure TQuickParametersTests.Test_ExistsParam_WithCustomSeparator_NonExistentParam_ReturnsFalse;
109+
begin
110+
// Issue #135: the two-arg overload must honour the custom separator.
111+
// For a param that does not exist, the result must still be False.
112+
Assert.IsFalse(fParams.ExistsParam('__nonexistent_param_xyz__', ':'),
113+
'A param that is not on the command line must return False even with a custom separator');
114+
end;
115+
116+
procedure TQuickParametersTests.Test_ExistsParam_WithColonSeparator_DoesNotRaise;
117+
begin
118+
Assert.WillNotRaise(
119+
procedure begin fParams.ExistsParam('someParam', ':'); end,
120+
nil,
121+
'ExistsParam with colon separator must not raise an exception');
122+
end;
123+
124+
procedure TQuickParametersTests.Test_ExistsParam_WithSpaceSeparator_DoesNotRaise;
125+
begin
126+
Assert.WillNotRaise(
127+
procedure begin fParams.ExistsParam('someParam', ' '); end,
128+
nil,
129+
'ExistsParam with space separator must not raise an exception');
130+
end;
131+
132+
procedure TQuickParametersTests.Test_ExistsParam_DefaultAndCustomSeparator_SameResultForAbsentParam;
133+
var
134+
resultDefault : Boolean;
135+
resultCustom : Boolean;
136+
begin
137+
// For a param that is not present, both overloads should agree.
138+
resultDefault := fParams.ExistsParam('__absent__');
139+
resultCustom := fParams.ExistsParam('__absent__', ':');
140+
Assert.AreEqual(resultDefault, resultCustom,
141+
'Both overloads must return the same result when the param is absent');
142+
end;
143+
144+
initialization
145+
TDUnitX.RegisterTestFixture(TQuickParametersTests);
146+
147+
end.

test/QuickLib.dpr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ uses
9696
Quick.Pooling.Tests in 'Quick.Pooling.Tests.pas',
9797
Quick.Data.Redis in 'Quick.Data.Redis.pas',
9898
Quick.Data.Redis.Tests in 'Quick.Data.Redis.Tests.pas',
99+
Quick.Parameters in 'Quick.Parameters.pas',
100+
Quick.Parameters.Tests in 'Quick.Parameters.Tests.pas',
99101
Quick.Process in 'Quick.Process.pas',
100102
Quick.Process.Tests in 'Quick.Process.Tests.pas';
101103

test/QuickLib.dproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,8 @@
223223
<DCCReference Include="Quick.Pooling.Tests.pas"/>
224224
<DCCReference Include="Quick.Data.Redis.pas"/>
225225
<DCCReference Include="Quick.Data.Redis.Tests.pas"/>
226+
<DCCReference Include="Quick.Parameters.pas"/>
227+
<DCCReference Include="Quick.Parameters.Tests.pas"/>
226228
<DCCReference Include="Quick.Process.pas"/>
227229
<DCCReference Include="Quick.Process.Tests.pas"/>
228230
<BuildConfiguration Include="Base">

0 commit comments

Comments
 (0)