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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
#![allow(dead_code)]
use indoc::indoc;
use pretty_assertions::assert_eq;
use tsify::Tsify;
#[test]
fn test_simple_doc_comment() {
/// A simple doc comment.
#[derive(Tsify)]
struct SimpleComment {
x: i32,
}
assert_eq!(
SimpleComment::DECL,
indoc! {"
/**
* A simple doc comment.
*/
export interface SimpleComment {
x: number;
}"
}
);
}
#[test]
fn test_doc_comment_with_quotes() {
/// A comment with "quoted text" inside.
#[derive(Tsify)]
struct QuotedComment {
x: i32,
}
assert_eq!(
QuotedComment::DECL,
indoc! {"
/**
* A comment with \"quoted text\" inside.
*/
export interface QuotedComment {
x: number;
}"
}
);
}
#[test]
fn test_multiline_doc_comment() {
/// First line of documentation.
/// Second line with more details.
/// Third line concludes.
#[derive(Tsify)]
struct MultilineComment {
x: i32,
}
assert_eq!(
MultilineComment::DECL,
indoc! {"
/**
* First line of documentation.
* Second line with more details.
* Third line concludes.
*/
export interface MultilineComment {
x: number;
}"
}
);
}
#[test]
fn test_field_doc_comments() {
/// Struct-level comment.
#[derive(Tsify)]
struct FieldComments {
/// The x coordinate.
x: i32,
/// The name field.
name: String,
}
assert_eq!(
FieldComments::DECL,
indoc! {"
/**
* Struct-level comment.
*/
export interface FieldComments {
/**
* The x coordinate.
*/
x: number;
/**
* The name field.
*/
name: string;
}"
}
);
}
macro_rules! my_types {
($($decl:item)+) => {$(
#[derive(Tsify)]
$decl
)+};
}
#[test]
fn test_doc_comment_without_quotes_through_macro() {
my_types! {
/// A comment without quotes.
struct MacroNoQuotes {
x: i32,
}
}
assert_eq!(
MacroNoQuotes::DECL,
indoc! {"
/**
* A comment without quotes.
*/
export interface MacroNoQuotes {
x: number;
}"
}
);
}
#[test]
fn test_doc_comment_with_quotes_through_macro() {
my_types! {
/// A comment with "quotes" inside.
struct MacroWithQuotes {
x: i32,
}
}
assert_eq!(
MacroWithQuotes::DECL,
indoc! {"
/**
* A comment with \"quotes\" inside.
*/
export interface MacroWithQuotes {
x: number;
}"
}
);
}
#[test]
fn test_field_doc_comment_through_macro() {
my_types! {
/// Struct comment
struct MacroFieldComments {
/// Field with "quoted" text
x: i32,
/// Field without quotes
y: String,
}
}
assert_eq!(
MacroFieldComments::DECL,
indoc! {"
/**
* Struct comment
*/
export interface MacroFieldComments {
/**
* Field with \"quoted\" text
*/
x: number;
/**
* Field without quotes
*/
y: string;
}"
}
);
}
#[test]
fn test_multiple_doc_lines_through_macro() {
my_types! {
/// First line of comment.
/// Second line with "quotes".
/// Third line.
struct MacroMultiLineComment {
x: i32,
}
}
assert_eq!(
MacroMultiLineComment::DECL,
indoc! {"
/**
* First line of comment.
* Second line with \"quotes\".
* Third line.
*/
export interface MacroMultiLineComment {
x: number;
}"
}
);
}