Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Passing tab character within string of a parameter in test case? #351

Closed
DaveMartel opened this issue Dec 24, 2024 · 2 comments
Closed

Passing tab character within string of a parameter in test case? #351

DaveMartel opened this issue Dec 24, 2024 · 2 comments

Comments

@DaveMartel
Copy link

I have not found any way to pass characters like #9, #13, #10 as part of a string in the parameters for test cases. This is needed when I am testing a routine to remove these and want to use parameterized tests. I can write individual tests without parameters and code it as part of the text, but it would be good to do something like

    [Test]
    [TestCase('RemoveTAB', 'A#9B', AB')]
    procedure TestRemoveControlChar(const InputString: string; const ExpectedResult: string);

In the routine to test handles a number of valid control characters, and it would be nice to have a test for each do with parameters. Just can't work out how to do it.

I have tried adding " around the string, but the " characters become party of the parameters.

@vincentparrett
Copy link
Member

Delphi does not support escaping characters like that, and the values part is a single string field.

this should work

    [TestCase('RemoveTAB', 'A' + #9 + 'B,AB')]
    procedure TestRemoveControlChar(const InputString: string; const ExpectedResult: string);

Note the comma to separate the values. See - DUnitX.Attributes TestCaseAttbute class.

@DaveMartel
Copy link
Author

Thank you @vincentparrett. I had tried various combinations, but that one I had missed. The only one I am now having issues with is #0, which obviously is quite a special character. It is just the code I am porting (and testing) is from c++. Not sure if I will ever see #0 in this project, but I would ideally like to have it working. The set of characters I am removing are #0#9#10#11#12#13#32. The actual code is in fact working, which is the goal (so the tests are not needed for now, but we should always have our tests ready for code changes... :-).

I just can't test #0 now...

Happy Christmas.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants