public void ReadOnlyNativeIndexerIsCorrectlyImported()
        {
            var metadataImporter = new MockMetadataImporter {
                GetPropertySemantics = p => PropertyScriptSemantics.NativeIndexer()
            };

            Compile(new[] { "class C { public int this[int i] { get { return 0; } } }" }, metadataImporter: metadataImporter);
            FindClass("C").InstanceMethods.Should().BeEmpty();
            FindClass("C").StaticMethods.Should().BeEmpty();
        }
Exemple #2
0
        public void CompoundAssigningToPropertyImplementedAsNativeIndexerWorks()
        {
            AssertCorrectForBulkOperators(
                @"int this[int x] { get { return 0; } set {} }
public void M() {
	int i = 0, j = 1, k = 2, l;
	// BEGIN
	l = this[i] += k;
	// END
}",
                @"	$l = this[$i] += $k;
", metadataImporter: new MockMetadataImporter {
                GetPropertySemantics = p => p.IsIndexer ? PropertyScriptSemantics.NativeIndexer() : PropertyScriptSemantics.Field(p.Name)
            });
        }
Exemple #3
0
        public void ReadingPropertyImplementedAsNativeIndexerWorks()
        {
            AssertCorrect(
                @"int this[int x] { get { return 0; } set {} }
public void M() {
	int a = 0, b = 0;
	// BEGIN
	int i = this[a];
	// END
}",
                @"	var $i = this[$a];
", metadataImporter: new MockMetadataImporter {
                GetPropertySemantics = p => p.IsIndexer ? PropertyScriptSemantics.NativeIndexer() : PropertyScriptSemantics.Field(p.Name)
            });
        }
        public void PostfixForPropertyImplementedAsNativeIndexerWorks()
        {
            AssertCorrectForBoth(
                @"int this[int x] { get { return 0; } set {} }
public void M() {
	int i = 0, j = 1;
	// BEGIN
	j = this[i]++;
	// END
}",
                @"	$j = this[$i]++;
", metadataImporter: new MockMetadataImporter {
                GetPropertySemantics = p => p.IsIndexer ? PropertyScriptSemantics.NativeIndexer() : PropertyScriptSemantics.Field(p.Name)
            });
        }
        public void LiftedPrefixForPropertyImplementedAsNativeIndexerWorksWhenUsingTheReturnValue()
        {
            AssertCorrectForBoth(
                @"int? this[int x] { get { return 0; } set {} }
public void M() {
	int i = 0;
	// BEGIN
	var x = ++this[i];
	// END
}",
                @"	var $x = this[$i] = $Lift(this[$i] + 1);
", metadataImporter: new MockMetadataImporter {
                GetPropertySemantics = p => p.IsIndexer ? PropertyScriptSemantics.NativeIndexer() : PropertyScriptSemantics.Field(p.Name)
            });
        }
Exemple #6
0
        public void AssigningToPropertyImplementedAsNativeIndexerWorksStruct()
        {
            AssertCorrect(
                @"int this[int x] { get { return 0; } set {} }
public void M() {
	int i = 0, j = 1, k = 2, l;
	// BEGIN
	l = this[i] = k;
	// END
}",
                @"	this[$i] = $Clone($k, {to_Int32});
	$l = $Clone(this[$i], {to_Int32});
", metadataImporter: new MockMetadataImporter {
                GetPropertySemantics = p => p.IsIndexer ? PropertyScriptSemantics.NativeIndexer() : PropertyScriptSemantics.Field(p.Name), GetTypeSemantics = t => TypeScriptSemantics.MutableValueType(t.Name)
            });
        }
Exemple #7
0
        public void DivisionCompoundAssignmentWorksForFloatingPointPropertiesImplementedAsNativeIndexers()
        {
            DoForAllFloatingPointTypes(type =>
                                       AssertCorrect(
                                           @"public type this[int x] { get { return 0; } set {} }
public void M() {
	int i = 0;
	type j = 0;
	// BEGIN
	this[i] /= j;
	// END
}
".Replace("type", type),
                                           @"	this[$i] /= $j;
", metadataImporter: new MockMetadataImporter {
                GetPropertySemantics = p => p.IsIndexer ? PropertyScriptSemantics.NativeIndexer() : PropertyScriptSemantics.Field(p.Name)
            }));
        }
Exemple #8
0
        public void DivisionCompoundAssignmentOnlyInvokesTargetOnceForIntegralPropertiesImplementedAsNativeIndexers()
        {
            DoForAllIntegerTypes(type =>
                                 AssertCorrect(
                                     @"class X { public type this[int x] { get { return 0; } set {} } }
public X F1() { return null; }
public void M() {
	int i = 0;
	type j = 0;
	// BEGIN
	F1()[i] /= j;
	// END
}
".Replace("type", type),
                                     @"	var $tmp1 = this.F1();
	$tmp1[$i] = $IntDiv($tmp1[$i], $j);
", metadataImporter: new MockMetadataImporter {
                GetPropertySemantics = p => p.IsIndexer ? PropertyScriptSemantics.NativeIndexer() : PropertyScriptSemantics.Field(p.Name)
            }));
        }