Exemple #1
0
        public ParserOptions ToParserOptions()
        {
            var parserOptions = new ParserOptions();
            foreach (var variable in Variables)
            {
                parserOptions.AddVariable(variable);
            }

            return parserOptions;
        }
        public void ParseSourceFilesSpecifications()
        {
            Parser parser = null;
            "Given new Parser".Context(() => parser = new Parser());

            SourceFiles parserOutput = null;
            "when ParseSourceFiles is invoked with SourceFiles"
                .Do(() =>
                        {
                            var sourceFiles = new SourceFiles
                                              	{
                                              		new SourceFile("main.js", "@rivet includes.push(\"include.js\"); includes.push(\"dir/include.js\"); includes.push(\"dir/dir/include.js\");"),
                                              		new SourceFile("include.js", "BEFORE\r\nTEST//##DEBUG\r\nAFTER\r\n"),
                                              		new SourceFile("dir\\include.js", "BEFORE\r\n//##DEBUG_STARTTEST\r\n//##DEBUG_ENDAFTER\r\n"),
                                              		new SourceFile("dir\\dir\\include.js", "var i = @VARIABLE_1;var j = @VARIABLE_2;")
                                              	};
                            var parserOptions = new ParserOptions();
                            parserOptions.AddVariable(new Variable("VARIABLE_1", "1"));
                            parserOptions.AddVariable(new Variable("VARIABLE_2", "2"));

                            parserOutput = parser.ParseSourceFiles(sourceFiles, parserOptions);
                        });

            "output contains 1 SourceFile".Assert(() => parserOutput.Count.ShouldEqual(1));
            "Identity of output file is \"main.js\"".Assert(() => parserOutput.First().Identity.ShouldEqual("main.js"));
            "Body of output file is \"BEFORE\r\nAFTER\r\nBEFORE\r\nAFTER\r\nvar i = 1;var j = 2;\"".Assert(() => parserOutput.First().Body.ShouldEqual("BEFORE\r\nAFTER\r\nBEFORE\r\nAFTER\r\nvar i = 1;var j = 2;"));
            "first output file has 3 components".Assert(() => parserOutput.First().Components.Count.ShouldEqual(3));
            "Identity of first component of output file is \"include.js\"".Assert(() => parserOutput.First().Components[0].Identity.ShouldEqual("include.js"));
            "Identity of second component of output file is \"dir\\include.js\"".Assert(() => parserOutput.First().Components[1].Identity.ShouldEqual("dir\\include.js"));
            "Identity of third component of output file is \"dir\\dir\\include.js\"".Assert(() => parserOutput.First().Components[2].Identity.ShouldEqual("dir\\dir\\include.js"));
        }
        public void ParseNestedSourceFilesSpecifications()
        {
            Parser parser = null;
            "Given new Parser".Context(() => parser = new Parser());

            SourceFiles parserOutput = null;
            "when ParseSourceFiles is invoked with SourceFiles containing nested references"
                .Do(() =>
                        {
                            var sourceFiles = new SourceFiles
                                              	{
                                              		new SourceFile("rivet-A.js", "@rivet includes.push(\"A.js\"); includes.push(\"rivet-B.js\");"),
                                              		new SourceFile("A.js", "A"),
                                              		new SourceFile("rivet-B.js", "@rivet includes.push(\"B.js\"); includes.push(\"rivet-C.js\");"),
                                              		new SourceFile("B.js", "B"),
                                              		new SourceFile("rivet-C.js", "@rivet includes.push(\"C1.js\"); includes.push(\"C2.js\");"),
                                              		new SourceFile("C1.js", "@VARIABLE"),
                                              		new SourceFile("C2.js", "C2"),
                                              	};
                            var parserOptions = new ParserOptions();
                            parserOptions.AddVariable(new Variable("VARIABLE", "C1"));

                            parserOutput = parser.ParseSourceFiles(sourceFiles, parserOptions);
                        });

            "output contains 3 SourceFile".Assert(() => parserOutput.Count.ShouldEqual(3));
            "group A nested references are resolved".Assert(() => parserOutput[0].Body.ShouldEqual("ABC1C2"));
            "Rivet file A is made up of 4 components".Assert(() => parserOutput[0].Components.Count.ShouldEqual(4));
            "group B nested references are resolved".Assert(() => parserOutput[1].Body.ShouldEqual("BC1C2"));
            "Rivet file B is made up of 3 components".Assert(() => parserOutput[1].Components.Count.ShouldEqual(3));
            "group C nested references are resolved".Assert(() => parserOutput[2].Body.ShouldEqual("C1C2"));
            "Rivet file C is made up of 2 components".Assert(() => parserOutput[2].Components.Count.ShouldEqual(2));
        }