Added and updated tests for constructor visibility

This commit is contained in:
AbubakerB
2016-02-03 22:48:33 +00:00
parent f869b41f14
commit c351ffcc75
31 changed files with 843 additions and 110 deletions

View File

@@ -82,7 +82,6 @@ interface E extends C {
}
class CC {
// Error, constructor cannot be protected
protected constructor() {
}
}

View File

@@ -1,18 +1,20 @@
// @declaration: true
class C {
public constructor(public x: number) { }
}
class D {
private constructor(public x: number) { } // error
private constructor(public x: number) { }
}
class E {
protected constructor(public x: number) { } // error
protected constructor(public x: number) { }
}
var c = new C(1);
var d = new D(1);
var e = new E(1);
var d = new D(1); // error
var e = new E(1); // error
module Generic {
class C<T> {
@@ -20,14 +22,14 @@ module Generic {
}
class D<T> {
private constructor(public x: T) { } // error
private constructor(public x: T) { }
}
class E<T> {
protected constructor(public x: T) { } // error
protected constructor(public x: T) { }
}
var c = new C(1);
var d = new D(1);
var e = new E(1);
var d = new D(1); // error
var e = new E(1); // error
}

View File

@@ -0,0 +1,42 @@
// @declaration: true
class BaseA {
public constructor(public x: number) { }
createInstance() { new BaseA(1); }
}
class BaseB {
protected constructor(public x: number) { }
createInstance() { new BaseB(1); }
}
class BaseC {
private constructor(public x: number) { }
createInstance() { new BaseC(1); }
}
class DerivedA extends BaseA {
constructor(public x: number) { super(x); }
createInstance() { new DerivedA(1); }
createBaseInstance() { new BaseA(1); }
}
class DerivedB extends BaseB {
constructor(public x: number) { super(x); }
createInstance() { new DerivedB(1); }
createBaseInstance() { new BaseB(1); } // error
}
class DerivedC extends BaseC { // error
constructor(public x: number) { super(x); }
createInstance() { new DerivedC(1); }
createBaseInstance() { new BaseC(1); } // error
}
var ba = new BaseA(1);
var bb = new BaseB(1); // error
var bc = new BaseC(1); // error
var da = new DerivedA(1);
var db = new DerivedB(1);
var dc = new DerivedC(1);

View File

@@ -0,0 +1,35 @@
// @declaration: true
class Foo {
constructor(public x: number) { }
}
class Bar {
public constructor(public x: number) { }
}
class Baz {
protected constructor(public x: number) { }
}
class Qux {
private constructor(public x: number) { }
}
// b is public
let a = Foo;
a = Bar;
a = Baz; // error Baz is protected
a = Qux; // error Qux is private
// b is protected
let b = Baz;
b = Foo; // error Foo is public
b = Bar; // error Baz is public
b = Qux; // error Qux is private
// c is private
let c = Qux;
c = Foo; // error Foo is public
c = Bar; // error Bar is public
c = Baz; // error Baz is protected

View File

@@ -0,0 +1,34 @@
// @declaration: true
class A {
public constructor(a: boolean) // error
protected constructor(a: number) // error
private constructor(a: string)
private constructor() {
}
}
class B {
protected constructor(a: number) // error
constructor(a: string)
constructor() {
}
}
class C {
protected constructor(a: number)
protected constructor(a: string)
protected constructor() {
}
}
class D {
constructor(a: number)
constructor(a: string)
public constructor() {
}
}

View File

@@ -1,10 +1,10 @@
// private constructors are not allowed
// @declaration: true
class C {
private constructor() { }
}
var c = new C();
var c = new C(); // error C is private
var r: () => void = c.constructor;
class C2 {
@@ -12,5 +12,5 @@ class C2 {
private constructor(x: any) { }
}
var c2 = new C2();
var c2 = new C2(); // error C2 is private
var r2: (x: number) => void = c2.constructor;

View File

@@ -0,0 +1,16 @@
// @declaration: true
class C {
protected constructor() { }
}
var c = new C(); // error C is protected
var r: () => void = c.constructor;
class C2 {
protected constructor(x: number);
protected constructor(x: any) { }
}
var c2 = new C2(); // error C2 is protected
var r2: (x: number) => void = c2.constructor;

View File

@@ -0,0 +1,9 @@
/// <reference path='fourslash.ts' />
////class A {
//// private constructor() {}
////}
////var x = new A(/*1*/
goTo.marker("1");
verify.not.signatureHelpPresent();

View File

@@ -0,0 +1,9 @@
/// <reference path='fourslash.ts' />
////class A {
//// protected constructor() {}
////}
////var x = new A(/*1*/
goTo.marker("1");
verify.not.signatureHelpPresent();