Ejemplo n.º 1
0
        public static void Split_Deconstruct_WithOptions()
        {
            Utf8String ustr = u8("a, , b, c,, d, e");

            // Note referential equality checks below (since we want to know exact slices
            // into the original buffer), not deep (textual) equality checks.

            {
                (Utf8String a, Utf8String b) = ustr.Split(',', Utf8StringSplitOptions.RemoveEmptyEntries);
                Assert.Equal(u8("a"), a);
                Assert.Equal(u8(" , b, c,, d, e"), b);
            }

            {
                (Utf8String a, Utf8String x, Utf8String b, Utf8String c, Utf8String d, Utf8String e) = ustr.Split(',', Utf8StringSplitOptions.RemoveEmptyEntries);
                Assert.Equal(u8("a"), a);  // "a"
                Assert.Equal(u8(" "), x);  // " "
                Assert.Equal(u8(" b"), b); // " b"
                Assert.Equal(u8(" c"), c); // " c"
                Assert.Equal(u8(" d"), d); // " d"
                Assert.Equal(u8(" e"), e); // " e"
            }

            {
                (Utf8String a, Utf8String b, Utf8String c, Utf8String d, Utf8String e, Utf8String f, Utf8String g, Utf8String h) = ustr.Split(',', Utf8StringSplitOptions.RemoveEmptyEntries | Utf8StringSplitOptions.TrimEntries);
                Assert.Equal(u8("a"), a);
                Assert.Equal(u8("b"), b);
                Assert.Equal(u8("c"), c);
                Assert.Equal(u8("d"), d);
                Assert.Equal(u8("e"), e);
                Assert.Null(f);
                Assert.Null(g);
                Assert.Null(h);
            }
        }
Ejemplo n.º 2
0
        public static void Split_Deconstruct()
        {
            Utf8String ustr = u8("a,b,c,d,e");

            {
                (Utf8String a, Utf8String b) = ustr.Split('x'); // not found
                Assert.Same(ustr, a);                           // Expected referential equality of input
                Assert.Null(b);
            }

            {
                (Utf8String a, Utf8String b) = ustr.Split(',');
                Assert.Equal(u8("a"), a);
                Assert.Equal(u8("b,c,d,e"), b);
            }

            {
                (Utf8String a, Utf8String b, Utf8String c, Utf8String d, Utf8String e) = ustr.Split(',');
                Assert.Equal(u8("a"), a);
                Assert.Equal(u8("b"), b);
                Assert.Equal(u8("c"), c);
                Assert.Equal(u8("d"), d);
                Assert.Equal(u8("e"), e);
            }

            {
                (Utf8String a, Utf8String b, Utf8String c, Utf8String d, Utf8String e, Utf8String f, Utf8String g, Utf8String h) = ustr.Split(',');
                Assert.Equal(u8("a"), a);
                Assert.Equal(u8("b"), b);
                Assert.Equal(u8("c"), c);
                Assert.Equal(u8("d"), d);
                Assert.Equal(u8("e"), e);
                Assert.Null(f);
                Assert.Null(g);
                Assert.Null(h);
            }
        }
Ejemplo n.º 3
0
        public void Split()
        {
            var str  = new Utf8String("0000;<control>;Cc;0;BN;;;;;N;NULL;;;;");
            var list = str.Split(new char[] { ';' });

            Assert.That(list, Is.EqualTo(new Utf8String[] {
                new Utf8String("0000"),
                new Utf8String("<control>"),
                new Utf8String("Cc"),
                new Utf8String("0"),
                new Utf8String("BN"),
                Utf8String.Empty,
                Utf8String.Empty,
                Utf8String.Empty,
                Utf8String.Empty,
                new Utf8String("N"),
                new Utf8String("NULL"),
                Utf8String.Empty,
                Utf8String.Empty,
                Utf8String.Empty,
                Utf8String.Empty,
            }));
        }