Repository: microsoft/garnet
File: test/Garnet.test/RespListTests.cs (C#)

Code before:
            db.ListTrim(key, 0, -3);
            nLen = db.ListLength(key);
            Assert.AreEqual(3, nLen);

            var vals = db.ListRange(key, 0, -1);
            Assert.AreEqual("val_8", vals[0].ToString());
            Assert.AreEqual("val_7", vals[1].ToString());
            Assert.AreEqual("val_6", vals[2].ToString());
        }

        private static object[] LTrimTestCases = {
            new object[] {0, 0, new[] {0} },
            new object[] {-2, -1, new[] {8, 9} },
            new object[] {-2, -2, new[] {8} },
            new object[] {3, 5, new[] {3, 4, 5} },
            new object[] {-12, 0, new[] {0} },
            new object[] {-12, 2, new[] {0, 1, 2} },
            new object[] {-12, -7, new[] {0, 1, 2, 3} },
            new object[] {-15, -11, Array.Empty<int>() },
            new object[] {8, 8, new[] {8} },
            new object[] {8, 12, new[] {8, 9} },
            new object[] {9, 12, new[] {9} },
            new object[] {10, 12, Array.Empty<int>() },
        };

        [Test]
        [TestCaseSource(nameof(LTrimTestCases))]
        public void MultiRPUSHAndLTRIM(int startIdx, int stopIdx, int[] expectedRemainingIdx)
        {
            using var redis = ConnectionMultiplexer.Connect(TestUtils.GetConfig());
            var db = redis.GetDatabase(0);

            var key = "List_Test";
            var nVals = 10;
            var values = new RedisValue[nVals];
            for (var i = 0; i < 10; i++)
            {
                values[i] = "val_" + i;
            }
            var nAdded = db.ListRightPush(key, values);
            Assert.AreEqual(nVals, nAdded);

            db.ListTrim(key, startIdx, stopIdx);
            var nLen = db.ListLength(key);
            Assert.AreEqual(expectedRemainingIdx.Length, nLen);
            var remainingVals = db.ListRange(key);
            for (var i = 0; i < remainingVals.Length; i++)
            {
                Assert.AreEqual(values[expectedRemainingIdx[i]], remainingVals[i].ToString());
            }
        }

Review comment (suggestion):
Add a start > end case (code handles it) and per docs the key should be removed in that case or if start > end of list

Code after:
            db.ListTrim(key, 0, -3);
            nLen = db.ListLength(key);
            Assert.AreEqual(3, nLen);

            var vals = db.ListRange(key, 0, -1);
            Assert.AreEqual("val_8", vals[0].ToString());
            Assert.AreEqual("val_7", vals[1].ToString());
            Assert.AreEqual("val_6", vals[2].ToString());
        }

        private static object[] LTrimTestCases = {
            new object[] {0, 0, new[] {0} },
            new object[] {-2, -1, new[] {8, 9} },
            new object[] {-2, -2, new[] {8} },
            new object[] {3, 5, new[] {3, 4, 5} },
            new object[] {-12, 0, new[] {0} },
            new object[] {-12, 2, new[] {0, 1, 2} },
            new object[] {-12, -7, new[] {0, 1, 2, 3} },
            new object[] {-15, -11, Array.Empty<int>() },
            new object[] {8, 8, new[] {8} },
            new object[] {8, 12, new[] {8, 9} },
            new object[] {9, 12, new[] {9} },
            new object[] {10, 12, Array.Empty<int>() },
            new object[] {5, 3, Array.Empty<int>()},
            new object[] {-3, -5, Array.Empty<int>()}
        };

        [Test]
        [TestCaseSource(nameof(LTrimTestCases))]
        public void MultiRPUSHAndLTRIM(int startIdx, int stopIdx, int[] expectedRemainingIdx)
        {
            using var redis = ConnectionMultiplexer.Connect(TestUtils.GetConfig());
            var db = redis.GetDatabase(0);

            var key = "List_Test";
            var nVals = 10;
            var values = new RedisValue[nVals];
            for (var i = 0; i < 10; i++)
            {
                values[i] = "val_" + i;
            }
            var nAdded = db.ListRightPush(key, values);
            Assert.AreEqual(nVals, nAdded);

            db.ListTrim(key, startIdx, stopIdx);
            var nLen = db.ListLength(key);
            Assert.AreEqual(expectedRemainingIdx.Length, nLen);
            var remainingVals = db.ListRange(key);
            for (var i = 0; i < remainingVals.Length; i++)
            {
                Assert.AreEqual(values[expectedRemainingIdx[i]], remainingVals[i].ToString());