2 // StronglyTypedResourceBuilderVerifyResourceNameTests.cs tests
3 // the VerifyResourceName method
6 // Gary Barnett (gary.barnett.mono@gmail.com)
8 // Copyright (C) Gary Barnett (2012)
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 using NUnit.Framework;
33 using System.Resources.Tools;
34 using Microsoft.CSharp;
36 namespace MonoTests.System.Resources.Tools {
38 public class StronglyTypedResourceBuilderVerifyResourceNameTests {
39 static string [] keywords = {"abstract", "as", "base", "bool", "break", "byte", "case", "catch", "char",
40 "checked", "class", "const", "continue", "decimal", "default", "delegate",
41 "do", "double", "else", "enum", "event", "explicit", "extern", "FALSE",
42 "false", "finally", "fixed", "float", "for", "foreach", "goto", "if",
43 "implicit", "in", "int", "interface", "internal", "is", "lock", "long",
44 "namespace", "new", "null", "object", "operator", "out", "override", "params",
45 "private", "protected", "public", "readonly", "ref", "return", "sbyte", "sealed",
46 "short", "sizeof", "stackalloc", "static", "string", "struct", "switch", "this",
47 "throw", "TRUE", "true", "try", "typeof", "uint", "ulong", "unchecked", "unsafe",
48 "ushort", "using", "virtual", "volatile", "void", "while" };
49 static char [] specialChars = { ' ', '\u00A0', '.', ',', ';', '|', '~', '@', '#', '%', '^', '&',
50 '*', '+', '-', '/', '\\', '<', '>', '?', '[', ']', '(', ')', '{',
51 '}', '\"', '\'', ':', '!'};
52 CSharpCodeProvider provider = new CSharpCodeProvider();
55 public void VerifyResourceNameEmpty ()
58 string output = StronglyTypedResourceBuilder.VerifyResourceName (string.Empty, provider);
60 Assert.AreEqual ("_", output);
63 [Test, ExpectedException (typeof (ArgumentNullException))]
64 public void VerifyResourceNameNull () {
65 // should throw exception
66 StronglyTypedResourceBuilder.VerifyResourceName (null, provider);
70 public void VerifyResourceNameProviderInvalidIdentifiers () {
71 // function tests by means of provider.IsValidIdentifier after other checks
74 output = StronglyTypedResourceBuilder.VerifyResourceName ("tes$t", provider);
76 Assert.AreEqual (null, output);
80 public void VerifyResourceNameProviderKeywords ()
82 // not complete list, doesnt really need to be
83 string expected, output;
85 foreach (string input in keywords) {
86 output = StronglyTypedResourceBuilder.VerifyResourceName (input, provider);
88 expected = provider.CreateValidIdentifier (input);
90 Assert.AreEqual (expected, output);
94 [Test, ExpectedException (typeof (ArgumentNullException))]
95 public void VerifyResourceNameProviderNull () {
96 // should throw exception
97 StronglyTypedResourceBuilder.VerifyResourceName ("tes$t", null);
101 public void VerifyResourceNameSpecialChars ()
103 // should replace with _
104 string input, expected, output;
106 foreach (char c in specialChars) {
107 input = string.Format ("{0}a{0}b{0}", c);
108 expected = string.Format ("{0}a{0}b{0}", '_');
110 output = StronglyTypedResourceBuilder.VerifyResourceName (input, provider);
112 Assert.AreEqual (expected, output);