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

How to understand "#data_array" in std::string? #383

Closed
beizhengren opened this issue Jun 5, 2020 · 2 comments
Closed

How to understand "#data_array" in std::string? #383

beizhengren opened this issue Jun 5, 2020 · 2 comments

Comments

@beizhengren
Copy link

beizhengren commented Jun 5, 2020

Description

Hi, thanks for your terrific work.
During I add a test for vector, I find #data_array, as following.
I have never seen the programmer in c++. How should I understand it?

out.push_back(std::string(#data_array "[") + std::to_string(out.size() + 1) + "]"); \

the original link: https://github.com/onqtam/doctest/blob/master/doc/markdown/parameterized-tests.md
Thanks!

@onqtam
Copy link
Member

onqtam commented Jun 5, 2020

Hi @beizhengren , If I understand you correctly, you are wondering what #data_array does exactly - that's a preprocessor operator and it turns whatever is passed to the macro into a C string literal. So for example:

    int data;
    std::list<int> my_real_data_array = {1, 2, 3, 4};
    DOCTEST_VALUE_PARAMETERIZED_DATA(data, my_real_data_array);

in this case there will be 4 subcases generated which will be named my_real_data_array[<index>].

Have a look at these links:

Let me know if this helps :)

@beizhengren
Copy link
Author

Hi @onqtam
Thank you so much for your quick and clear reply!
It's my first time to know replacing text macros.
It help me a a lot!^ ^

@onqtam onqtam closed this as completed Jun 5, 2020
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