"""
Test lldb data formatter subsystem.
"""

import lldb
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
from lldbsuite.test import lldbutil


class TestDataFormatterStdQueue(TestBase):
    SHARED_BUILD_TESTCASE = False

    def setUp(self):
        TestBase.setUp(self)
        self.namespace = "std"

    def check_variable(self, name):
        var = self.frame().FindVariable(name)
        self.assertTrue(var.IsValid())

        queue = self.namespace + "::queue"
        self.assertIn(queue, var.GetDisplayTypeName())
        self.assertEqual(var.GetNumChildren(), 5)
        for i in range(5):
            ch = var.GetChildAtIndex(i)
            self.assertTrue(ch.IsValid())
            self.assertEqual(ch.GetValueAsSigned(), i + 1)

    @expectedFailureAll(
        bugnumber="llvm.org/pr36109", debug_info="gmodules", triple=".*-android"
    )
    @add_test_categories(["libc++"])
    def test_libcxx(self):
        """Test that std::queue is displayed correctly"""
        self.build(dictionary={"USE_LIBCPP": 1})
        lldbutil.run_to_source_breakpoint(
            self, "// break here", lldb.SBFileSpec("main.cpp", False)
        )

        self.check_variable("q1")
        self.check_variable("q2")
