public void Parse_ShouldAbleToParseMultipleRows_WhenValidInputIsPassed() { // Given var input = "1,2,3\n4,5,6\n"; var visitor = new CsvTreeVisitorStub(CsvLanguageElements.Row); var treeFactory = new CsvTreeFactoryStub(); var underTest = new CsvCompiler(); // When underTest.Parse(input, visitor, treeFactory); var result = visitor.GetVisitedRules(); // Then Assert.That(result, Is.Not.Empty); Assert.That(result, Contains.Item("Row(1,2,3\n)")); Assert.That(result, Contains.Item("Row(4,5,6\n)")); }
public void Parse_ShouldAbleToParseMultipleRows_WhenValidInputIsPassed() { // Given var input = "1,2,3\n4,5,6\n"; var visitor = new CsvTreeVisitorStub(CsvLanguageElements.Row); var treeFactory = new CsvTreeFactoryStub(); var underTest = new CsvCompiler(); // When underTest.Parse(input, visitor, treeFactory); var result = visitor.GetVisitedRules(); // Then Assert.That(result, Is.Not.Empty); Assert.That(result, Contains.Item("Row(1,2,3\n)")); Assert.That(result, Contains.Item("Row(4,5,6\n)")); }
public void SelectChildrenOperand_ShouldReturnAllChildrenOfRows_WhenCsvDocumentNodeIsPassedAndSelectRelativeNodesOperandIsUsed() { // Given var compiler = new CsvCompiler(); var input = "first,second,third"; var documentNode = compiler.Parse(input).As <CsvCompilationUnit>(); // When var right = new SelectionCombinator(new FieldSelector()); var combinator = new RelativeNodeCombinator(new UniversalCombinator(), right); var result = combinator.Calculate(new[] { documentNode }); // Then Assert.That(result, Is.Not.Empty); Assert.That(result, Has.All.InstanceOf <FieldDeclarationSyntax>()); }
public void SelectChildrenOperand_ShouldReturnAllChildrenOfRows_WhenCsvDocumentNodeIsPassedAndSelectRelativeNodesOperandIsUsed() { // Given var compiler = new CsvCompiler(); var input = "first,second,third"; var documentNode = compiler.Parse(input).As<CsvCompilationUnit>(); // When var right = new SelectionCombinator(new FieldSelector()); var combinator = new RelativeNodeCombinator(new UniversalCombinator(), right); var result = combinator.Calculate(new[] { documentNode }); // Then Assert.That(result, Is.Not.Empty); Assert.That(result, Has.All.InstanceOf<FieldDeclarationSyntax>()); }
public void Compilation_ShouldCompileAndExecuteCsvInput_WhenProperQueryIsPassed() { // Given var csvInput = "first,second,third,fourth"; var csvCompiler = new CsvCompiler(); var query = "UniversalSelector FieldNodeSelector | @get-text | @to-upper-case | @to-string"; // When var csvSyntaxTree = csvCompiler.Parse(csvInput); var controlFlowDescriptor = Compiler.Parse(query); var controlFlow = ControlFlowFactory.Create(controlFlowDescriptor); var result = controlFlow.Execute(csvSyntaxTree); // Then Assert.That(result, Is.Not.Null); Assert.That(result, Is.EquivalentTo(new[] { "FIRST", "SECOND", "THIRD", "FOURTH" })); }
public void SelectChildrenOperand_ShouldReturnAllChildrenOfRows_WhenCsvDocumentNodeIsPassed() { // Given var compiler = new CsvCompiler(); var input = "first,second,third"; var documentNode = compiler.Parse(input).As <CsvCompilationUnit>(); var underTest = new RowSelector(); // When var left = new AbsoluteCombinator(underTest); var right = new AbsoluteCombinator(new FieldSelector()); var combinator = new ChildrenCombinator(left, right); var result = combinator.Calculate(documentNode.Children); // Then Assert.That(result, Has.All.InstanceOf <FieldDeclarationSyntax>()); }
public void SelectChildrenOperand_ShouldReturnAllChildrenOfRows_WhenCsvDocumentNodeIsPassed() { // Given var compiler = new CsvCompiler(); var input = "first,second,third"; var documentNode = compiler.Parse(input).As<CsvCompilationUnit>(); var underTest = new RowSelector(); // When var left = new AbsoluteCombinator(underTest); var right = new AbsoluteCombinator(new FieldSelector()); var combinator = new ChildrenCombinator(left, right); var result = combinator.Calculate(documentNode.Children); // Then Assert.That(result, Has.All.InstanceOf<FieldDeclarationSyntax>()); }
public void Parse_ShouldCreateParseTree_WhenValidInputIsPassed() { // Given var input = "one,two\nthree,four"; var underTest = new CsvCompiler(); // When var node = underTest.Parse(input) as CsvCompilationUnit; var fields = node.ToEnumerable().OfType<FieldDeclarationSyntax>(); var allOfThemIsTextField = fields.All(field => field.IsTextField); var fieldValues = fields.Select(getTextFromNode); // Then Assert.That(allOfThemIsTextField, Is.True); Assert.That(fieldValues, Is.EquivalentTo(new[] { "one", "two", "three", "four" })); }
public void Parse_ShouldCreateParseTree_WhenValidInputIsPassed() { // Given var input = "one,two\nthree,four"; var underTest = new CsvCompiler(); // When var node = underTest.Parse(input) as CsvCompilationUnit; var fields = node.ToEnumerable().OfType <FieldDeclarationSyntax>(); var allOfThemIsTextField = fields.All(field => field.IsTextField); var fieldValues = fields.Select(getTextFromNode); // Then Assert.That(allOfThemIsTextField, Is.True); Assert.That(fieldValues, Is.EquivalentTo(new[] { "one", "two", "three", "four" })); }
public void Parse_ShouldAbleToParseMixedTypedFields_WhenValidInputIsPassed() { // Given var input = "\"1\",2,,\"4\",5"; var underTest = new CsvCompiler(); // When var node = underTest.Parse(input).As<CsvCompilationUnit>(); var fields = node.ToEnumerable().OfType<FieldDeclarationSyntax>(); var stringFields = fields.Where(field => field.IsStringField) .Select(getTextFromNode); var textFields = fields.Where(field => field.IsTextField) .Select(getTextFromNode); var emptyFields = fields.Where(field => field.IsEmptyField) .Select(getTextFromNode); // Then Assert.That(stringFields, Is.EquivalentTo(new[] { "\"1\"", "\"4\"" })); Assert.That(textFields, Is.EquivalentTo(new[] { "2", "5" })); Assert.That(emptyFields, Is.EquivalentTo(new[] { "" })); }
public void Parse_ShouldAbleToParseMixedTypedFields_WhenValidInputIsPassed() { // Given var input = "\"1\",2,,\"4\",5"; var underTest = new CsvCompiler(); // When var node = underTest.Parse(input).As <CsvCompilationUnit>(); var fields = node.ToEnumerable().OfType <FieldDeclarationSyntax>(); var stringFields = fields.Where(field => field.IsStringField) .Select(getTextFromNode); var textFields = fields.Where(field => field.IsTextField) .Select(getTextFromNode); var emptyFields = fields.Where(field => field.IsEmptyField) .Select(getTextFromNode); // Then Assert.That(stringFields, Is.EquivalentTo(new[] { "\"1\"", "\"4\"" })); Assert.That(textFields, Is.EquivalentTo(new[] { "2", "5" })); Assert.That(emptyFields, Is.EquivalentTo(new[] { "" })); }
/// <summary> /// Initializes a new instance of the <see cref="CsvCompilerModule"/> class. /// </summary> public CsvCompilerModule(Bootstrapper bootstrapper) : base(bootstrapper) { csvCompiler = new CsvCompiler(); }
/// <summary> /// Initializes a new instance of the <see cref="CsvCompilerModule"/> class. /// </summary> public CsvCompilerModule(Bootstrapper bootstrapper) : base(bootstrapper) { csvCompiler = new CsvCompiler(); }