public void AbsoluteDependentUpon() { string result = CreateVisualBasicManifestResourceName.CreateManifestNameImpl ( @"f:\myproject\SubFolder\MyForm.resx", null, // Link file name true, null, // Root namespace null, null, StreamHelpers.StringToStream( @" Namespace Nested.TestNamespace Class TestClass End Class End Namespace "), null ); Assert.AreEqual("Nested.TestNamespace.TestClass", result); }
public void DependentWithEmbeddedCulture() { string result = CreateVisualBasicManifestResourceName.CreateManifestNameImpl ( @"f:\myproject\SubFolder\MyForm.fr-fr.resx", null, // Link file name true, "RootNamespace", // Root namespace null, null, StreamHelpers.StringToStream( @" Namespace Nested.TestNamespace Class TestClass End Class End Namespace "), null ); Assert.AreEqual("RootNamespace.Nested.TestNamespace.TestClass.fr-fr", result); }
public void DependentWithCultureMetadata() { string result = CreateVisualBasicManifestResourceName.CreateManifestNameImpl ( @"f:\myproject\SubFolder\MyForm.resx", null, // Link file name true, null, // Root namespace null, "en-GB", StreamHelpers.StringToStream( @" Namespace Nested.TestNamespace Class TestClass End Class End Namespace "), null ); Assert.Equal("Nested.TestNamespace.TestClass.en-GB", result); }
public void AbsoluteDependentUpon() { string result = CreateVisualBasicManifestResourceName.CreateManifestNameImpl ( fileName: @"f:\myproject\SubFolder\MyForm.resx", linkFileName: null, // Link file name prependCultureAsDirectory: true, rootNamespace: null, // Root namespace dependentUponFileName: null, culture: null, binaryStream: StreamHelpers.StringToStream( @" Namespace Nested.TestNamespace Class TestClass End Class End Namespace "), log: null ); Assert.Equal("Nested.TestNamespace.TestClass", result); }
public void Regress172107() { // Can't embed the 'Ã' directly because the string is Unicode already and the Unicode<-->ANSI transform // isn't bidirectional. MemoryStream sourcesStream = (MemoryStream)StreamHelpers.StringToStream("namespace d?a { class Class {} }"); // Instead, directly write the ANSI character into the memory buffer. sourcesStream.Seek(11, SeekOrigin.Begin); sourcesStream.WriteByte(0xc3); // Plug the 'Ã' in sourcesStream.Seek(0, SeekOrigin.Begin); string result = CreateCSharpManifestResourceName.CreateManifestNameImpl ( @"irrelevent", null, true, null, // Root namespace null, null, sourcesStream, null ); MemoryStream m = new MemoryStream(); m.Write(new byte[] { 0x64, 0xc3, 0x61, 0x2e, 0x43, 0x6c, 0x61, 0x73, 0x73 }, 0, 9); // dÃa.Class in ANSI m.Flush(); m.Seek(0, SeekOrigin.Begin); StreamReader r = new StreamReader(m, System.Text.Encoding.Default, true); // HIGHCHAR: Test reads ANSI because that's the scenario. string className = r.ReadToEnd(); Assert.Equal(className, result); }
/* * Method: AssertTokenize * * Tokenize a string ('source') and compare it to the expected set of tokens. * Also compare the source that is regenerated by concatenating all of the tokens * to 'expectedSource'. */ static private void AssertTokenize ( string source, string expectedSource, string expectedTokenKey, int expectedLastLineNumber ) { VisualBasicTokenizer tokens = new VisualBasicTokenizer ( StreamHelpers.StringToStream(source), false ); string results = ""; string tokenKey = ""; int lastLine = 0; bool syntaxError = false; foreach (Token t in tokens) { results += t.InnerText; lastLine = t.Line; if (!syntaxError) { // Its not really a file name, but GetExtension serves the purpose of getting the class name without // the namespace prepended. string tokenClass = t.ToString(); int pos = tokenClass.LastIndexOfAny(new char[] { '+', '.' }); if (t is VisualBasicTokenizer.LineTerminatorToken) { tokenKey += "eol"; } else if (t is WhitespaceToken) { tokenKey += "."; } else { tokenKey += tokenClass.Substring(pos + 1); tokenKey += "("; tokenKey += t.InnerText; tokenKey += ")"; } } if (t is SyntaxErrorToken) { // Stop processing after the first syntax error because // the order of tokens after this is an implementation detail and // shouldn't be encoded into the unit tests. syntaxError = true; } } tokenKey = tokenKey.Replace("Token", ""); if (expectedSource != results || expectedTokenKey != tokenKey) { Console.WriteLine(tokenKey); } Assert.AreEqual(expectedSource, results); Assert.AreEqual(expectedTokenKey, tokenKey); Assert.AreEqual(expectedLastLineNumber, lastLine); }