public void ReturnsAndCommentsValidDirectives() { // Given IPreprocessor preprocessor = new TestPreprocessor(); DirectiveParser directiveParser = new DirectiveParser(preprocessor); string configScript = @"#valid a b c #invalid a b c #validx y z A= =B #valid x y z C"; // When directiveParser.Parse(configScript); // Then Assert.AreEqual(@"//#valid a b c #invalid a b c #validx y z A= =B //#valid x y z C", directiveParser.Code); CollectionAssert.AreEqual(new[] { Tuple.Create((int?)1, "valid", "a b c"), Tuple.Create((int?)6, "valid", "x y z") }, directiveParser.DirectiveValues.Select(x => Tuple.Create(x.Line, x.Name, x.Value))); }
public void DoesNotProcessDirectivesWithSpaceAfterHash() { // Given IPreprocessor preprocessor = new TestPreprocessor(); DirectiveParser directiveParser = new DirectiveParser(preprocessor); string configScript = @"# valid a b c A"; // When directiveParser.Parse(configScript); // Then Assert.AreEqual(@"# valid a b c A", directiveParser.Code); CollectionAssert.IsEmpty(directiveParser.DirectiveValues); }
public void ReturnsSameCode() { // Given IPreprocessor preprocessor = new TestPreprocessor(); DirectiveParser directiveParser = new DirectiveParser(preprocessor); string configScript = @"A B C"; // When directiveParser.Parse(configScript); // Then CollectionAssert.IsEmpty(directiveParser.DirectiveValues); Assert.AreEqual(@"A B C", directiveParser.Code); }
/// <summary> /// Configures the engine using the specified script. /// </summary> /// <param name="script">The script.</param> public void Configure(string script) { CheckDisposed(); if (_configured) { throw new InvalidOperationException("Configuration has already been performed."); } _configured = true; // Parse the script (or use an empty result if no script) DirectiveParser directiveParser = new DirectiveParser(_preprocessor); if (script != null) { directiveParser.Parse(script); } // Process preprocessor directives _preprocessor.ProcessDirectives(this, directiveParser.DirectiveValues); // Initialize everything (order here is very important) AddRecipePackageAndSetTheme(); AddThemePackagesAndPath(); InstallPackages(); LoadAssemblies(); CatalogClasses(); AddNamespaces(); AddFileProviders(); ApplyRecipe(); SetMetadata(); // Finally evaluate the script Evaluate(directiveParser.Code); }