[bcl] Remove more NET_2_0 checks from class libs
[mono.git] / mcs / class / System.Design / Test / System.Resources.Tools / StronglyTypedResourceBuilderVerifyResourceNameTests.cs
1 //
2 // StronglyTypedResourceBuilderVerifyResourceNameTests.cs tests
3 // the VerifyResourceName method
4 //
5 // Author:
6 //      Gary Barnett (gary.barnett.mono@gmail.com)
7 // 
8 // Copyright (C) Gary Barnett (2012)
9 //
10 //
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:
18 // 
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 // 
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.
29 //
30
31 using NUnit.Framework;
32 using System;
33 using System.Resources.Tools;
34 using Microsoft.CSharp;
35
36 namespace MonoTests.System.Resources.Tools {
37         [TestFixture]
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();
53                 
54                 [Test]
55                 public void VerifyResourceNameEmpty ()
56                 {
57                         // should return _
58                         string output = StronglyTypedResourceBuilder.VerifyResourceName (string.Empty, provider);
59                         
60                         Assert.AreEqual ("_", output);
61                 }
62
63                 [Test, ExpectedException (typeof (ArgumentNullException))]
64                 public void VerifyResourceNameNull () {
65                         // should throw exception
66                         StronglyTypedResourceBuilder.VerifyResourceName (null, provider);
67                 }
68
69                 [Test]
70                 public void VerifyResourceNameProviderInvalidIdentifiers () {
71                         // function tests by means of provider.IsValidIdentifier after other checks
72                         string output;
73                         
74                         output = StronglyTypedResourceBuilder.VerifyResourceName ("tes$t", provider);
75                         
76                         Assert.AreEqual (null, output);
77                 }
78                 
79                 [Test]
80                 public void VerifyResourceNameProviderKeywords ()
81                 {
82                         // not complete list, doesnt really need to be
83                         string expected, output;
84                         
85                         foreach (string input in keywords) {
86                                 output = StronglyTypedResourceBuilder.VerifyResourceName (input, provider);
87                                 
88                                 expected = provider.CreateValidIdentifier (input);
89                                 
90                                 Assert.AreEqual (expected, output);
91                         }
92                 }
93
94                 [Test, ExpectedException (typeof (ArgumentNullException))]
95                 public void VerifyResourceNameProviderNull () {
96                         // should throw exception
97                         StronglyTypedResourceBuilder.VerifyResourceName ("tes$t", null);
98                 }
99
100                 [Test]
101                 public void VerifyResourceNameSpecialChars ()
102                 {
103                         // should replace with _
104                         string input, expected, output;
105                         
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}", '_');
109                                 
110                                 output = StronglyTypedResourceBuilder.VerifyResourceName (input, provider);
111                                 
112                                 Assert.AreEqual (expected, output);
113                         }
114                 }
115
116
117         }
118 }
119