public void ReturnsExpectedOutput_When_RightInput( string inputLine, int[] expectedOutput) { var result = _sut.Parse(inputLine); Assert.Equal(expectedOutput, result); }
public IModel Parse(IModel model) { CobolModel cobolModel = model as CobolModel; string data = cobolModel != null ? cobolModel.Data : null; if (!string.IsNullOrEmpty(data)) { IReader reader = Reader.CreateStringReader(data); int linesRead; if (lineMatcher.Matches(reader, 0, out linesRead)) { string modelData = modelParser.Parse(0, data); string impliedData = impliedParser.Parse(0, data); if (!string.IsNullOrEmpty(impliedData)) { return(new HierarchyModel(modelFactory(cobolModel.Name, modelData, cobolModel.Comment), new [] { impliedFactory(name, impliedData, "Implied") })); } } } return(model); }
private void AssertNoChange(ILineParser matcher, params string[] args) { foreach (string line in args) { Assert.That(matcher.Parse(0, line), Is.EqualTo(line), line); } }
private void AssertWillParse(ILineParser parser, string expected, params string[] args) { foreach (string line in args) { Assert.That(parser.Parse(0, line), Is.EqualTo(expected), line); } }
public void TestBegindAndEndComment() { LineType lineType = LineType.Unassigned; lineType = _Parser.Parse("/*Some comment code*/"); Assert.IsTrue(lineType == LineType.LineComment, "Line should be a full comment"); lineType = _Parser.Parse("void foo(int x, int y, /*int z*/);"); Assert.IsTrue(lineType == LineType.Code, "Line is code"); lineType = _Parser.Parse("void foo(int x, int y, /*)"); Assert.IsTrue(lineType == LineType.BeginComment, "Line type should be begin comment"); lineType = _Parser.Parse("/*sfsfsdfsdf*/some code/*klsflsfd*/"); Assert.IsTrue(lineType == LineType.LineComment, "Line type should be line comment"); }
private static void ProcessLine(FrequencyDictionary <string> dictionary, string value) { foreach (var val in LineParser.Parse(value)) { dictionary.Add(val.ToLower()); } }
/// <summary> /// Get all single fixed format lines from a text file parsed into a strongly typed array /// Default delimiter is '|'. Override by specifying the delimiter in parser settings. /// Example File - /// "John Walsh|456RT4|True|Male" /// "Simone Walsh|456RT5|True|Female" /// </summary> /// <typeparam name="T">Typed Line Class</typeparam> /// <returns> /// Collection of Files each parsed with typed class arrays /// </returns> public File <T>[] GetFiles <T>() where T : FileLine, new() { var files = fileProvider.GetFiles(); return(files.Select(file => new File <T> { FileMeta = new FileMeta { FileName = file.FileName, FilePath = file.FilePath, FileSize = file.FileSize, Lines = file.Lines, }, Data = lineParser.Parse <T>(file.Lines) }) .ToArray()); }
private GroupedItem <T>[] Group( IEnumerable <string> block ) { _Status = SortStatus.Grouping; return (block .AsParallel() .GroupBy(x => x) .Select(g => new GroupedItem <T> { Count = g.Count(), Item = _lineParser.Parse(g.FirstOrDefault()) } ).ToArray()); }
public void ShouldReturnVideogame(string line, int index) { // Arrange var expected = TestData.Videogames[index]; // Act var actual = _lineParser.Parse(line); // Assert CollectionAssert.AreEqual(new[] { expected }, new[] { actual }, new RecursiveComparer()); }
public static IEnumerable<TestLine> GenerateTestRows(int count) { var input = new List<string>(); for (var i = 0; i < count; i++) { var String = Guid.NewGuid(); input.Add($"{String.GetHashCode()}. {String}"); } return input.Select(x => _parser.Parse(x)); }
public async Task <List <Videogame> > Parse(string file) { var videogames = new List <Videogame>(); using (var stream = File.OpenRead(file)) using (var reader = new StreamReader(stream)) { while (!reader.EndOfStream) { var line = await reader.ReadLineAsync(); var videogame = _lineParser.Parse(line); videogames.Add(videogame); } } return(videogames); }
public InputTriangle Read() { var fileLines = _fileReader.Read(); var linesParsed = new List <int[]>(); for (int i = 0; i < fileLines.Length; i++) { try { linesParsed.Add(_lineParser.Parse(fileLines[i])); } catch { throw new FormatException($"Exception during parsing input file -> line number: {i + 1}"); } } return(new InputTriangle { Levels = linesParsed.ToArray() }); }
/// <summary> /// Parses a file /// </summary> /// <param name="fileStream">file stream</param> /// <returns></returns> ILineCount IFileParser.Parse(FileStream fileStream) { LineCounter lineCounter = LineCounter.CreateLineCounter(); ILineParser lineParser = lineCounter.GetLineParser(); fileStream.Position = 0; LineCountImp lineCount = new LineCountImp(); if (fileStream.CanRead) { StreamReader sr = new StreamReader(fileStream); bool inComment = false; while (sr.Peek() > -1) { string line = sr.ReadLine(); LineType lineType = lineParser.Parse(line); if (lineType == LineType.BeginComment) { inComment = true; } lineCount.SetLine((inComment ? LineType.LineComment : lineType)); if (lineType == LineType.EndComment) { inComment = false; } } } return(lineCount); }
public IModel Parse(IReader reader) { int numLines; if (lineMatcher.Matches(reader, 0, out numLines)) { string[] lines = reader.ReadLines(numLines); int lineNo = 0; List <string> data = new List <string>(); List <string> comment = new List <string>(); foreach (string line in lines) { string dataLine = dataParser.Parse(lineNo, line); if (!string.IsNullOrEmpty(dataLine)) { data.Add(dataLine); } string commentLine = commentParser.Parse(lineNo, line); if (!string.IsNullOrEmpty(commentLine)) { comment.Add(commentLine); } lineNo++; } IModel model = modelFactory(name, string.Join(" ", data), string.Join("\n", comment)); if (impliedModelParsers != null) { return(impliedModelParsers.Aggregate(model, (current, impliedParser) => impliedParser.Matches(current) ? impliedParser.Parse(current) : current)); } return(model); } return(null); }
private void AssertWillParse(ILineParser parser, string expected, params string[] args) { foreach (string line in args) { Assert.That(parser.Parse(0,line), Is.EqualTo(expected), line); } }
private void AssertNoChange(ILineParser matcher, params string[] args) { foreach (string line in args) { Assert.That(matcher.Parse(0,line), Is.EqualTo(line), line); } }
public void LineParser() { _lineParser.Parse(Line); }
public void LineParserSpans() { _lineParserSpans.Parse(Line); }
/// <summary> /// Reads and parses the single source line. /// </summary> /// <returns>The parsed line.</returns> public virtual ILine Read() { var line = rte.InputOutput.ReadLine(); return(parser.Parse(line)); }