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
/// Extension methods for `Braced`
pub trait ExtendBraced<T> {
	fn new(body: T) -> Self;
}

impl<T> ExtendBraced<T> for weedle::common::Braced<T> {
	fn new(body: T) -> Self {
		Self {
			open_brace: weedle::term::OpenBrace,
			body,
			close_brace: weedle::term::CloseBrace,
		}
	}
}

/// Extension methods for `Bracketed`
pub trait ExtendBracketed<T> {
	fn new(body: T) -> Self;
}

impl<T> ExtendBracketed<T> for weedle::common::Bracketed<T> {
	fn new(body: T) -> Self {
		Self {
			open_bracket: weedle::term::OpenBracket,
			body,
			close_bracket: weedle::term::CloseBracket,
		}
	}
}

/// Extension methods for `Docstring`
pub trait ExtendDocstring {
	fn new(s: &str) -> Self;
	fn as_str(&self) -> &str;
}

impl ExtendDocstring for weedle::common::Docstring {
	fn new(s: &str) -> Self {
		Self(s.into())
	}

	fn as_str(&self) -> &str {
		self.0.as_str()
	}
}

/// Extension methods for `Generics`
pub trait ExtendGenerics<T> {
	fn new(body: T) -> Self;
}

impl<T> ExtendGenerics<T> for weedle::common::Generics<T> {
	fn new(body: T) -> Self {
		Self {
			open_angle: weedle::term::LessThan,
			body,
			close_angle: weedle::term::GreaterThan,
		}
	}
}

/// Extension methods for `Parenthesized`
pub trait ExtendParenthesized<T> {
	fn new(body: T) -> Self;
}

impl<T> ExtendParenthesized<T> for weedle::common::Parenthesized<T> {
	fn new(body: T) -> Self {
		Self {
			open_paren: weedle::term::OpenParen,
			body,
			close_paren: weedle::term::CloseParen,
		}
	}
}

/// Extension methods for `Punctuated`
pub trait ExtendPunctuated<T, S> {
	fn new(list: Vec<T>, separator: S) -> Self;
}

impl<T, S> ExtendPunctuated<T, S> for weedle::common::Punctuated<T, S> {
	fn new(list: Vec<T>, separator: S) -> Self {
		Self { list, separator }
	}
}

/// Extension methods for `PunctuatedNonEmpty`
pub trait ExtendPunctuatedNonEmpty<T, S> {
	fn new(list: Vec<T>, separator: S) -> Self;
}

impl<T, S> ExtendPunctuatedNonEmpty<T, S> for weedle::common::PunctuatedNonEmpty<T, S> {
	fn new(list: Vec<T>, separator: S) -> Self {
		Self { list, separator }
	}
}

#[cfg(test)]
mod extend_braced {
	use crate::extend::ExtendBraced;
	use weedle::common::{Braced, Identifier};

	#[test]
	fn test() {
		assert_eq!(Braced::new(Identifier("Foo")).body, Identifier("Foo"));
	}
}

#[cfg(test)]
mod extend_bracketed {
	use crate::extend::ExtendBracketed;
	use weedle::common::{Bracketed, Identifier};

	#[test]
	fn test() {
		assert_eq!(Bracketed::new(Identifier("Foo")).body, Identifier("Foo"));
	}
}

#[cfg(test)]
mod extend_docstring {
	use crate::extend::ExtendDocstring;
	use weedle::common::Docstring;

	#[test]
	fn test() {
		assert_eq!(Docstring::new("Foo").0, String::from("Foo"));
		assert_eq!(Docstring::new("Foo").as_str(), "Foo");
	}
}

#[cfg(test)]
mod extend_generics {
	use crate::extend::{ExtendGenerics, ExtendType};
	use weedle::common::Generics;
	use weedle::types::Type;

	#[test]
	fn test() {
		assert_eq!(Generics::new(Type::single_any()).body, Type::single_any());
	}
}

#[cfg(test)]
mod extend_parenthesized {
	use crate::extend::ExtendParenthesized;
	use weedle::common::{Identifier, Parenthesized};

	#[test]
	fn test() {
		assert_eq!(
			Parenthesized::new(Identifier("Foo")).body,
			Identifier("Foo")
		);
	}
}

#[cfg(test)]
mod extend_punctuated {
	use crate::extend::ExtendPunctuated;
	use weedle::common::Punctuated;
	use weedle::term::Comma;

	#[test]
	fn test() {
		let punct = Punctuated::new(vec!["Alice", "Bob"], Comma);
		assert_eq!(punct.list, vec!["Alice", "Bob"]);
	}
}

#[cfg(test)]
mod extend_punctuated_non_empty {
	use crate::extend::ExtendPunctuatedNonEmpty;
	use weedle::common::PunctuatedNonEmpty;
	use weedle::term::Comma;

	#[test]
	fn test() {
		let punct = PunctuatedNonEmpty::new(vec!["Alice", "Bob"], Comma);
		assert_eq!(punct.list, vec!["Alice", "Bob"]);
	}
}