public void Lines_OptionsInvalid() { TextReader s = new StringReader (""); s.Lines ((TextReaderCodaOptions) (-1)); }
/// <summary> /// Enumerates the lines of text inside the string. /// </summary> /// /// <param name="input"> /// The string to process on a line-by-line basis. /// </param> /// /// <returns> /// An enumeration of the lines contained in <paramref name="input"/>. /// </returns> public static IEnumerable<string> Lines(this string input) { using (var sr = new StringReader(input)) { foreach (var line in sr.Lines()) { yield return line; } } }
public void lines() { Assert.Throws<ArgumentNullException>(() => StreamExtensions.Lines(null)); using (var reader = new StringReader(string.Empty)) { Assert.False(reader.Lines().Any()); Assert.Equal(-1, reader.Read()); } using (var reader = new StringReader(string.Empty)) { Assert.False(reader.Lines(true).Any()); Assert.Throws<ObjectDisposedException>(() => reader.Read()); } using (var reader = new StringReader($"First{Environment.NewLine}Second{Environment.NewLine}")) { var lines = reader.Lines(); Assert.Equal(3, lines.Count()); Assert.Equal("First", lines[0]); Assert.Equal("Second", lines[1]); Assert.Equal(string.Empty, lines[2]); Assert.False(reader.Lines().Any()); Assert.Equal(-1, reader.Read()); } }