Skip to content

Commit aa99427

Browse files
committed
Add decorator behavioral tests
1 parent 2496577 commit aa99427

File tree

747 files changed

+25150
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

747 files changed

+25150
-0
lines changed

src/decorator/README.md

+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# Decorator Test Notes
2+
3+
## Terminology
4+
5+
Some terms are simplified in these tests to make it easier to communicate
6+
meaning and intent.
7+
8+
- **static** is used to refer to all class elements that are used with the
9+
`static` keyword, including fields and methods. This should be thought of as
10+
"elements that belong to the class definition".
11+
12+
- **instance** is used to refer to all class elements that are used _without_
13+
the static keyword, including fields and methods. This should be thought as
14+
"elements that belong to the class instance". Some of these elements are
15+
assigned to the class prototype rather than the instance, but from a typical
16+
usage perspective, a user will only call these methods when dealing with an
17+
instance of the class. Most users do not ever deal directly with the class
18+
prototype.
19+
20+
- **methods** refers to all public/private _methods_, _getters_, and _setters_.
21+
These are elements that do _not_ have a per-instance initializer, and for this
22+
reason they are grouped together for things like initialization and decorator
23+
application.
24+
25+
- **fields** refers to all public/private _fields_ and _accessors_. Accessors
26+
here refers to auto-accessors created with the `accessor` keyword, _NOT_
27+
getters and setters created with the `get` and `set` keywords. These are
28+
elements that _have_ an initialization step per-instance, and grouped
29+
together for initialization and decorator application for that reason.
30+
31+
- **Extra-initializers** refers to all initializers added via
32+
`context.addInitializer`. This distinguishes them from standard initializers
33+
for fields and accessors, which run in a different order and with different
34+
timing.
35+
36+
## Structure
37+
38+
- Element decorator templates all follow the same basic structure in order to
39+
share as much code as possible for repeated tests.
40+
41+
- The class element being tested is named `element` for public elements and
42+
`#element` for private elements.
43+
44+
- If the element is gettable, there is a `getElement` public method that
45+
directly gets the element. If the element is a field, accessor, or getter,
46+
this will call any getters and return the value. If it is a method, it will
47+
return the method itself. Setters are not gettable.
48+
49+
- These is a `setElement` public method that directly sets the element. If the
50+
element is a field, accessor, or setter, this will call any setters and set
51+
the value. Getters and methods are not settable.
52+
53+
- Each element template folder is broken down into the following directory
54+
structure:
55+
56+
```
57+
.
58+
└── [element type]/
59+
└── [test case type]/
60+
├── private/
61+
│ ├── instance/
62+
│ │ ├── cls-decl.template
63+
│ │ └── cls-expr.template
64+
│ └── static/
65+
│ ├── cls-decl.template
66+
│ └── cls-expr.template
67+
└── public/
68+
├── instance/
69+
│ ├── cls-decl.template
70+
│ └── cls-expr.template
71+
└── static/
72+
└── cls-decl.template/
73+
└── cls-expr.template
74+
```
75+
76+
This structure allows each test to easily select the types of values it
77+
applies to and test them across both class declarations and expressions.
78+
Private and public are split out because there are some common differences
79+
between them (e.g. `context.private`, `context.name`) and the same is true for
80+
static vs instance (e.g. `context.static`).
81+
82+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright (C) 2024 Kristen Maevyn Hewell Garrett. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
esid: sec-applydecoratorstoelementdefinition
6+
desc: Accessor decorator cannot return invalid getter
7+
template: accessors/error/**/*
8+
features: [decorators]
9+
---*/
10+
11+
//- decorators
12+
function dec() {
13+
return {
14+
get: 123
15+
};
16+
}
17+
18+
//- application
19+
@dec
20+
21+
//- error
22+
TypeError
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright (C) 2024 Kristen Maevyn Hewell Garrett. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
esid: sec-applydecoratorstoelementdefinition
6+
desc: Accessor decorator cannot return invalid init
7+
template: accessors/error/**/*
8+
features: [decorators]
9+
---*/
10+
11+
//- decorators
12+
function dec() {
13+
return {
14+
init: 123
15+
};
16+
}
17+
18+
//- application
19+
@dec
20+
21+
//- error
22+
TypeError
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright (C) 2024 Kristen Maevyn Hewell Garrett. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
esid: sec-applydecoratorstoelementdefinition
6+
desc: Accessor decorator cannot return invalid setter
7+
template: accessors/error/**/*
8+
features: [decorators]
9+
---*/
10+
11+
//- decorators
12+
function dec() {
13+
return {
14+
set: 123
15+
};
16+
}
17+
18+
//- application
19+
@dec
20+
21+
//- error
22+
TypeError
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright (C) 2024 Kristen Maevyn Hewell Garrett. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
esid: sec-applydecoratorstoelementdefinition
6+
desc: Accessor decorator cannot return invalid init
7+
template: accessors/error/**/*
8+
features: [decorators]
9+
---*/
10+
11+
//- decorators
12+
function dec() {
13+
return 123;
14+
}
15+
16+
//- application
17+
@dec
18+
19+
//- error
20+
TypeError
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright (C) 2024 Kristen Maevyn Hewell Garrett. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
esid: sec-applydecoratorstoelementdefinition
6+
desc: Accessor decorator can return a new getter
7+
template: accessors/standard/**/*
8+
features: [decorators]
9+
---*/
10+
11+
//- decorators
12+
function dec({ get }) {
13+
return {
14+
get() {
15+
assert.sameValue(get.call(this), undefined);
16+
return 123;
17+
}
18+
};
19+
}
20+
21+
//- application
22+
@dec
23+
24+
//- assertions
25+
assert.sameValue(classOrInstance.getElement(), 123);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright (C) 2024 Kristen Maevyn Hewell Garrett. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
esid: sec-applydecoratorstoelementdefinition
6+
desc: Accessor decorator can return a new init
7+
template: accessors/standard/**/*
8+
features: [decorators]
9+
---*/
10+
11+
//- decorators
12+
function dec() {
13+
return {
14+
init(value) {
15+
assert.sameValue(value, undefined);
16+
return 123;
17+
}
18+
};
19+
}
20+
21+
//- application
22+
@dec
23+
24+
//- assertions
25+
assert.sameValue(classOrInstance.getElement(), 123);
26+
classOrInstance.setElement(456);
27+
assert.sameValue(classOrInstance.getElement(), 456);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright (C) 2024 Kristen Maevyn Hewell Garrett. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
esid: sec-applydecoratorstoelementdefinition
6+
desc: Accessor decorator can return a new getter
7+
template: accessors/standard/**/*
8+
features: [decorators]
9+
---*/
10+
11+
//- decorators
12+
function dec({ set }) {
13+
return {
14+
set(value) {
15+
assert.sameValue(value, 123);
16+
set.call(this, 456);
17+
}
18+
};
19+
}
20+
21+
//- application
22+
@dec
23+
24+
//- assertions
25+
assert.sameValue(classOrInstance.getElement(), undefined);
26+
classOrInstance.setElement(123);
27+
assert.sameValue(classOrInstance.getElement(), 456);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright (C) 2024 Kristen Maevyn Hewell Garrett. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
esid: sec-applydecoratorstoelementdefinition
6+
desc: Accessor decorator can return a new getter
7+
template: accessors/with-init/**/*
8+
features: [decorators]
9+
---*/
10+
11+
//- initializer
12+
123
13+
14+
//- decorators
15+
function dec({ get }) {
16+
return {
17+
get() {
18+
assert.sameValue(get.call(this), 123);
19+
return 456;
20+
}
21+
};
22+
}
23+
24+
//- application
25+
@dec
26+
27+
//- assertions
28+
assert.sameValue(classOrInstance.getElement(), 456);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright (C) 2024 Kristen Maevyn Hewell Garrett. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
esid: sec-applydecoratorstoelementdefinition
6+
desc: Accessor decorator can return a new init that chains with default initializer
7+
template: accessors/with-init/**/*
8+
features: [decorators]
9+
---*/
10+
11+
//- initializer
12+
123
13+
14+
//- decorators
15+
function dec({ get, set }) {
16+
return {
17+
init(value) {
18+
assert.sameValue(value, 123);
19+
return 456;
20+
}
21+
};
22+
}
23+
24+
//- application
25+
@dec
26+
27+
//- assertions
28+
assert.sameValue(classOrInstance.getElement(), 456);
29+
classOrInstance.setElement(789);
30+
assert.sameValue(classOrInstance.getElement(), 789);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright (C) 2024 Kristen Maevyn Hewell Garrett. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
esid: sec-applydecoratorstoelementdefinition
6+
desc: Accessor decorator can return a new setter when initializer is present
7+
template: accessors/with-init/**/*
8+
features: [decorators]
9+
---*/
10+
11+
//- initializer
12+
123
13+
14+
//- decorators
15+
function dec({ set }) {
16+
return {
17+
set(value) {
18+
assert.sameValue(value, 456);
19+
set.call(this, 789);
20+
}
21+
};
22+
}
23+
24+
//- application
25+
@dec
26+
27+
//- assertions
28+
assert.sameValue(classOrInstance.getElement(), 123);
29+
classOrInstance.setElement(456);
30+
assert.sameValue(classOrInstance.getElement(), 789);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright (C) 2024 Kristen Maevyn Hewell Garrett. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
path: language/statements/class/decorator/accessor/error/private/instance/
6+
name: private acessor decorator evaluation error in class declaration
7+
features: [class, decorators, class-fields-private]
8+
esid: prod-FieldDefinition
9+
---*/
10+
11+
/*{ decorators }*/
12+
13+
function evaluate() {
14+
class C {
15+
/*{ application }*/
16+
accessor #element;
17+
}
18+
}
19+
20+
assert.throws(/*{ error }*/, evaluate);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright (C) 2024 Kristen Maevyn Hewell Garrett. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
path: language/expressions/class/decorator/accessor/error/private/instance/
6+
name: private acessor decorator behavior in class expression
7+
features: [class, decorators, class-fields-private]
8+
esid: prod-FieldDefinition
9+
---*/
10+
11+
/*{ decorators }*/
12+
13+
function evaluate() {
14+
var C = class {
15+
/*{ application }*/
16+
accessor #element;
17+
}
18+
}
19+
20+
assert.throws(/*{ error }*/, evaluate);
21+

0 commit comments

Comments
 (0)