aboutsummaryrefslogtreecommitdiffstats
path: root/tests/Test_Qt.DotNet.Generator/Test_GenerateIndexer.cs
blob: 842453f0d45cf0569c5fb015fba7b9c9d5da623c (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
43
44
45
46
47
48
/***************************************************************************************************
 Copyright (C) 2025 The Qt Company Ltd.
 SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
***************************************************************************************************/

using System;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Test_Qt.DotNet.Generator
{
    using Support;

    [TestClass]
    public class Test_GenerateIndexer
    {
        public TestContext TestContext { get; set; }

        [TestMethod]
        public async Task QDotNetFunction_TemplateArgs_Should_Not_PrefixStar()
        {
            const string source = """
            public sealed class Foo {}
            public sealed class Bar {}
            public class Subject
            {
               public int this[Foo k, Bar v] { get => 0; set {} }
            }
            """;

            var result = await TestCodeGenerator.GenerateAsync([source],
                ct: TestContext.CancellationTokenSource.Token);

            // Make sure the generator has emitted a header and source file
            Assert.IsTrue(result.Sink.Files.TryGetValue(@"source/hpp/subject.h", out _));
            Assert.IsTrue(result.Sink.Files.TryGetValue(@"source/cpp/subject.cpp", out var subject));

            // Make sure we do not emit prefixed template arguments
            var lines = subject.Split(["\r\n", "\r", "\n"], StringSplitOptions.None);
            foreach (var line in lines) {
                Assert.DoesNotMatchRegex(
                    new Regex(@"(^|,)\s*\*\s*(?:QtDotNet::Global::)?(Foo|Bar)(\s|,|$|>)"),
                    line.Trim());
            }
        }
    }
}