-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add exemplar analyzer for poetry-club-door-policy (#86)
* Add exemplar analyzer for poetry-club-door-policy * Bump the version * Move to correct folder
- Loading branch information
1 parent
55d9d15
commit 9456137
Showing
8 changed files
with
442 additions
and
1 deletion.
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
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "@exercism/javascript-analyzer", | ||
"version": "0.12.0", | ||
"version": "0.13.0", | ||
"description": "Exercism analyzer for javascript", | ||
"repository": "https://github.com/exercism/javascript-analyzer", | ||
"author": "Derk-Jan Karrenbeld <[email protected]>", | ||
|
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,5 @@ | ||
import { ExemplarAnalyzer } from '../__exemplar' | ||
|
||
export class PoetryClubDoorPolicyAnalyzer extends ExemplarAnalyzer { | ||
// TODO: implement actual analyzer | ||
} |
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,41 @@ | ||
import path from 'path' | ||
import { PoetryClubDoorPolicyAnalyzer } from '~src/analyzers/concept/poetry-club-door-policy' | ||
import { EXEMPLAR_SOLUTION } from '~src/comments/shared' | ||
import { DirectoryWithConfigInput } from '~src/input/DirectoryWithConfigInput' | ||
import { makeAnalyze, makeOptions } from '~test/helpers/smoke' | ||
|
||
const inputDir = path.join( | ||
__dirname, | ||
'..', | ||
'..', | ||
'fixtures', | ||
'poetry-club-door-policy', | ||
'exemplar' | ||
) | ||
|
||
const analyze = makeAnalyze( | ||
() => new PoetryClubDoorPolicyAnalyzer(), | ||
makeOptions({ | ||
get inputDir(): string { | ||
return inputDir | ||
}, | ||
get exercise(): string { | ||
return 'freelancer-rates' | ||
}, | ||
}) | ||
) | ||
|
||
describe('When running analysis on poetry-club-door-policy', () => { | ||
it('recognises the exemplar solution', async () => { | ||
const input = new DirectoryWithConfigInput(inputDir) | ||
|
||
const [solution] = await input.read() | ||
const output = await analyze(solution) | ||
|
||
expect(output.comments.length).toBe(1) | ||
expect(output.comments[0].type).toBe('celebratory') | ||
expect(output.comments[0].externalTemplate).toBe( | ||
EXEMPLAR_SOLUTION().externalTemplate | ||
) | ||
}) | ||
}) |
11 changes: 11 additions & 0 deletions
11
test/fixtures/poetry-club-door-policy/exemplar/.meta/config.json
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,11 @@ | ||
{ | ||
"blurb": "Learn about strings using poems to get into the poetry club.", | ||
"authors": ["SleeplessByte"], | ||
"contributors": ["hayashi-ay"], | ||
"files": { | ||
"solution": ["door-policy.js"], | ||
"test": ["door-policy.spec.js"], | ||
"exemplar": [".meta/exemplar.js"] | ||
}, | ||
"forked_from": [] | ||
} |
74 changes: 74 additions & 0 deletions
74
test/fixtures/poetry-club-door-policy/exemplar/.meta/exemplar.js
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,74 @@ | ||
// @ts-check | ||
// | ||
// ☝🏽 The line above enables type checking for this file. Various IDEs interpret | ||
// the @ts-check directive. It will give you helpful autocompletion on the web | ||
// and supported IDEs when implementing this exercise. You don't need to | ||
// understand types, JSDoc, or TypeScript in order to complete this JavaScript | ||
// exercise, and can completely ignore this comment block and directive. | ||
// | ||
// 👋🏽 Hi again! | ||
// | ||
// A quick reminder about exercise stubs: | ||
// | ||
// 💡 You're allowed to completely clear any stub before you get started. Often | ||
// we recommend using the stub, because they are already set-up correctly to | ||
// work with the tests, which you can find in ./door-policy.spec.js. | ||
// | ||
// 💡 You don't need to write JSDoc comment blocks yourself; it is not expected | ||
// in idiomatic JavaScript, but some companies and style-guides do enforce them. | ||
// | ||
// Good luck with that door policy! | ||
|
||
/** | ||
* Respond with the correct character, given the blurb, if this were said at | ||
* the front door. | ||
* | ||
* @param {string} blurb | ||
* @returns {string} | ||
*/ | ||
export function frontDoorResponse(blurb) { | ||
return blurb[0]; | ||
} | ||
|
||
/** | ||
* Respond with the correct character, given the blurb, if this were said at | ||
* the back door. | ||
* | ||
* @param {string} blurb | ||
* @returns {string} | ||
*/ | ||
export function backDoorResponse(blurb) { | ||
const trimmed = blurb.trim(); | ||
return trimmed[trimmed.length - 1]; | ||
} | ||
|
||
/** | ||
* Give the password for the front-door, given the responses. | ||
* | ||
* @param {string} responses the responses | ||
* @returns {string} the password | ||
*/ | ||
export function frontDoorPassword(responses) { | ||
return capitalize(responses); | ||
} | ||
|
||
/** | ||
* Give the password for the back-door, given the responses. | ||
* | ||
* @param {string} responses the responses | ||
* @returns {string} the password | ||
*/ | ||
export function backDoorPassword(responses) { | ||
return `${capitalize(responses)}, please`; | ||
} | ||
|
||
/** | ||
* Capitalizes a word, meaning only the first character is a capital, and the | ||
* remaining letters are lower case. | ||
* | ||
* @param {string} word | ||
* @returns {string} | ||
*/ | ||
function capitalize(word) { | ||
return word[0].toUpperCase() + word.slice(1).toLowerCase(); | ||
} |
74 changes: 74 additions & 0 deletions
74
test/fixtures/poetry-club-door-policy/exemplar/door-policy.js
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,74 @@ | ||
// @ts-check | ||
// | ||
// ☝🏽 The line above enables type checking for this file. Various IDEs interpret | ||
// the @ts-check directive. It will give you helpful autocompletion on the web | ||
// and supported IDEs when implementing this exercise. You don't need to | ||
// understand types, JSDoc, or TypeScript in order to complete this JavaScript | ||
// exercise, and can completely ignore this comment block and directive. | ||
// | ||
// 👋🏽 Hi again! | ||
// | ||
// A quick reminder about exercise stubs: | ||
// | ||
// 💡 You're allowed to completely clear any stub before you get started. Often | ||
// we recommend using the stub, because they are already set-up correctly to | ||
// work with the tests, which you can find in ./door-policy.spec.js. | ||
// | ||
// 💡 You don't need to write JSDoc comment blocks yourself; it is not expected | ||
// in idiomatic JavaScript, but some companies and style-guides do enforce them. | ||
// | ||
// Good luck with that door policy! | ||
|
||
/** | ||
* Respond with the correct character, given the blurb, if this were said at | ||
* the front door. | ||
* | ||
* @param {string} blurb | ||
* @returns {string} | ||
*/ | ||
export function frontDoorResponse(blurb) { | ||
return blurb[0]; | ||
} | ||
|
||
/** | ||
* Respond with the correct character, given the blurb, if this were said at | ||
* the back door. | ||
* | ||
* @param {string} blurb | ||
* @returns {string} | ||
*/ | ||
export function backDoorResponse(blurb) { | ||
const trimmed = blurb.trim(); | ||
return trimmed[trimmed.length - 1]; | ||
} | ||
|
||
/** | ||
* Give the password for the front-door, given the responses. | ||
* | ||
* @param {string} responses the responses | ||
* @returns {string} the password | ||
*/ | ||
export function frontDoorPassword(responses) { | ||
return capitalize(responses); | ||
} | ||
|
||
/** | ||
* Give the password for the back-door, given the responses. | ||
* | ||
* @param {string} responses the responses | ||
* @returns {string} the password | ||
*/ | ||
export function backDoorPassword(responses) { | ||
return `${capitalize(responses)}, please`; | ||
} | ||
|
||
/** | ||
* Capitalizes a word, meaning only the first character is a capital, and the | ||
* remaining letters are lower case. | ||
* | ||
* @param {string} word | ||
* @returns {string} | ||
*/ | ||
function capitalize(word) { | ||
return word[0].toUpperCase() + word.slice(1).toLowerCase(); | ||
} |
Oops, something went wrong.