Ejemplo n.º 1
0
        public void ReadingNotUsableFieldGivesAnError()
        {
            var er = new MockErrorReporter(false);

            Compile(new[] { "class Class { int UnusableField; public void M() { int x = UnusableField; } }" }, metadataImporter: new MockMetadataImporter {
                GetFieldSemantics = f => FieldScriptSemantics.NotUsableFromScript()
            }, errorReporter: er);
            Assert.That(er.AllMessagesText.Any(m => m.StartsWith("Error:") && m.Contains("Class.UnusableField")));
        }
        public void ReadingNotUsableFieldGivesAnError()
        {
            var er = new MockErrorReporter(false);

            Compile(new[] { "class Class { int UnusableField; public void M() { int x = UnusableField; } }" }, metadataImporter: new MockMetadataImporter {
                GetFieldSemantics = f => FieldScriptSemantics.NotUsableFromScript()
            }, errorReporter: er);
            Assert.That(er.AllMessages.Any(msg => msg.Severity == MessageSeverity.Error && msg.FormattedMessage.Contains("Class.UnusableField")));
        }
        public void EnumValueWhichIsNotUsableFromScriptIsNotImported()
        {
            var md = new MockMetadataImporter {
                GetFieldSemantics = f => f.Name == "Member2" ? FieldScriptSemantics.NotUsableFromScript() : FieldScriptSemantics.Field("$" + f.Name)
            };

            Compile(new[] { "enum MyEnum { Member1, Member2, Member3 }" }, metadataImporter: md);
            FindEnum("MyEnum").Values.Select(v => v.Name).Should().BeEquivalentTo(new[] { "$Member1", "$Member3" });
        }
Ejemplo n.º 4
0
        public void FieldsThatAreNotUsableFromScriptAreNotImported()
        {
            var metadataImporter = new MockMetadataImporter {
                GetFieldSemantics = f => FieldScriptSemantics.NotUsableFromScript()
            };

            Compile(new[] { "class C { public int SomeField; }" }, metadataImporter: metadataImporter);
            FindClass("C").UnnamedConstructor.Body.Statements.Should().BeEmpty();
            FindClass("C").StaticInitStatements.Should().BeEmpty();
            FindClass("C").InstanceMethods.Should().BeEmpty();
            FindClass("C").StaticMethods.Should().BeEmpty();
        }
        public void FieldsThatAreNotUsableFromScriptAreNotImported()
        {
            var metadataImporter = new MockMetadataImporter {
                GetConstructorSemantics = c => ConstructorScriptSemantics.Unnamed(skipInInitializer: c.DeclaringType.IsKnownType(KnownTypeCode.Object)), GetFieldSemantics = f => FieldScriptSemantics.NotUsableFromScript()
            };

            Compile(new[] { "class C { public int SomeField; }" }, metadataImporter: metadataImporter);
            FindClass("C").UnnamedConstructor.Body.Statements.Should().BeEmpty();
            FindClass("C").StaticInitStatements.Should().BeEmpty();
            FindClass("C").InstanceMethods.Should().BeEmpty();
            FindClass("C").StaticMethods.Should().BeEmpty();
        }