Skip to content

Commit

Permalink
updated language quircks
Browse files Browse the repository at this point in the history
  • Loading branch information
BrentBlanckaert committed Nov 15, 2024
1 parent 3602bb8 commit e28fdd1
Show file tree
Hide file tree
Showing 16 changed files with 81 additions and 16 deletions.
13 changes: 13 additions & 0 deletions tests/exercises/echo-function-file-input/solution/correct-async.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import * as fs from "fs";

function echoFile(content: any) {
return new Promise((resolve: (value: unknown) => void, reject: (reason?: any) => void) => {
fs.readFile(content, {encoding:'utf8', flag:'r'}, (err: any, data: unknown) => {
if (err) {
reject(err);
} else {
resolve(data);
}
});
}).then((c: string) => c.trim());
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
- tab: "My tab"
contexts:
- testcases:
- expression: 'echo("input-1")'
return: !object {}
3 changes: 3 additions & 0 deletions tests/exercises/echo-function/solution/correct-async.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
async function echo(content: any) {
return content;
}
3 changes: 3 additions & 0 deletions tests/exercises/echo-function/solution/typescript-object.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
function echo(_ignored: any) {
return Object.create(null);
}
4 changes: 4 additions & 0 deletions tests/exercises/js-ts-exceptions/solution/correct-temp.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
throw {
name: "AssertionError",
message: "Valid exceptions"
}
2 changes: 2 additions & 0 deletions tests/exercises/js-ts-exceptions/solution/correct.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

throw new Error("Valid exceptions");
4 changes: 4 additions & 0 deletions tests/exercises/js-ts-exceptions/solution/wrong-message.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
throw {
"name": "AssertionError",
"boodschap": "Valid exceptions"
};
1 change: 1 addition & 0 deletions tests/exercises/js-ts-exceptions/solution/wrong-null.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
throw null;
1 change: 1 addition & 0 deletions tests/exercises/js-ts-exceptions/solution/wrong.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
throw "Valid exceptions";
61 changes: 45 additions & 16 deletions tests/test_language_quircks.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,18 @@ def test_javascript_vanilla_object(tmp_path: Path, pytestconfig: pytest.Config):
updates = assert_valid_output(result, pytestconfig)
assert updates.find_status_enum() == ["correct"]

def test_typescript_vanilla_object(tmp_path: Path, pytestconfig: pytest.Config):
conf = configuration(
pytestconfig,
"echo-function",
"typescript",
tmp_path,
"typescript-object.yaml",
"typescript-object",
)
result = execute_config(conf)
updates = assert_valid_output(result, pytestconfig)
assert updates.find_status_enum() == ["correct"]

def test_python_input_prompt_is_ignored(tmp_path: Path, pytestconfig: pytest.Config):
conf = configuration(
Expand Down Expand Up @@ -76,11 +88,12 @@ def test_haskell_function_arguments_without_brackets(
)


def test_javascript_exception_correct(tmp_path: Path, pytestconfig: pytest.Config):
@pytest.mark.parametrize("lang", ["javascript", "typescript"])
def test_js_ts_exception_correct(lang:str, tmp_path: Path, pytestconfig: pytest.Config):
conf = configuration(
pytestconfig,
"js-exceptions",
"javascript",
"js-ts-exceptions",
lang,
tmp_path,
"plan.yaml",
"correct",
Expand All @@ -91,11 +104,12 @@ def test_javascript_exception_correct(tmp_path: Path, pytestconfig: pytest.Confi
assert len(updates.find_all("append-message")) == 0


def test_javascript_exception_correct_temp(tmp_path: Path, pytestconfig: pytest.Config):
@pytest.mark.parametrize("lang", ["javascript", "typescript"])
def test_js_ts_exception_correct_temp(lang:str, tmp_path: Path, pytestconfig: pytest.Config):
conf = configuration(
pytestconfig,
"js-exceptions",
"javascript",
"js-ts-exceptions",
lang,
tmp_path,
"plan.yaml",
"correct-temp",
Expand All @@ -106,11 +120,12 @@ def test_javascript_exception_correct_temp(tmp_path: Path, pytestconfig: pytest.
assert len(updates.find_all("append-message")) == 0


def test_javascript_exception_wrong(tmp_path: Path, pytestconfig: pytest.Config):
@pytest.mark.parametrize("lang", ["javascript", "typescript"])
def test_js_ts_exception_wrong(lang:str, tmp_path: Path, pytestconfig: pytest.Config):
conf = configuration(
pytestconfig,
"js-exceptions",
"javascript",
"js-ts-exceptions",
lang,
tmp_path,
"plan.yaml",
"wrong",
Expand All @@ -121,11 +136,12 @@ def test_javascript_exception_wrong(tmp_path: Path, pytestconfig: pytest.Config)
assert len(updates.find_all("append-message")) == 1


def test_javascript_exception_wrong_null(tmp_path: Path, pytestconfig: pytest.Config):
@pytest.mark.parametrize("lang", ["javascript", "typescript"])
def test_js_ts_exception_wrong_null(lang:str, tmp_path: Path, pytestconfig: pytest.Config):
conf = configuration(
pytestconfig,
"js-exceptions",
"javascript",
"js-ts-exceptions",
lang,
tmp_path,
"plan.yaml",
"wrong-null",
Expand All @@ -136,13 +152,14 @@ def test_javascript_exception_wrong_null(tmp_path: Path, pytestconfig: pytest.Co
assert len(updates.find_all("append-message")) == 0


def test_javascript_exception_missing_message(
tmp_path: Path, pytestconfig: pytest.Config
@pytest.mark.parametrize("lang", ["javascript", "typescript"])
def test_js_ts_exception_missing_message(
lang:str, tmp_path: Path, pytestconfig: pytest.Config
):
conf = configuration(
pytestconfig,
"js-exceptions",
"javascript",
"js-ts-exceptions",
lang,
tmp_path,
"plan.yaml",
"wrong-message",
Expand All @@ -163,3 +180,15 @@ def test_javascript_async(exercise: str, tmp_path: Path, pytestconfig: pytest.Co
result = execute_config(conf)
updates = assert_valid_output(result, pytestconfig)
assert updates.find_status_enum() == ["correct"]

@pytest.mark.parametrize("exercise", ["echo-function-file-input", "echo-function"])
def test_typescript_async(exercise: str, tmp_path: Path, pytestconfig: pytest.Config):
conf = configuration(
pytestconfig, exercise, "typescript", tmp_path, "one.tson", "correct-async"
)
workdir = Path(conf.resources).parent / "workdir"
if workdir.exists():
shutil.copytree(workdir, tmp_path, dirs_exist_ok=True)
result = execute_config(conf)
updates = assert_valid_output(result, pytestconfig)
assert updates.find_status_enum() == ["correct"]

0 comments on commit e28fdd1

Please sign in to comment.