Exemple #1
0
        public void OkDoesNotEqualError()
        {
            var x = IntResult.Ok(1);
            var y = IntResult.Err("bar");

            Assert.AreNotEqual(x, y);
        }
Exemple #2
0
        public void ErrorDoesNotEqualDifferentError()
        {
            var x = IntResult.Err("foo");
            var y = IntResult.Err("bar");

            Assert.AreNotEqual(x, y);
        }
Exemple #3
0
        public void ErrorEqualsError()
        {
            var x = IntResult.Err("boom");
            var y = IntResult.Err("boom");

            Assert.AreEqual(x, y);
        }
Exemple #4
0
        public void ComprehensionsWork()
        {
            var result =
                from x in IntResult.Ok(2)
                select x + 1;

            Assert.AreEqual(IntResult.Ok(3), result);

            var error =
                from x in IntResult.Err("boom")
                select x + 1;

            Assert.AreEqual(IntResult.Err("boom"), error);

            var error2 =
                from x in IntResult.Ok(3)
                from y in IntResult.Err("boom")
                select x + y;

            Assert.AreEqual(IntResult.Err("boom"), error2);

            var result2 =
                from x in IntResult.Ok(3)
                from y in IntResult.Ok(4)
                select x + y;

            Assert.AreEqual(result2, IntResult.Ok(7));
        }
Exemple #5
0
        public void BindRailroadsErrors()
        {
            var result = IntResult.Ok(21);
            var actual =
                result
                .Bind(r => IntResult.Err("boom"))
                .Bind(r => IntResult.Ok(r + 1));

            Assert.AreEqual("boom", actual.Error());
        }
Exemple #6
0
        public void MapErrMapsToANewErrorType()
        {
            var expected =
                Result <int, SomeError> .Err(new SomeError("boom"));

            var actual =
                IntResult.Err("boom")
                .MapErr(e => new SomeError(e));

            Assert.AreEqual(expected, actual);
        }
Exemple #7
0
        public void MapOrElseMapsErrors()
        {
            var expected =
                Result <int, SomeError> .Err(new SomeError("boom"));

            var actual =
                IntResult.Err("boom")
                .MapOrElse(
                    x => x * 2,
                    e => new SomeError(e)
                    );

            Assert.AreEqual(expected, actual);
        }