Skip to content

Commit 9456137

Browse files
Add exemplar analyzer for poetry-club-door-policy (#86)
* Add exemplar analyzer for poetry-club-door-policy * Bump the version * Move to correct folder
1 parent 55d9d15 commit 9456137

File tree

8 files changed

+442
-1
lines changed

8 files changed

+442
-1
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 0.13.0
4+
5+
- Use generic ExemplarAnalyzer for `poetry-club-door-analyzer`
6+
37
## 0.12.0
48

59
- Add generic ExemplarAnalyzer

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@exercism/javascript-analyzer",
3-
"version": "0.12.0",
3+
"version": "0.13.0",
44
"description": "Exercism analyzer for javascript",
55
"repository": "https://github.com/exercism/javascript-analyzer",
66
"author": "Derk-Jan Karrenbeld <[email protected]>",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { ExemplarAnalyzer } from '../__exemplar'
2+
3+
export class PoetryClubDoorPolicyAnalyzer extends ExemplarAnalyzer {
4+
// TODO: implement actual analyzer
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import path from 'path'
2+
import { PoetryClubDoorPolicyAnalyzer } from '~src/analyzers/concept/poetry-club-door-policy'
3+
import { EXEMPLAR_SOLUTION } from '~src/comments/shared'
4+
import { DirectoryWithConfigInput } from '~src/input/DirectoryWithConfigInput'
5+
import { makeAnalyze, makeOptions } from '~test/helpers/smoke'
6+
7+
const inputDir = path.join(
8+
__dirname,
9+
'..',
10+
'..',
11+
'fixtures',
12+
'poetry-club-door-policy',
13+
'exemplar'
14+
)
15+
16+
const analyze = makeAnalyze(
17+
() => new PoetryClubDoorPolicyAnalyzer(),
18+
makeOptions({
19+
get inputDir(): string {
20+
return inputDir
21+
},
22+
get exercise(): string {
23+
return 'freelancer-rates'
24+
},
25+
})
26+
)
27+
28+
describe('When running analysis on poetry-club-door-policy', () => {
29+
it('recognises the exemplar solution', async () => {
30+
const input = new DirectoryWithConfigInput(inputDir)
31+
32+
const [solution] = await input.read()
33+
const output = await analyze(solution)
34+
35+
expect(output.comments.length).toBe(1)
36+
expect(output.comments[0].type).toBe('celebratory')
37+
expect(output.comments[0].externalTemplate).toBe(
38+
EXEMPLAR_SOLUTION().externalTemplate
39+
)
40+
})
41+
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"blurb": "Learn about strings using poems to get into the poetry club.",
3+
"authors": ["SleeplessByte"],
4+
"contributors": ["hayashi-ay"],
5+
"files": {
6+
"solution": ["door-policy.js"],
7+
"test": ["door-policy.spec.js"],
8+
"exemplar": [".meta/exemplar.js"]
9+
},
10+
"forked_from": []
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
// @ts-check
2+
//
3+
// ☝🏽 The line above enables type checking for this file. Various IDEs interpret
4+
// the @ts-check directive. It will give you helpful autocompletion on the web
5+
// and supported IDEs when implementing this exercise. You don't need to
6+
// understand types, JSDoc, or TypeScript in order to complete this JavaScript
7+
// exercise, and can completely ignore this comment block and directive.
8+
//
9+
// 👋🏽 Hi again!
10+
//
11+
// A quick reminder about exercise stubs:
12+
//
13+
// 💡 You're allowed to completely clear any stub before you get started. Often
14+
// we recommend using the stub, because they are already set-up correctly to
15+
// work with the tests, which you can find in ./door-policy.spec.js.
16+
//
17+
// 💡 You don't need to write JSDoc comment blocks yourself; it is not expected
18+
// in idiomatic JavaScript, but some companies and style-guides do enforce them.
19+
//
20+
// Good luck with that door policy!
21+
22+
/**
23+
* Respond with the correct character, given the blurb, if this were said at
24+
* the front door.
25+
*
26+
* @param {string} blurb
27+
* @returns {string}
28+
*/
29+
export function frontDoorResponse(blurb) {
30+
return blurb[0];
31+
}
32+
33+
/**
34+
* Respond with the correct character, given the blurb, if this were said at
35+
* the back door.
36+
*
37+
* @param {string} blurb
38+
* @returns {string}
39+
*/
40+
export function backDoorResponse(blurb) {
41+
const trimmed = blurb.trim();
42+
return trimmed[trimmed.length - 1];
43+
}
44+
45+
/**
46+
* Give the password for the front-door, given the responses.
47+
*
48+
* @param {string} responses the responses
49+
* @returns {string} the password
50+
*/
51+
export function frontDoorPassword(responses) {
52+
return capitalize(responses);
53+
}
54+
55+
/**
56+
* Give the password for the back-door, given the responses.
57+
*
58+
* @param {string} responses the responses
59+
* @returns {string} the password
60+
*/
61+
export function backDoorPassword(responses) {
62+
return `${capitalize(responses)}, please`;
63+
}
64+
65+
/**
66+
* Capitalizes a word, meaning only the first character is a capital, and the
67+
* remaining letters are lower case.
68+
*
69+
* @param {string} word
70+
* @returns {string}
71+
*/
72+
function capitalize(word) {
73+
return word[0].toUpperCase() + word.slice(1).toLowerCase();
74+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
// @ts-check
2+
//
3+
// ☝🏽 The line above enables type checking for this file. Various IDEs interpret
4+
// the @ts-check directive. It will give you helpful autocompletion on the web
5+
// and supported IDEs when implementing this exercise. You don't need to
6+
// understand types, JSDoc, or TypeScript in order to complete this JavaScript
7+
// exercise, and can completely ignore this comment block and directive.
8+
//
9+
// 👋🏽 Hi again!
10+
//
11+
// A quick reminder about exercise stubs:
12+
//
13+
// 💡 You're allowed to completely clear any stub before you get started. Often
14+
// we recommend using the stub, because they are already set-up correctly to
15+
// work with the tests, which you can find in ./door-policy.spec.js.
16+
//
17+
// 💡 You don't need to write JSDoc comment blocks yourself; it is not expected
18+
// in idiomatic JavaScript, but some companies and style-guides do enforce them.
19+
//
20+
// Good luck with that door policy!
21+
22+
/**
23+
* Respond with the correct character, given the blurb, if this were said at
24+
* the front door.
25+
*
26+
* @param {string} blurb
27+
* @returns {string}
28+
*/
29+
export function frontDoorResponse(blurb) {
30+
return blurb[0];
31+
}
32+
33+
/**
34+
* Respond with the correct character, given the blurb, if this were said at
35+
* the back door.
36+
*
37+
* @param {string} blurb
38+
* @returns {string}
39+
*/
40+
export function backDoorResponse(blurb) {
41+
const trimmed = blurb.trim();
42+
return trimmed[trimmed.length - 1];
43+
}
44+
45+
/**
46+
* Give the password for the front-door, given the responses.
47+
*
48+
* @param {string} responses the responses
49+
* @returns {string} the password
50+
*/
51+
export function frontDoorPassword(responses) {
52+
return capitalize(responses);
53+
}
54+
55+
/**
56+
* Give the password for the back-door, given the responses.
57+
*
58+
* @param {string} responses the responses
59+
* @returns {string} the password
60+
*/
61+
export function backDoorPassword(responses) {
62+
return `${capitalize(responses)}, please`;
63+
}
64+
65+
/**
66+
* Capitalizes a word, meaning only the first character is a capital, and the
67+
* remaining letters are lower case.
68+
*
69+
* @param {string} word
70+
* @returns {string}
71+
*/
72+
function capitalize(word) {
73+
return word[0].toUpperCase() + word.slice(1).toLowerCase();
74+
}

0 commit comments

Comments
 (0)