diff --git a/DN.VariableResolver.pas b/DN.VariableResolver.pas index b0dfad5..e3735f7 100644 --- a/DN.VariableResolver.pas +++ b/DN.VariableResolver.pas @@ -38,6 +38,8 @@ constructor TVariableResolver.Create(const AVariables, AValues: array of string) inherited Create(); FVariables := OpenToDynamicArray(AVariables); FValues := OpenToDynamicArray(AValues); + if Length(FVariables) <> Length(FValues) then + raise EArgumentException.Create('Number of elements in Variables argument does not match number of elements in Values argument'); end; function TVariableResolver.Resolve(const AText: string): string; diff --git a/Tests/Tests.VariableResolver.pas b/Tests/Tests.VariableResolver.pas new file mode 100644 index 0000000..5c8e7a5 --- /dev/null +++ b/Tests/Tests.VariableResolver.pas @@ -0,0 +1,84 @@ +unit Tests.VariableResolver; + +interface + +uses + TestFramework, + DN.VariableResolver, + DN.VariableResolver.Intf; + +type + TVariableResolverTest = class(TTestCase) + protected + FSut: IVariableResolver; + procedure SetUp; override; + procedure TearDown; override; + published + procedure Create_UnevenVarValueLists_Expect_Exception; + procedure Resolve_ExistingVar_CorrectCase_Expect_Resolved; + procedure Resolve_ExistingVar_DifferentCase_Expect_Resolved; + procedure Resolve_UnknownVar_Expect_Untouched; + procedure Resolve_TextWithoutVars_IncludingIdentifierOfExistingVar_Expect_Untouched; + end; + +implementation + +uses + SysUtils; + +const + CTestInputA = 'Here is some $(FooVar)'; + CTestOutputA = 'Here is some FooVal'; + CTestInputB = 'Here is some $(foovar) for you'; + CTestOutputB = 'Here is some FooVal for you'; + CTestInputC = 'Here is some $(unknown) for you'; + CTestOutputC = CTestInputC; + CTestInputD = 'Here is some FooVar for you'; + CTestOutputD = CTestInputD; + +{ TVariableReplacementTest } + + +procedure TVariableResolverTest.Create_UnevenVarValueLists_Expect_Exception; +begin + ExpectedException := EArgumentException; + FSut := TVariableResolver.Create(['Val'], []); +end; + +procedure TVariableResolverTest.Resolve_ExistingVar_CorrectCase_Expect_Resolved; +begin + CheckEquals(CTestOutputA, FSut.Resolve(CTestInputA)); +end; + +procedure TVariableResolverTest.Resolve_ExistingVar_DifferentCase_Expect_Resolved; +begin + CheckEquals(CTestOutputB, FSut.Resolve(CTestInputB)); +end; + +procedure TVariableResolverTest.Resolve_TextWithoutVars_IncludingIdentifierOfExistingVar_Expect_Untouched; +begin + CheckEquals(CTestOutputD, FSut.Resolve(CTestInputD)); +end; + +procedure TVariableResolverTest.Resolve_UnknownVar_Expect_Untouched; +begin + CheckEquals(CTestOutputC, FSut.Resolve(CTestInputC)); +end; + +procedure TVariableResolverTest.SetUp; +begin + inherited; + FSut := TVariableResolver.Create(['FooVar'], ['FooVal']); +end; + +procedure TVariableResolverTest.TearDown; +begin + inherited; + FSut := nil; +end; + +initialization; + +RegisterTest(TVariableResolverTest.Suite); + +end. diff --git a/Tests/Tests.dpr b/Tests/Tests.dpr new file mode 100644 index 0000000..d5e0b35 --- /dev/null +++ b/Tests/Tests.dpr @@ -0,0 +1,28 @@ +program Tests; +{ + + Delphi DUnit Test Project + ------------------------- + This project contains the DUnit test framework and the GUI/Console test runners. + Add "CONSOLE_TESTRUNNER" to the conditional defines entry in the project options + to use the console test runner. Otherwise the GUI test runner will be used by + default. + +} + +{$IFDEF CONSOLE_TESTRUNNER} + {$IFNDEF TESTINSIGHT} + {$APPTYPE CONSOLE} + {$ENDIF} +{$ENDIF} + +uses + TestInsight.DUnit, + Tests.VariableResolver in 'Tests.VariableResolver.pas'; + +{$R *.RES} + +begin + RunRegisteredTests(); +end. + diff --git a/Tests/Tests.dproj b/Tests/Tests.dproj new file mode 100644 index 0000000..813e3a0 --- /dev/null +++ b/Tests/Tests.dproj @@ -0,0 +1,141 @@ + + + {2526018A-5A5F-4EB7-A812-F0E2AE7A7EB1} + 15.4 + None + True + Debug + Win32 + 1 + Console + Tests.dpr + + + true + + + true + Base + true + + + true + Base + true + + + true + Base + true + + + true + Base + true + + + true + Cfg_1 + true + true + + + true + Base + true + + + CompanyName=;FileDescription=;FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProductName=;ProductVersion=1.0.0.0;Comments= + None + 1031 + $(BDS)\Source\DUnit\src;..;$(DCC_UnitSearchPath) + System;Xml;Data;Datasnap;Web;Soap;Vcl;Vcl.Imaging;Vcl.Touch;Vcl.Samples;Vcl.Shell;$(DCC_Namespace) + CONSOLE_TESTRUNNER;TESTINSIGHT;$(DCC_Define) + Tests + . + .\$(Platform)\$(Config) + false + false + false + false + false + + + FireDACASADriver;FireDACSqliteDriver;bindcompfmx;DBXSqliteDriver;FireDACPgDriver;FireDACODBCDriver;RESTBackendComponents;fmx;rtl;dbrtl;DbxClientDriver;IndySystem;FireDACCommon;bindcomp;inetdb;tethering;DBXInterBaseDriver;xmlrtl;DbxCommonDriver;IndyProtocols;dbxcds;DBXMySQLDriver;FireDACCommonDriver;bindcompdbx;soaprtl;bindengine;FMXTee;fmxFireDAC;FireDACADSDriver;CustomIPTransport;FireDAC;dsnap;IndyIPServer;fmxase;IndyCore;IndyIPCommon;CloudService;FireDACIBDriver;FmxTeeUI;inet;fmxobj;FireDACMySQLDriver;soapmidas;soapserver;inetdbxpress;dsnapxml;fmxdae;RESTComponents;FireDACMSAccDriver;dbexpress;IndyIPClient;$(DCC_UsePackage) + + + FireDACASADriver;FireDACSqliteDriver;bindcompfmx;DBXSqliteDriver;vcldbx;FireDACPgDriver;FireDACODBCDriver;RESTBackendComponents;fmx;rtl;dbrtl;DbxClientDriver;IndySystem;FireDACCommon;bindcomp;inetdb;tethering;TeeDB;inetdbbde;DBXInterBaseDriver;Tee;vclFireDAC;xmlrtl;svnui;DbxCommonDriver;vclimg;IndyProtocols;dbxcds;DBXMySQLDriver;FireDACCommonDriver;MetropolisUILiveTile;bindcompdbx;soaprtl;bindengine;vclactnband;vcldb;vcldsnap;bindcompvcl;FMXTee;TeeUI;vclie;fmxFireDAC;FireDACADSDriver;vcltouch;CustomIPTransport;vclribbon;VclSmp;FireDAC;dsnap;IndyIPServer;VCLRESTComponents;fmxase;vcl;IndyCore;IndyIPCommon;CloudService;dsnapcon;FireDACIBDriver;FmxTeeUI;inet;fmxobj;FireDACMySQLDriver;soapmidas;vclx;soapserver;inetdbxpress;svn;dsnapxml;fmxdae;RESTComponents;bdertl;VirtualTreesR;OmniThreadLibraryRuntimeXE6;FireDACMSAccDriver;dbexpress;adortl;IndyIPClient;$(DCC_UsePackage) + 1033 + Winapi;System.Win;Data.Win;Datasnap.Win;Web.Win;Soap.Win;Xml.Win;Bde;$(DCC_Namespace) + CompanyName=;FileDescription=;FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProductName=;ProductVersion=1.0.0.0;Comments= + + + FireDACASADriver;FireDACSqliteDriver;bindcompfmx;DBXSqliteDriver;FireDACPgDriver;FireDACODBCDriver;RESTBackendComponents;fmx;rtl;dbrtl;DbxClientDriver;IndySystem;FireDACCommon;bindcomp;inetdb;tethering;TeeDB;DBXInterBaseDriver;Tee;vclFireDAC;xmlrtl;DbxCommonDriver;vclimg;IndyProtocols;dbxcds;DBXMySQLDriver;FireDACCommonDriver;MetropolisUILiveTile;bindcompdbx;soaprtl;bindengine;vclactnband;vcldb;vcldsnap;bindcompvcl;FMXTee;TeeUI;vclie;fmxFireDAC;FireDACADSDriver;vcltouch;CustomIPTransport;vclribbon;VclSmp;FireDAC;dsnap;IndyIPServer;VCLRESTComponents;fmxase;vcl;IndyCore;IndyIPCommon;CloudService;dsnapcon;FireDACIBDriver;FmxTeeUI;inet;fmxobj;FireDACMySQLDriver;soapmidas;vclx;soapserver;inetdbxpress;dsnapxml;fmxdae;RESTComponents;VirtualTreesR;FireDACMSAccDriver;dbexpress;adortl;IndyIPClient;$(DCC_UsePackage) + + + DEBUG;$(DCC_Define) + true + false + true + true + true + + + 1033 + None + false + + + false + RELEASE;$(DCC_Define) + 0 + 0 + + + + MainSource + + + + Cfg_2 + Base + + + Base + + + Cfg_1 + Base + + + + Delphi.Personality.12 + + + + + Tests.dpr + + + Microsoft Office 2000 Sample Automation Server Wrapper Components + Microsoft Office XP Sample Automation Server Wrapper Components + + + + + False + True + False + + + DUnit / Delphi Win32 + Console + + + + + 12 + + + +