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
|
//
// StronglyTypedResourceBuilderVerifyResourceNameTests.cs tests
// the VerifyResourceName method
//
// Author:
// Gary Barnett (gary.barnett.mono@gmail.com)
//
// Copyright (C) Gary Barnett (2012)
//
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using NUnit.Framework;
using System;
using System.Resources.Tools;
using Microsoft.CSharp;
namespace MonoTests.System.Resources.Tools {
[TestFixture]
public class StronglyTypedResourceBuilderVerifyResourceNameTests {
static string [] keywords = {"abstract", "as", "base", "bool", "break", "byte", "case", "catch", "char",
"checked", "class", "const", "continue", "decimal", "default", "delegate",
"do", "double", "else", "enum", "event", "explicit", "extern", "FALSE",
"false", "finally", "fixed", "float", "for", "foreach", "goto", "if",
"implicit", "in", "int", "interface", "internal", "is", "lock", "long",
"namespace", "new", "null", "object", "operator", "out", "override", "params",
"private", "protected", "public", "readonly", "ref", "return", "sbyte", "sealed",
"short", "sizeof", "stackalloc", "static", "string", "struct", "switch", "this",
"throw", "TRUE", "true", "try", "typeof", "uint", "ulong", "unchecked", "unsafe",
"ushort", "using", "virtual", "volatile", "void", "while" };
static char [] specialChars = { ' ', '\u00A0', '.', ',', ';', '|', '~', '@', '#', '%', '^', '&',
'*', '+', '-', '/', '\\', '<', '>', '?', '[', ']', '(', ')', '{',
'}', '\"', '\'', ':', '!'};
CSharpCodeProvider provider = new CSharpCodeProvider();
[Test]
public void VerifyResourceNameEmpty ()
{
// should return _
string output = StronglyTypedResourceBuilder.VerifyResourceName (string.Empty, provider);
Assert.AreEqual ("_", output);
}
[Test, ExpectedException (typeof (ArgumentNullException))]
public void VerifyResourceNameNull () {
// should throw exception
StronglyTypedResourceBuilder.VerifyResourceName (null, provider);
}
[Test]
public void VerifyResourceNameProviderInvalidIdentifiers () {
// function tests by means of provider.IsValidIdentifier after other checks
string output;
output = StronglyTypedResourceBuilder.VerifyResourceName ("tes$t", provider);
Assert.AreEqual (null, output);
}
[Test]
public void VerifyResourceNameProviderKeywords ()
{
// not complete list, doesnt really need to be
string expected, output;
foreach (string input in keywords) {
output = StronglyTypedResourceBuilder.VerifyResourceName (input, provider);
expected = provider.CreateValidIdentifier (input);
Assert.AreEqual (expected, output);
}
}
[Test, ExpectedException (typeof (ArgumentNullException))]
public void VerifyResourceNameProviderNull () {
// should throw exception
StronglyTypedResourceBuilder.VerifyResourceName ("tes$t", null);
}
[Test]
public void VerifyResourceNameSpecialChars ()
{
// should replace with _
string input, expected, output;
foreach (char c in specialChars) {
input = string.Format ("{0}a{0}b{0}", c);
expected = string.Format ("{0}a{0}b{0}", '_');
output = StronglyTypedResourceBuilder.VerifyResourceName (input, provider);
Assert.AreEqual (expected, output);
}
}
}
}
|