1"""
2Test default template arguments.
3"""
4
5import lldb
6from lldbsuite.test.decorators import *
7from lldbsuite.test.lldbtest import *
8from lldbsuite.test import lldbutil
9
10class TestDefaultTemplateArgs(TestBase):
11
12    @no_debug_info_test
13    def test(self):
14        self.build()
15        lldbutil.run_to_source_breakpoint(self, "// break here", lldb.SBFileSpec("main.cpp"))
16
17        # Declare a template with a template argument that has a default argument.
18        self.expect("expr --top-level -- template<typename T = int> struct $X { int v; };")
19
20        # The type we display to the user should omit the argument with the default
21        # value.
22        result = self.expect_expr("$X<> x; x",  result_type="$X<>")
23        # The internal name should also always show all arguments (even if they
24        # have their default value).
25        self.assertEqual(result.GetTypeName(), "$X<int>")
26
27        # Test the template but this time specify a non-default value for the
28        # template argument.
29        # Both internal type name and the one we display to the user should
30        # show the non-default value in the type name.
31        result = self.expect_expr("$X<long> x; x", result_type="$X<long>")
32        self.assertEqual(result.GetTypeName(), "$X<long>")
33
34        # Test that the formatters are using the internal type names that
35        # always include all template arguments.
36        self.expect("type summary add '$X<int>' --summary-string 'summary1'")
37        self.expect_expr("$X<> x; x", result_summary="summary1")
38        self.expect("type summary add '$X<long>' --summary-string 'summary2'")
39        self.expect_expr("$X<long> x; x", result_summary="summary2")
40