public void GetLineNo_Passes() { var br = System.Environment.NewLine; { var text = "a\n" + "b\n" + "c\n" + "d" ; var lineNo = 1; for (var i = 0; i < text.Length; ++i) { Assert.AreEqual(lineNo, text.GetLineNo(i), $"Fail... pos={i}"); if (text[i] == '\n') { lineNo++; } } } var rnd = new System.Random(); for (var i = 0; i < 1000; ++i) { var newlineCount = rnd.Range(1, 20); var text = Enumerable.Range(0, newlineCount) .Select(_i => rnd.RandomString(rnd.Range(1, 10))) .Aggregate("", (_s, _c) => _s + _c + br); Assert.AreEqual(newlineCount, text.GetLineNo(), $"Fail..."); var pos = rnd.Range(0, text.Length); var newlineCount2 = 1; for (var j = 0; j < pos; ++j) { if (text[j] == '\n') { newlineCount2++; } } Assert.AreEqual(newlineCount2, text.GetLineNo(pos), $"Fail to specify pos({pos})..."); } }