コード例 #1
0
		public void EmptyTextReaderRead() {
			using (TestStringReader reader = new TestStringReader(0)) {
				TextBuffer charBuffer = new TextBuffer(reader);
				LineInfo position;
				Assert.Equal(string.Empty, charBuffer.Read(0, out position));
			}
		}
コード例 #2
0
		public void EmptyTextReaderLook() {
			using (TestStringReader reader = new TestStringReader(0)) {
				TextBuffer charBuffer = new TextBuffer(reader);
				char ch;
				Assert.False(charBuffer.TryLookahead(0, out ch));
			}
		}
コード例 #3
0
		public void MarkLongDistanceAndReplay() {
			using (TestStringReader reader = new TestStringReader(1024*20)) {
				TextBuffer charBuffer = new TextBuffer(reader);
				char ch;
				LineInfo position;
				Assert.Equal(reader.ToString().Substring(0, 128), charBuffer.Read(128, out position));
				int offset = 0;
				for (int i = 128; i < 1024*16; i++) {
					Assert.True(charBuffer.TryLookahead(ref offset, out ch));
					Assert.Equal(reader[i], ch);
				}
				offset = 0;
				for (int i = 128; i < 1024*8; i++) {
					Assert.True(charBuffer.TryLookahead(ref offset, out ch));
					Assert.Equal(reader[i], ch);
				}
				Assert.Equal(reader.ToString().Substring(128), charBuffer.Read(reader.Length-128, out position));
				Assert.False(charBuffer.TryLookahead(0, out ch));
			}
		}
コード例 #4
0
		public void ReadAndRollback() {
			using (TestStringReader reader = new TestStringReader(1024*20)) {
				TextBuffer charBuffer = new TextBuffer(reader);
				LineInfo position1;
				Assert.Equal(reader.ToString().Substring(0, 1280), charBuffer.Read(1280, out position1));
				Assert.Equal(charBuffer.Position, 1280);
				charBuffer.Rollback();
				Assert.Equal(charBuffer.Position, 0);
				LineInfo position2;
				Assert.Equal(reader.ToString().Substring(0, 1280), charBuffer.Read(1280, out position2));
				Assert.Equal(position1, position2);
			}
		}
コード例 #5
0
		public void ReadSingleChar() {
			using (TestStringReader reader = new TestStringReader(1)) {
				TextBuffer charBuffer = new TextBuffer(reader);
				LineInfo position;
				Assert.Equal(reader[0].ToString(CultureInfo.InvariantCulture), charBuffer.Read(1, out position));
				char ch;
				Assert.False(charBuffer.TryLookahead(0, out ch));
			}
		}
コード例 #6
0
		public void ReadManyChars() {
			using (TestStringReader reader = new TestStringReader(1024*1024)) {
				TextBuffer charBuffer = new TextBuffer(reader);
				char ch;
				for (int i = 0; i < reader.Length; i++) {
					Assert.True(charBuffer.TryLookahead(i, out ch));
					Assert.Equal(reader[i], ch);
				}
				Assert.False(charBuffer.TryLookahead(reader.Length, out ch));
			}
		}
コード例 #7
0
		public void MultilineLfCr() {
			using (TestStringReader reader = new TestStringReader("1\n\r\n\r3")) {
				TextBuffer charBuffer = new TextBuffer(reader);
				LineInfo position;
				charBuffer.Read(reader.Length, out position);
				Assert.Equal(1, position.Line);
				Assert.Equal(3, charBuffer.Line);
			}
		}