ConditionChecks.dpr 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. program ConditionChecks;
  2. {$APPTYPE CONSOLE}
  3. {$R *.res}
  4. uses
  5. Classes,
  6. System.SysUtils,
  7. Quick.Console,
  8. Quick.Conditions;
  9. type
  10. EMyException = class(Exception);
  11. var
  12. result : string;
  13. num : Int64;
  14. fnum : Double;
  15. obj : TStream;
  16. begin
  17. try
  18. //text must start with h and end with o
  19. result := 'Hello';
  20. Condition.Requires(result,'result')
  21. .IsNotEmpty
  22. .StartsWith('h',True)
  23. .EndsWith('o');
  24. //text longer than 10 and contains check
  25. result := 'Text to check';
  26. Condition.Requires(result,'result')
  27. .IsNotEmpty
  28. .IsLongerThan(10)
  29. .Contains('check',True);
  30. //text must be shorter than 10
  31. result := 'Text';
  32. Condition.Requires(result,'result')
  33. .IsNotEmpty
  34. .IsShorterThan(10);
  35. //text must be not lowercase
  36. result := 'Text';
  37. Condition.Requires(result,'result')
  38. .IsNotEmpty
  39. .IsNotLowerCase;
  40. //num min 1 and max 10
  41. num := 10;
  42. Condition.Requires(num,'num')
  43. .IsInRange(1,10,'value for num is out of range');
  44. fnum := 7.3;
  45. Condition.Requires(fnum,'fnum')
  46. .IsGreaterThan(5)
  47. .IsLessOrEqual(8)
  48. .IsNotInRange(6,7);
  49. obj := TStringStream.Create;
  50. Condition.Requires(obj,'obj')
  51. .WithExceptionOnFailure(EMyException)
  52. .IsNotNull
  53. .IsOfType(TStream)
  54. .Evaluate(obj.Size = 0);
  55. obj.Free;
  56. Condition.Ensures(obj,'obj')
  57. .IsNotNull;
  58. cout('All conditions passed!',ccGreen);
  59. ConsoleWaitForEnterKey;
  60. except
  61. on E: Exception do
  62. Writeln(E.ClassName, ': ', E.Message);
  63. end;
  64. end.