From dd3d13a7a83171ef1203db13e760c7a075075005 Mon Sep 17 00:00:00 2001 From: jbhoosreddy Date: Wed, 29 Aug 2018 21:04:05 -0400 Subject: [PATCH] test: Add private generator method tests (#1343) --- .../default/class-decl-method.template | 2 +- .../class-decl-private-method.template | 50 +++++++++++++++++++ .../class-decl-static-private-method.template | 48 ++++++++++++++++++ .../class-expr-private-method.template | 50 +++++++++++++++++++ .../class-expr-static-private-method.template | 48 ++++++++++++++++++ 5 files changed, 197 insertions(+), 1 deletion(-) create mode 100644 src/generators/default/class-decl-private-method.template create mode 100644 src/generators/default/class-decl-static-private-method.template create mode 100644 src/generators/default/class-expr-private-method.template create mode 100644 src/generators/default/class-expr-static-private-method.template diff --git a/src/generators/default/class-decl-method.template b/src/generators/default/class-decl-method.template index 334145980a..a1562a76fa 100644 --- a/src/generators/default/class-decl-method.template +++ b/src/generators/default/class-decl-method.template @@ -2,7 +2,7 @@ // This code is governed by the BSD license found in the LICENSE file. /*--- path: language/statements/class/gen-method- -name: Geenerator method as a ClassDeclaration element +name: Generator method as a ClassDeclaration element esid: prod-GeneratorMethod info: | ClassElement : diff --git a/src/generators/default/class-decl-private-method.template b/src/generators/default/class-decl-private-method.template new file mode 100644 index 0000000000..70f8505f37 --- /dev/null +++ b/src/generators/default/class-decl-private-method.template @@ -0,0 +1,50 @@ +// Copyright (C) 2018 Jaideep Bhoosreddy. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +path: language/statements/class/gen-method- +name: Generator private method as a ClassDeclaration element +features: [class-methods-private] +esid: prod-GeneratorPrivateMethod +info: | + ClassElement : + PrivateMethodDefinition + + MethodDefinition : + GeneratorMethod + + 14.4 Generator Function Definitions + + GeneratorMethod : + * PropertyName ( UniqueFormalParameters ) { GeneratorBody } +features: [generators] +---*/ + +var callCount = 0; + +class C { + *#gen() { + callCount += 1; + /*{ body }*/ + } + gen() { + return this.#gen(); + } +} + +const c = new C(); + +// Test the private fields do not appear as properties before set to value +assert.sameValue(Object.hasOwnProperty.call(C.prototype, "#gen"), false, "test 1"); +assert.sameValue(Object.hasOwnProperty.call(C, "#gen"), false, "test 2"); +assert.sameValue(Object.hasOwnProperty.call(c, "#gen"), false, "test 3"); + +var iter = c.gen(); + +/*{ assertions }*/ + +assert.sameValue(callCount, 1); + +// Test the private fields do not appear as properties after set to value +assert.sameValue(Object.hasOwnProperty.call(C.prototype, "#gen"), false, "test 1"); +assert.sameValue(Object.hasOwnProperty.call(C, "#gen"), false, "test 2"); +assert.sameValue(Object.hasOwnProperty.call(c, "#gen"), false, "test 3"); diff --git a/src/generators/default/class-decl-static-private-method.template b/src/generators/default/class-decl-static-private-method.template new file mode 100644 index 0000000000..b11b7e9d55 --- /dev/null +++ b/src/generators/default/class-decl-static-private-method.template @@ -0,0 +1,48 @@ +// Copyright (C) 2018 Jaideep Bhoosreddy. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +path: language/statements/class/gen-private-method-static- +name: Static generator private method as a ClassDeclaration element +features: [class-methods-private] +esid: prod-GeneratorPrivateMethod +info: | + ClassElement : + static PrivateMethodDefinition + + MethodDefinition : + GeneratorMethod + + 14.4 Generator Function Definitions + + GeneratorMethod : + * PropertyName ( UniqueFormalParameters ) { GeneratorBody } +features: [generators] +---*/ + +var callCount = 0; + +class C { + static #*gen() { + callCount += 1; + /*{ body }*/ + } + static gen() { + return C.gen(); + } +} + +var gen = C.gen; + +// Test the private fields do not appear as properties before set to value +assert.sameValue(Object.hasOwnProperty.call(C.prototype, "#gen"), false, "test 1"); +assert.sameValue(Object.hasOwnProperty.call(C, "#gen"), false, "test 2"); + +var iter = gen(); + +/*{ assertions }*/ + +assert.sameValue(callCount, 1); + +// Test the private fields do not appear as properties before set to value +assert.sameValue(Object.hasOwnProperty.call(C.prototype, "#gen"), false, "test 1"); +assert.sameValue(Object.hasOwnProperty.call(C, "#gen"), false, "test 2"); \ No newline at end of file diff --git a/src/generators/default/class-expr-private-method.template b/src/generators/default/class-expr-private-method.template new file mode 100644 index 0000000000..7404d7ed12 --- /dev/null +++ b/src/generators/default/class-expr-private-method.template @@ -0,0 +1,50 @@ +// Copyright (C) 2018 Jaideep Bhoosreddy. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +path: language/expressions/class/gen-private-method- +name: Generator private method as a ClassExpression element +features: [class-methods-private] +esid: prod-GeneratorPrivateMethod +info: | + ClassElement : + PrivateMethodDefinition + + MethodDefinition : + GeneratorMethod + + 14.4 Generator Function Definitions + + GeneratorMethod : + * PropertyName ( UniqueFormalParameters ) { GeneratorBody } +features: [generators] +---*/ + +var callCount = 0; + +var C = class { + *gen() { + callCount += 1; + /*{ body }*/ + } + gen() { + return this.#gen(); + } +} + +const c = new C(); + +// Test the private fields do not appear as properties before set to value +assert.sameValue(Object.hasOwnProperty.call(C.prototype, "#gen"), false, "test 1"); +assert.sameValue(Object.hasOwnProperty.call(C, "#gen"), false, "test 2"); +assert.sameValue(Object.hasOwnProperty.call(c, "#gen"), false, "test 3"); + +var iter = c.gen(); + +/*{ assertions }*/ + +assert.sameValue(callCount, 1); + +// Test the private fields do not appear as properties after set to value +assert.sameValue(Object.hasOwnProperty.call(C.prototype, "#gen"), false, "test 1"); +assert.sameValue(Object.hasOwnProperty.call(C, "#gen"), false, "test 2"); +assert.sameValue(Object.hasOwnProperty.call(c, "#gen"), false, "test 3"); diff --git a/src/generators/default/class-expr-static-private-method.template b/src/generators/default/class-expr-static-private-method.template new file mode 100644 index 0000000000..22cd887146 --- /dev/null +++ b/src/generators/default/class-expr-static-private-method.template @@ -0,0 +1,48 @@ +// Copyright (C) 2018 Jaideep Bhoosreddy. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +path: language/expressions/class/gen-private-method-static- +name: Static generator private method as a ClassExpression element +features: [class-methods-private] +esid: prod-GeneratorPrivateMethod +info: | + ClassElement : + static PrivateMethodDefinition + + MethodDefinition : + GeneratorMethod + + 14.4 Generator Function Definitions + + GeneratorMethod : + * PropertyName ( UniqueFormalParameters ) { GeneratorBody } +features: [generators] +---*/ + +var callCount = 0; + +var C = class { + static *gen() { + callCount += 1; + /*{ body }*/ + } + static gen() { + return C.gen(); + } +} + +var gen = C.gen; + +// Test the private fields do not appear as properties before set to value +assert.sameValue(Object.hasOwnProperty.call(C.prototype, "#gen"), false, "test 1"); +assert.sameValue(Object.hasOwnProperty.call(C, "#gen"), false, "test 2"); + +var iter = gen(); + +/*{ assertions }*/ + +assert.sameValue(callCount, 1); + +// Test the private fields do not appear as properties before set to value +assert.sameValue(Object.hasOwnProperty.call(C.prototype, "#gen"), false, "test 1"); +assert.sameValue(Object.hasOwnProperty.call(C, "#gen"), false, "test 2");