Exemple #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);
        }
Exemple #2
0
        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);
        }
Exemple #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);
        }
Exemple #4
0
        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);
        }
Exemple #5
0
        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);
        }
Exemple #6
0
        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);
        }
Exemple #7
0
        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);
        }
Exemple #8
0
        public void inOut()
        {
            String actual;

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

            Assert.Equal(MAGNA_CARTA, actual);
        }
Exemple #9
0
        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);
        }
Exemple #10
0
        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);
        }
Exemple #11
0
        public void csvInOut()
        {
            String actual;

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

            Assert.Equal(PLANETS_GODS, actual);
        }
Exemple #12
0
        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
        }
Exemple #13
0
        public void tabInOutImplicit()
        {
            String actual;

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

            Assert.Equal(ECONOMIC_FREEDOM, actual);
        }
Exemple #14
0
        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);
        }
Exemple #15
0
        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));
        }
Exemple #16
0
        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);
        }
Exemple #17
0
        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());
        }
Exemple #18
0
        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);
        }
Exemple #19
0
        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);
        }
Exemple #20
0
        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);
        }
Exemple #21
0
        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);
        }
Exemple #22
0
        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);
        }
Exemple #23
0
        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);
        }
Exemple #24
0
        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);
        }
Exemple #25
0
        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);
        }
Exemple #26
0
        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);
        }
Exemple #27
0
        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);
        }
Exemple #28
0
        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);
        }
Exemple #29
0
        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);
        }
Exemple #30
0
        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);
        }