Skip to content

Commit

Permalink
Add exemplar analyzer for poetry-club-door-policy (#86)
Browse files Browse the repository at this point in the history
* Add exemplar analyzer for poetry-club-door-policy

* Bump the version

* Move to correct folder
  • Loading branch information
SleeplessByte authored Apr 2, 2021
1 parent 55d9d15 commit 9456137
Show file tree
Hide file tree
Showing 8 changed files with 442 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 0.13.0

- Use generic ExemplarAnalyzer for `poetry-club-door-analyzer`

## 0.12.0

- Add generic ExemplarAnalyzer
Expand Down
2 changes: 1 addition & 1 deletion package.json
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]>",
Expand Down
5 changes: 5 additions & 0 deletions src/analyzers/concept/poetry-club-door-policy/index.ts
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
}
41 changes: 41 additions & 0 deletions test/analyzers/poetry-club-door-analyzer/exemplar.ts
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 test/fixtures/poetry-club-door-policy/exemplar/.meta/config.json
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 test/fixtures/poetry-club-door-policy/exemplar/.meta/exemplar.js
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 test/fixtures/poetry-club-door-policy/exemplar/door-policy.js
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();
}
Loading

0 comments on commit 9456137

Please sign in to comment.