コード例 #1
0
        public void codeFunc()
        {
            CodeParser parser = new CodeParser();

            parser.parseCode(p, "readString(\"test\").lineFilterFunc(line => true)", compilePnyx: false);
            String actual = p.processToString();

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

            using (Pnyx p = new Pnyx())
            {
                p.readString(PLANETS_GODS);
                p.parseCsv();
                p.columnFilter(3, new Grep {
                    textToFind = "titan", caseSensitive = false
                });
                actual = p.processToString();
            }

            Assert.Equal(PLANETS_GODS_TITANS, actual);

            using (Pnyx p = new Pnyx())
            {
                p.readString(PLANETS_GODS);
                p.parseCsv();
                p.columnFilter(1, new Grep {
                    textToFind = "titan", caseSensitive = false
                });
                actual = p.processToString();
            }

            Assert.Equal("", actual);
        }
コード例 #3
0
        public void verifyColumnSorting()
        {
            const String input =
                @"a,a,9
a,c,7
a,b,5
c,a,1
a,d,8
";
            String actual;

            using (Pnyx p = new Pnyx())
            {
                p.readString(input);
                p.parseCsv();
                p.sort(columnNumbers: new [] { 1, 3 });
                actual = p.processToString();
            }

            const String expect =
                @"a,b,5
a,c,7
a,d,8
a,a,9
c,a,1
";

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

            using (Pnyx p = new Pnyx())
            {
                p.tailStream(p2 => p2.readString(MAGNA_CARTA), 2);
                actual = p.processToString();
            }

            const String expected =
                @"Matthew Fitz Herbert, Thomas Basset, Alan Basset, Philip Daubeny, Robert de Roppeley,
John Marshal, John Fitz Hugh, and other loyal subjects:";

            Assert.Equal(expected, actual);


            // Uses buffer instead of manipulating the stream
            using (Pnyx p = new Pnyx())
            {
                p.readString(MAGNA_CARTA);
                p.tail(2);
                actual = p.processToString();
            }
            Assert.Equal(expected, actual);
        }
コード例 #5
0
ファイル: PnyxTest.cs プロジェクト: ericraider33/pnyx.net
        public void teeLine()
        {
            StringBuilder capture = new StringBuilder();
            String        actualA;

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

            using (p)
            {
                p.readString(PLANETS_GODS_TITANS);
                p.tee(pn =>
                {
                    teeP = pn;
                    pn.captureText(capture);
                });
                actualA = p.processToString();
            }
            String actualB = capture.ToString();

            Assert.Equal(actualA, PLANETS_GODS_TITANS);
            Assert.Equal(actualB, PLANETS_GODS_TITANS);
            Assert.Equal(FluentState.Disposed, p.state);
            Assert.Equal(FluentState.Disposed, teeP.state);
        }
コード例 #6
0
ファイル: PnyxTest.cs プロジェクト: ericraider33/pnyx.net
        public void tailStreamRow()
        {
            String actual;

            using (Pnyx p = new Pnyx())
            {
                p.tailStream(p2 => p2.readString(PLANETS_GODS), 2);
                p.parseCsv();
                actual = p.processToString();
            }

            const String expected =
                @"Uranus,Uranus,""Father of the Titans""
Zeus,Jupiter,""Sky god, supreme ruler of the Olympians""
";

            Assert.Equal(expected, actual);


            // Uses buffer instead of manipulating the stream
            using (Pnyx p = new Pnyx())
            {
                p.readString(PLANETS_GODS);
                p.parseCsv();
                p.tail(2);
                actual = p.processToString();
            }
            Assert.Equal(expected, actual);
        }
コード例 #7
0
ファイル: PnyxTest.cs プロジェクト: ericraider33/pnyx.net
        public void teeRow()
        {
            MemoryStream capture = new MemoryStream();
            String       actualA;

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

            using (p)
            {
                p.readString(PLANETS_GODS_FORMAT_ISSUES);
                p.parseCsv(strict: false);
                p.tee(pn =>
                {
                    teeP = pn;
                    pn.writeStream(capture);
                });
                actualA = p.processToString();
            }
            String actualB = p.streamInformation.getOutputEncoding().GetString(capture.ToArray());

            Assert.Equal(actualA, PLANETS_GODS);
            Assert.Equal(actualB, PLANETS_GODS);
            Assert.Equal(FluentState.Disposed, p.state);
            Assert.Equal(FluentState.Disposed, teeP.state);
        }
コード例 #8
0
ファイル: PnyxTest.cs プロジェクト: ericraider33/pnyx.net
        public void inOut()
        {
            String actual;

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

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

            using (Pnyx p = new Pnyx())
            {
                p.asCsv(pn => pn.readString(PLANETS_GODS_FORMAT_ISSUES), strict: false);
                actual = p.processToString();
            }

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

            using (Pnyx p = new Pnyx())
            {
                p.readString(PLANETS_GODS_FORMAT_ISSUES);
                actual = p.processToString((pnyx, stream) => pnyx.writeCsvStream(stream, strict: false));
            }

            Assert.Equal(PLANETS_GODS, actual);
        }
コード例 #11
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);
        }
コード例 #12
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
        }
コード例 #13
0
ファイル: PnyxTest.cs プロジェクト: ericraider33/pnyx.net
        public void tabInOutImplicit()
        {
            String actual;

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

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

            using (Pnyx p = new Pnyx())
            {
                p.setSettings(outputNewline: "\n");
                p.readLineFunc(() => new[] { "a", "b", "c" });
                actual = p.processToString();
            }

            Assert.Equal("a\nb\nc", actual);
        }
コード例 #15
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));
        }
コード例 #16
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);
        }
コード例 #17
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());
        }
コード例 #18
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);
        }
コード例 #19
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);
        }
コード例 #20
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);
        }
コード例 #21
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);
        }
コード例 #22
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);
        }
コード例 #23
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);
        }
コード例 #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 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);
        }
コード例 #26
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);
        }
コード例 #27
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);
        }
コード例 #28
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);
        }
コード例 #29
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);
        }
コード例 #30
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);
        }