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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
|
/**
* Copyright (c) David Miller. All rights reserved.
* The use and distribution terms for this software are covered by the
* Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
* which can be found in the file epl-v10.html at the root of this distribution.
* By using this software in any fashion, you are agreeing to be bound by
* the terms of this license.
* You must not remove this notice, or any other, from this software.
**/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using Rhino.Mocks;
using clojure.lang;
using RMExpect = Rhino.Mocks.Expect;
using System.Collections;
namespace Clojure.Tests.LibTests
{
[TestFixture]
public class SymbolTests : AssertionHelper
{
#region c-tor tests
[Test]
public void Intern2CreatesSymbolWithNoNS()
{
Symbol sym = Symbol.intern(null, "abc");
Expect(sym.Name, EqualTo("abc"));
Expect(sym.Namespace, Null);
Expect(sym.meta(), Null);
}
[Test]
public void Intern2CreatesSymbolWithNS()
{
Symbol sym = Symbol.intern("def", "abc");
Expect(sym.Name, EqualTo("abc"));
Expect(sym.Namespace, EqualTo("def"));
Expect(sym.meta(), Null);
}
[Test]
public void Intern2InternsStrings()
{
String symname = new StringBuilder().Append("ab").Append("c").ToString();
String nsname = new StringBuilder().Append("ab").Append("c").ToString();
Symbol sym1 = Symbol.intern(nsname,symname);
Symbol sym2 = Symbol.intern(nsname,symname);
Expect(String.IsInterned(sym1.Name),Not.Null);
Expect(String.IsInterned(sym1.Namespace), Not.Null);
Expect(Object.ReferenceEquals(sym1.Name, sym2.Name));
Expect(Object.ReferenceEquals(sym1.Namespace, sym2.Namespace));
Expect(object.ReferenceEquals(sym1.Name, symname), False);
}
[Test]
public void Intern1CreatesSymbolWithNoNS()
{
Symbol sym = Symbol.intern("abc");
Expect(sym.Name, EqualTo("abc"));
Expect(sym.Namespace, Null);
Expect(sym.meta(), Null);
}
[Test]
public void Intern1CreatesSymbolWithNS()
{
Symbol sym = Symbol.intern("def/abc");
Expect(sym.Name, EqualTo("abc"));
Expect(sym.Namespace, EqualTo("def"));
Expect(sym.meta(), Null);
}
[Test]
public void Intern1CreatesSymbolWithNSFromLastSlash()
{
Symbol sym = Symbol.intern("ghi/def/abc");
Expect(sym.Name, EqualTo("abc"));
Expect(sym.Namespace, EqualTo("ghi/def"));
Expect(sym.meta(), Null);
}
[Test]
public void Intern1InternsStrings()
{
String name = new StringBuilder().Append("def/").Append("abc").ToString();
Symbol sym1 = Symbol.intern(name);
Symbol sym2 = Symbol.intern(name);
Expect(String.IsInterned(sym1.Name), Not.Null);
Expect(String.IsInterned(sym1.Namespace), Not.Null);
Expect(Object.ReferenceEquals(sym1.Name, sym2.Name));
Expect(Object.ReferenceEquals(sym1.Namespace, sym2.Namespace));
}
#endregion
#region Object overrides
[Test]
public void SymToStringWithNoNSIsJustName()
{
Symbol sym = Symbol.intern("abc");
Expect(sym.ToString(), EqualTo("abc"));
}
[Test]
public void SymToStringWithNsConcatenatesNames()
{
Symbol sym = Symbol.intern("def", "abc");
Expect(sym.ToString(), EqualTo("def/abc"));
}
[Test]
public void EqualsOnIdentityIsTrue()
{
Symbol sym = Symbol.intern("abc");
Expect(sym.Equals(sym));
}
[Test]
public void EqualsOnNonSymbolIsFalse()
{
Symbol sym = Symbol.intern("abc");
Expect(sym.Equals("abc"), False);
}
[Test]
public void EqualsOnDissimilarSymbolIsFalse()
{
Symbol sym1 = Symbol.intern("abc");
Symbol sym2 = Symbol.intern("ab");
Symbol sym3 = Symbol.intern("def", "abc");
Symbol sym4 = Symbol.intern("de","abc");
Expect(sym1.Equals(sym2), False);
Expect(sym1.Equals(sym3), False);
Expect(sym3.Equals(sym4), False);
}
[Test]
public void EqualsOnSimilarSymbolIsTrue()
{
Symbol sym1 = Symbol.intern("abc");
Symbol sym2 = Symbol.intern("abc");
Symbol sym3 = Symbol.intern("def", "abc");
Symbol sym4 = Symbol.intern("def", "abc");
Expect(sym1.Equals(sym2));
Expect(sym3.Equals(sym4));
}
[Test]
public void HashCodeDependsOnNames()
{
Symbol sym1 = Symbol.intern("abc");
Symbol sym2 = Symbol.intern("abc");
Symbol sym3 = Symbol.intern("def", "abc");
Symbol sym4 = Symbol.intern("def", "abc");
Symbol sym5 = Symbol.intern("ab");
Symbol sym6 = Symbol.intern("de", "abc");
Expect(sym1.GetHashCode(), EqualTo(sym2.GetHashCode()));
Expect(sym3.GetHashCode(), EqualTo(sym4.GetHashCode()));
Expect(sym1.GetHashCode(), Not.EqualTo(sym3.GetHashCode()));
Expect(sym1.GetHashCode(), Not.EqualTo(sym5.GetHashCode()));
Expect(sym3.GetHashCode(), Not.EqualTo(sym6.GetHashCode()));
}
#endregion
#region Named tests
// We've been testing these all along.
#endregion
#region IFn tests
[Test]
public void Invoke2IndexesIntoItsFirstArg()
{
Symbol sym1 = Symbol.intern("abc");
Symbol sym2 = Symbol.intern("abc");
Symbol sym3 = Symbol.intern("ab");
IDictionary dict = new Hashtable();
dict[sym1] = 7;
dict["abc"] = 8;
Expect(sym1.invoke(dict), EqualTo(7));
Expect(sym2.invoke(dict), EqualTo(7));
Expect(sym3.invoke(dict), Null);
}
[Test]
public void Invoke3IndexesIntoItsFirstArg()
{
Symbol sym1 = Symbol.intern("abc");
Symbol sym2 = Symbol.intern("abc");
Symbol sym3 = Symbol.intern("ab");
IDictionary dict = new Hashtable();
dict[sym1] = 7;
dict["abc"] = 8;
Expect(sym1.invoke(dict,20), EqualTo(7));
Expect(sym2.invoke(dict,20), EqualTo(7));
Expect(sym3.invoke(dict,20), EqualTo(20));
}
[Test]
[ExpectedException(typeof(ArgumentException))]
public void InvokeOnNoArgsFails()
{
Symbol sym1 = Symbol.intern("abc");
object o = sym1.invoke();
}
[Test]
[ExpectedException(typeof(ArgumentException))]
public void InvokeOnTooManyArgsFails()
{
Symbol sym1 = Symbol.intern("abc");
IDictionary dict = new Hashtable();
dict[sym1] = 7;
dict["abc"] = 8;
object o = sym1.invoke(dict,20,null);
}
#endregion
#region IComparable tests
[Test]
[ExpectedException(typeof(InvalidOperationException))]
public void CompareToNonSymbolFails()
{
Symbol sym1 =
|