1"""
2Test basic std::vector functionality but with a declaration from
3the debug info (the Foo struct) as content.
4"""
5
6from lldbsuite.test.decorators import *
7from lldbsuite.test.lldbtest import *
8from lldbsuite.test import lldbutil
9
10
11class TestDbgInfoContentVector(TestBase):
12    @add_test_categories(["libc++"])
13    @skipIf(compiler=no_match("clang"))
14    @skipIf(compiler="clang", compiler_version=["<", "12.0"])
15    @skipIf(macos_version=["<", "14.0"])
16    @skipIfDarwin  # https://github.com/llvm/llvm-project/issues/106475
17    def test(self):
18        self.build()
19
20        lldbutil.run_to_source_breakpoint(
21            self, "// Set break point at this line.", lldb.SBFileSpec("main.cpp")
22        )
23
24        self.runCmd("settings set target.import-std-module true")
25
26        if self.expectedCompiler(["clang"]) and self.expectedCompilerVersion(
27            [">", "16.0"]
28        ):
29            vector_type = "std::vector<Foo>"
30        else:
31            vector_type = "std::vector<Foo, std::allocator<Foo> >"
32
33        size_type = "size_type"
34        value_type = "value_type"
35        iterator = "iterator"
36        # LLDB's formatter provides us with a artificial 'item' member.
37        iterator_children = [ValueCheck(name="item")]
38        riterator = "reverse_iterator"
39        riterator_children = [
40            ValueCheck(),  # Deprecated __t_ member; no need to check
41            ValueCheck(name="current"),
42        ]
43
44        self.expect_expr(
45            "a",
46            result_type=vector_type,
47            result_children=[
48                ValueCheck(children=[ValueCheck(value="3")]),
49                ValueCheck(children=[ValueCheck(value="1")]),
50                ValueCheck(children=[ValueCheck(value="2")]),
51            ],
52        )
53
54        self.expect_expr("a.size()", result_type=size_type, result_value="3")
55        self.expect_expr("a.front().a", result_type="int", result_value="3")
56        self.expect_expr("a[1].a", result_type="int", result_value="1")
57        self.expect_expr("a.back().a", result_type="int", result_value="2")
58
59        self.expect("expr std::reverse(a.begin(), a.end())")
60        self.expect_expr("a.front().a", result_type="int", result_value="2")
61
62        self.expect_expr("a.begin()->a", result_type="int", result_value="2")
63        self.expect_expr("a.rbegin()->a", result_type="int", result_value="3")
64
65        self.expect("expr a.pop_back()")
66        self.expect_expr("a.back().a", result_type="int", result_value="1")
67        self.expect_expr("a.size()", result_type=size_type, result_value="2")
68
69        self.expect_expr("a.at(0).a", result_type="int", result_value="2")
70
71        self.expect("expr a.push_back({4})")
72        self.expect_expr("a.back().a", result_type="int", result_value="4")
73        self.expect_expr("a.size()", result_type=size_type, result_value="3")
74
75        self.expect_expr(
76            "a.begin()", result_type=iterator, result_children=iterator_children
77        )
78        self.expect_expr(
79            "a.rbegin()", result_type=riterator, result_children=riterator_children
80        )
81