"docs/vscode:/vscode.git/clone" did not exist on "56c6cfeaedfb6f3f96d1a4ef5099c3d121efadea"
stringutils.cpp 2.2 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include <migraphx/stringutils.hpp>
#include <test.hpp>

TEST_CASE(interpolate_string_simple1)
{
    std::string input = "Hello ${w}!";
    auto s            = migraphx::interpolate_string(input, {{"w", "world"}});
    EXPECT(s == "Hello world!");
}

TEST_CASE(interpolate_string_simple2)
{
    std::string input = "${hello}";
    auto s            = migraphx::interpolate_string(input, {{"hello", "bye"}});
    EXPECT(s == "bye");
}

TEST_CASE(interpolate_string_unbalanced)
{
    std::string input = "${hello";
    EXPECT(test::throws([&] { migraphx::interpolate_string(input, {{"hello", "bye"}}); }));
}

TEST_CASE(interpolate_string_extra_space)
{
    std::string input = "${  hello  }";
    auto s            = migraphx::interpolate_string(input, {{"hello", "bye"}});
    EXPECT(s == "bye");
}

TEST_CASE(interpolate_string_multiple)
{
    std::string input = "${h} ${w}!";
    auto s            = migraphx::interpolate_string(input, {{"w", "world"}, {"h", "Hello"}});
    EXPECT(s == "Hello world!");
}

TEST_CASE(interpolate_string_next)
{
    std::string input = "${hh}${ww}!";
    auto s            = migraphx::interpolate_string(input, {{"ww", "world"}, {"hh", "Hello"}});
    EXPECT(s == "Helloworld!");
}

TEST_CASE(interpolate_string_dollar_sign)
{
    std::string input = "$hello";
    auto s            = migraphx::interpolate_string(input, {{"hello", "bye"}});
    EXPECT(s == "$hello");
}

TEST_CASE(interpolate_string_missing)
{
    std::string input = "${hello}";
    EXPECT(test::throws([&] { migraphx::interpolate_string(input, {{"h", "bye"}}); }));
}

TEST_CASE(interpolate_string_custom1)
{
    std::string input = "****{{a}}****";
    auto s            = migraphx::interpolate_string(input, {{"a", "b"}}, "{{", "}}");
    EXPECT(s == "****b****");
}

TEST_CASE(interpolate_string_custom2)
{
    std::string input = "****{{{a}}}****";
    auto s            = migraphx::interpolate_string(input, {{"a", "b"}}, "{{{", "}}}");
    EXPECT(s == "****b****");
}

TEST_CASE(interpolate_string_custom3)
{
    std::string input = "****{{{{a}}}}****";
    auto s            = migraphx::interpolate_string(input, {{"a", "b"}}, "{{{{", "}}}}");
    EXPECT(s == "****b****");
}

int main(int argc, const char* argv[]) { test::run(argc, argv); }