Exemplo n.º 1
0
 public IEnumerable<Project> Interpret(string dslText)
 {
     var reader = new StringReader(dslText);
     Project project = null;
     foreach (var line in reader.ReadLines().Select( s => s.Replace("\n", "")))
     {
         if(line.EndsWith(":"))
         {
             if(project != null)
             {
                 yield return project;
             }
             project = new Project(line);
         }
         else if(project != null && Regex.Match(line, @"^-\s*").Success)
         {
             project.AddTask(new TaskItem(line));
         }
         else if(project != null)
         {
             if (project.Tasks.Count == 0)
                 project.AddNote(line);
             else
                 project.Tasks.Last().AddNote(line);
         }
     }
     yield return project;
 }
        static string[][] GetExpected(string testCase)
        {
            using (var ss = new StringReader(testCase ?? ""))
            {
                var lines = ss.ReadLines().ToArray();

                return lines.Select(l => l.Split('\t')).ToArray();
            }
        }
Exemplo n.º 3
0
        public void Test_ReadLines()
        {
            const string testCase = "A\r\nB\rC\nD\n\rE\n\nF\r\rG\r\r\nH\n\r\nI\r\n\rJ\n\n\rK\r\n";

            using (var stringReader = new StringReader(testCase))
            {
                var expected = stringReader.ReadLines().ToArray();
                var found = testCase.ReadLines().Select(ss => ss.ToString()).ToArray();

                TestFor.Equality(expected.Length + 1, found.Length, "ReadLines in the presence of ending linebreak should read one line extra compared to StringReader");
                TestFor.SequenceEquality(expected, found.Take(expected.Length), "ReadLines should otherwise match StringReader behavior");
            }
        }
Exemplo n.º 4
0
        public void TestReadLines()
        {
            var text = @"line1
            line2
            line3
            ";
              var expectedLines = new[] {
            "line1",
            "line2",
            "line3",
              };

              var reader = new StringReader(text);
              var index = 0;

              foreach (var line in reader.ReadLines()) {
            Assert.AreEqual(expectedLines[index++], line);
              }

              Assert.AreEqual(expectedLines.Length, index);
        }
Exemplo n.º 5
0
        public BlameModel GetBlame(string path)
        {
            string referenceName;
            var commit = GetCommitByPath(ref path, out referenceName);
            if (commit == null)
                return null;

            var entry = commit[path];
            if (entry == null || entry.TargetType != TreeEntryTargetType.Blob)
                return null;

            var blob = (Blob)entry.Target;
            var bytes = blob.GetContentStream().ToBytes();
            var encoding = FileHelper.DetectEncoding(bytes, CpToEncoding(commit.Encoding), _i18n.Value);
            if (encoding == null)
                return null;

            var code = FileHelper.ReadToEnd(bytes, encoding);
            var reader = new StringReader(code);

            var hunks = GitCache.Get<BlameHunkModel[]>(blob.Sha, "blame");
            if (hunks == null)
            {
                var blame = _repository.Blame(path, new BlameOptions { StartingAt = commit });
                hunks = blame.Select(s => new BlameHunkModel
                {
                    Code = reader.ReadLines(s.LineCount),
                    StartLine = s.FinalStartLineNumber,
                    EndLine = s.LineCount,
                    MessageShort = s.FinalCommit.MessageShort.RepetitionIfEmpty(NoCommitMessage),
                    Sha = s.FinalCommit.Sha,
                    Author = s.FinalCommit.Author.Name,
                    AuthorEmail = s.FinalCommit.Author.Email,
                    AuthorDate = s.FinalCommit.Author.When,
                })
                .ToArray();
                GitCache.Set(blob.Sha, "blame", hunks);
            }

            var model = new BlameModel
            {
                ReferenceName = referenceName,
                Sha = commit.Sha,
                Path = string.IsNullOrEmpty(path) ? "" : path,
                SizeString = FileHelper.GetSizeString(blob.Size),
                Brush = FileHelper.GetBrush(path),
                Hunks = hunks,
                BranchSelector = GetBranchSelectorModel(referenceName, commit.Sha, path),
                PathBar = new PathBarModel
                {
                    Name = Name,
                    Action = "Tree",
                    Path = path,
                    ReferenceName = referenceName,
                    ReferenceSha = commit.Sha,
                    HideLastSlash = true,
                },
            };

            return model;
        }
 public static IEnumerable<string> ReadLines(this string s)
 {
     using (var r = new StringReader(s))
         foreach (var line in r.ReadLines())
             yield return line;
 }