Ejemplo n.º 1
0
        public void JavaScriptSubstringWorks()
        {
            var numbers = "0123456789";

            // Let's start by using both begin and end.
            Assert.AreEqual(StringPrototype.Substring(numbers, 3, 7), "3456");

            // What happens when we start with a negative number.
            Assert.AreEqual(StringPrototype.Substring(numbers, -7, 7), "0123456");

            // What happens when we use two negative numbers.
            Assert.AreEqual(StringPrototype.Substring(numbers, -7, -3), "");

            // What happens when we omit the last argument.
            Assert.AreEqual(StringPrototype.Substring(numbers, 3), "3456789");

            // And with the negative, end-relevant index.
            Assert.AreEqual(StringPrototype.Substring(numbers, -7), "0123456789");

            // If the index is out of range, it returns the empty string.
            Assert.AreEqual(StringPrototype.Substring(numbers, 100, 101), "");

            Assert.AreEqual(StringPrototype.Substring(numbers, 2, 4), "23");
        }
Ejemplo n.º 2
0
        public static void TestUseCase()
        {
            var s = "0123456789";

            // Not C# API #2392
            Assert.AreEqual("0123456789", StringPrototype.Substring(s, -1), "JavaScript Substring(-1)");
            Assert.AreEqual("56789", StringPrototype.Substring(s, 5), "JavaScript Substring(5)");
            Assert.AreEqual("", StringPrototype.Substring(s, 10), "JavaScript Substring(10)");
            Assert.AreEqual("1", StringPrototype.Substring(s, 1, 2), "JavaScript Substring(1, 2)");
            Assert.AreEqual("123456789", StringPrototype.Substring(s, 1, 10), "JavaScript Substring(1, 10)");

            Assert.AreEqual("9", s.Substring(-1), "Substring(-1)");
            Assert.AreEqual("56789", s.Substring(5), "Substring(5)");
            Assert.AreEqual("", s.Substring(10), "Substring(10)");
            Assert.AreEqual("12", s.Substring(1, 2), "Substring(1, 2)");
            Assert.AreEqual("123456789", s.Substring(1, 10), "Substring(1, 10)");

            // Not C# API #2392
            Assert.AreEqual("9", s.Substr(-1), "Substr(-1)");
            Assert.AreEqual("56789", s.Substr(5), "Substr(5)");
            Assert.AreEqual("", s.Substr(10), "Substr(10)");
            Assert.AreEqual("12", s.Substr(1, 2), "Substr(1, 2)");
            Assert.AreEqual("123456789", s.Substr(1, 10), "Substr(1, 10)");
        }
Ejemplo n.º 3
0
 public void JavaScriptSubstringWithEndIndexWorks()
 {
     Assert.AreEqual("cd", StringPrototype.Substring("abcde", 2, 4));
 }