Skip to content

Commit

Permalink
refactor tera templates to use snake_case filter
Browse files Browse the repository at this point in the history
  • Loading branch information
senekor committed Apr 1, 2024
1 parent 4bbce68 commit 075e4c8
Show file tree
Hide file tree
Showing 43 changed files with 47 additions and 47 deletions.
2 changes: 1 addition & 1 deletion exercises/practice/acronym/.meta/test_template.tera
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use acronym::*;
{% for test in cases %}
#[test]
#[ignore]
fn {{ test.description | slugify | replace(from="-", to="_") }}() {
fn {{ test.description | snake_case }}() {
let input = {{ test.input.phrase | json_encode() }};
let output = abbreviate(input);
let expected = {{ test.expected | json_encode() }};
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/affine-cipher/.meta/test_template.tera
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use affine_cipher::AffineCipherError::NotCoprime;
{% for test in cases %}
#[test]
#[ignore]
fn {{ test.description | slugify | replace(from="-", to="_") }}() {
fn {{ test.description | snake_case }}() {
let phrase = {{ test.input.phrase | json_encode() }};
let (a, b) = ({{ test.input.key.a }}, {{ test.input.key.b }});
let output = {{ test.property }}(phrase, a, b);
Expand Down
4 changes: 2 additions & 2 deletions exercises/practice/allergies/.meta/test_template.tera
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ fn compare_allergy_vectors(expected: &[Allergen], actual: &[Allergen]) {
#[ignore]
{%- if test.property == "allergicTo" %}
{# canonical data contains multiple cases named "allergic to everything" for different items #}
fn {{ test.description | slugify | replace(from="-", to="_") }}_{{ test.input.item }}() {
fn {{ test.description | snake_case }}_{{ test.input.item }}() {
let allergies = Allergies::new({{ test.input.score }});
{%- if test.expected %}
assert!(allergies.is_allergic_to(&Allergen::{{ test.input.item | title }}))
{% else %}
assert!(!allergies.is_allergic_to(&Allergen::{{ test.input.item | title }}))
{% endif -%}
{% else %}
fn {{ test.description | slugify | replace(from="-", to="_") }}() {
fn {{ test.description | snake_case }}() {
let allergies = Allergies::new({{ test.input.score }}).allergies();
let expected = &[
{% for allergen in test.expected %}
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/anagram/.meta/test_template.tera
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::collections::HashSet;
{% for test in cases %}
#[test]
#[ignore]
fn {{ test.description | slugify | replace(from="-", to="_") }}() {
fn {{ test.description | snake_case }}() {
let word = {{ test.input.subject | json_encode() }};
let inputs = &{{ test.input.candidates | json_encode() }};
let output = anagrams_for(word, inputs);
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/book-store/.meta/test_template.tera
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use book_store::*;
{% for test in cases %}
#[test]
#[ignore]
fn {{ test.description | slugify | replace(from="-", to="_") }}() {
fn {{ test.description | snake_case }}() {
let input = &{{ test.input.basket | json_encode() }};
let output = lowest_price(input);
let expected = {{ test.expected | json_encode() }};
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/custom-set/.meta/test_template.tera
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use custom_set::CustomSet;
{% for test in cases %}
#[test]
#[ignore]
fn {{ test.description | slugify | replace(from="-", to="_") }}() {
fn {{ test.description | snake_case }}() {
{%- if test.property == "empty" %}
let set = CustomSet::<i32>::new(&{{ test.input.set | json_encode() }});
assert!(
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/eliuds-eggs/.meta/test_template.tera
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use eliuds_eggs::*;
{% for test in cases %}
#[test]
#[ignore]
fn test_{{ test.description | slugify | replace(from="-", to="_") }}() {
fn test_{{ test.description | snake_case }}() {
let input = {{ test.input.number }};
let output = egg_count(input);
let expected = {{ test.expected | json_encode() }};
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/knapsack/.meta/test_template.tera
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use knapsack::*;
{% for test in cases %}
#[test]
#[ignore]
fn test_{{ test.description | slugify | replace(from="-", to="_") }}() {
fn test_{{ test.description | snake_case }}() {
let max_weight = {{ test.input.maximumWeight }};
let items = [
{% for item in test.input.items -%}
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/leap/.meta/test_template.tera
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use leap::*;
{% for test in cases %}
#[test]
#[ignore]
fn {{ test.description | slugify | replace(from="-", to="_") }}() {
fn {{ test.description | snake_case }}() {
{%- if test.expected %}
assert!(is_leap_year({{ test.input.year }}));
{% else %}
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/matrix/.meta/test_template.tera
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use matrix::*;
{% for test in cases %}
#[test]
#[ignore]
fn {{ test.description | slugify | replace(from="-", to="_") }}() {
fn {{ test.description | snake_case }}() {
let matrix = Matrix::new({{ test.input.string | json_encode() }});
{% if test.expected -%}
assert_eq!(matrix.{{ test.property }}({{ test.input.index }}), Some(vec!{{ test.expected | json_encode() }}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use pascals_triangle::PascalsTriangle;
{% for test in cases %}
#[test]
#[ignore]
fn {{ test.description | slugify | replace(from="-", to="_") }}() {
fn {{ test.description | snake_case }}() {
let pt = PascalsTriangle::new({{ test.input.count }});
let expected: Vec<Vec<u32>> = vec![{% for row in test.expected -%}
vec!{{ row | json_encode() }},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use perfect_numbers::*;
{% for test in cases %}
#[test]
#[ignore]
fn {{ test.description | slugify | replace(from="-", to="_") }}() {
fn {{ test.description | snake_case }}() {
let input = {{ test.input.number | json_encode() }};
let output = classify(input);
{%- if test.expected is object %}
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/phone-number/.meta/test_template.tera
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use phone_number::*;
{% for test in cases %}
#[test]
#[ignore]
fn {{ test.description | slugify | replace(from="-", to="_") }}() {
fn {{ test.description | snake_case }}() {
let input = {{ test.input.phrase | json_encode() }};
let output = number(input);
{%- if test.expected is object %}
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/pig-latin/.meta/test_template.tera
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use pig_latin::*;
{% for test in cases %}
#[test]
#[ignore]
fn {{ test.description | slugify | replace(from="-", to="_") }}() {
fn {{ test.description | snake_case }}() {
let input = {{ test.input.phrase | json_encode() }};
let output = translate(input);
let expected = {{ test.expected | json_encode() }};
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/poker/.meta/test_template.tera
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::collections::HashSet;
{% for test in cases %}
#[test]
#[ignore]
fn {{ test.description | slugify | replace(from="-", to="_") }}() {
fn {{ test.description | snake_case }}() {
let input = &{{ test.input.hands | json_encode() }};
let output = winning_hands(input).into_iter().collect::<HashSet<_>>();
let expected = {{ test.expected | json_encode() }}.into_iter().collect::<HashSet<_>>();
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/prime-factors/.meta/test_template.tera
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use prime_factors::*;
{% for test in cases %}
#[test]
#[ignore]
fn {{ test.description | slugify | replace(from="-", to="_") }}() {
fn {{ test.description | snake_case }}() {
let factors = factors({{ test.input.value }});
let expected = {{ test.expected | json_encode() }};
assert_eq!(factors, expected);
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/proverb/.meta/test_template.tera
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use proverb::*;
{% for test in cases %}
#[test]
#[ignore]
fn {{ test.description | slugify | replace(from="-", to="_") }}() {
fn {{ test.description | snake_case }}() {
let input = &{{ test.input.strings | json_encode() }};
let output = build_proverb(input);
{% if test.expected | length == 0 -%}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::collections::HashSet;
{% for test in cases %}
#[test]
#[ignore]
fn {{ test.description | slugify | replace(from="-", to="_") }}() {
fn {{ test.description | snake_case }}() {
let input = {{ test.input.n | json_encode() }};
let output = find(input);
let expected = {{ test.expected | json_encode() }};
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/queen-attack/.meta/test_template.tera
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use queen_attack::*;
{% for test in cases %}
#[test]
#[ignore]
fn {{ test.description | slugify | replace(from="-", to="_") }}() {
fn {{ test.description | snake_case }}() {
{% if test.property == "create" %}
let chess_position = ChessPosition::new({{ test.input.queen.position.row }}, {{ test.input.queen.position.column }});
{%- if test.expected is object %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use rail_fence_cipher::RailFence;
{% for test in cases %}
#[test]
#[ignore]
fn {{ test.description | slugify | replace(from="-", to="_") }}() {
fn {{ test.description | snake_case }}() {
let input = {{ test.input.msg | json_encode() }};
let rails = {{ test.input.rails | json_encode() }};
let rail_fence = RailFence::new(rails);
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/raindrops/.meta/test_template.tera
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use raindrops::*;
{% for test in cases %}
#[test]
#[ignore]
fn test_{{ test.description | slugify | replace(from="-", to="_") }}() {
fn test_{{ test.description | snake_case }}() {
let input = {{ test.input.number | json_encode() }};
let output = raindrops(input);
let expected = {{ test.expected | json_encode() }};
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/rectangles/.meta/test_template.tera
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use rectangles::*;
{% for test in cases %}
#[test]
#[ignore]
fn test_{{ test.description | slugify | replace(from="-", to="_") }}() {
fn test_{{ test.description | snake_case }}() {
{% if test.input.strings | length > 1 -%}
#[rustfmt::skip]
{%- endif %}
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/reverse-string/.meta/test_template.tera
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use reverse_string::*;
{% if test.description is starting_with("grapheme cluster") -%}
#[cfg(feature = "grapheme")]
{% endif -%}
fn {{ test.description | slugify | replace(from="-", to="_") }}() {
fn {{ test.description | snake_case }}() {
let input = {{ test.input.value | json_encode() }};
let output = reverse(input);
let expected = {{ test.expected | json_encode() }};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use rna_transcription::{Dna, Rna};
{% for test in cases %}
#[test]
#[ignore]
fn {{ test.description | slugify | replace(from="-", to="_") }}() {
fn {{ test.description | snake_case }}() {
let input = {{ test.input.dna | json_encode() }};
{% if test.property == "invalidDna" -%}
let output = Dna::new(input);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use robot_simulator::*;
{% for test in cases %}
#[test]
#[ignore]
fn {{ test.description | slugify | replace(from="-", to="_") }}() {
fn {{ test.description | snake_case }}() {
{%- if test.property == "create" %}
let robot = Robot::new({{ test.input.position.x }}, {{ test.input.position.y }}, Direction::{{ test.input.direction | title }});
assert_eq!(robot.position(), ({{ test.expected.position.x }}, {{ test.expected.position.y }}));
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/roman-numerals/.meta/test_template.tera
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use roman_numerals::Roman;
{% for test in cases %}
#[test]
#[ignore]
fn number_{{ test.description | slugify | replace(from="-", to="_") }}() {
fn number_{{ test.description | snake_case }}() {
let input = {{ test.input.number | json_encode() }};
let output = Roman::from(input).to_string();
let expected = {{ test.expected | json_encode() }};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use rotational_cipher as cipher;
{% for test in cases %}
#[test]
#[ignore]
fn {{ test.description | slugify | replace(from="-", to="_") }}() {
fn {{ test.description | snake_case }}() {
let text = {{ test.input.text | json_encode() }};
let shift_key = {{ test.input.shiftKey | json_encode() }};
let output = cipher::rotate(text, shift_key);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use run_length_encoding as rle;
{% for test in cases %}
#[test]
#[ignore]
fn {{ test.property }}_{{ test.description | slugify | replace(from="-", to="_") }}() {
fn {{ test.property }}_{{ test.description | snake_case }}() {
let input = {{ test.input.string | json_encode() }};
{% if test.property == "consistency" -%}
let output = rle::decode(&rle::encode(input));
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/saddle-points/.meta/test_template.tera
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ fn find_sorted_saddle_points(input: &[Vec<u64>]) -> Vec<(usize, usize)> {
{% for test in cases %}
#[test]
#[ignore]
fn {{ test.description | slugify | replace(from="-", to="_") }}() {
fn {{ test.description | snake_case }}() {
let input = &[{% for row in test.input.matrix %}
vec!{{ row }},
{% endfor %}];
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/say/.meta/test_template.tera
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use say::*;
{% for test in cases %}
#[test]
#[ignore]
fn {{ test.description | slugify | replace(from="-", to="_") }}() {
fn {{ test.description | snake_case }}() {
let input = {{ test.input.number | json_encode() }};
let output = encode(input);
let expected = {{ test.expected | json_encode() }};
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/scrabble-score/.meta/test_template.tera
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use scrabble_score::*;
{% for test in cases %}
#[test]
#[ignore]
fn {{ test.description | slugify | replace(from="-", to="_") }}() {
fn {{ test.description | snake_case }}() {
let input = {{ test.input.word | json_encode() }};
let output = score(input);
let expected = {{ test.expected | json_encode() }};
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/series/.meta/test_template.tera
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use series::*;
{% for test in cases %}
#[test]
#[ignore]
fn {{ test.description | slugify | replace(from="-", to="_") }}() {
fn {{ test.description | snake_case }}() {
let input = {{ test.input.series | json_encode() }};
let length = {{ test.input.sliceLength | json_encode() }};
let output = series(input, length);
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/sieve/.meta/test_template.tera
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use sieve::*;
{% for test in cases %}
#[test]
#[ignore]
fn {{ test.description | slugify | replace(from="-", to="_") }}() {
fn {{ test.description | snake_case }}() {
let input = {{ test.input.limit | json_encode() }};
let output = primes_up_to(input);
let expected = {{ test.expected | json_encode() }};
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/space-age/.meta/test_template.tera
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ fn assert_in_delta(expected: f64, actual: f64) {
{% for test in cases %}
#[test]
#[ignore]
fn {{ test.description | slugify | replace(from="-", to="_") }}() {
fn {{ test.description | snake_case }}() {
let seconds = {{ test.input.seconds | json_encode() }};
let duration = Duration::from(seconds);
let output = {{ test.input.planet }}::years_during(&duration);
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/spiral-matrix/.meta/test_template.tera
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use spiral_matrix::*;
{% for test in cases %}
#[test]
#[ignore]
fn {{ test.description | slugify | replace(from="-", to="_") }}() {
fn {{ test.description | snake_case }}() {
let input = {{ test.input.size | json_encode() }};
let output = spiral_matrix(input);
let expected: [[u32; {{ test.input.size }}]; {{ test.input.size }}] = [
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/sublist/.meta/test_template.tera
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use sublist::*;
{% for test in cases %}
#[test]
#[ignore]
fn {{ test.description | slugify | replace(from="-", to="_") }}() {
fn {{ test.description | snake_case }}() {
let list_one: &[i32] = &{{ test.input.listOne | json_encode() }};
let list_two: &[i32] = &{{ test.input.listTwo | json_encode() }};
let output = sublist(list_one, list_two);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use sum_of_multiples::*;
{% for test in cases %}
#[test]
#[ignore]
fn {{ test.description | slugify | replace(from="-", to="_") }}() {
fn {{ test.description | snake_case }}() {
let factors = &{{ test.input.factors | json_encode() }};
let limit = {{ test.input.limit | json_encode() }};
let output = sum_of_multiples(limit, factors);
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/tournament/.meta/test_template.tera
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use tournament::*;
{% for test in cases %}
#[test]
#[ignore]
fn {{ test.description | slugify | replace(from="-", to="_") }}() {
fn {{ test.description | snake_case }}() {
let input: &[&str] = &{{ test.input.rows | json_encode() }};
let input = input.join("\n");
let output = tally(&input);
Expand Down
8 changes: 4 additions & 4 deletions exercises/practice/triangle/.meta/test_template.tera
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use triangle::Triangle;
{% if test.description is containing("float") %}
#[cfg(feature = "generic")]
{% endif -%}
fn {{ test.description | slugify | replace(from="-", to="_") }}() {
fn {{ test.description | snake_case }}() {
let input = {{ test.input.sides | json_encode() }};
let output = Triangle::build(input).unwrap();
{%- if test.expected %}
Expand All @@ -30,7 +30,7 @@ use triangle::Triangle;
{% if test.scenarios and test.scenarios is containing("floating-point") %}
#[cfg(feature = "generic")]
{% endif -%}
fn {{ test.description | slugify | replace(from="-", to="_") }}() {
fn {{ test.description | snake_case }}() {
let input = {{ test.input.sides | json_encode() }};
let output = Triangle::build(input).unwrap();
{%- if test.expected %}
Expand All @@ -52,7 +52,7 @@ use triangle::Triangle;
{% if test.scenarios and test.scenarios is containing("floating-point") %}
#[cfg(feature = "generic")]
{% endif -%}
fn {{ test.description | slugify | replace(from="-", to="_") }}() {
fn {{ test.description | snake_case }}() {
let input = {{ test.input.sides | json_encode() }};
let output = Triangle::build(input).unwrap();
{%- if test.expected %}
Expand All @@ -74,7 +74,7 @@ use triangle::Triangle;
{% if test.scenarios and test.scenarios is containing("floating-point") %}
#[cfg(feature = "generic")]
{% endif -%}
fn {{ test.description | slugify | replace(from="-", to="_") }}() {
fn {{ test.description | snake_case }}() {
let input = {{ test.input.sides | json_encode() }};
let output = Triangle::build(input);
assert!(output.is_none());
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/two-bucket/.meta/test_template.tera
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use two_bucket::*;
{% for test in cases %}
#[test]
#[ignore]
fn {{ test.description | slugify | replace(from="-", to="_") }}() {
fn {{ test.description | snake_case }}() {
let output = solve(
{{ test.input.bucketOne }}, {{ test.input.bucketTwo }}, {{ test.input.goal }},
&{{ self::bucket(label=test.input.startBucket) }},
Expand Down
Loading

0 comments on commit 075e4c8

Please sign in to comment.