Skip to content

Commit

Permalink
Allow configuring the runner.
Browse files Browse the repository at this point in the history
  • Loading branch information
wolframkriesing committed Oct 30, 2023
1 parent f55f583 commit 2267152
Show file tree
Hide file tree
Showing 20 changed files with 413 additions and 17 deletions.
18 changes: 9 additions & 9 deletions katas/es1/language/function-api/arguments.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
describe('The `arguments` prop - discouraged since 1997 (and might not work)', () => {
it('WHEN accessing `arguments` in strict mode THEN the JS throws', () => {
const fn = function() {}
assert.throws(() => fn.arguments);
});
it('WHEN reading `arguments` using an Object-method THEN it returns `undefined`', () => {
const fn = function() {}
assert.equal(Object.getOwnPropertyDescriptor(fn, 'arguments'), undefined);
});
it('WHEN reading `arguments` in the function body THEN it is an array-like object containing all parameters the function was called with', () => {
let args;
const fn = function() {
Expand All @@ -15,4 +7,12 @@ describe('The `arguments` prop - discouraged since 1997 (and might not work)', (
fn(1, 'abc', {x: 'y'});
assert.deepStrictEqual(Array.from(args), [1, 'abc', {x: 'y'}]);
});
});
it('WHEN `arguments` is defined inside a function THEN this is NOT overridden', () => {
//: {"jskatas": {"runnerOptions": {"strictMode": false}}}
const fn = function() {
const arguments = 'arg';
return arguments;
}
assert.equal(fn('the argument'), 'arg');
});
});
2 changes: 1 addition & 1 deletion katas/es1/learn-by-rewriting/__all__.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
},
{
"url": "https://www.ecma-international.org/ecma-262/5.1/#sec-15.4.4.14",
"comment": "The definition of \"Array.prototype.indexOf\" in ECMAScript 5.1 (ECMA-262) specification.",
"comment": "The definition of \"Array.prototype.indexOf\" in ECMAScript 5 (ECMA-262) specification.",
"tags": [
"spec"
]
Expand Down
2 changes: 1 addition & 1 deletion katas/es1/learn-by-rewriting/__grouped__.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
},
{
"url": "https://www.ecma-international.org/ecma-262/5.1/#sec-15.4.4.14",
"comment": "The definition of \"Array.prototype.indexOf\" in ECMAScript 5.1 (ECMA-262) specification.",
"comment": "The definition of \"Array.prototype.indexOf\" in ECMAScript 5 (ECMA-262) specification.",
"tags": [
"spec"
]
Expand Down
2 changes: 1 addition & 1 deletion katas/es11/language/__all__.json
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@
"id": 1
},
{
"bundle": "es5.1/language",
"bundle": "es5/language",
"id": 1
}
],
Expand Down
2 changes: 1 addition & 1 deletion katas/es11/language/__grouped__.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
"id": 1
},
{
"bundle": "es5.1/language",
"bundle": "es5/language",
"id": 1
}
],
Expand Down
125 changes: 125 additions & 0 deletions katas/es5/language/__all__.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
{
"name": "ECMAScript 5",
"nameSlug": "es5-katas",
"items": [
{
"name": "`function.bind()`",
"description": "The `bind()` method creates a new function with a given scope and optionally parameter(s).",
"path": "function-api/bind",
"level": "ADVANCED",
"requiresKnowledgeFrom": [],
"links": [
{
"url": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind",
"comment": "The MDN docs about `bind()`.",
"tags": [
"mdn",
"docs"
]
},
{
"url": "https://262.ecma-international.org/5.1/#sec-15.3.4.5",
"comment": "The ECMAScript Language Specification, 5 Edition, Section 15.3.4.5, when `bind()` was introduced.",
"tags": [
"spec"
]
}
],
"groupName": "function API",
"groupNameSlug": "function-api",
"publishDateRfc822": "Mon, 16 Oct 2023 19:00:00 GMT",
"id": 1
},
{
"name": "`function.length` (with ES5 features)",
"description": "The `length` property indicates the number of parameters a function expects.",
"path": "function-api/length",
"level": "BEGINNER",
"requiresKnowledgeFrom": [
{
"bundle": "es5/language",
"id": 1
}
],
"links": [
{
"url": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/length",
"comment": "The MDN docs about `length`.",
"tags": [
"mdn",
"docs"
]
},
{
"url": "https://262.ecma-international.org/5.1/#sec-15.3.5.1",
"comment": "The ECMAScript Language Specification, 5 Edition, Section 15.3.5.1.",
"tags": [
"spec"
]
}
],
"groupName": "function API",
"groupNameSlug": "function-api",
"publishDateRfc822": "Wed, 18 Oct 2023 19:00:00 GMT",
"id": 2
},
{
"name": "`function.arguments` (as modified since ES5)",
"description": "The `arguments` property of a function is an object that contains all the arguments passed to the function.",
"path": "function-api/arguments",
"level": "BEGINNER",
"requiresKnowledgeFrom": [],
"links": [],
"groupName": "function API",
"groupNameSlug": "function-api",
"id": 3
},
{
"name": "Turn strict mode on/off",
"description": "The `use strict` directive indicates that the code should be executed in \"strict mode\", where you can for example not use undeclared variables.",
"path": "strict-mode/on-off",
"level": "ADVANCED",
"requiresKnowledgeFrom": [
{
"bundle": "es1/language",
"id": 15
}
],
"links": [
{
"url": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode",
"comment": "The MDN docs about strict mode.",
"tags": [
"mdn",
"docs"
]
},
{
"url": "https://262.ecma-international.org/5.1/#sec-4.2.2",
"comment": "Chapter 4.2.2 in the specification explains that and why ECMAScript offers a \"strict mode\" to restrict language features, and that it can coexist with non-strict code in the same program.",
"tags": [
"spec"
]
},
{
"url": "https://262.ecma-international.org/5.1/#sec-10.1.1",
"comment": "Chapter 10.1.1 in the specification explains how to turn strict mode on and off.",
"tags": [
"spec"
]
},
{
"url": "https://262.ecma-international.org/5.1/#sec-C",
"comment": "Appendix C \"The strict mode restriction and exceptions\" explains the differences between strict mode and non-strict mode in detail.",
"tags": [
"spec"
]
}
],
"groupName": "Strict mode",
"groupNameSlug": "strict-mode",
"publishDateRfc822": "Mon, 16 Oct 2023 19:00:00 GMT",
"id": 4
}
]
}
133 changes: 133 additions & 0 deletions katas/es5/language/__grouped__.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
{
"name": "ECMAScript 5",
"nameSlug": "es5-katas",
"groups": {
"function API": {
"items": [
{
"name": "`function.bind()`",
"description": "The `bind()` method creates a new function with a given scope and optionally parameter(s).",
"path": "function-api/bind",
"level": "ADVANCED",
"requiresKnowledgeFrom": [],
"publishDateUTC": "2023-10-16T19:00:00.000Z",
"links": [
{
"url": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind",
"comment": "The MDN docs about `bind()`.",
"tags": [
"mdn",
"docs"
]
},
{
"url": "https://262.ecma-international.org/5.1/#sec-15.3.4.5",
"comment": "The ECMAScript Language Specification, 5 Edition, Section 15.3.4.5, when `bind()` was introduced.",
"tags": [
"spec"
]
}
],
"groupName": "function API",
"id": "1"
},
{
"name": "`function.length` (with ES5 features)",
"description": "The `length` property indicates the number of parameters a function expects.",
"path": "function-api/length",
"level": "BEGINNER",
"requiresKnowledgeFrom": [
{
"bundle": "es5/language",
"id": 1
}
],
"publishDateUTC": "2023-10-18T19:00:00.000Z",
"links": [
{
"url": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/length",
"comment": "The MDN docs about `length`.",
"tags": [
"mdn",
"docs"
]
},
{
"url": "https://262.ecma-international.org/5.1/#sec-15.3.5.1",
"comment": "The ECMAScript Language Specification, 5 Edition, Section 15.3.5.1.",
"tags": [
"spec"
]
}
],
"groupName": "function API",
"id": "2"
},
{
"name": "`function.arguments` (as modified since ES5)",
"description": "The `arguments` property of a function is an object that contains all the arguments passed to the function.",
"path": "function-api/arguments",
"level": "BEGINNER",
"requiresKnowledgeFrom": [],
"links": [],
"groupName": "function API",
"id": "3"
}
],
"slug": "function-api",
"name": "function API"
},
"Strict mode": {
"items": [
{
"name": "Turn strict mode on/off",
"description": "The `use strict` directive indicates that the code should be executed in \"strict mode\", where you can for example not use undeclared variables.",
"path": "strict-mode/on-off",
"level": "ADVANCED",
"requiresKnowledgeFrom": [
{
"bundle": "es1/language",
"id": 15
}
],
"publishDateUTC": "2023-10-16T19:00:00.000Z",
"links": [
{
"url": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode",
"comment": "The MDN docs about strict mode.",
"tags": [
"mdn",
"docs"
]
},
{
"url": "https://262.ecma-international.org/5.1/#sec-4.2.2",
"comment": "Chapter 4.2.2 in the specification explains that and why ECMAScript offers a \"strict mode\" to restrict language features, and that it can coexist with non-strict code in the same program.",
"tags": [
"spec"
]
},
{
"url": "https://262.ecma-international.org/5.1/#sec-10.1.1",
"comment": "Chapter 10.1.1 in the specification explains how to turn strict mode on and off.",
"tags": [
"spec"
]
},
{
"url": "https://262.ecma-international.org/5.1/#sec-C",
"comment": "Appendix C \"The strict mode restriction and exceptions\" explains the differences between strict mode and non-strict mode in detail.",
"tags": [
"spec"
]
}
],
"groupName": "Strict mode",
"id": "4"
}
],
"slug": "strict-mode",
"name": "Strict mode"
}
}
}
16 changes: 16 additions & 0 deletions katas/es5/language/function-api/arguments.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
describe('The `arguments` prop - discouraged since 1997 (and might not work)', () => {
// it('WHEN accessing `arguments` in strict mode THEN the JS throws', () => {
// const fn = function() {}
// assert.throws(() => fn.arguments);
// });
// it('WHEN accessing `arguments` inside a function, in strict mode THEN the JS throws', () => {
// const fn = function() {
// return arguments;
// }
// // assert.deepEqual(Object.getOwnPropertyDescriptors(fn()), {});
// });
// it('WHEN reading `arguments` using an Object-method THEN it returns `undefined`', () => {
// const fn = function() {}
// assert.equal(Object.getOwnPropertyDescriptor(fn, 'arguments'), undefined);
// });
});
27 changes: 27 additions & 0 deletions katas/es5/language/function-api/bind.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
describe('Using `fn.bind()` creates a new function with scope (and parameters) pre-configured', () => {
describe('GIVEN we bind a scope to a function', () => {
it('WHEN we call the bound function with a custom object THEN the scope of `this` refers to the given object', () => {
const fn = function() {
return this.newVariable;
};
const boundFn = fn.____({myScopeVariable: 'forty-two'});
assert.strictEqual(boundFn(), 'forty-two');
});
it('WHEN binding a string to String\'s `toUpperCase` THEN calling the resulting function returns the upper case value of the string', () => {
const yell = String.prototype.toUpperCase('hello');
assert.strictEqual(yell(), 'HELLO');
});
it('WHEN binding Array\'s `slice()` method THEN array-like values can dynamically be converted to an array', () => {
const arrayLike = {length: 1, 0: 'a'};
const toArray = function (a) { return Array.prototype.bind(a)(); };
assert.deepStrictEqual(toArray(arrayLike), ['a']);
});
});
describe('GIVEN we bind parameters to a function', () => {
it('WHEN binding the first parameter of a function THEN the bound function can be called just with the seconds parameter', () => {
const add = function(a, b) { return a + b; };
const add5 = add.bind();
assert.strictEqual(add5(10), 15);
});
});
});
14 changes: 14 additions & 0 deletions katas/es5/language/function-api/length.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
describe('The property `function.length` indicates the number of parameters a function expects', () => {
describe('GIVEN we read the `length` from a bound function', () => {
it('WHEN binding a function with 3 parameters THEN the bound value has still a `length` of 3', () => {
const fn = function(a, b, c) {};
const boundFn = fn.____(null);
assert.equal(boundFn.length, 3);
});
it('WHEN binding a function (that expects three parameters) with one parameter THEN the `length` will reduced by 1, it will be 2', () => {
const fn = function(a, b, c) {};
const boundFn = fn.bind(null, 1, 2, 3);
assert.equal(boundFn.length, 2);
});
});
});
Loading

0 comments on commit 2267152

Please sign in to comment.