示例#1
0
        // pnyx -e=documentation pncs.cmd.examples.documentation.library.ExampleProcessorChain processorChain
        public static void processorChain()
        {
            StreamInformation streamInformation = new StreamInformation(new Settings());

            // Writes to STDOUT
            ILineProcessor dest = new LineProcessorToStream(streamInformation, Console.OpenStandardOutput());

            // Grep filter / processor pair
            ILineFilter grepFilter = new Grep {
                textToFind = "world", caseSensitive = false
            };
            ILineProcessor grepProcessor = new LineFilterProcessor {
                filter = grepFilter, processor = dest
            };

            // Sed transformer / processor pair
            ILineTransformer sedTransformer = new SedReplace("World", "World, with love from Pnyx..", null);
            ILineProcessor   sedProcessor   = new LineTransformerProcessor {
                transform = sedTransformer, processor = grepProcessor
            };

            // Reads from source
            using (StringStreamFactory streamFactory = new StringStreamFactory("Hello World."))
            {
                using (StreamToLineProcessor source = new StreamToLineProcessor(streamInformation, streamFactory))
                {
                    source.setNextLineProcessor(sedProcessor);

                    // Runs
                    source.process();                // All I/O occurs on this step
                }
            }

            // outputs: Hello World, with love from Pnyx...
        }
示例#2
0
        // https://github.com/ericraider33/pnyx.net/issues/1
        public void bug1()
        {
            SedReplace replace = new SedReplace("set[ ]*", "_", "");

            Assert.Equal("y _x", replace.transformLine("y set x"));
            Assert.Equal("_x", replace.transformLine("set x"));

            replace = new SedReplace("set[ ]*", "_", "i");
            Assert.Equal("y _x", replace.transformLine("y set x"));
            Assert.Equal("_x", replace.transformLine("set x"));
        }
示例#3
0
        public void basic()
        {
            SedReplace replace = new SedReplace("eoe", "XXX", "g");

            Assert.Equal("my text XXX is here", replace.transformLine("my text eoe is here"));
            Assert.Equal("my XXX XXX XXX", replace.transformLine("my eoe eoe eoe"));
            Assert.Equal("XXXXXXXXX", replace.transformLine("eoeeoeeoe"));

            replace = new SedReplace("eoe", "XXX", null);            // same as "1"
            Assert.Equal("my text XXX is here", replace.transformLine("my text eoe is here"));
            Assert.Equal("my XXX eoe eoe", replace.transformLine("my eoe eoe eoe"));
            Assert.Equal("XXXeoeeoe", replace.transformLine("eoeeoeeoe"));

            replace = new SedReplace("eoe", "XXX", "2");
            Assert.Equal("my text eoe is here", replace.transformLine("my text eoe is here"));
            Assert.Equal("my eoe XXX eoe", replace.transformLine("my eoe eoe eoe"));
            Assert.Equal("eoeXXXeoe", replace.transformLine("eoeeoeeoe"));

            replace = new SedReplace("eoe", "XXX", "g2");
            Assert.Equal("my text eoe is here", replace.transformLine("my text eoe is here"));
            Assert.Equal("my eoe XXX XXX", replace.transformLine("my eoe eoe eoe"));
            Assert.Equal("eoeXXXXXX", replace.transformLine("eoeeoeeoe"));
        }
示例#4
0
        private void verify(String pattern, String replacement, String flags, String source, String expected)
        {
            SedReplace replace = new SedReplace(pattern, replacement, flags);

            Assert.Equal(expected, replace.transformLine(source));
        }