Skip to content

Commit

Permalink
Step 2 for denoland/deno#9350
Browse files Browse the repository at this point in the history
  • Loading branch information
kdy1 committed Feb 16, 2021
1 parent a53186c commit 71486f5
Show file tree
Hide file tree
Showing 11 changed files with 92 additions and 0 deletions.
13 changes: 13 additions & 0 deletions bundler/tests/deno-exec/deno-9350/step2/input/entry.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { parse } from "https://deno.land/std@0.86.0/flags/mod.ts";

import { getNumericInput, printQuestion } from "./helpers/mod";
import printStats from "./print_stats.ts";

const args = parse(Deno.args);

console.log(args.stats);

printStats();
printQuestion("How many times have you played");

console.log(await getNumericInput());
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { TRIVIA } from "../types/mod";
import { getUserInput, printQuestion } from "./mod";

export async function askTriviaQuestion(
selectedTrivia: TRIVIA,
): Promise<void> {
printQuestion(selectedTrivia.question);

await getUserInput();

console.log("The correct answer is:", selectedTrivia.correctAnswer);

console.log("Source:", selectedTrivia.source.name, "\n");
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { SOURCE } from "../types/mod";

export const generateTVSource = (name: string): SOURCE => ({
name,
mediaType: "Television",
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { readLines } from "https://deno.land/std@6.0/io/mod.ts";
import { printQuestion } from "./mod";

export const getNumericInput = (): Promise<number> => Promise.resolve(4);

export async function getUserInput(): Promise<string> {
printQuestion("What would you like to enter");

const reader = readLines(Deno.stdin);

return (await reader.next()).value;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function printQuestion(question: string): void {
console.log(question, "?????");
}
5 changes: 5 additions & 0 deletions bundler/tests/deno-exec/deno-9350/step2/input/helpers/mod.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export * from "./ask_trivia";
export * from "./generate_source";
export * from "./get_user_input";
export * from "./logger";
export * from "./pick_trivia";
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { TRIVIA } from "../types/mod";
import { ALL_TRIVIA } from "../trivia/mod";

export function getFirstTrivia(
providedTrivia: TRIVIA[] = ALL_TRIVIA,
): TRIVIA {
return providedTrivia[0];
}
5 changes: 5 additions & 0 deletions bundler/tests/deno-exec/deno-9350/step2/input/print_stats.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { ALL_TRIVIA } from "./trivia/mod";

export default () => {
console.log("Number of Trivia Questions:", ALL_TRIVIA.length);
};
11 changes: 11 additions & 0 deletions bundler/tests/deno-exec/deno-9350/step2/input/trivia/a_tv_show.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { generateTVSource } from "../helpers/mod";
import { TRIVIA } from "../types/mod";

const trivia: TRIVIA[] = [{
question: "Where did episode 1 take place",
correctAnswer: "On a boat",
wrongAnswers: ["On a plane", "On a mountain", "On a beach"],
source: generateTVSource("A TV Show Episode 1"),
}];

export default trivia;
4 changes: 4 additions & 0 deletions bundler/tests/deno-exec/deno-9350/step2/input/trivia/mod.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { TRIVIA } from "../types/mod.ts";
import aTVShow from "./a_tv_show.ts";

export const ALL_TRIVIA: TRIVIA[] = [...aTVShow];
11 changes: 11 additions & 0 deletions bundler/tests/deno-exec/deno-9350/step2/input/types/mod.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export interface SOURCE {
name: string;
mediaType: string;
}

export interface TRIVIA {
question: string;
correctAnswer: string;
wrongAnswers: [string, string, string];
source: SOURCE;
}

0 comments on commit 71486f5

Please sign in to comment.