public void TestEqualitySemantics()
        {
            CSharpCompilationOptions first  = CreateCSharpCompilationOptions();
            CSharpCompilationOptions second = CreateCSharpCompilationOptions();

            Assert.Equal(first, second);
            Assert.Equal(first.GetHashCode(), second.GetHashCode());
        }
        public void WithNullable()
        {
            CSharpCompilationOptions a = CreateCSharpCompilationOptions();

            Assert.False(a.Nullable);
            Assert.Equal(a, a);
            Assert.Equal(a.GetHashCode(), a.GetHashCode());
            Assert.Same(a, a.WithNullable(false));

            CSharpCompilationOptions b = a.WithNullable(true);

            Assert.True(b.Nullable);
            Assert.NotEqual(a, b);
            Assert.Equal(b, b);
            Assert.Equal(b.GetHashCode(), b.GetHashCode());
            Assert.Same(b, b.WithNullable(true));

            CSharpCompilationOptions c = a.WithNullable(true);

            Assert.True(c.Nullable);
            Assert.NotEqual(a, c);
            Assert.NotSame(b, c);
            Assert.Equal(b, c);
            Assert.Equal(b.GetHashCode(), c.GetHashCode());

            CSharpCompilationOptions e = b.WithNullable(false);

            Assert.False(e.Nullable);
            Assert.NotSame(a, e);
            Assert.Equal(a, e);
            Assert.Equal(a.GetHashCode(), e.GetHashCode());
            Assert.NotEqual(b, e);
            Assert.NotEqual(c, e);

            var i = new CSharpCompilationOptions(OutputKind.ConsoleApplication);

            Assert.False(i.Nullable);

            var j = new CSharpCompilationOptions(OutputKind.ConsoleApplication, nullable: true);

            Assert.True(j.Nullable);

            var k = new CSharpCompilationOptions(OutputKind.ConsoleApplication, nullable: false);

            Assert.False(k.Nullable);
        }
Esempio n. 3
0
        public void WithNullable()
        {
            CSharpCompilationOptions a = CreateCSharpCompilationOptions();

            Assert.Null(a.Nullable);
            Assert.Equal(a, a);
            Assert.Equal(a.GetHashCode(), a.GetHashCode());
            Assert.Same(a, a.WithNullable(null));

            CSharpCompilationOptions b = a.WithNullable(true);

            Assert.True(b.Nullable);
            Assert.NotEqual(a, b);
            Assert.Equal(b, b);
            Assert.Equal(b.GetHashCode(), b.GetHashCode());
            Assert.Same(b, b.WithNullable(true));

            CSharpCompilationOptions c = a.WithNullable(true);

            Assert.True(c.Nullable);
            Assert.NotEqual(a, c);
            Assert.NotSame(b, c);
            Assert.Equal(b, c);
            Assert.Equal(b.GetHashCode(), c.GetHashCode());

            CSharpCompilationOptions d = a.WithNullable(false);

            Assert.False(d.Nullable);
            Assert.NotEqual(a, d);
            Assert.NotEqual(b, d);
            Assert.NotEqual(c, d);
            Assert.Equal(d, d);
            Assert.Equal(d.GetHashCode(), d.GetHashCode());
            Assert.Same(d, d.WithNullable(false));

            CSharpCompilationOptions e = b.WithNullable(false);

            Assert.False(e.Nullable);
            Assert.NotEqual(a, e);
            Assert.NotEqual(b, e);
            Assert.NotEqual(c, e);
            Assert.NotSame(d, e);
            Assert.Equal(d, e);
            Assert.Equal(d.GetHashCode(), e.GetHashCode());

            CSharpCompilationOptions f = d.WithNullable(true);

            Assert.True(f.Nullable);
            Assert.NotEqual(a, f);
            Assert.Equal(b, f);
            Assert.Equal(b.GetHashCode(), f.GetHashCode());
            Assert.Equal(c, f);
            Assert.Equal(c.GetHashCode(), f.GetHashCode());
            Assert.NotEqual(d, f);
            Assert.NotEqual(e, f);
            Assert.Same(f, f.WithNullable(true));

            CSharpCompilationOptions g = b.WithNullable(null);

            Assert.Null(g.Nullable);
            Assert.Equal(a, g);
            Assert.Equal(a.GetHashCode(), g.GetHashCode());
            Assert.NotEqual(b, g);
            Assert.NotEqual(c, g);
            Assert.NotEqual(d, g);
            Assert.NotEqual(e, g);
            Assert.NotEqual(f, g);

            CSharpCompilationOptions h = d.WithNullable(null);

            Assert.Null(h.Nullable);
            Assert.Equal(a, h);
            Assert.Equal(a.GetHashCode(), h.GetHashCode());
            Assert.NotEqual(b, h);
            Assert.NotEqual(c, h);
            Assert.NotEqual(d, h);
            Assert.NotEqual(e, h);
            Assert.NotEqual(f, h);
            Assert.Equal(g, h);
            Assert.Equal(g.GetHashCode(), h.GetHashCode());

            var i = new CSharpCompilationOptions(OutputKind.ConsoleApplication, nullable: null);

            Assert.Null(i.Nullable);

            var j = new CSharpCompilationOptions(OutputKind.ConsoleApplication, nullable: true);

            Assert.True(j.Nullable);

            var k = new CSharpCompilationOptions(OutputKind.ConsoleApplication, nullable: false);

            Assert.False(k.Nullable);
        }
Esempio n. 4
0
        public void WithNullable()
        {
            CSharpCompilationOptions a = CreateCSharpCompilationOptions();

            Assert.Equal(NullableContextOptions.Disabled, a.NullableContextOptions);
            Assert.Equal(a, a);
            Assert.Equal(a.GetHashCode(), a.GetHashCode());
            Assert.Same(a, a.WithNullableContextOptions(NullableContextOptions.Disabled));

            CSharpCompilationOptions b = a.WithNullableContextOptions(NullableContextOptions.Enabled);

            Assert.Equal(NullableContextOptions.Enabled, b.NullableContextOptions);
            Assert.NotEqual(a, b);
            Assert.Equal(b, b);
            Assert.Equal(b.GetHashCode(), b.GetHashCode());
            Assert.Same(b, b.WithNullableContextOptions(NullableContextOptions.Enabled));

            CSharpCompilationOptions c = a.WithNullableContextOptions(NullableContextOptions.Enabled);

            Assert.Equal(NullableContextOptions.Enabled, c.NullableContextOptions);
            Assert.NotEqual(a, c);
            Assert.NotSame(b, c);
            Assert.Equal(b, c);
            Assert.Equal(b.GetHashCode(), c.GetHashCode());

            CSharpCompilationOptions e = b.WithNullableContextOptions(NullableContextOptions.Disabled);

            Assert.Equal(NullableContextOptions.Disabled, e.NullableContextOptions);
            Assert.NotSame(a, e);
            Assert.Equal(a, e);
            Assert.Equal(a.GetHashCode(), e.GetHashCode());
            Assert.NotEqual(b, e);
            Assert.NotEqual(c, e);

            CSharpCompilationOptions d = a.WithNullableContextOptions(NullableContextOptions.SafeOnly);

            Assert.Equal(NullableContextOptions.SafeOnly, d.NullableContextOptions);
            Assert.NotEqual(a, d);
            Assert.NotEqual(b, d);
            Assert.NotEqual(c, d);
            Assert.Equal(d, d);
            Assert.Equal(d.GetHashCode(), d.GetHashCode());
            Assert.Same(d, d.WithNullableContextOptions(NullableContextOptions.SafeOnly));

            CSharpCompilationOptions f = b.WithNullableContextOptions(NullableContextOptions.SafeOnly);

            Assert.Equal(NullableContextOptions.SafeOnly, f.NullableContextOptions);
            Assert.NotEqual(a, f);
            Assert.NotEqual(b, f);
            Assert.NotEqual(c, f);
            Assert.NotSame(d, f);
            Assert.Equal(d, f);
            Assert.Equal(d.GetHashCode(), f.GetHashCode());

            CSharpCompilationOptions g = d.WithNullableContextOptions(NullableContextOptions.Enabled);

            Assert.Equal(NullableContextOptions.Enabled, g.NullableContextOptions);
            Assert.NotEqual(a, g);
            Assert.NotSame(b, g);
            Assert.Equal(b, g);
            Assert.Equal(b.GetHashCode(), g.GetHashCode());
            Assert.NotEqual(d, g);

            CSharpCompilationOptions h = d.WithNullableContextOptions(NullableContextOptions.Disabled);

            Assert.Equal(NullableContextOptions.Disabled, h.NullableContextOptions);
            Assert.Equal(a, h);
            Assert.Equal(a.GetHashCode(), h.GetHashCode());
            Assert.NotEqual(b, h);
            Assert.NotEqual(c, h);
            Assert.NotEqual(d, h);

            var i = new CSharpCompilationOptions(OutputKind.ConsoleApplication);

            Assert.Equal(NullableContextOptions.Disabled, i.NullableContextOptions);

            var j = new CSharpCompilationOptions(OutputKind.ConsoleApplication, nullableContextOptions: NullableContextOptions.Enabled);

            Assert.Equal(NullableContextOptions.Enabled, j.NullableContextOptions);

            var k = new CSharpCompilationOptions(OutputKind.ConsoleApplication, nullableContextOptions: NullableContextOptions.Disabled);

            Assert.Equal(NullableContextOptions.Disabled, k.NullableContextOptions);

            var l = new CSharpCompilationOptions(OutputKind.ConsoleApplication, nullableContextOptions: NullableContextOptions.SafeOnly);

            Assert.Equal(NullableContextOptions.SafeOnly, l.NullableContextOptions);
        }