コード例 #1
0
        public void Test_Complex()
        {
            var ansel = new AnselEncoding();

            Assert.IsNotNull(ansel);

            byte[] data;
            string res, sampleUnic, sampleAnsel;

            // code: E0 (Unicode: hook above, 0309)/low rising tone mark/
            sampleAnsel = "αAαBαCαDαEαFαGαHαIαJαKαLαMαNαOαPαQαRαSαTαUαVαWαXαYαZ";
            sampleUnic  = "ẢB̉C̉D̉ẺF̉G̉H̉ỈJ̉K̉L̉M̉N̉ỎP̉Q̉R̉S̉T̉ỦV̉W̉X̉ỶZ̉";

            //Assert.AreEqual(52, ansel.GetByteCount(sampleAnsel));

            //chars = sampleUnic.ToCharArray();
            //Assert.AreEqual(52, ansel.GetByteCount(chars, 0, chars.Length));
            //Assert.AreEqual(52, ansel.GetByteCount(sampleUnic));

            data = Encoding.GetEncoding(437).GetBytes(sampleAnsel);
            Assert.AreEqual(52, data.Length);

            res = ansel.GetString(data);
            Assert.AreEqual(sampleUnic, res);
            Assert.AreEqual(52, res.Length);

            res = ansel.GetString(data, 0, data.Length);
            Assert.AreEqual(sampleUnic, res);
            Assert.AreEqual(52, res.Length);

            data = ansel.GetBytes(res);
            res  = Encoding.GetEncoding(437).GetString(data);
            Assert.AreEqual(sampleAnsel, res.Trim('\0')); //FIXME: ALERT!
        }
コード例 #2
0
        public void Test_GetString()
        {
            var ansel = new AnselEncoding();

            char[] chars = null;
            string s     = null;

            byte[] bytes = null;

            Assert.Throws(typeof(ArgumentNullException), () => { ansel.GetString(null, 0, 0); });
            bytes = Encoding.GetEncoding(437).GetBytes("test");
            Assert.Throws(typeof(ArgumentOutOfRangeException), () => { ansel.GetString(bytes, -1, 0); });
            Assert.Throws(typeof(ArgumentOutOfRangeException), () => { ansel.GetString(bytes, 0, -1); });
            var res1 = ansel.GetString(bytes, 0, 0);

            Assert.AreEqual(string.Empty, res1);
            res1 = ansel.GetString(bytes, 0, bytes.Length);
            Assert.AreEqual("test", res1);
        }