Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions exercises/practice/collatz-conjecture/.meta/generator.jai
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
to_test_case :: (canonical_case: CanonicalCase) -> Test {
_, number := get_number_property(canonical_case.input, "number");
_, number := get_property(canonical_case.input, "number");

lines: [..] string;
if canonical_case.error {
array_add(*lines, tprint("ok, _ := steps(%);", number));
array_add(*lines, tprint("ok, _ := steps(%);", to_code(number)));
array_add(*lines, tprint("assert_equal(false, ok);"));
} else {
array_add(*lines, tprint("ok, number_of_steps := steps(%);", number));
array_add(*lines, tprint("ok, number_of_steps := steps(%);", to_code(number)));
array_add(*lines, tprint("assert_equal(true, ok);"));
array_add(*lines, tprint("assert_equal(%, number_of_steps);", canonical_case.expected.number));
array_add(*lines, tprint("assert_equal(%, number_of_steps);", to_code(canonical_case.expected)));
}

return Test.{
Expand Down
5 changes: 2 additions & 3 deletions exercises/practice/difference-of-squares/.meta/generator.jai
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
to_test_case :: (canonical_case: CanonicalCase) -> Test {
expected := canonical_case.expected.number;
_, number := get_number_property(canonical_case.input, "number");
_, number := get_property(canonical_case.input, "number");

return Test.{
name = to_test_name(canonical_case.description),
body = tprint("assert_equal(%, %(%));", expected, to_snake_case(canonical_case.property), number),
body = tprint("assert_equal(%, %(%));", to_code(canonical_case.expected), to_snake_case(canonical_case.property), to_code(number)),
skip = canonical_case.index > 0
};
}
Expand Down
5 changes: 2 additions & 3 deletions exercises/practice/eliuds-eggs/.meta/generator.jai
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
to_test_case :: (canonical_case: CanonicalCase) -> Test {
expected := canonical_case.expected.number;
_, number := get_number_property(canonical_case.input, "number");
_, number := get_property(canonical_case.input, "number");

return Test.{
name = tprint("count_%", to_test_name(canonical_case.description_path)),
body = tprint("assert_equal(%, egg_count(%));", expected, number),
body = tprint("assert_equal(%, egg_count(%));", to_code(canonical_case.expected), to_code(number)),
skip = canonical_case.index > 0
};
}
Expand Down
10 changes: 5 additions & 5 deletions exercises/practice/hamming/.meta/generator.jai
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
to_test_case :: (canonical_case: CanonicalCase) -> Test {
_, strand1 := get_string_property(canonical_case.input, "strand1");
_, strand2 := get_string_property(canonical_case.input, "strand2");
_, strand1 := get_property(canonical_case.input, "strand1");
_, strand2 := get_property(canonical_case.input, "strand2");

lines: [..] string;
if canonical_case.error {
array_add(*lines, tprint("ok, _ := hamming_distance(%, %);", escape_string(strand1), escape_string(strand2)));
array_add(*lines, tprint("ok, _ := hamming_distance(%, %);", to_code(strand1), to_code(strand2)));
array_add(*lines, tprint("assert_equal(false, ok);"));
} else {
array_add(*lines, tprint("ok, distance := hamming_distance(%, %);", escape_string(strand1), escape_string(strand2)));
array_add(*lines, tprint("ok, distance := hamming_distance(%, %);", to_code(strand1), to_code(strand2)));
array_add(*lines, tprint("assert_equal(true, ok);"));
array_add(*lines, tprint("assert_equal(%, distance);", canonical_case.expected.number));
array_add(*lines, tprint("assert_equal(%, distance);", to_code(canonical_case.expected)));
}

return Test.{
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/hello-world/.meta/generator.jai
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
to_test_case :: (canonical_case: CanonicalCase) -> Test {
return Test.{
name = to_test_name(canonical_case.description_path),
body = "assert_equal(\"Hello, World!\", hello());",
body = tprint("assert_equal(%, hello());", to_code(canonical_case.expected)),
skip = canonical_case.index > 0
};
}
Expand Down
5 changes: 2 additions & 3 deletions exercises/practice/leap/.meta/generator.jai
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
to_test_case :: (canonical_case: CanonicalCase) -> Test {
expected := canonical_case.expected.boolean;
_, year := get_number_property(canonical_case.input, "year");
_, year := get_property(canonical_case.input, "year");

return Test.{
name = to_test_name(canonical_case.description_path),
body = tprint("assert_equal(%, is_leap_year(%));", expected, year),
body = tprint("assert_equal(%, is_leap_year(%));", to_code(canonical_case.expected), to_code(year)),
skip = canonical_case.index > 0
};
}
Expand Down
4 changes: 2 additions & 2 deletions exercises/practice/reverse-string/.meta/generator.jai
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
to_test_case :: (canonical_case: CanonicalCase) -> Test {
expected := canonical_case.expected.str;
_, value := get_string_property(canonical_case.input, "value");
_, value := get_property(canonical_case.input, "value");

return Test.{
name = to_test_name(canonical_case.description_path),
body = tprint("assert_equal(%, reverse_string(%));", escape_string(expected), escape_string(value)),
body = tprint("assert_equal(%, reverse_string(%));", to_code(canonical_case.expected), to_code(value)),
skip = canonical_case.index > 0
};
}
Expand Down
4 changes: 2 additions & 2 deletions exercises/practice/roman-numerals/.meta/generator.jai
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
to_test_case :: (canonical_case: CanonicalCase) -> Test {
expected := canonical_case.expected.str;
_, number := get_number_property(canonical_case.input, "number");
_, number := get_property(canonical_case.input, "number");

return Test.{
name = tprint("number_%", to_test_name(to_lower_copy(canonical_case.description))),
body = tprint("assert_equal(%, to_roman(%));", escape_string(expected), number),
body = tprint("assert_equal(%, to_roman(%));", to_code(canonical_case.expected), to_code(number)),
skip = canonical_case.index > 0
};
}
Expand Down
4 changes: 2 additions & 2 deletions exercises/practice/sum-of-multiples/.meta/generator.jai
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
to_test_case :: (canonical_case: CanonicalCase) -> Test {
_, factors := get_property(canonical_case.input, "factors");
_, limit := get_number_property(canonical_case.input, "limit");
_, limit := get_property(canonical_case.input, "limit");

return Test.{
name = to_test_name(canonical_case.description_path),
body = tprint("assert_equal(%, sum(%, %));", output(canonical_case.expected), output(factors), limit),
body = tprint("assert_equal(%, sum(%, %));", to_code(canonical_case.expected), to_code(factors), to_code(limit)),
skip = canonical_case.index > 0
};
}
Expand Down
8 changes: 4 additions & 4 deletions exercises/practice/two-fer/.meta/generator.jai
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
to_test_case :: (canonical_case: CanonicalCase) -> Test {
expected := escape_string(canonical_case.expected.str);
_, name := get_string_property(canonical_case.input, "name");
name = ifx name.count escape_string(name) else "";
_, name := get_property(canonical_case.input, "name");

return Test.{
name = to_test_name(canonical_case.description_path),
body = tprint("assert_equal(%, two_fer(%));", expected, name),
body = ifx name.str.count
then tprint("assert_equal(%, two_fer(%));", to_code(canonical_case.expected), to_code(name))
else tprint("assert_equal(%, two_fer());", to_code(canonical_case.expected)),
skip = canonical_case.index > 0
};
}
Expand Down
6 changes: 3 additions & 3 deletions exercises/shared/generator/formatting.jai
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ to_snake_case :: (str: string) -> string {
return builder_to_string(*builder);
}

output :: (value: JSON_Value) -> string {
to_code :: (value: JSON_Value) -> string {
builder: String_Builder;
init_string_builder(*builder);

Expand All @@ -40,7 +40,7 @@ output :: (value: JSON_Value) -> string {
append(*builder, ".[");
for value.array {
if it_index > 0 append(*builder, ", ");
append(*builder, output(it));
append(*builder, to_code(it));
}
append(*builder, "]");
case .OBJECT;
Expand All @@ -51,7 +51,7 @@ output :: (value: JSON_Value) -> string {
first = false;
append(*builder, escape_string(key));
append(*builder, ": ");
append(*builder, output(val));
append(*builder, to_code(val));
}
append(*builder, "}");
}
Expand Down
Loading