Пример #1
0
            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)));
            }
Пример #2
0
            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);
            }
Пример #3
0
            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);
            }
Пример #4
0
        /// <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);
        }