Esempio n. 1
0
        public void SimpleParseFirst()
        {
            var parser = new TsvParser(noneIn: "none", noneOut: "mynone");

            string[][] str =
            {
                new[] { "1",     "2",     "3",     "4" },
                new[] { "test1", "test2", "none" },
                new[] { "none",  "test3", "test4", ""  }
            };

            var obj = parser.Parse(str);

            Assert.AreEqual("test4", obj[1, 2]);
            Assert.AreEqual("mynone", obj[1, 3]);
            Assert.AreEqual("mynone", obj[0, 2]);
            Assert.AreEqual("mynone", obj[0, 3]);
            Assert.AreEqual("2", obj.Header[1]);
            Assert.AreEqual(4, obj.ColumnCount);
            Assert.AreEqual("mynone", obj.None);
            Assert.AreEqual(2, obj.RowCount);
            Assert.AreEqual(2, obj.Rows.GetLength(0));
            Assert.AreEqual(4, obj.Rows.GetLength(1));
            Assert.AreEqual("test1", obj.GetRow(0)[0]);
            Assert.AreEqual("mynone", obj.GetColumn("1")[1]);
            Assert.AreEqual(-1, obj.GetColumnIndex("33"));
        }
Esempio n. 2
0
        public void TsvListSecond()
        {
            var parser = new TsvParser(noneIn: "none", noneOut: "mynone");

            string[][] str =
            {
                new[] { "1",     "1",     "3",     "4" },
                new[] { "test1", "test2", "none" },
                new[] { "none",  "test3", "test4", ""  }
            };

            var obj = parser.Parse(str);
        }
Esempio n. 3
0
        public void SimpleParseSecond()
        {
            var parser = new TsvParser(firstIsHeader: false, noneIn: "none", noneOut: "mynone");
            var text   = "test1\ttest2\test3\nnone\ttest4\ttest5";
            var obj    = parser.Parse(text);

            obj.AddHeader("newHeder1", new[] { "newTest1", "newTest2" });
            obj.AddRow(new [] { "newRowItem1", "newRowItem2" });

            Assert.AreEqual("Item1", obj.Header[1]);
            Assert.AreEqual("newHeder1", obj.Header[3]);
            Assert.AreEqual(3, obj.RowCount);
            Assert.AreEqual(4, obj.ColumnCount);
            Assert.AreEqual("newRowItem2", obj.GetRow(2)[1]);
            Assert.AreEqual("mynone", obj.GetRow(2)[2]);
            Assert.AreEqual("newTest1", obj.GetRow(0)[3]);
        }
Esempio n. 4
0
        private void MenuItemImportTsv_OnClick(object sender, RoutedEventArgs e)
        {
            var dialog = new Microsoft.Win32.OpenFileDialog()
            {
                Title       = "Select TSV-formatted file to load",
                Filter      = "Supported files|*.tsv;*.txt",
                Multiselect = false
            };

            var result = dialog.ShowDialog();

            if (result != null && result.Value)
            {
                using (var stream = new StreamReader(dialog.OpenFile()))
                {
                    SetMap(TsvParser.Parse(stream));
                }
            }
        }