public void EncodingTest() { const string s = "üöäß\nÖÄÜ\n"; var t = new Text(s, Encoding.GetEncoding("latin1")); Assert.AreEqual("üöäß\n", t.GetLine(1)); Assert.AreEqual("ÖÄÜ\n", t.GetLine(2)); Assert.Throws(typeof(ArgumentOutOfRangeException), () => t.GetLine(3)); Assert.AreEqual(2, t.NumberOfLines); Assert.AreEqual(Encoding.UTF8, new Text("hmm").Encoding); Assert.AreEqual(Encoding.GetEncoding("latin1"), new Text("hmm", Encoding.GetEncoding("latin1")).Encoding); Assert.AreEqual(s, t.ToString()); Assert.AreEqual(9, t.Length); Assert.AreEqual(9, new Text(s).Length); Assert.AreEqual(2, new Text("你好").Length); Assert.AreEqual(6, new Text("你好").RawLength); Assert.AreEqual(2, new Text("你好", Encoding.UTF32).Length); Assert.AreEqual(8, new Text("你好", Encoding.UTF32).RawLength); }
public void GetLineTest() { var text = new Text(TEXT); Assert.AreEqual("Player Queen:\r\n", text.GetLine(1)); Assert.AreEqual("\r\n", text.GetLine(4)); Assert.AreEqual(new[] { (byte)'P', (byte)'l', (byte)'a', (byte)'y', (byte)'e', (byte)'r', (byte)' ', (byte)'Q', (byte)'u', (byte)'e', (byte)'e', (byte)'n', (byte)':', (byte)'\r', (byte)'\n' }, text.GetRawLine(1)); Assert.AreEqual(new[] { (byte)'\r', (byte)'\n' }, text.GetRawLine(4)); Assert.AreEqual("The lady doth protest too much, methinks.", text.GetLine(18)); Assert.Throws(typeof(ArgumentOutOfRangeException), () => text.GetLine(-1)); Assert.Throws(typeof(ArgumentOutOfRangeException), () => text.GetLine(0)); Assert.Throws(typeof(ArgumentOutOfRangeException), () => text.GetLine(19)); Assert.AreEqual(18, text.NumberOfLines); }