public void WideSelection()
 {
     CompositeFormatter compositeFormatter = new CompositeFormatter();
     StubFormatter formatter = new StubFormatter();
     compositeFormatter.AddFormatter(typeof(IList), formatter, true);
     Assert.IsNull(compositeFormatter.SelectFormatter(typeof(Guid)));
     Assert.AreSame(formatter, compositeFormatter.SelectFormatter(typeof(ArrayList)));
     Assert.AreSame(formatter, compositeFormatter.SelectFormatter(typeof(int[])));
 }
Exemplo n.º 2
0
        public void StubFormatterCanUseBuiltInRules()
        {
            StubFormatter formatter = new StubFormatter();

            // Just try a couple of basic types.
            Assert.AreEqual("\"abc\"", formatter.Format("abc"));
            Assert.AreEqual("1.2m", formatter.Format(1.2m));
            Assert.AreEqual("'\\n'", formatter.Format('\n'));
        }
Exemplo n.º 3
0
            public void Will_write_the_header()
            {
                StubLanguageParser stubLanguageParser = new StubLanguageParser();
                CodeColorizer      codeColorizer      = new CodeColorizer(stubLanguageParser);
                const string       sourceCode         = "fnord";
                StubFormatter      stubFormatter      = new StubFormatter();
                StubStyleSheet     stubStyleSheet     = new StubStyleSheet();
                StubTextWriter     stubTextWriter     = new StubTextWriter();

                codeColorizer.Colorize(sourceCode, new StubLanguage(), stubFormatter, stubStyleSheet, stubTextWriter);

                Assert.Equal(stubTextWriter, stubFormatter.WriteHeader__textWriter);
                Assert.Equal(stubStyleSheet, stubFormatter.WriteHeader__styleSheet);
            }
Exemplo n.º 4
0
            public void Will_write_the_footer()
            {
                StubLanguageParser languageParser = new StubLanguageParser();
                CodeColorizer      codeColorizer  = new CodeColorizer(languageParser);
                const string       sourceCode     = "fnord";
                StubFormatter      formatter      = new StubFormatter();
                StubStyleSheet     styleSheet     = new StubStyleSheet();
                StubTextWriter     writer         = new StubTextWriter();

                codeColorizer.Colorize(sourceCode, new StubLanguage(), formatter, styleSheet, writer);

                Assert.Equal(writer, formatter.WriteFooter__writer);
                Assert.Equal(styleSheet, formatter.WriteFooter__styleSheet);
            }
Exemplo n.º 5
0
            public void Will_write_the_parsed_source_code()
            {
                StubLanguageParser languageParser = new StubLanguageParser();

                languageParser.Parse__do = (sourceCodeToParse, language, parsedSourceCodeHandler) =>
                {
                    parsedSourceCodeHandler("parsedSourceCode1", new List <Scope>());
                    parsedSourceCodeHandler("parsedSourceCode2", new List <Scope>());
                };
                CodeColorizer codeColorizer = new CodeColorizer(languageParser);
                const string  sourceCode    = "fnord";
                StubFormatter formatter     = new StubFormatter();

                codeColorizer.Colorize(sourceCode, new StubLanguage(), formatter, new StubStyleSheet(), new StubTextWriter());

                Assert.Equal("parsedSourceCode2", formatter.Write__parsedSourceCode.Pop());
                Assert.Equal("parsedSourceCode1", formatter.Write__parsedSourceCode.Pop());
            }
            public void Will_write_the_parsed_source_code()
            {
                StubLanguageParser languageParser = new StubLanguageParser();
                languageParser.Parse__do = (sourceCodeToParse, language, parsedSourceCodeHandler) =>
                {
                    parsedSourceCodeHandler("parsedSourceCode1", new List<Scope>());
                    parsedSourceCodeHandler("parsedSourceCode2", new List<Scope>());
                };
                CodeColorizer codeColorizer = new CodeColorizer(languageParser);
                const string sourceCode = "fnord";
                StubFormatter formatter = new StubFormatter();

                codeColorizer.Colorize(sourceCode, new StubLanguage(), formatter, new StubStyleSheet(), new StubTextWriter());

                Assert.Equal("parsedSourceCode2", formatter.Write__parsedSourceCode.Pop());
                Assert.Equal("parsedSourceCode1", formatter.Write__parsedSourceCode.Pop());
            }
            public void Will_write_the_header()
            {
                StubLanguageParser stubLanguageParser = new StubLanguageParser();
                CodeColorizer codeColorizer = new CodeColorizer(stubLanguageParser);
                const string sourceCode = "fnord";
                StubFormatter stubFormatter = new StubFormatter();
                StubStyleSheet stubStyleSheet = new StubStyleSheet();
                StubTextWriter stubTextWriter = new StubTextWriter();

                codeColorizer.Colorize(sourceCode, new StubLanguage(), stubFormatter, stubStyleSheet, stubTextWriter);

                Assert.Equal(stubTextWriter, stubFormatter.WriteHeader__textWriter);
                Assert.Equal(stubStyleSheet, stubFormatter.WriteHeader__styleSheet);
            }
            public void Will_write_the_footer()
            {
                StubLanguageParser languageParser = new StubLanguageParser();
                CodeColorizer codeColorizer = new CodeColorizer(languageParser);
                const string sourceCode = "fnord";
                StubFormatter formatter = new StubFormatter();
                StubStyleSheet styleSheet = new StubStyleSheet();
                StubTextWriter writer = new StubTextWriter();

                codeColorizer.Colorize(sourceCode, new StubLanguage(), formatter, styleSheet, writer);

                Assert.Equal(writer, formatter.WriteFooter__writer);
                Assert.Equal(styleSheet, formatter.WriteFooter__styleSheet);
            }