Beispiel #1
0
        public void FileTest_Ansi()
        {
            byte question = (byte)'?';               // 63

            string filename = @"c:\temp\csvw_ft10.txt";

            File.Delete(filename);
            Assert.IsFalse(File.Exists(filename));

            List <string[]> list = new List <string[]> ();

            list.Add(new string[] { "ϴ" });

            ac.DelimitedValuesWriter csv = new DelimitedValuesWriter();
            csv.Encoding = new ASCIIEncoding();
            csv.WriteFile(filename, list);
            Assert.IsTrue(File.Exists(filename));

            FileInfo fo = new FileInfo(filename);

            Assert.AreEqual(3, fo.Length);

            byte[] bytes = File.ReadAllBytes(filename);
            Assert.AreEqual(fo.Length, bytes.Length);

            //Array.ForEach<byte>( bytes, p => Console.WriteLine( p ) ) ;
            Assert.AreEqual(new byte[] { question, 13, 10 }, bytes);
        }
Beispiel #2
0
        public void FileTest_Utf16_BigEndian_Omega()
        {
            string filename = @"c:\temp\csvw_ft9.txt";

            File.Delete(filename);
            Assert.IsFalse(File.Exists(filename));

            List <string[]> list = new List <string[]> ();

            list.Add(new string[] { "ϴ" });

            ac.DelimitedValuesWriter csv = new DelimitedValuesWriter();
            csv.Encoding = new UnicodeEncoding(true, true);
            csv.WriteFile(filename, list);
            Assert.IsTrue(File.Exists(filename));

            FileInfo fo = new FileInfo(filename);

            Assert.AreEqual(8, fo.Length);

            byte[] bytes = File.ReadAllBytes(filename);
            Assert.AreEqual(fo.Length, bytes.Length);

            //Array.ForEach<byte>( bytes, p => Console.WriteLine( p ) ) ;
            Assert.AreEqual(new byte[] { 0xFE, 0xFF, 0x03, 0xF4, 0, 13, 0, 10 }, bytes);
        }
Beispiel #3
0
        public void FileTest_Utf8_Omega()
        {
            string filename = @"c:\temp\csvw_ft6.txt";

            File.Delete(filename);
            Assert.IsFalse(File.Exists(filename));

            List <string[]> list = new List <string[]> ();

            list.Add(new string[] { "ϴ" });

            ac.DelimitedValuesWriter csv = new DelimitedValuesWriter();
            csv.WriteFile(filename, list);
            Assert.IsTrue(File.Exists(filename));

            FileInfo fo = new FileInfo(filename);

            Assert.AreEqual(7, fo.Length);

            byte[] bytes = File.ReadAllBytes(filename);
            Assert.AreEqual(fo.Length, bytes.Length);

            //Array.ForEach<byte>( bytes, p => Console.WriteLine( p ) ) ;
            Assert.AreEqual(new byte[] { 0xEF, 0xBB, 0xBF, 0xCF, 0xB4, 13, 10 }, bytes);
        }
Beispiel #4
0
        public void FileTest_Utf8_NoPreamble()
        {
            UTF8Encoding enc = new UTF8Encoding();

            string filename = @"c:\temp\csvw_ft3.txt";

            File.Delete(filename);
            Assert.IsFalse(File.Exists(filename));

            List <string[]> list = new List <string[]> ();

            list.Add(new string[] { "" });

            ac.DelimitedValuesWriter csv = new DelimitedValuesWriter();
            csv.Encoding = enc;
            csv.WriteFile(filename, list);
            Assert.IsTrue(File.Exists(filename));

            FileInfo fo = new FileInfo(filename);

            Assert.AreEqual(2, fo.Length);

            byte[] bytes = File.ReadAllBytes(filename);
            Assert.AreEqual(fo.Length, bytes.Length);

            //Array.ForEach<byte>( bytes, p => Console.WriteLine( p ) ) ;
            Assert.AreEqual(new byte[] { 13, 10 }, bytes);
        }
Beispiel #5
0
        public void FileTest_ZeroByteFile2()
        {
            string filename = @"c:\temp\csvw_ft1.txt";

            File.Delete(filename);
            Assert.IsFalse(File.Exists(filename));

            List <string[]> list = new List <string[]> ();

            ac.DelimitedValuesWriter csv = new DelimitedValuesWriter();
            csv.WriteFile(filename, list);
            Assert.IsTrue(File.Exists(filename));

            FileInfo fo = new FileInfo(filename);

            Assert.AreEqual(0, fo.Length);
        }
Beispiel #6
0
        public void FileTest_MultiLine()
        {
            string filename = @"c:\temp\csvw_ft11.txt";

            File.Delete(filename);
            Assert.IsFalse(File.Exists(filename));

            List <string[]> list = new List <string[]> ();

            list.Add(new string[] { " the ", " fat ", " catch ", " of ", "the", "  dayחטיי " });
            list.Add(new string[] { " go ", " you ", " good ", " thing ", " ", null });

            ac.DelimitedValuesWriter csv = new DelimitedValuesWriter();
            csv.WriteFile(filename, list);
            Assert.IsTrue(File.Exists(filename));

            string actual = File.ReadAllText(filename);

            Console.WriteLine("[{0}]", actual);

            string expected =
                @" the , fat , catch , of ,the,  dayחטיי 
 go , you , good , thing , ,
";

            Assert.AreEqual(expected, actual);

            // trim me
            csv.Trim      = true;
            csv.Delimiter = "|";
            csv.WriteFile(filename, list);
            Assert.IsTrue(File.Exists(filename));

            actual = File.ReadAllText(filename);
            Console.WriteLine("[{0}]", actual);

            expected =
                @"the|fat|catch|of|the|dayחטיי
go|you|good|thing||
";
            Assert.AreEqual(expected, actual);

            // rabbit ears always
            csv.Delimter2UseOnlyWhenNecessary = false;
            csv.WriteFile(filename, list);
            Assert.IsTrue(File.Exists(filename));

            actual = File.ReadAllText(filename);
            Console.WriteLine("[{0}]", actual);

            expected =
                @"""the""|""fat""|""catch""|""of""|""the""|""dayחטיי""
""go""|""you""|""good""|""thing""|""""|""""
";
            Assert.AreEqual(expected, actual);

            // rabbit ears sometimes
            list = new List <string[]> ();
            list.Add(new string[] { " the ", " fat ", " cat|ch ", " of ", "the", "  dayחטיי " });
            list.Add(new string[] { " go ", " you ||| ", " go|od ", " thing ", " ", null, "|" });

            csv.Delimter2UseOnlyWhenNecessary = true;
            csv.WriteFile(filename, list);
            Assert.IsTrue(File.Exists(filename));

            actual = File.ReadAllText(filename);
            Console.WriteLine("[{0}]", actual);

            expected =
                @"the|fat|""cat|ch""|of|the|dayחטיי
go|""you |||""|""go|od""|thing|||""|""
";
            Assert.AreEqual(expected, actual);
        }