summaryrefslogtreecommitdiffhomepage
path: root/CompilerDriver/cc2/regression-tests/mixed-inspect-values.cpp2
blob: c2f1d77daddfb712f8a64c6add0c336b01aed1dd (plain)
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
auto in(int min, int max) {
    return [=](int x){ return min <= x && x <= max; };
}

in_2_3: (x: int) -> bool = 2 <= x && x <= 3;

main: ()->int = {
    v: std::variant<double, std::string, double> = ();
    v = "rev dodgson";
    test(v);

    o: std::optional<int> = ();
    test(o);
    o = 42;
    test(o);

    a: std::any = 0;
    test(a);
    a = "plugh" as std::string;
    test(a);

    test(0);
    test(1);
    test(2);
    test(3);
    test(-42);
    test("xyzzy" as std::string);
    test(3.14);
}

test: (x:_) = {
    forty_two := 42;
    std::cout << inspect x -> std::string {
        is 0           = "zero";
        is (in(1,2))   = "1 or 2";
        is (in_2_3)    = "3";
        is (forty_two) = "the answer";
        is int         = "integer " + cpp2::to_string(x);
        is std::string = x as std::string;
        is _           = "(no match)";
    } << "\n";
}