⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 stringstest.cs

📁 大名鼎鼎的mono是.NET平台的跨平台(支持linux
💻 CS
📖 第 1 页 / 共 5 页
字号:
// StringsTest.cs - NUnit Test Cases for Microsoft.VisualBasic.Strings //// Mizrahi Rafael (rafim@mainsoft.com)// Boris Kirzner <borisk@mainsoft.com>//// // Copyright (c) 2002-2006 Mainsoft Corporation.// Copyright (C) 2004 Novell, Inc (http://www.novell.com)//// 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.IO;using Microsoft.VisualBasic;using System.Globalization;namespace MonoTests.Microsoft_VisualBasic{	[TestFixture]	public class StringsTest 	{		public StringsTest()		{		}		[SetUp]		public void GetReady()		{			System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo ("en-US");		}		[TearDown]		public void Clean() 		{		}			#region Asc Tests		[Test]		[Category("NotWorking")]		public void Asc1() 		{			Assert.AreEqual(97,Strings.Asc("a"));			Assert.AreEqual(97,Strings.Asc("abc"));			Assert.AreEqual(230, Strings.Asc ("æ"));			Assert.AreEqual(65,Strings.Asc("A"));			Assert.AreEqual(33,Strings.Asc("!"));			Assert.AreEqual(51,Strings.Asc("3"));			Assert.AreEqual(43,Strings.Asc("+"));						Assert.AreEqual(63,Strings.Asc("\u1994"));			Assert.AreEqual(63,Strings.Asc("\u5666"));			Assert.AreEqual(63,Strings.Asc("耀"));			Assert.AreEqual(63,Strings.Asc("耂"));		}		[Test]		[ExpectedException(typeof(ArgumentException))]		public void Asc2() 		{			int i = Strings.Asc(null);		}		[Test]		[ExpectedException(typeof(ArgumentException))]		public void Asc3() 		{			int i = Strings.Asc("");		}		#endregion		#region AscW Tests		[Test]		public void AscW1() 		{			Assert.AreEqual(51,Strings.AscW("3"));			Assert.AreEqual(33,Strings.AscW("!"));			Assert.AreEqual(65,Strings.AscW("A"));			//Assert.AreEqual(1494,Strings.AscW("×–"));			Assert.AreEqual(97,Strings.AscW("abc"));			Assert.AreEqual(97,Strings.AscW("a"));			Assert.AreEqual(6548,Strings.AscW("\u1994"));			Assert.AreEqual(22118,Strings.AscW("\u5666"));			Assert.AreEqual(32768,Strings.AscW("\u8000"));			Assert.AreEqual(32770,Strings.AscW("\u8002"));		}		[Test]		[ExpectedException(typeof(ArgumentException))]		public void AscW2() 		{			int i = Strings.AscW(null);		}		[Test]		[ExpectedException(typeof(ArgumentException))]		public void AscW3() 		{			int i = Strings.AscW("");		}		#endregion		#region Chr Tests		[Test]		public void ChrTest()		{			Assert.AreEqual (System.Convert.ToChar(0), Microsoft.VisualBasic.Strings.Chr(0), "Chr#0");			Assert.AreEqual (System.Convert.ToChar(1), Microsoft.VisualBasic.Strings.Chr(1), "Chr#1");			Assert.AreEqual (System.Convert.ToChar(127), Microsoft.VisualBasic.Strings.Chr(127), "Chr#2");		}		[Test]		[ExpectedException (typeof(ArgumentException))]		public void ChrTestArgumentException1()		{			// CharCode < -32768 Or CharCode > 65535			int MinValue = -32768;			Char c;			c = Microsoft.VisualBasic.Strings.Chr(MinValue - 1);		}		[Test]		[ExpectedException (typeof(ArgumentException))]		public void ChrTestArgumentException2()		{			// Negative value			Char c;			c = Microsoft.VisualBasic.Strings.Chr(-1);		}		[Test]		[ExpectedException (typeof(ArgumentException))]		public void ChrTestArgumentException3()		{			// higher than 255 value			Char c;			c = Microsoft.VisualBasic.Strings.Chr(256);		}		#endregion		#region ChrW Tests		[Test]		public void ChrWTest()		{			Assert.AreEqual (System.Convert.ToChar(0), Microsoft.VisualBasic.Strings.ChrW(0), "ChrW#0");			Assert.AreEqual (System.Convert.ToChar(1), Microsoft.VisualBasic.Strings.ChrW(1), "ChrW#1");			Assert.AreEqual ('A', Microsoft.VisualBasic.Strings.ChrW(65), "ChrW#Number1");			Assert.AreEqual (Microsoft.VisualBasic.Strings.ChrW(-1000), Microsoft.VisualBasic.Strings.ChrW(-1000 + 65536), "ChrW#Unicode1");		}		[Test]		[ExpectedException (typeof(ArgumentException))]		public void ChrWTestArgumentException1()		{			// CharCode < -32768 Or CharCode > 65535			int MinValue = -32768;			Char c;			c = Microsoft.VisualBasic.Strings.ChrW(MinValue - 1);		}		[Test]		[ExpectedException (typeof(ArgumentException))]		public void ChrWTestArgumentException2()		{			// CharCode < -32768 Or CharCode > 65535			int MaxValue = 65535;			Char c;			c = Microsoft.VisualBasic.Strings.ChrW(MaxValue + 1);		}		//		//		[Test]		//		[ExpectedException (typeof(InvalidCastException))]		//		public void ChrWTestInvalidCastException1()		//		{		//			string s = "test";		//			Char c;		//			c = Microsoft.VisualBasic.Strings.ChrW(s);		//		}		#endregion		#region Filter Tests		[Test]		public void Filter1()		{			string[] arr = new string[] {"Test","ss","aaaaaaaaaaa"};			string[] res = Strings.Filter(arr,"s",false,CompareMethod.Text);			Assert.AreEqual("aaaaaaaaaaa",res[0]);		}		[Test]		public void Filter2()		{			string[] arr = new string[] {"Dado","Ben","David"};			string[] res = Strings.Filter(arr,"Da",true,CompareMethod.Binary);			Assert.AreEqual("Dado",res[0]);			Assert.AreEqual("David",res[1]);		}		[Test]		public void Filter3()		{			string[] arr = new string[] {"AAA","BBB","CCC"};			string[] res = Strings.Filter(arr,"b",true,CompareMethod.Binary);			Assert.AreEqual(0,res.Length);		}		[Test]			//[ExpectedException (typeof(ArgumentException))]		[ExpectedException (typeof(NullReferenceException))]		public void Filter4()		{			string[] res = Strings.Filter(null,"abc",true,CompareMethod.Text);		}		#endregion		#region Format Tests				[Test]		public void Format_Numeric_GeneralNumber()		{			Assert.AreEqual("1234.4321",Strings.Format(1234.4321, "General Number"));			Assert.AreEqual("1234.4321",Strings.Format(1234.4321, "G"));			Assert.AreEqual("1234.4321",Strings.Format(1234.4321, "g"));			Assert.AreEqual("GeneralNumber",Strings.Format(1234.4321, "GeneralNumber"));			Assert.AreEqual("G ",Strings.Format(1234.4321, "G "));			Assert.AreEqual("GGG",Strings.Format(1234.4321, "GGG"));		}		[Test]		public void Format_Numeric_Currency()		{			Assert.AreEqual("$1,234.43",Strings.Format(1234.4321, "Currency"));			Assert.AreEqual("$1,234.43",Strings.Format(1234.4321, "C"));			Assert.AreEqual("$1,234.43",Strings.Format(1234.4321, "c"));			Assert.AreEqual("C ",Strings.Format(1234.4321, "C "));			Assert.AreEqual("ccc",Strings.Format(1234.4321, "ccc"));		}		[Test]		public void Format_Numeric_Fixed()		{			Assert.AreEqual("1234.43",Strings.Format(1234.4321, "Fixed"));			Assert.AreEqual("1234.43",Strings.Format(1234.4321, "F"));			Assert.AreEqual("1234.43",Strings.Format(1234.4321, "f"));			Assert.AreEqual("Fixed " ,Strings.Format(1234.4321, "Fixed "));			Assert.AreEqual("F ",Strings.Format(1234.4321, "F "));			Assert.AreEqual("f ",Strings.Format(1234.4321, "f "));		}		[Test]		public void Format_Numeric_Standard()		{			Assert.AreEqual("1,234.43",Strings.Format(1234.4321, "Standard"));			Assert.AreEqual("1,234.43",Strings.Format(1234.4321, "N"));			Assert.AreEqual("1,234.43",Strings.Format(1234.4321, "n"));			Assert.AreEqual("n ",Strings.Format(1234.4321, "n "));			Assert.AreEqual("N ",Strings.Format(1234.4321, "N "));		}		[Test]		public void Format_Numeric_Percent()		{			Assert.AreEqual("123443.21%",Strings.Format(1234.4321, "Percent"));			Assert.AreEqual("123443.21%",Strings.Format(1234.4321, "percent"));			Assert.AreEqual("123,443.21 %",Strings.Format(1234.4321, "P"));			Assert.AreEqual("123,443.21 %",Strings.Format(1234.4321, "p"));			Assert.AreEqual("%",Strings.Format(1234.4321, "%"));		}		[Test]		public void Format_Numeric_Scientific()		{			Assert.AreEqual("1.23E+03",Strings.Format(1234.4321, "Scientific"));			Assert.AreEqual("1.234432E+003",Strings.Format(1234.4321, "E"));			Assert.AreEqual("1.234432e+003",Strings.Format(1234.4321, "e"));			Assert.AreEqual("e ",Strings.Format(1234.4321, "e "));			Assert.AreEqual("E ",Strings.Format(1234.4321, "E "));		}		[Test]		public void Format_Numeric_Hexadecimal()		{			Assert.AreEqual("4D2",Strings.Format(1234, "X"));			Assert.AreEqual("4d2",Strings.Format(1234, "x"));			Assert.AreEqual("x ",Strings.Format(1234.4321, "x "));			Assert.AreEqual("X ",Strings.Format(1234.4321, "X "));		}		[Test]		public void Format_Numeric_YesNo()		{			Assert.AreEqual("Yes",Strings.Format(1234.4321, "Yes/No"));			Assert.AreEqual("No",Strings.Format(0, "Yes/No"));			Assert.AreEqual("Yes",Strings.Format(-12, "Yes/No"));			Assert.AreEqual("Yes",Strings.Format(123, "yes/no"));			Assert.AreEqual("No/Yes",Strings.Format(0, "No/Yes"));			Assert.AreEqual("-no",Strings.Format(-12, "no"));		}		[Test]		public void Format_Numeric_TrueFalse()		{			Assert.AreEqual("True",Strings.Format(1, "True/False"));			Assert.AreEqual("False",Strings.Format(0, "True/False"));			Assert.AreEqual("True",Strings.Format(-1, "True/False"));		}		[Test]		public void Format_Numeric_OnOff()		{			Assert.AreEqual("On",Strings.Format(1234.4321, "On/Off"));						Assert.AreEqual("On",Strings.Format(-12, "ON/OFF"));			Assert.AreEqual("ON/OF",Strings.Format(0, "ON/OF"));		}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -