Skip to content

Commit 7624339

Browse files
committed
Add sketch of tests
1 parent f23898a commit 7624339

File tree

7 files changed

+117
-0
lines changed

7 files changed

+117
-0
lines changed

test/Interop/Cxx/templates/Inputs/module.modulemap

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,15 @@ module Mangling {
3737
module LinkageOfSwiftSymbolsForImportedTypes {
3838
header "linkage-of-swift-symbols-for-imported-types.h"
3939
}
40+
41+
module VariadicClassTemplate {
42+
header "variadic-class-template.h"
43+
}
44+
45+
module NonTypeTemplateParameter {
46+
header "non-type-template-parameter.h"
47+
}
48+
49+
module TemplateTemplateParameter {
50+
header "template-template-parameter.h"
51+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#ifndef TEST_INTEROP_CXX_TEMPLATES_INPUTS_NON_TYPE_PARAMETER_H
2+
#define TEST_INTEROP_CXX_TEMPLATES_INPUTS_NON_TYPE_PARAMETER_H
3+
4+
template<class T, auto Size>
5+
struct MagicArray {
6+
T t[Size];
7+
};
8+
9+
typedef MagicArray<int, 2> MagicIntPair;
10+
11+
#endif // TEST_INTEROP_CXX_TEMPLATES_INPUTS_NON_TYPE_PARAMETER_H
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#ifndef TEST_INTEROP_CXX_TEMPLATES_INPUTS_TEMPLATE_TEMPLATE_PARAMETER_H
2+
#define TEST_INTEROP_CXX_TEMPLATES_INPUTS_TEMPLATE_TEMPLATE_PARAMETER_H
3+
4+
template<template <class> class V>
5+
struct Asdf {
6+
V<IntWrapper> i;
7+
};
8+
9+
struct IntWrapper {
10+
int value;
11+
int getValue() const { return value; }
12+
};
13+
14+
template <class T>
15+
struct MagicWrapper {
16+
T t;
17+
int getValuePlusArg(int arg) const { return t.getValue() + arg; }
18+
};
19+
20+
typedef Asdf<MagicWrapper> Hohoho;
21+
#endif // TEST_INTEROP_CXX_TEMPLATES_INPUTS_TEMPLATE_TEMPLATE_PARAMETER_H
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#ifndef TEST_INTEROP_CXX_TEMPLATES_INPUTS_VARIADIC_CLASS_TEMPLATE_H
2+
#define TEST_INTEROP_CXX_TEMPLATES_INPUTS_VARIADIC_CLASS_TEMPLATE_H
3+
4+
template <class... Ts> struct Tuple {};
5+
6+
template <class T, class... Ts>
7+
struct Tuple<T, Ts...> : Tuple<Ts...> {
8+
Tuple(T t, Ts... ts) : Tuple<Ts...>(ts...), t(t) {}
9+
10+
T get() { return t; }
11+
T rest() { return Tuple<Ts...>::get(); }
12+
13+
T t;
14+
};
15+
16+
struct IntWrapper {
17+
int value;
18+
int getValue() const { return value; }
19+
};
20+
21+
typedef Tuple<IntWrapper, IntWrapper> Pair;
22+
23+
#endif // TEST_INTEROP_CXX_TEMPLATES_INPUTS_VARIADIC_CLASS_TEMPLATE_H
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// RUN: %target-run-simple-swift(-I %S/Inputs -Xfrontend -enable-cxx-interop -Xcc -std=c++17)
2+
//
3+
// REQUIRES: executable_test
4+
5+
import NonTypeParameter
6+
import StdlibUnittest
7+
8+
var TemplatesTestSuite = TestSuite("TemplatesTestSuite")
9+
10+
TemplatesTestSuite.test("variadic-class-template") {
11+
let pair = MagicIntPair()
12+
pair.t = [10, 20]
13+
expectEqual(pair.t, [10, 20])
14+
}
15+
16+
runAllTests()
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// RUN: %target-run-simple-swift(-I %S/Inputs -Xfrontend -enable-cxx-interop -Xcc -std=c++17)
2+
//
3+
// REQUIRES: executable_test
4+
5+
import NonTypeParameter
6+
import StdlibUnittest
7+
8+
var TemplatesTestSuite = TestSuite("TemplatesTestSuite")
9+
10+
TemplatesTestSuite.test("variadic-class-template") {
11+
let a = IntWrapper(value: 42)
12+
let hohoho = Hohoho()
13+
hohoho.i = a
14+
}
15+
16+
runAllTests()
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// RUN: %target-run-simple-swift(-I %S/Inputs -Xfrontend -enable-cxx-interop -Xcc -std=c++17)
2+
//
3+
// REQUIRES: executable_test
4+
5+
import VariadicClassTemplate
6+
import StdlibUnittest
7+
8+
var TemplatesTestSuite = TestSuite("TemplatesTestSuite")
9+
10+
TemplatesTestSuite.test("variadic-class-template") {
11+
let a = IntWrapper(value: 10)
12+
let b = IntWrapper(value: 20)
13+
let pair = Pair(a, b)
14+
expectEqual(pair.get(), 10)
15+
expectEqual(pair.rest().get(), 20)
16+
}
17+
18+
runAllTests()

0 commit comments

Comments
 (0)