-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
306 additions
and
109 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,9 @@ | |
mk: | ||
bun run dev | ||
|
||
c: | ||
bunx astro check | ||
|
||
f: | ||
bunx prettier --write . | ||
|
||
|
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,5 +1,6 @@ | ||
import { Language } from "@/lib/testing"; | ||
|
||
export const LANGUAGE_MONACO_LANGUAGES: Record<Language, string> = { | ||
export const MONACO_LANGUAGE_ID: Record<Language, string> = { | ||
[Language.PHP]: "php", | ||
[Language.TypeScript]: "typescript", | ||
}; |
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
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,39 +1,53 @@ | ||
<script lang="ts"> | ||
import { Language, RUNNER_LANGUAGES, Runner } from '@/lib/testing'; | ||
import { Language } from '@/lib/testing'; | ||
import Editor from '@/components/editor.svelte'; | ||
import EditorTestingPanel, { type TestCasesStates } from '@/components/editor-testing-panel.svelte'; | ||
import { testCases, CaseType, type Inputs, type Outputs, CASE_TYPES } from './test-cases' | ||
import { testRunnerFactories as phpTestRunnerFactories } from './php/test-runners' | ||
import code from './php/code.php?raw'; | ||
const defaultRunner = Runner.PhpWasm | ||
import { tsTestRunnerFactories, jsTestRunnerFactories } from './js/test-runners' | ||
const INITIAL_VALUES: Record<Language, string> = { | ||
[Language.PHP]: code, | ||
const INITIAL_VALUES: Record<Language, Promise<string>> = { | ||
[Language.PHP]: import('./php/code.php?raw').then(m => m.default), | ||
[Language.TypeScript]: import('./js/code.ts?raw').then(m => m.default), | ||
[Language.JavaScript]: import('./js/code.js?raw').then(m => m.default), | ||
} | ||
const CASES_FACTORIES: Record<Runner, () => TestCasesStates<CaseType, Inputs, Outputs>> = { | ||
[Runner.PhpWasm]: () => CASE_TYPES.map(id => ({ | ||
const CASES_FACTORIES: Record<Language, () => TestCasesStates<CaseType, Inputs, Outputs>> = { | ||
[Language.PHP]: () => CASE_TYPES.map(id => ({ | ||
id, | ||
isRunning: false, | ||
lastTestId: -1, | ||
testCase: testCases[id], | ||
testRunner: phpTestRunnerFactories[id], | ||
})) as TestCasesStates<CaseType, Inputs, Outputs>, | ||
[Language.TypeScript]: () => CASE_TYPES.map(id => ({ | ||
id, | ||
isRunning: false, | ||
lastTestId: -1, | ||
testCase: testCases[id], | ||
testRunner: tsTestRunnerFactories[id], | ||
})) as TestCasesStates<CaseType, Inputs, Outputs>, | ||
[Language.JavaScript]: () => CASE_TYPES.map(id => ({ | ||
id, | ||
isRunning: false, | ||
lastTestId: -1, | ||
testCase: testCases[id], | ||
testRunner: jsTestRunnerFactories[id], | ||
})) as TestCasesStates<CaseType, Inputs, Outputs>, | ||
} | ||
const defaultLanguage = Language.PHP; | ||
</script> | ||
|
||
<Editor | ||
{defaultRunner} | ||
initialValue={INITIAL_VALUES[RUNNER_LANGUAGES[defaultRunner]]} | ||
runners={[Runner.PhpWasm]} | ||
onLanguageChange={(lang, model) => { | ||
model.setValue(INITIAL_VALUES[lang]) | ||
{defaultLanguage} | ||
languages={[Language.PHP, Language.TypeScript, Language.JavaScript]} | ||
onLanguageChange={async (lang, model) => { | ||
model.setValue(await INITIAL_VALUES[lang]) | ||
}} | ||
> | ||
{#snippet children(runner, model)} | ||
<EditorTestingPanel {model} cases={CASES_FACTORIES[runner]()} /> | ||
{#snippet children(lang, model)} | ||
<EditorTestingPanel {model} cases={CASES_FACTORIES[lang]()} /> | ||
{/snippet} | ||
</Editor> |
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,25 @@ | ||
const PaymentSystemType = { | ||
PayPal: "paypal", | ||
WebMoney: "webmoney", | ||
CatBank: "cat-bank", | ||
}; | ||
|
||
export function case1(type, base, amount) { | ||
throw new Error("Not implemented"); | ||
} | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
const PaymentSystemActionType = { | ||
Payment: "payment", | ||
Payout: "payout", | ||
}; | ||
|
||
export function case2(type, base, action, amount) { | ||
throw new Error("Not implemented"); | ||
} |
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,36 @@ | ||
const enum PaymentSystemType { | ||
PayPal = "paypal", | ||
WebMoney = "webmoney", | ||
CatBank = "cat-bank", | ||
} | ||
|
||
export function case1( | ||
type: PaymentSystemType, | ||
base: number, | ||
amount: number | ||
): number { | ||
throw new Error("Not implemented"); | ||
} | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
const enum PaymentSystemActionType { | ||
Payment = "payment", | ||
Payout = "payout", | ||
} | ||
|
||
export function case2( | ||
type: PaymentSystemType, | ||
base: number, | ||
action: PaymentSystemActionType, | ||
amount: number | ||
): number { | ||
throw new Error("Not implemented"); | ||
} |
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 @@ | ||
import type { PaymentSystemActionType, PaymentSystemType } from "../reference"; | ||
|
||
export interface TestingModule { | ||
case1(type: PaymentSystemType, base: number, amount: number): number; | ||
case2( | ||
type: PaymentSystemType, | ||
base: number, | ||
action: PaymentSystemActionType, | ||
amount: number | ||
): number; | ||
} |
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,71 @@ | ||
import type { TestRunnerFactory } from "@/lib/testing"; | ||
import { TsTestRunner, JsTestRunner } from "@/lib/testing/js"; | ||
|
||
import { | ||
CaseType, | ||
type ComplexTestInput, | ||
type Inputs, | ||
type Outputs, | ||
type SimpleTestInput, | ||
} from "../test-cases"; | ||
import type { TestingModule } from "./model"; | ||
|
||
class SimpleJsTestRunner extends JsTestRunner< | ||
TestingModule, | ||
SimpleTestInput, | ||
number | ||
> { | ||
async executeTest(m: TestingModule, input: SimpleTestInput): Promise<number> { | ||
return m.case1(input.paymentSystem, input.base, input.amount); | ||
} | ||
} | ||
|
||
class ComplexJsTestRunner extends JsTestRunner< | ||
TestingModule, | ||
ComplexTestInput, | ||
number | ||
> { | ||
async executeTest( | ||
m: TestingModule, | ||
input: ComplexTestInput | ||
): Promise<number> { | ||
return m.case2(input.paymentSystem, input.base, input.action, input.amount); | ||
} | ||
} | ||
|
||
export const jsTestRunnerFactories: { | ||
[k in CaseType]: TestRunnerFactory<Inputs[k], Outputs[k]>; | ||
} = { | ||
[CaseType.Simple]: async (code) => new SimpleJsTestRunner(code), | ||
[CaseType.Complex]: async (code) => new ComplexJsTestRunner(code), | ||
}; | ||
|
||
class SimpleTsTestRunner extends TsTestRunner< | ||
TestingModule, | ||
SimpleTestInput, | ||
number | ||
> { | ||
async executeTest(m: TestingModule, input: SimpleTestInput): Promise<number> { | ||
return m.case1(input.paymentSystem, input.base, input.amount); | ||
} | ||
} | ||
|
||
class ComplexTsTestRunner extends TsTestRunner< | ||
TestingModule, | ||
ComplexTestInput, | ||
number | ||
> { | ||
async executeTest( | ||
m: TestingModule, | ||
input: ComplexTestInput | ||
): Promise<number> { | ||
return m.case2(input.paymentSystem, input.base, input.action, input.amount); | ||
} | ||
} | ||
|
||
export const tsTestRunnerFactories: { | ||
[k in CaseType]: TestRunnerFactory<Inputs[k], Outputs[k]>; | ||
} = { | ||
[CaseType.Simple]: async (code) => new SimpleTsTestRunner(code), | ||
[CaseType.Complex]: async (code) => new ComplexTsTestRunner(code), | ||
}; |
25 changes: 0 additions & 25 deletions
25
src/content/design-patterns/factory/php/complex-test-runner.ts
This file was deleted.
Oops, something went wrong.
21 changes: 0 additions & 21 deletions
21
src/content/design-patterns/factory/php/simple-test-runner.ts
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.