-
Notifications
You must be signed in to change notification settings - Fork 464
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
747 changed files
with
25,150 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
# Decorator Test Notes | ||
|
||
## Terminology | ||
|
||
Some terms are simplified in these tests to make it easier to communicate | ||
meaning and intent. | ||
|
||
- **static** is used to refer to all class elements that are used with the | ||
`static` keyword, including fields and methods. This should be thought of as | ||
"elements that belong to the class definition". | ||
|
||
- **instance** is used to refer to all class elements that are used _without_ | ||
the static keyword, including fields and methods. This should be thought as | ||
"elements that belong to the class instance". Some of these elements are | ||
assigned to the class prototype rather than the instance, but from a typical | ||
usage perspective, a user will only call these methods when dealing with an | ||
instance of the class. Most users do not ever deal directly with the class | ||
prototype. | ||
|
||
- **methods** refers to all public/private _methods_, _getters_, and _setters_. | ||
These are elements that do _not_ have a per-instance initializer, and for this | ||
reason they are grouped together for things like initialization and decorator | ||
application. | ||
|
||
- **fields** refers to all public/private _fields_ and _accessors_. Accessors | ||
here refers to auto-accessors created with the `accessor` keyword, _NOT_ | ||
getters and setters created with the `get` and `set` keywords. These are | ||
elements that _have_ an initialization step per-instance, and grouped | ||
together for initialization and decorator application for that reason. | ||
|
||
- **Extra-initializers** refers to all initializers added via | ||
`context.addInitializer`. This distinguishes them from standard initializers | ||
for fields and accessors, which run in a different order and with different | ||
timing. | ||
|
||
## Structure | ||
|
||
- Element decorator templates all follow the same basic structure in order to | ||
share as much code as possible for repeated tests. | ||
|
||
- The class element being tested is named `element` for public elements and | ||
`#element` for private elements. | ||
|
||
- If the element is gettable, there is a `getElement` public method that | ||
directly gets the element. If the element is a field, accessor, or getter, | ||
this will call any getters and return the value. If it is a method, it will | ||
return the method itself. Setters are not gettable. | ||
|
||
- These is a `setElement` public method that directly sets the element. If the | ||
element is a field, accessor, or setter, this will call any setters and set | ||
the value. Getters and methods are not settable. | ||
|
||
- Each element template folder is broken down into the following directory | ||
structure: | ||
|
||
``` | ||
. | ||
└── [element type]/ | ||
└── [test case type]/ | ||
├── private/ | ||
│ ├── instance/ | ||
│ │ ├── cls-decl.template | ||
│ │ └── cls-expr.template | ||
│ └── static/ | ||
│ ├── cls-decl.template | ||
│ └── cls-expr.template | ||
└── public/ | ||
├── instance/ | ||
│ ├── cls-decl.template | ||
│ └── cls-expr.template | ||
└── static/ | ||
└── cls-decl.template/ | ||
└── cls-expr.template | ||
``` | ||
|
||
This structure allows each test to easily select the types of values it | ||
applies to and test them across both class declarations and expressions. | ||
Private and public are split out because there are some common differences | ||
between them (e.g. `context.private`, `context.name`) and the same is true for | ||
static vs instance (e.g. `context.static`). | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Copyright (C) 2024 Kristen Maevyn Hewell Garrett. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-applydecoratorstoelementdefinition | ||
desc: Accessor decorator cannot return invalid getter | ||
template: accessors/error/**/* | ||
features: [decorators] | ||
---*/ | ||
|
||
//- decorators | ||
function dec() { | ||
return { | ||
get: 123 | ||
}; | ||
} | ||
|
||
//- application | ||
@dec | ||
|
||
//- error | ||
TypeError |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Copyright (C) 2024 Kristen Maevyn Hewell Garrett. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-applydecoratorstoelementdefinition | ||
desc: Accessor decorator cannot return invalid init | ||
template: accessors/error/**/* | ||
features: [decorators] | ||
---*/ | ||
|
||
//- decorators | ||
function dec() { | ||
return { | ||
init: 123 | ||
}; | ||
} | ||
|
||
//- application | ||
@dec | ||
|
||
//- error | ||
TypeError |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Copyright (C) 2024 Kristen Maevyn Hewell Garrett. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-applydecoratorstoelementdefinition | ||
desc: Accessor decorator cannot return invalid setter | ||
template: accessors/error/**/* | ||
features: [decorators] | ||
---*/ | ||
|
||
//- decorators | ||
function dec() { | ||
return { | ||
set: 123 | ||
}; | ||
} | ||
|
||
//- application | ||
@dec | ||
|
||
//- error | ||
TypeError |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Copyright (C) 2024 Kristen Maevyn Hewell Garrett. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-applydecoratorstoelementdefinition | ||
desc: Accessor decorator cannot return invalid init | ||
template: accessors/error/**/* | ||
features: [decorators] | ||
---*/ | ||
|
||
//- decorators | ||
function dec() { | ||
return 123; | ||
} | ||
|
||
//- application | ||
@dec | ||
|
||
//- error | ||
TypeError |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Copyright (C) 2024 Kristen Maevyn Hewell Garrett. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-applydecoratorstoelementdefinition | ||
desc: Accessor decorator can return a new getter | ||
template: accessors/standard/**/* | ||
features: [decorators] | ||
---*/ | ||
|
||
//- decorators | ||
function dec({ get }) { | ||
return { | ||
get() { | ||
assert.sameValue(get.call(this), undefined); | ||
return 123; | ||
} | ||
}; | ||
} | ||
|
||
//- application | ||
@dec | ||
|
||
//- assertions | ||
assert.sameValue(classOrInstance.getElement(), 123); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Copyright (C) 2024 Kristen Maevyn Hewell Garrett. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-applydecoratorstoelementdefinition | ||
desc: Accessor decorator can return a new init | ||
template: accessors/standard/**/* | ||
features: [decorators] | ||
---*/ | ||
|
||
//- decorators | ||
function dec() { | ||
return { | ||
init(value) { | ||
assert.sameValue(value, undefined); | ||
return 123; | ||
} | ||
}; | ||
} | ||
|
||
//- application | ||
@dec | ||
|
||
//- assertions | ||
assert.sameValue(classOrInstance.getElement(), 123); | ||
classOrInstance.setElement(456); | ||
assert.sameValue(classOrInstance.getElement(), 456); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Copyright (C) 2024 Kristen Maevyn Hewell Garrett. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-applydecoratorstoelementdefinition | ||
desc: Accessor decorator can return a new getter | ||
template: accessors/standard/**/* | ||
features: [decorators] | ||
---*/ | ||
|
||
//- decorators | ||
function dec({ set }) { | ||
return { | ||
set(value) { | ||
assert.sameValue(value, 123); | ||
set.call(this, 456); | ||
} | ||
}; | ||
} | ||
|
||
//- application | ||
@dec | ||
|
||
//- assertions | ||
assert.sameValue(classOrInstance.getElement(), undefined); | ||
classOrInstance.setElement(123); | ||
assert.sameValue(classOrInstance.getElement(), 456); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Copyright (C) 2024 Kristen Maevyn Hewell Garrett. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-applydecoratorstoelementdefinition | ||
desc: Accessor decorator can return a new getter | ||
template: accessors/with-init/**/* | ||
features: [decorators] | ||
---*/ | ||
|
||
//- initializer | ||
123 | ||
|
||
//- decorators | ||
function dec({ get }) { | ||
return { | ||
get() { | ||
assert.sameValue(get.call(this), 123); | ||
return 456; | ||
} | ||
}; | ||
} | ||
|
||
//- application | ||
@dec | ||
|
||
//- assertions | ||
assert.sameValue(classOrInstance.getElement(), 456); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Copyright (C) 2024 Kristen Maevyn Hewell Garrett. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-applydecoratorstoelementdefinition | ||
desc: Accessor decorator can return a new init that chains with default initializer | ||
template: accessors/with-init/**/* | ||
features: [decorators] | ||
---*/ | ||
|
||
//- initializer | ||
123 | ||
|
||
//- decorators | ||
function dec({ get, set }) { | ||
return { | ||
init(value) { | ||
assert.sameValue(value, 123); | ||
return 456; | ||
} | ||
}; | ||
} | ||
|
||
//- application | ||
@dec | ||
|
||
//- assertions | ||
assert.sameValue(classOrInstance.getElement(), 456); | ||
classOrInstance.setElement(789); | ||
assert.sameValue(classOrInstance.getElement(), 789); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Copyright (C) 2024 Kristen Maevyn Hewell Garrett. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-applydecoratorstoelementdefinition | ||
desc: Accessor decorator can return a new setter when initializer is present | ||
template: accessors/with-init/**/* | ||
features: [decorators] | ||
---*/ | ||
|
||
//- initializer | ||
123 | ||
|
||
//- decorators | ||
function dec({ set }) { | ||
return { | ||
set(value) { | ||
assert.sameValue(value, 456); | ||
set.call(this, 789); | ||
} | ||
}; | ||
} | ||
|
||
//- application | ||
@dec | ||
|
||
//- assertions | ||
assert.sameValue(classOrInstance.getElement(), 123); | ||
classOrInstance.setElement(456); | ||
assert.sameValue(classOrInstance.getElement(), 789); |
20 changes: 20 additions & 0 deletions
20
src/decorator/accessors/error/private/instance/cls-decl.template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Copyright (C) 2024 Kristen Maevyn Hewell Garrett. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
path: language/statements/class/decorator/accessor/error/private/instance/ | ||
name: private acessor decorator evaluation error in class declaration | ||
features: [class, decorators, class-fields-private] | ||
esid: prod-FieldDefinition | ||
---*/ | ||
|
||
/*{ decorators }*/ | ||
|
||
function evaluate() { | ||
class C { | ||
/*{ application }*/ | ||
accessor #element; | ||
} | ||
} | ||
|
||
assert.throws(/*{ error }*/, evaluate); |
21 changes: 21 additions & 0 deletions
21
src/decorator/accessors/error/private/instance/cls-expr.template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Copyright (C) 2024 Kristen Maevyn Hewell Garrett. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
path: language/expressions/class/decorator/accessor/error/private/instance/ | ||
name: private acessor decorator behavior in class expression | ||
features: [class, decorators, class-fields-private] | ||
esid: prod-FieldDefinition | ||
---*/ | ||
|
||
/*{ decorators }*/ | ||
|
||
function evaluate() { | ||
var C = class { | ||
/*{ application }*/ | ||
accessor #element; | ||
} | ||
} | ||
|
||
assert.throws(/*{ error }*/, evaluate); | ||
|
Oops, something went wrong.