コード例 #1
0
        // pnyx -e=documentation pncs.cmd.examples.documentation.library.ExampleRow printDelimiter
        public static void print()
        {
            const String input = "Socialism,Communism,Fascism";

            using (Pnyx p = new Pnyx())
            {
                p.readString(input);
                p.parseCsv();
                p.print("Failed Systems: $1, $2, and $3");
                p.writeStdout();
            }
            // outputs: Failed Systems: Socialism, Communism, and Fascism
        }
コード例 #2
0
ファイル: PnyxTest.cs プロジェクト: ericraider33/pnyx.net
        public void csvInOut()
        {
            String actual;

            using (Pnyx p = new Pnyx())
            {
                p.readString(PLANETS_GODS);
                p.parseCsv();
                actual = p.processToString();
            }

            Assert.Equal(PLANETS_GODS, actual);
        }
コード例 #3
0
 public static void helloWorld()
 {
     using (Pnyx p = new Pnyx())
     {
         p.readString("Hello World.");
         p.sed("World", "World, with love from Pnyx.."); // transforms each line
         p.grep("world", caseSensitive: false);          // filters each line
         p.writeStdout();
         p.compile();                                    // Builds processors and wires filters together
         p.process();                                    // Runs processors (All IO is done here)
     }
     // outputs: Hello World, with love from Pnyx...
 }
コード例 #4
0
ファイル: PnyxTest.cs プロジェクト: ericraider33/pnyx.net
        public void columnDefinition(bool maxWidth, bool hasHeaderRow, bool minWidth, bool nullable, String expected)
        {
            String actual;

            using (Pnyx p = new Pnyx())
            {
                p.readString(ECONOMIC_FREEDOM);
                p.parseTab(hasHeader: hasHeaderRow);
                p.columnDefinition(null, maxWidth, hasHeaderRow, minWidth, nullable, swapRowsAndColumns: false);
                actual = p.processToString();
            }
            Assert.Equal(expected, actual);
        }
コード例 #5
0
        // pnyx -e=documentation pncs.cmd.examples.documentation.library.ExampleRow printDelimiter
        public static void printDelimiter()
        {
            const String input = "col1,\"Column, zwei\"";

            using (Pnyx p = new Pnyx())
            {
                p.readString(input);
                p.parseCsv();
                p.printDelimiter("|");
                p.writeStdout();
            }
            // outputs: col1|Column, zwei
        }
コード例 #6
0
ファイル: PnyxTest.cs プロジェクト: ericraider33/pnyx.net
        public void count(String source, int expected)
        {
            String actual;

            using (Pnyx p = new Pnyx())
            {
                p.readString(source);
                p.countLines();
                actual = p.processToString();
            }

            Assert.Equal(expected, int.Parse(actual));
        }
コード例 #7
0
ファイル: ExampleLine.cs プロジェクト: ericraider33/pnyx.net
        // pnyx -e=documentation pncs.cmd.examples.documentation.library.ExampleLine embeddedNewlineParseCsv
        public static void embeddedNewlineAutoAsCsv()
        {
            const String input = "a,\"Long\nText\n\"";

            using (Pnyx p = new Pnyx())
            {
                p.readString(input); // CsvStreamToRowProcessor (auto-wired)
                p.parseCsv(strict: false);
                p.selectColumns(2, 1);
                p.writeStdout();
            }
            // "Long\nText\n",a
        }
コード例 #8
0
ファイル: ExampleLine.cs プロジェクト: ericraider33/pnyx.net
        // pnyx -e=documentation pncs.cmd.examples.documentation.library.ExampleLine embeddedNewlineAsCsv
        public static void embeddedNewlineAsCsv()
        {
            const String input = "a,\"Long\nText\n\"";

            using (Pnyx p = new Pnyx())
            {
                p.asCsv(p2 => p.readString(input)); // CsvStreamToRowProcessor
                p.selectColumns(2, 1);
                p.writeStdout();
            }
            // outputs:
            // "Long\nText\n",a
        }
コード例 #9
0
ファイル: ExampleLine.cs プロジェクト: ericraider33/pnyx.net
        // pnyx -e=documentation pncs.cmd.examples.documentation.library.ExampleLine rowConverter
        public static void rowConverter()
        {
            const String input = "set x := (set == 0 ? 0 : 100 / set)";

            using (Pnyx p = new Pnyx())
            {
                p.readString(input);
                p.lineToRow(new ExampleRowConverter());
                p.withColumns(p2 => p2.sed("set[ ]*", "var ", "i"), 1); // replace set from first column
                p.writeStdout();                                        // internally converts back to line
            }
            // outputs: var x := (set == 0 ? 0 : 100 / set)
        }
コード例 #10
0
ファイル: PnyxEndTest.cs プロジェクト: ericraider33/pnyx.net
        public void setEndRow()
        {
            TestEndRow processor = new TestEndRow();

            using (Pnyx p = new Pnyx())
            {
                p.readString("a,1\nb,2\nc,3");
                p.parseCsv();
                p.endRow(processor);
            }

            Assert.Equal("a|1\nb|2\nc|3\nEOF\n", processor.ToString());
        }
コード例 #11
0
ファイル: PnyxTest.cs プロジェクト: ericraider33/pnyx.net
        public void csvInOutFixFormatting()
        {
            String actual;

            using (Pnyx p = new Pnyx())
            {
                p.readString(PLANETS_GODS_FORMAT_ISSUES);
                p.parseCsv(strict: false);
                actual = p.processToString();
            }

            Assert.Equal(PLANETS_GODS, actual); // verifies that output is formatted properly, even if input is loose
        }
コード例 #12
0
ファイル: PnyxTest.cs プロジェクト: ericraider33/pnyx.net
        public void countRow()
        {
            String actual;

            using (Pnyx p = new Pnyx())
            {
                p.readString(PLANETS_GODS);
                p.parseCsv();
                p.countLines();
                actual = p.processToString();
            }

            Assert.Equal("7,7,7", actual.TrimEnd());
        }
コード例 #13
0
        // pnyx -e=documentation pncs.cmd.examples.documentation.library.ExampleSettings instance
        public static void instance()
        {
            const String input = "line one\nline two";

            using (Pnyx p = new Pnyx())
            {
                p.setSettings(stdIoDefault: true);
                p.readString(input);
                p.process(); // automatically writes to STD-OUT
            }
            // outputs STD-OUT:
            // line one
            // line two
        }
コード例 #14
0
ファイル: ExampleLine.cs プロジェクト: ericraider33/pnyx.net
        // pnyx -e=documentation pncs.cmd.examples.documentation.library.ExampleLine parseDelimiter
        public static void parseDelimiter()
        {
            const String input = "a|b|c|d|e|f|g";

            using (Pnyx p = new Pnyx())
            {
                p.readString(input);
                p.sed("[aceg]", @"\0\0", "gi");     // duplicates every other char
                p.parseDelimiter("|");
                p.print("$1,$3,$5,$7|$2,$4,$6");
                p.writeStdout();
            }
            // outputs: aa,cc,ee,gg|b,d,f
        }
コード例 #15
0
ファイル: PnyxTest.cs プロジェクト: ericraider33/pnyx.net
        public void rowFilterShimOr()
        {
            String actual;

            using (Pnyx p = new Pnyx())
            {
                p.readString(PLANETS_GODS_TITANS);
                p.parseCsv();
                p.grep("u");                        // U needs to be present in any column
                actual = p.processToString();
            }

            Assert.Equal(PLANETS_GODS_TITANS, actual);
        }
コード例 #16
0
ファイル: PnyxTest.cs プロジェクト: ericraider33/pnyx.net
        public void tabInOutExplicit()
        {
            String actual;

            using (Pnyx p = new Pnyx())
            {
                p.readString(ECONOMIC_FREEDOM);
                p.parseTab();
                p.printTab();
                actual = p.processToString();
            }

            Assert.Equal(ECONOMIC_FREEDOM, actual);
        }
コード例 #17
0
ファイル: PnyxTest.cs プロジェクト: ericraider33/pnyx.net
        public void lineTransform()
        {
            String actual;

            using (Pnyx p = new Pnyx())
            {
                p.readString(EARTH);
                p.sed(",", "\t", "g");
                actual = p.processToString();
            }

            const String expected = "Gaia\tTerra\t\"Mother goddess of the earth\"";

            Assert.Equal(expected, actual);
        }
コード例 #18
0
ファイル: PnyxTest.cs プロジェクト: ericraider33/pnyx.net
        public void printLine()
        {
            String actual;

            using (Pnyx p = new Pnyx())
            {
                p.readString("Logic");
                p.print("$0 $0");
                actual = p.processToString();
            }

            const String expected = "Logic Logic";

            Assert.Equal(expected, actual);
        }
コード例 #19
0
        // pnyx -e=documentation pncs.cmd.examples.documentation.library.ExampleRow filterFunc
        public static void filterFunc()
        {
            const String input = @"Line one,KEEPER
Line two,Loser
";

            using (Pnyx p = new Pnyx())
            {
                p.readString(input);
                p.parseCsv();
                p.rowFilterFunc(x => TextUtil.isUpperCase(x[1]));
                p.writeStdout();
            }
            // outputs:
            // "Line one",KEEPER
        }
コード例 #20
0
ファイル: PnyxTest.cs プロジェクト: ericraider33/pnyx.net
        public void lineFilter()
        {
            String actual;

            using (Pnyx p = new Pnyx())
            {
                p.readString(MAGNA_CARTA);
                p.grep("god", caseSensitive: false);
                actual = p.processToString();
            }

            const String expected = @"KNOW THAT BEFORE GOD, for the health of our soul and those of our ancestors and heirs, 
to the honour of God, the exaltation of the holy Church, and the better ordering of our";

            Assert.Equal(expected, actual);
        }
コード例 #21
0
ファイル: PnyxTest.cs プロジェクト: ericraider33/pnyx.net
        public void columnToLine()
        {
            String actual;

            using (Pnyx p = new Pnyx())
            {
                p.readString(EARTH);
                p.parseCsv();
                p.printColumn(2);
                actual = p.processToString();
            }

            const String expected = "Terra";

            Assert.Equal(expected, actual);
        }
コード例 #22
0
ファイル: PnyxTest.cs プロジェクト: ericraider33/pnyx.net
        public void columns()
        {
            String actual;

            using (Pnyx p = new Pnyx())
            {
                p.readString(EARTH);
                p.parseCsv();
                p.selectColumns(3, 2, 1);
                actual = p.processToString();
            }

            const String expected = @"""Mother goddess of the earth"",Terra,Gaia";

            Assert.Equal(expected, actual);
        }
コード例 #23
0
ファイル: PnyxTest.cs プロジェクト: ericraider33/pnyx.net
        public void printRow()
        {
            String actual;

            using (Pnyx p = new Pnyx())
            {
                p.readString(EARTH);
                p.parseCsv();
                p.print("$3,$2,$1");
                actual = p.processToString();
            }

            const String expected = "Mother goddess of the earth,Terra,Gaia";

            Assert.Equal(expected, actual);
        }
コード例 #24
0
ファイル: PnyxTest.cs プロジェクト: ericraider33/pnyx.net
        public void rowTransform()
        {
            String actual;

            using (Pnyx p = new Pnyx())
            {
                p.readString(EARTH);
                p.parseCsv();
                p.sed("Ter.*", "Forma", "g");
                actual = p.processToString();
            }

            const String expected = "Gaia,Forma,\"Mother goddess of the earth\"";

            Assert.Equal(expected, actual);
        }
コード例 #25
0
ファイル: PnyxTest.cs プロジェクト: ericraider33/pnyx.net
        public void rowFilter()
        {
            String actual;

            using (Pnyx p = new Pnyx())
            {
                p.readString(PLANETS_GODS);
                p.parseCsv();
                p.grep("war");
                actual = p.processToString();
            }

            const String expected = "Ares,Mars,\"Hated god of war\"\r\n";

            Assert.Equal(expected, actual);
        }
コード例 #26
0
ファイル: PnyxTest.cs プロジェクト: ericraider33/pnyx.net
        public void teeServile()
        {
            MemoryStream capture = new MemoryStream();

            Pnyx teeP = null;
            Pnyx p    = new Pnyx();

            p.readString(PLANETS_GODS_TITANS);
            p.tee(pn =>
            {
                teeP = pn;
                pn.writeStream(capture);
            });

            Assert.Equal(FluentState.CompiledServile, teeP.state);
            Assert.Throws <IllegalStateException>(() => teeP.process());
        }
コード例 #27
0
ファイル: PnyxTest.cs プロジェクト: ericraider33/pnyx.net
        public void or()
        {
            String actual;

            using (Pnyx p = new Pnyx())
            {
                p.readString(PLANETS_GODS);
                p.or(pn =>
                {
                    pn.grep("Cronus");
                    pn.grep("Uranus");
                });
                actual = p.processToString();
            }

            Assert.Equal(PLANETS_GODS_TITANS, actual);
        }
コード例 #28
0
ファイル: PnyxTest.cs プロジェクト: ericraider33/pnyx.net
        public void tabHasHeader()
        {
            const String source = "headerA\theaderB\nvalueA1\tvalueB1";
            String       actual;

            using (Pnyx p = new Pnyx())
            {
                p.readString(source);
                p.parseTab(hasHeader: true);
                p.sed("[AB]", "X");
                actual = p.processToString();
            }

            const String expected = "headerA\theaderB\nvalueX1\tvalueX1";

            Assert.Equal(expected, actual);
        }
コード例 #29
0
ファイル: PnyxTest.cs プロジェクト: ericraider33/pnyx.net
        public void lineToRow()
        {
            String       actual;
            const String tabSource = "1) Be fruitful and multiply\t2) and fill the earth and subdue it";

            using (Pnyx p = new Pnyx())
            {
                p.readString(tabSource);
                p.sed("[\t]", ",", "g");
                p.parseCsv(strict: false);
                actual = p.processToString();
            }

            const String expected = @"""1) Be fruitful and multiply"",""2) and fill the earth and subdue it""";

            Assert.Equal(expected, actual);
        }
コード例 #30
0
ファイル: PnyxTest.cs プロジェクト: ericraider33/pnyx.net
        public void lineBuffering()
        {
            String actual;

            using (Pnyx p = new Pnyx())
            {
                p.setSettings(defaultNewline: StreamInformation.newlineString(NewLineEnum.Windows));
                p.readString(EARTH);
                p.sedAppendLine("The Lord is my shepherd");
                actual = p.processToString();
            }

            const String expected = @"Gaia,Terra,""Mother goddess of the earth""
The Lord is my shepherd";

            Assert.Equal(expected, actual);
        }