From f0cfd47c3d2b1ef7751b16f8e6382bc5ca49ee65 Mon Sep 17 00:00:00 2001 From: Remo Senekowitsch Date: Thu, 15 Aug 2024 12:37:59 +0200 Subject: [PATCH] generator: replace snake_case with make_ident (#1969) [no important files changed] --- docs/CONTRIBUTING.md | 4 +- .../practice/acronym/.meta/test_template.tera | 2 +- .../affine-cipher/.meta/test_template.tera | 2 +- .../all-your-base/.meta/test_template.tera | 2 +- .../allergies/.meta/test_template.tera | 4 +- .../alphametics/.meta/test_template.tera | 2 +- .../practice/anagram/.meta/test_template.tera | 2 +- .../.meta/test_template.tera | 2 +- .../beer-song/.meta/test_template.tera | 4 +- .../binary-search/.meta/test_template.tera | 2 +- .../practice/bob/.meta/test_template.tera | 2 +- .../book-store/.meta/test_template.tera | 2 +- .../circular-buffer/.meta/test_template.tera | 2 +- .../.meta/test_template.tera | 2 +- .../custom-set/.meta/test_template.tera | 2 +- .../eliuds-eggs/.meta/test_template.tera | 2 +- .../practice/forth/.meta/test_template.tera | 4 +- .../practice/grep/.meta/test_template.tera | 2 +- .../isbn-verifier/.meta/test_template.tera | 2 +- .../practice/isogram/.meta/test_template.tera | 2 +- .../knapsack/.meta/test_template.tera | 2 +- exercises/practice/knapsack/tests/knapsack.rs | 10 ++-- .../practice/leap/.meta/test_template.tera | 2 +- .../practice/matrix/.meta/test_template.tera | 2 +- .../nth-prime/.meta/test_template.tera | 2 +- .../.meta/test_template.tera | 2 +- .../practice/pangram/.meta/test_template.tera | 2 +- .../pascals-triangle/.meta/test_template.tera | 2 +- .../perfect-numbers/.meta/test_template.tera | 2 +- .../phone-number/.meta/test_template.tera | 2 +- .../pig-latin/.meta/test_template.tera | 2 +- .../practice/poker/.meta/test_template.tera | 2 +- .../prime-factors/.meta/test_template.tera | 2 +- .../.meta/test_template.tera | 2 +- .../practice/proverb/.meta/test_template.tera | 2 +- .../.meta/test_template.tera | 2 +- .../queen-attack/.meta/test_template.tera | 2 +- .../.meta/test_template.tera | 2 +- .../raindrops/.meta/test_template.tera | 2 +- .../practice/raindrops/tests/raindrops.rs | 34 ++++++------ .../rectangles/.meta/test_template.tera | 2 +- .../practice/rectangles/tests/rectangles.rs | 26 ++++----- .../reverse-string/.meta/test_template.tera | 2 +- .../.meta/test_template.tera | 2 +- .../robot-simulator/.meta/test_template.tera | 2 +- .../roman-numerals/.meta/test_template.tera | 2 +- .../roman-numerals/tests/roman-numerals.rs | 54 +++++++++---------- .../.meta/test_template.tera | 2 +- .../.meta/test_template.tera | 2 +- .../saddle-points/.meta/test_template.tera | 2 +- .../practice/say/.meta/test_template.tera | 2 +- .../scrabble-score/.meta/test_template.tera | 2 +- .../practice/series/.meta/test_template.tera | 2 +- .../practice/sieve/.meta/test_template.tera | 2 +- .../space-age/.meta/test_template.tera | 2 +- .../spiral-matrix/.meta/test_template.tera | 2 +- .../practice/sublist/.meta/test_template.tera | 2 +- .../sum-of-multiples/.meta/test_template.tera | 2 +- .../tournament/.meta/test_template.tera | 2 +- .../triangle/.meta/test_template.tera | 8 +-- .../two-bucket/.meta/test_template.tera | 2 +- .../.meta/test_template.tera | 2 +- .../word-count/.meta/test_template.tera | 2 +- .../practice/wordy/.meta/test_template.tera | 2 +- .../practice/xorcism/.meta/test_template.tera | 2 +- rust-tooling/generate/src/custom_filters.rs | 24 ++------- .../templates/default_test_template.tera | 2 +- 67 files changed, 136 insertions(+), 150 deletions(-) diff --git a/docs/CONTRIBUTING.md b/docs/CONTRIBUTING.md index fd5c9e3a6..51ca7dded 100644 --- a/docs/CONTRIBUTING.md +++ b/docs/CONTRIBUTING.md @@ -146,8 +146,8 @@ In that case, you can use the group description to organize the tests in modules There are some custom tera filters in [`rust-tooling`](/rust-tooling/generate/src/custom_filters.rs). Here's the hopefully up-to-date list: - `to_hex` formats ints in hexadecimal -- `snake_case` massages an arbitrary string into a decent Rust identifier -- `make_test_ident` is like snake case, but prepends `test_` if the string starts with a digit +- `make_ident` turns an arbitrary string into a decent Rust identifier. + Most useful for generating function names from test descriptions. - `fmt_num` format number literals (insert `_` every third digit) Feel free to add your own in the crate `rust-tooling`. diff --git a/exercises/practice/acronym/.meta/test_template.tera b/exercises/practice/acronym/.meta/test_template.tera index 5f8bee34d..e20a88d95 100644 --- a/exercises/practice/acronym/.meta/test_template.tera +++ b/exercises/practice/acronym/.meta/test_template.tera @@ -3,7 +3,7 @@ use acronym::*; {% for test in cases %} #[test] #[ignore] -fn {{ test.description | snake_case }}() { +fn {{ test.description | make_ident }}() { let input = {{ test.input.phrase | json_encode() }}; let output = abbreviate(input); let expected = {{ test.expected | json_encode() }}; diff --git a/exercises/practice/affine-cipher/.meta/test_template.tera b/exercises/practice/affine-cipher/.meta/test_template.tera index 8f26ae364..bcb4aa736 100644 --- a/exercises/practice/affine-cipher/.meta/test_template.tera +++ b/exercises/practice/affine-cipher/.meta/test_template.tera @@ -6,7 +6,7 @@ use affine_cipher::AffineCipherError::NotCoprime; {% for test in test_group.cases %} #[test] #[ignore] -fn {{ test.description | snake_case }}() { +fn {{ test.description | make_ident }}() { 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); diff --git a/exercises/practice/all-your-base/.meta/test_template.tera b/exercises/practice/all-your-base/.meta/test_template.tera index 829e823c7..1e8fe4c10 100644 --- a/exercises/practice/all-your-base/.meta/test_template.tera +++ b/exercises/practice/all-your-base/.meta/test_template.tera @@ -3,7 +3,7 @@ use allyourbase as ayb; {% for test in cases %} #[test] #[ignore] -fn {{ test.description | make_test_ident }}() { +fn {{ test.description | make_ident }}() { let input_base = {{ test.input.inputBase }}; let input_digits = &{{ test.input.digits | json_encode() }}; let output_base = {{ test.input.outputBase }}; diff --git a/exercises/practice/allergies/.meta/test_template.tera b/exercises/practice/allergies/.meta/test_template.tera index da8cced1e..9b050e434 100644 --- a/exercises/practice/allergies/.meta/test_template.tera +++ b/exercises/practice/allergies/.meta/test_template.tera @@ -20,7 +20,7 @@ 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 | snake_case }}_{{ test.input.item }}() { +fn {{ test.description | make_ident }}_{{ test.input.item }}() { let allergies = Allergies::new({{ test.input.score }}); {%- if test.expected %} assert!(allergies.is_allergic_to(&Allergen::{{ test.input.item | title }})) @@ -28,7 +28,7 @@ fn {{ test.description | snake_case }}_{{ test.input.item }}() { assert!(!allergies.is_allergic_to(&Allergen::{{ test.input.item | title }})) {% endif -%} {% else %} -fn {{ test.description | snake_case }}() { +fn {{ test.description | make_ident }}() { let allergies = Allergies::new({{ test.input.score }}).allergies(); let expected = &[ {% for allergen in test.expected %} diff --git a/exercises/practice/alphametics/.meta/test_template.tera b/exercises/practice/alphametics/.meta/test_template.tera index a67a99381..c71e14f23 100644 --- a/exercises/practice/alphametics/.meta/test_template.tera +++ b/exercises/practice/alphametics/.meta/test_template.tera @@ -3,7 +3,7 @@ use alphametics::*; {% for test in cases %} #[test] #[ignore] -fn {{ test.description | snake_case }}() { +fn {{ test.description | make_ident }}() { let answer = solve({{ test.input.puzzle | json_encode() }}); {%- if test.expected is object %} let expected = [ diff --git a/exercises/practice/anagram/.meta/test_template.tera b/exercises/practice/anagram/.meta/test_template.tera index e856d8900..2fb8bc521 100644 --- a/exercises/practice/anagram/.meta/test_template.tera +++ b/exercises/practice/anagram/.meta/test_template.tera @@ -4,7 +4,7 @@ use std::collections::HashSet; {% for test in cases %} #[test] #[ignore] -fn {{ test.description | snake_case }}() { +fn {{ test.description | make_ident }}() { let word = {{ test.input.subject | json_encode() }}; let inputs = &{{ test.input.candidates | json_encode() }}; let output = anagrams_for(word, inputs); diff --git a/exercises/practice/armstrong-numbers/.meta/test_template.tera b/exercises/practice/armstrong-numbers/.meta/test_template.tera index d5c167b8d..f60a5d881 100644 --- a/exercises/practice/armstrong-numbers/.meta/test_template.tera +++ b/exercises/practice/armstrong-numbers/.meta/test_template.tera @@ -3,7 +3,7 @@ use armstrong_numbers::*; {% for test in cases %} #[test] #[ignore] -fn {{ test.description | snake_case }}() { +fn {{ test.description | make_ident }}() { assert!({% if not test.expected %} ! {% endif %}is_armstrong_number({{ test.input.number | fmt_num }})) } {% endfor -%} diff --git a/exercises/practice/beer-song/.meta/test_template.tera b/exercises/practice/beer-song/.meta/test_template.tera index 0f32c94e4..842f5af64 100644 --- a/exercises/practice/beer-song/.meta/test_template.tera +++ b/exercises/practice/beer-song/.meta/test_template.tera @@ -1,12 +1,12 @@ {% for stupid_uselessly_nested_test_group in cases -%} {% for test_group in stupid_uselessly_nested_test_group.cases -%} -mod {{ test_group.description | snake_case }} { +mod {{ test_group.description | make_ident }} { use beer_song::*; {% for test in test_group.cases %} #[test] #[ignore] - fn {{ test.description | snake_case }}() { + fn {{ test.description | make_ident }}() { assert_eq!( {% if stupid_uselessly_nested_test_group.description == "verse" -%} verse({{ test.input.startBottles }}).trim(), diff --git a/exercises/practice/binary-search/.meta/test_template.tera b/exercises/practice/binary-search/.meta/test_template.tera index 59cf54ae0..34fa5f46e 100644 --- a/exercises/practice/binary-search/.meta/test_template.tera +++ b/exercises/practice/binary-search/.meta/test_template.tera @@ -3,7 +3,7 @@ use binary_search::*; {% for test in cases %} #[test] #[ignore] -fn {{ test.description | snake_case }}() { +fn {{ test.description | make_ident }}() { assert_eq!(find(&{{ test.input.array | json_encode() }}, {{ test.input.value }}), {% if test.expected is object -%} None {%- else -%} diff --git a/exercises/practice/bob/.meta/test_template.tera b/exercises/practice/bob/.meta/test_template.tera index dd7557012..20e41953f 100644 --- a/exercises/practice/bob/.meta/test_template.tera +++ b/exercises/practice/bob/.meta/test_template.tera @@ -3,7 +3,7 @@ use bob::*; {% for test in cases %} #[test] #[ignore] -fn {{ test.description | snake_case }}() { +fn {{ test.description | make_ident }}() { assert_eq!(reply({{ test.input.heyBob | json_encode() }}), "{{ test.expected }}"); } {% endfor -%} diff --git a/exercises/practice/book-store/.meta/test_template.tera b/exercises/practice/book-store/.meta/test_template.tera index 81ffc2d1e..702c05b73 100644 --- a/exercises/practice/book-store/.meta/test_template.tera +++ b/exercises/practice/book-store/.meta/test_template.tera @@ -3,7 +3,7 @@ use book_store::*; {% for test in cases %} #[test] #[ignore] -fn {{ test.description | snake_case }}() { +fn {{ test.description | make_ident }}() { let input = &{{ test.input.basket | json_encode() }}; let output = lowest_price(input); let expected = {{ test.expected | json_encode() }}; diff --git a/exercises/practice/circular-buffer/.meta/test_template.tera b/exercises/practice/circular-buffer/.meta/test_template.tera index 36a0193d8..84f5d6ea3 100644 --- a/exercises/practice/circular-buffer/.meta/test_template.tera +++ b/exercises/practice/circular-buffer/.meta/test_template.tera @@ -4,7 +4,7 @@ use std::rc::Rc; {% for test in cases %} #[test] #[ignore] -fn {{ test.description | snake_case }}() { +fn {{ test.description | make_ident }}() { let mut buffer = CircularBuffer{% if loop.index == 1 %}::{% endif %}::new({{ test.input.capacity }}); {%- for op in test.input.operations %} {%- if op.operation == "read" %} diff --git a/exercises/practice/collatz-conjecture/.meta/test_template.tera b/exercises/practice/collatz-conjecture/.meta/test_template.tera index 8a4d405ce..1f2720a26 100644 --- a/exercises/practice/collatz-conjecture/.meta/test_template.tera +++ b/exercises/practice/collatz-conjecture/.meta/test_template.tera @@ -3,7 +3,7 @@ use collatz_conjecture::*; {% for test in cases %} #[test] #[ignore] -fn {{ test.description | snake_case }}() { +fn {{ test.description | make_ident }}() { let output = collatz({{ test.input.number | fmt_num }}); let expected = {% if test.expected is object %} None diff --git a/exercises/practice/custom-set/.meta/test_template.tera b/exercises/practice/custom-set/.meta/test_template.tera index b97fda33c..e2aac4f24 100644 --- a/exercises/practice/custom-set/.meta/test_template.tera +++ b/exercises/practice/custom-set/.meta/test_template.tera @@ -4,7 +4,7 @@ use custom_set::CustomSet; {% for test in test_group.cases %} #[test] #[ignore] -fn {{ test.description | snake_case }}() { +fn {{ test.description | make_ident }}() { {%- if test.property == "empty" %} let set = CustomSet::::new(&{{ test.input.set | json_encode() }}); assert!( diff --git a/exercises/practice/eliuds-eggs/.meta/test_template.tera b/exercises/practice/eliuds-eggs/.meta/test_template.tera index 9a2306d5b..1687e0108 100644 --- a/exercises/practice/eliuds-eggs/.meta/test_template.tera +++ b/exercises/practice/eliuds-eggs/.meta/test_template.tera @@ -3,7 +3,7 @@ use eliuds_eggs::*; {% for test in cases %} #[test] #[ignore] -fn test_{{ test.description | snake_case }}() { +fn {{ test.description | make_ident }}() { let input = {{ test.input.number | fmt_num }}; let output = egg_count(input); let expected = {{ test.expected | json_encode() }}; diff --git a/exercises/practice/forth/.meta/test_template.tera b/exercises/practice/forth/.meta/test_template.tera index 1cc59aef5..dc7152268 100644 --- a/exercises/practice/forth/.meta/test_template.tera +++ b/exercises/practice/forth/.meta/test_template.tera @@ -1,11 +1,11 @@ {% for test_group in cases %} -mod {{ test_group.description | snake_case }} { +mod {{ test_group.description | make_ident }} { use forth::*; {% for test in test_group.cases %} #[test] #[ignore] -fn {{ test.description | snake_case }}() { +fn {{ test.description | make_ident }}() { let mut f = Forth::new(); {% if test.property == "evaluateBoth" -%} {% for instr in test.input.instructionsFirst -%} diff --git a/exercises/practice/grep/.meta/test_template.tera b/exercises/practice/grep/.meta/test_template.tera index de27f4dc3..e585a4ebd 100644 --- a/exercises/practice/grep/.meta/test_template.tera +++ b/exercises/practice/grep/.meta/test_template.tera @@ -32,7 +32,7 @@ fn grep_returns_result() { #[test] #[ignore] -fn {{ test.description | snake_case }}() { +fn {{ test.description | make_ident }}() { let pattern = {{ test.input.pattern | json_encode() }}; let flags = Flags::new(&{{ test.input.flags | json_encode() }}); let files = Files::new(&[ diff --git a/exercises/practice/isbn-verifier/.meta/test_template.tera b/exercises/practice/isbn-verifier/.meta/test_template.tera index c51d0e82c..3a3dc7233 100644 --- a/exercises/practice/isbn-verifier/.meta/test_template.tera +++ b/exercises/practice/isbn-verifier/.meta/test_template.tera @@ -3,7 +3,7 @@ use isbn_verifier::*; {% for test in cases %} #[test] #[ignore] -fn {{ test.description | snake_case }}() { +fn {{ test.description | make_ident }}() { {% if test.expected %} assert!(is_valid_isbn("{{ test.input.isbn }}")); {% else %} diff --git a/exercises/practice/isogram/.meta/test_template.tera b/exercises/practice/isogram/.meta/test_template.tera index 51bd452ba..70e9382ae 100644 --- a/exercises/practice/isogram/.meta/test_template.tera +++ b/exercises/practice/isogram/.meta/test_template.tera @@ -3,7 +3,7 @@ use isogram::*; {% for test in cases %} #[test] #[ignore] -fn {{ test.description | snake_case }}() { +fn {{ test.description | make_ident }}() { {% if test.expected %} assert!(check({{ test.input.phrase | json_encode() }})); {% else %} diff --git a/exercises/practice/knapsack/.meta/test_template.tera b/exercises/practice/knapsack/.meta/test_template.tera index 3cbe97694..1a6a7ad53 100644 --- a/exercises/practice/knapsack/.meta/test_template.tera +++ b/exercises/practice/knapsack/.meta/test_template.tera @@ -3,7 +3,7 @@ use knapsack::*; {% for test in cases %} #[test] #[ignore] -fn test_{{ test.description | snake_case }}() { +fn {{ test.description | make_ident }}() { let max_weight = {{ test.input.maximumWeight }}; let items = [ {% for item in test.input.items -%} diff --git a/exercises/practice/knapsack/tests/knapsack.rs b/exercises/practice/knapsack/tests/knapsack.rs index 0463142a9..f601dac8c 100644 --- a/exercises/practice/knapsack/tests/knapsack.rs +++ b/exercises/practice/knapsack/tests/knapsack.rs @@ -1,7 +1,7 @@ use knapsack::*; #[test] -fn test_no_items() { +fn no_items() { let max_weight = 100; let items = []; let output = maximum_value(max_weight, &items); @@ -11,7 +11,7 @@ fn test_no_items() { #[test] #[ignore] -fn test_one_item_too_heavy() { +fn one_item_too_heavy() { let max_weight = 10; let items = [Item { weight: 100, @@ -24,7 +24,7 @@ fn test_one_item_too_heavy() { #[test] #[ignore] -fn test_five_items_cannot_be_greedy_by_weight() { +fn five_items_cannot_be_greedy_by_weight() { let max_weight = 10; let items = [ Item { @@ -55,7 +55,7 @@ fn test_five_items_cannot_be_greedy_by_weight() { #[test] #[ignore] -fn test_five_items_cannot_be_greedy_by_value() { +fn five_items_cannot_be_greedy_by_value() { let max_weight = 10; let items = [ Item { @@ -86,7 +86,7 @@ fn test_five_items_cannot_be_greedy_by_value() { #[test] #[ignore] -fn test_example_knapsack() { +fn example_knapsack() { let max_weight = 10; let items = [ Item { diff --git a/exercises/practice/leap/.meta/test_template.tera b/exercises/practice/leap/.meta/test_template.tera index c93330cbb..bed0ba0a6 100644 --- a/exercises/practice/leap/.meta/test_template.tera +++ b/exercises/practice/leap/.meta/test_template.tera @@ -3,7 +3,7 @@ use leap::*; {% for test in cases %} #[test] #[ignore] -fn {{ test.description | snake_case }}() { +fn {{ test.description | make_ident }}() { {%- if test.expected %} assert!(is_leap_year({{ test.input.year }})); {% else %} diff --git a/exercises/practice/matrix/.meta/test_template.tera b/exercises/practice/matrix/.meta/test_template.tera index eff2a7edb..c857c4ca4 100644 --- a/exercises/practice/matrix/.meta/test_template.tera +++ b/exercises/practice/matrix/.meta/test_template.tera @@ -3,7 +3,7 @@ use matrix::*; {% for test in cases %} #[test] #[ignore] -fn {{ test.description | snake_case }}() { +fn {{ test.description | make_ident }}() { 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() }})); diff --git a/exercises/practice/nth-prime/.meta/test_template.tera b/exercises/practice/nth-prime/.meta/test_template.tera index 4f3e44aa2..a69cc5c50 100644 --- a/exercises/practice/nth-prime/.meta/test_template.tera +++ b/exercises/practice/nth-prime/.meta/test_template.tera @@ -3,7 +3,7 @@ use nth_prime::*; {% for test in cases %} #[test] #[ignore] -fn {{ test.description | snake_case }}() { +fn {{ test.description | make_ident }}() { let output = nth({{ test.input.number - 1 | fmt_num }}); let expected = {{ test.expected | fmt_num }}; assert_eq!(output, expected); diff --git a/exercises/practice/palindrome-products/.meta/test_template.tera b/exercises/practice/palindrome-products/.meta/test_template.tera index 53828a5c5..e184921f5 100644 --- a/exercises/practice/palindrome-products/.meta/test_template.tera +++ b/exercises/practice/palindrome-products/.meta/test_template.tera @@ -26,7 +26,7 @@ fn palindrome_new_return_none() { {% for test in cases %} #[test] #[ignore] -fn {{ test.description | snake_case }}() { +fn {{ test.description | make_ident }}() { {%- if test.property == "smallest" %} let output = palindrome_products({{ test.input.min }}, {{ test.input.max }}).map(|(min, _)| min.into_inner()); {%- else %} diff --git a/exercises/practice/pangram/.meta/test_template.tera b/exercises/practice/pangram/.meta/test_template.tera index 49c14ea0b..8d9eb5cd4 100644 --- a/exercises/practice/pangram/.meta/test_template.tera +++ b/exercises/practice/pangram/.meta/test_template.tera @@ -3,7 +3,7 @@ use pangram::*; {% for test in cases %} #[test] #[ignore] -fn {{ test.description | snake_case }}() { +fn {{ test.description | make_ident }}() { let sentence = {{ test.input.sentence | json_encode() }}; {% if test.expected -%} assert!(is_pangram(sentence)); diff --git a/exercises/practice/pascals-triangle/.meta/test_template.tera b/exercises/practice/pascals-triangle/.meta/test_template.tera index 6acfd5305..60e67468c 100644 --- a/exercises/practice/pascals-triangle/.meta/test_template.tera +++ b/exercises/practice/pascals-triangle/.meta/test_template.tera @@ -2,7 +2,7 @@ use pascals_triangle::PascalsTriangle; {% for test in cases %} #[test] #[ignore] -fn {{ test.description | snake_case }}() { +fn {{ test.description | make_ident }}() { let pt = PascalsTriangle::new({{ test.input.count }}); let expected: Vec> = vec![{% for row in test.expected -%} vec!{{ row | json_encode() }}, diff --git a/exercises/practice/perfect-numbers/.meta/test_template.tera b/exercises/practice/perfect-numbers/.meta/test_template.tera index 8d90392dc..82be1fa7b 100644 --- a/exercises/practice/perfect-numbers/.meta/test_template.tera +++ b/exercises/practice/perfect-numbers/.meta/test_template.tera @@ -4,7 +4,7 @@ use perfect_numbers::*; {% for test in test_group.cases %} #[test] #[ignore] -fn {{ test.description | snake_case }}() { +fn {{ test.description | make_ident }}() { let input = {{ test.input.number | fmt_num }}; let output = classify(input); {%- if test.expected is object %} diff --git a/exercises/practice/phone-number/.meta/test_template.tera b/exercises/practice/phone-number/.meta/test_template.tera index e9871c39f..3f50cc8f6 100644 --- a/exercises/practice/phone-number/.meta/test_template.tera +++ b/exercises/practice/phone-number/.meta/test_template.tera @@ -3,7 +3,7 @@ use phone_number::*; {% for test in cases %} #[test] #[ignore] -fn {{ test.description | snake_case }}() { +fn {{ test.description | make_ident }}() { let input = {{ test.input.phrase | json_encode() }}; let output = number(input); {%- if test.expected is object %} diff --git a/exercises/practice/pig-latin/.meta/test_template.tera b/exercises/practice/pig-latin/.meta/test_template.tera index 0316cfc77..a6e1b9dff 100644 --- a/exercises/practice/pig-latin/.meta/test_template.tera +++ b/exercises/practice/pig-latin/.meta/test_template.tera @@ -4,7 +4,7 @@ use pig_latin::*; {% for test in test_group.cases %} #[test] #[ignore] -fn {{ test.description | snake_case }}() { +fn {{ test.description | make_ident }}() { let input = {{ test.input.phrase | json_encode() }}; let output = translate(input); let expected = {{ test.expected | json_encode() }}; diff --git a/exercises/practice/poker/.meta/test_template.tera b/exercises/practice/poker/.meta/test_template.tera index 7962198ad..546fe4850 100644 --- a/exercises/practice/poker/.meta/test_template.tera +++ b/exercises/practice/poker/.meta/test_template.tera @@ -4,7 +4,7 @@ use std::collections::HashSet; {% for test in cases %} #[test] #[ignore] -fn {{ test.description | snake_case }}() { +fn {{ test.description | make_ident }}() { let input = &{{ test.input.hands | json_encode() }}; let output = winning_hands(input).into_iter().collect::>(); let expected = {{ test.expected | json_encode() }}.into_iter().collect::>(); diff --git a/exercises/practice/prime-factors/.meta/test_template.tera b/exercises/practice/prime-factors/.meta/test_template.tera index 2a0bbb62b..0c80353ba 100644 --- a/exercises/practice/prime-factors/.meta/test_template.tera +++ b/exercises/practice/prime-factors/.meta/test_template.tera @@ -3,7 +3,7 @@ use prime_factors::*; {% for test in cases %} #[test] #[ignore] -fn {{ test.description | snake_case }}() { +fn {{ test.description | make_ident }}() { let factors = factors({{ test.input.value | fmt_num }}); let expected = [{% for factor in test.expected -%} {{ factor | fmt_num }}, diff --git a/exercises/practice/protein-translation/.meta/test_template.tera b/exercises/practice/protein-translation/.meta/test_template.tera index 27d1b694d..5b10a3706 100644 --- a/exercises/practice/protein-translation/.meta/test_template.tera +++ b/exercises/practice/protein-translation/.meta/test_template.tera @@ -3,7 +3,7 @@ use protein_translation::*; {% for test in cases %} #[test] #[ignore] -fn {{ test.description | snake_case }}() { +fn {{ test.description | make_ident }}() { assert_eq!( translate({{ test.input.strand | json_encode() }}), {% if test.expected is object %} diff --git a/exercises/practice/proverb/.meta/test_template.tera b/exercises/practice/proverb/.meta/test_template.tera index afa61b9c6..3dbfb203d 100644 --- a/exercises/practice/proverb/.meta/test_template.tera +++ b/exercises/practice/proverb/.meta/test_template.tera @@ -3,7 +3,7 @@ use proverb::*; {% for test in cases %} #[test] #[ignore] -fn {{ test.description | snake_case }}() { +fn {{ test.description | make_ident }}() { let input = &{{ test.input.strings | json_encode() }}; let output = build_proverb(input); {% if test.expected | length == 0 -%} diff --git a/exercises/practice/pythagorean-triplet/.meta/test_template.tera b/exercises/practice/pythagorean-triplet/.meta/test_template.tera index 6801d172b..904903c2c 100644 --- a/exercises/practice/pythagorean-triplet/.meta/test_template.tera +++ b/exercises/practice/pythagorean-triplet/.meta/test_template.tera @@ -4,7 +4,7 @@ use std::collections::HashSet; {% for test in cases %} #[test] #[ignore] -fn {{ test.description | snake_case }}() { +fn {{ test.description | make_ident }}() { let input = {{ test.input.n | fmt_num }}; let output = find(input); let expected = [{% for triple in test.expected -%} diff --git a/exercises/practice/queen-attack/.meta/test_template.tera b/exercises/practice/queen-attack/.meta/test_template.tera index 642f877f3..941f42d33 100644 --- a/exercises/practice/queen-attack/.meta/test_template.tera +++ b/exercises/practice/queen-attack/.meta/test_template.tera @@ -4,7 +4,7 @@ use queen_attack::*; {% for test in test_group.cases %} #[test] #[ignore] -fn {{ test.description | snake_case }}() { +fn {{ test.description | make_ident }}() { {% if test.property == "create" %} let chess_position = ChessPosition::new({{ test.input.queen.position.row }}, {{ test.input.queen.position.column }}); {%- if test.expected is object %} diff --git a/exercises/practice/rail-fence-cipher/.meta/test_template.tera b/exercises/practice/rail-fence-cipher/.meta/test_template.tera index e0c6de5fa..c9ada5303 100644 --- a/exercises/practice/rail-fence-cipher/.meta/test_template.tera +++ b/exercises/practice/rail-fence-cipher/.meta/test_template.tera @@ -4,7 +4,7 @@ use rail_fence_cipher::RailFence; {% for test in test_group.cases %} #[test] #[ignore] -fn {{ test.description | snake_case }}() { +fn {{ test.description | make_ident }}() { let input = {{ test.input.msg | json_encode() }}; let rails = {{ test.input.rails | json_encode() }}; let rail_fence = RailFence::new(rails); diff --git a/exercises/practice/raindrops/.meta/test_template.tera b/exercises/practice/raindrops/.meta/test_template.tera index 53b990bec..8e97f5142 100644 --- a/exercises/practice/raindrops/.meta/test_template.tera +++ b/exercises/practice/raindrops/.meta/test_template.tera @@ -3,7 +3,7 @@ use raindrops::*; {% for test in cases %} #[test] #[ignore] -fn test_{{ test.description | snake_case }}() { +fn {{ test.description | make_ident }}() { let input = {{ test.input.number | json_encode() }}; let output = raindrops(input); let expected = {{ test.expected | json_encode() }}; diff --git a/exercises/practice/raindrops/tests/raindrops.rs b/exercises/practice/raindrops/tests/raindrops.rs index d6999c98d..ea34ac57e 100644 --- a/exercises/practice/raindrops/tests/raindrops.rs +++ b/exercises/practice/raindrops/tests/raindrops.rs @@ -1,7 +1,7 @@ use raindrops::*; #[test] -fn test_the_sound_for_1_is_1() { +fn the_sound_for_1_is_1() { let input = 1; let output = raindrops(input); let expected = "1"; @@ -10,7 +10,7 @@ fn test_the_sound_for_1_is_1() { #[test] #[ignore] -fn test_the_sound_for_3_is_pling() { +fn the_sound_for_3_is_pling() { let input = 3; let output = raindrops(input); let expected = "Pling"; @@ -19,7 +19,7 @@ fn test_the_sound_for_3_is_pling() { #[test] #[ignore] -fn test_the_sound_for_5_is_plang() { +fn the_sound_for_5_is_plang() { let input = 5; let output = raindrops(input); let expected = "Plang"; @@ -28,7 +28,7 @@ fn test_the_sound_for_5_is_plang() { #[test] #[ignore] -fn test_the_sound_for_7_is_plong() { +fn the_sound_for_7_is_plong() { let input = 7; let output = raindrops(input); let expected = "Plong"; @@ -37,7 +37,7 @@ fn test_the_sound_for_7_is_plong() { #[test] #[ignore] -fn test_the_sound_for_6_is_pling_as_it_has_a_factor_3() { +fn the_sound_for_6_is_pling_as_it_has_a_factor_3() { let input = 6; let output = raindrops(input); let expected = "Pling"; @@ -55,7 +55,7 @@ fn test_2_to_the_power_3_does_not_make_a_raindrop_sound_as_3_is_the_exponent_not #[test] #[ignore] -fn test_the_sound_for_9_is_pling_as_it_has_a_factor_3() { +fn the_sound_for_9_is_pling_as_it_has_a_factor_3() { let input = 9; let output = raindrops(input); let expected = "Pling"; @@ -64,7 +64,7 @@ fn test_the_sound_for_9_is_pling_as_it_has_a_factor_3() { #[test] #[ignore] -fn test_the_sound_for_10_is_plang_as_it_has_a_factor_5() { +fn the_sound_for_10_is_plang_as_it_has_a_factor_5() { let input = 10; let output = raindrops(input); let expected = "Plang"; @@ -73,7 +73,7 @@ fn test_the_sound_for_10_is_plang_as_it_has_a_factor_5() { #[test] #[ignore] -fn test_the_sound_for_14_is_plong_as_it_has_a_factor_of_7() { +fn the_sound_for_14_is_plong_as_it_has_a_factor_of_7() { let input = 14; let output = raindrops(input); let expected = "Plong"; @@ -82,7 +82,7 @@ fn test_the_sound_for_14_is_plong_as_it_has_a_factor_of_7() { #[test] #[ignore] -fn test_the_sound_for_15_is_plingplang_as_it_has_factors_3_and_5() { +fn the_sound_for_15_is_plingplang_as_it_has_factors_3_and_5() { let input = 15; let output = raindrops(input); let expected = "PlingPlang"; @@ -91,7 +91,7 @@ fn test_the_sound_for_15_is_plingplang_as_it_has_factors_3_and_5() { #[test] #[ignore] -fn test_the_sound_for_21_is_plingplong_as_it_has_factors_3_and_7() { +fn the_sound_for_21_is_plingplong_as_it_has_factors_3_and_7() { let input = 21; let output = raindrops(input); let expected = "PlingPlong"; @@ -100,7 +100,7 @@ fn test_the_sound_for_21_is_plingplong_as_it_has_factors_3_and_7() { #[test] #[ignore] -fn test_the_sound_for_25_is_plang_as_it_has_a_factor_5() { +fn the_sound_for_25_is_plang_as_it_has_a_factor_5() { let input = 25; let output = raindrops(input); let expected = "Plang"; @@ -109,7 +109,7 @@ fn test_the_sound_for_25_is_plang_as_it_has_a_factor_5() { #[test] #[ignore] -fn test_the_sound_for_27_is_pling_as_it_has_a_factor_3() { +fn the_sound_for_27_is_pling_as_it_has_a_factor_3() { let input = 27; let output = raindrops(input); let expected = "Pling"; @@ -118,7 +118,7 @@ fn test_the_sound_for_27_is_pling_as_it_has_a_factor_3() { #[test] #[ignore] -fn test_the_sound_for_35_is_plangplong_as_it_has_factors_5_and_7() { +fn the_sound_for_35_is_plangplong_as_it_has_factors_5_and_7() { let input = 35; let output = raindrops(input); let expected = "PlangPlong"; @@ -127,7 +127,7 @@ fn test_the_sound_for_35_is_plangplong_as_it_has_factors_5_and_7() { #[test] #[ignore] -fn test_the_sound_for_49_is_plong_as_it_has_a_factor_7() { +fn the_sound_for_49_is_plong_as_it_has_a_factor_7() { let input = 49; let output = raindrops(input); let expected = "Plong"; @@ -136,7 +136,7 @@ fn test_the_sound_for_49_is_plong_as_it_has_a_factor_7() { #[test] #[ignore] -fn test_the_sound_for_52_is_52() { +fn the_sound_for_52_is_52() { let input = 52; let output = raindrops(input); let expected = "52"; @@ -145,7 +145,7 @@ fn test_the_sound_for_52_is_52() { #[test] #[ignore] -fn test_the_sound_for_105_is_plingplangplong_as_it_has_factors_3_5_and_7() { +fn the_sound_for_105_is_plingplangplong_as_it_has_factors_3_5_and_7() { let input = 105; let output = raindrops(input); let expected = "PlingPlangPlong"; @@ -154,7 +154,7 @@ fn test_the_sound_for_105_is_plingplangplong_as_it_has_factors_3_5_and_7() { #[test] #[ignore] -fn test_the_sound_for_3125_is_plang_as_it_has_a_factor_5() { +fn the_sound_for_3125_is_plang_as_it_has_a_factor_5() { let input = 3125; let output = raindrops(input); let expected = "Plang"; diff --git a/exercises/practice/rectangles/.meta/test_template.tera b/exercises/practice/rectangles/.meta/test_template.tera index a75dcde9c..fed71856c 100644 --- a/exercises/practice/rectangles/.meta/test_template.tera +++ b/exercises/practice/rectangles/.meta/test_template.tera @@ -3,7 +3,7 @@ use rectangles::*; {% for test in cases %} #[test] #[ignore] -fn test_{{ test.description | snake_case }}() { +fn {{ test.description | make_ident }}() { {% if test.input.strings | length > 1 -%} #[rustfmt::skip] {%- endif %} diff --git a/exercises/practice/rectangles/tests/rectangles.rs b/exercises/practice/rectangles/tests/rectangles.rs index 59950a834..954268284 100644 --- a/exercises/practice/rectangles/tests/rectangles.rs +++ b/exercises/practice/rectangles/tests/rectangles.rs @@ -1,7 +1,7 @@ use rectangles::*; #[test] -fn test_no_rows() { +fn no_rows() { let input = &[]; let output = count(input); let expected = 0; @@ -10,7 +10,7 @@ fn test_no_rows() { #[test] #[ignore] -fn test_no_columns() { +fn no_columns() { let input = &[""]; let output = count(input); let expected = 0; @@ -19,7 +19,7 @@ fn test_no_columns() { #[test] #[ignore] -fn test_no_rectangles() { +fn no_rectangles() { let input = &[" "]; let output = count(input); let expected = 0; @@ -28,7 +28,7 @@ fn test_no_rectangles() { #[test] #[ignore] -fn test_one_rectangle() { +fn one_rectangle() { #[rustfmt::skip] let input = &[ "+-+", @@ -42,7 +42,7 @@ fn test_one_rectangle() { #[test] #[ignore] -fn test_two_rectangles_without_shared_parts() { +fn two_rectangles_without_shared_parts() { #[rustfmt::skip] let input = &[ " +-+", @@ -58,7 +58,7 @@ fn test_two_rectangles_without_shared_parts() { #[test] #[ignore] -fn test_five_rectangles_with_shared_parts() { +fn five_rectangles_with_shared_parts() { #[rustfmt::skip] let input = &[ " +-+", @@ -74,7 +74,7 @@ fn test_five_rectangles_with_shared_parts() { #[test] #[ignore] -fn test_rectangle_of_height_1_is_counted() { +fn rectangle_of_height_1_is_counted() { #[rustfmt::skip] let input = &[ "+--+", @@ -87,7 +87,7 @@ fn test_rectangle_of_height_1_is_counted() { #[test] #[ignore] -fn test_rectangle_of_width_1_is_counted() { +fn rectangle_of_width_1_is_counted() { #[rustfmt::skip] let input = &[ "++", @@ -114,7 +114,7 @@ fn test_1x1_square_is_counted() { #[test] #[ignore] -fn test_only_complete_rectangles_are_counted() { +fn only_complete_rectangles_are_counted() { #[rustfmt::skip] let input = &[ " +-+", @@ -130,7 +130,7 @@ fn test_only_complete_rectangles_are_counted() { #[test] #[ignore] -fn test_rectangles_can_be_of_different_sizes() { +fn rectangles_can_be_of_different_sizes() { #[rustfmt::skip] let input = &[ "+------+----+", @@ -146,7 +146,7 @@ fn test_rectangles_can_be_of_different_sizes() { #[test] #[ignore] -fn test_corner_is_required_for_a_rectangle_to_be_complete() { +fn corner_is_required_for_a_rectangle_to_be_complete() { #[rustfmt::skip] let input = &[ "+------+----+", @@ -162,7 +162,7 @@ fn test_corner_is_required_for_a_rectangle_to_be_complete() { #[test] #[ignore] -fn test_large_input_with_many_rectangles() { +fn large_input_with_many_rectangles() { #[rustfmt::skip] let input = &[ "+---+--+----+", @@ -181,7 +181,7 @@ fn test_large_input_with_many_rectangles() { #[test] #[ignore] -fn test_rectangles_must_have_four_sides() { +fn rectangles_must_have_four_sides() { #[rustfmt::skip] let input = &[ "+-+ +-+", diff --git a/exercises/practice/reverse-string/.meta/test_template.tera b/exercises/practice/reverse-string/.meta/test_template.tera index 56b1c8e6b..1ddf9e050 100644 --- a/exercises/practice/reverse-string/.meta/test_template.tera +++ b/exercises/practice/reverse-string/.meta/test_template.tera @@ -6,7 +6,7 @@ use reverse_string::*; {% if test.description is starting_with("grapheme cluster") -%} #[cfg(feature = "grapheme")] {% endif -%} -fn {{ test.description | snake_case }}() { +fn {{ test.description | make_ident }}() { let input = {{ test.input.value | json_encode() }}; let output = reverse(input); let expected = {{ test.expected | json_encode() }}; diff --git a/exercises/practice/rna-transcription/.meta/test_template.tera b/exercises/practice/rna-transcription/.meta/test_template.tera index ab0ed6016..8f3f2b8ce 100644 --- a/exercises/practice/rna-transcription/.meta/test_template.tera +++ b/exercises/practice/rna-transcription/.meta/test_template.tera @@ -2,7 +2,7 @@ use rna_transcription::{Dna, Rna}; {% for test in cases %} #[test] #[ignore] -fn {{ test.description | snake_case }}() { +fn {{ test.description | make_ident }}() { let input = {{ test.input.dna | json_encode() }}; {% if test.property == "invalidDna" -%} let output = Dna::new(input); diff --git a/exercises/practice/robot-simulator/.meta/test_template.tera b/exercises/practice/robot-simulator/.meta/test_template.tera index 6581819e1..1b01e73a0 100644 --- a/exercises/practice/robot-simulator/.meta/test_template.tera +++ b/exercises/practice/robot-simulator/.meta/test_template.tera @@ -4,7 +4,7 @@ use robot_simulator::*; {% for test in test_group.cases %} #[test] #[ignore] -fn {{ test.description | snake_case }}() { +fn {{ test.description | make_ident }}() { {%- 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 }})); diff --git a/exercises/practice/roman-numerals/.meta/test_template.tera b/exercises/practice/roman-numerals/.meta/test_template.tera index c82367cd9..308f567d6 100644 --- a/exercises/practice/roman-numerals/.meta/test_template.tera +++ b/exercises/practice/roman-numerals/.meta/test_template.tera @@ -3,7 +3,7 @@ use roman_numerals::Roman; {% for test in cases %} #[test] #[ignore] -fn number_{{ test.description | snake_case }}() { +fn {{ test.description | make_ident }}() { let input = {{ test.input.number | json_encode() }}; let output = Roman::from(input).to_string(); let expected = {{ test.expected | json_encode() }}; diff --git a/exercises/practice/roman-numerals/tests/roman-numerals.rs b/exercises/practice/roman-numerals/tests/roman-numerals.rs index 34df41ae1..336b42e9d 100644 --- a/exercises/practice/roman-numerals/tests/roman-numerals.rs +++ b/exercises/practice/roman-numerals/tests/roman-numerals.rs @@ -1,7 +1,7 @@ use roman_numerals::Roman; #[test] -fn number_1_is_i() { +fn test_1_is_i() { let input = 1; let output = Roman::from(input).to_string(); let expected = "I"; @@ -10,7 +10,7 @@ fn number_1_is_i() { #[test] #[ignore] -fn number_2_is_ii() { +fn test_2_is_ii() { let input = 2; let output = Roman::from(input).to_string(); let expected = "II"; @@ -19,7 +19,7 @@ fn number_2_is_ii() { #[test] #[ignore] -fn number_3_is_iii() { +fn test_3_is_iii() { let input = 3; let output = Roman::from(input).to_string(); let expected = "III"; @@ -28,7 +28,7 @@ fn number_3_is_iii() { #[test] #[ignore] -fn number_4_is_iv() { +fn test_4_is_iv() { let input = 4; let output = Roman::from(input).to_string(); let expected = "IV"; @@ -37,7 +37,7 @@ fn number_4_is_iv() { #[test] #[ignore] -fn number_5_is_v() { +fn test_5_is_v() { let input = 5; let output = Roman::from(input).to_string(); let expected = "V"; @@ -46,7 +46,7 @@ fn number_5_is_v() { #[test] #[ignore] -fn number_6_is_vi() { +fn test_6_is_vi() { let input = 6; let output = Roman::from(input).to_string(); let expected = "VI"; @@ -55,7 +55,7 @@ fn number_6_is_vi() { #[test] #[ignore] -fn number_9_is_ix() { +fn test_9_is_ix() { let input = 9; let output = Roman::from(input).to_string(); let expected = "IX"; @@ -64,7 +64,7 @@ fn number_9_is_ix() { #[test] #[ignore] -fn number_16_is_xvi() { +fn test_16_is_xvi() { let input = 16; let output = Roman::from(input).to_string(); let expected = "XVI"; @@ -73,7 +73,7 @@ fn number_16_is_xvi() { #[test] #[ignore] -fn number_27_is_xxvii() { +fn test_27_is_xxvii() { let input = 27; let output = Roman::from(input).to_string(); let expected = "XXVII"; @@ -82,7 +82,7 @@ fn number_27_is_xxvii() { #[test] #[ignore] -fn number_48_is_xlviii() { +fn test_48_is_xlviii() { let input = 48; let output = Roman::from(input).to_string(); let expected = "XLVIII"; @@ -91,7 +91,7 @@ fn number_48_is_xlviii() { #[test] #[ignore] -fn number_49_is_xlix() { +fn test_49_is_xlix() { let input = 49; let output = Roman::from(input).to_string(); let expected = "XLIX"; @@ -100,7 +100,7 @@ fn number_49_is_xlix() { #[test] #[ignore] -fn number_59_is_lix() { +fn test_59_is_lix() { let input = 59; let output = Roman::from(input).to_string(); let expected = "LIX"; @@ -109,7 +109,7 @@ fn number_59_is_lix() { #[test] #[ignore] -fn number_66_is_lxvi() { +fn test_66_is_lxvi() { let input = 66; let output = Roman::from(input).to_string(); let expected = "LXVI"; @@ -118,7 +118,7 @@ fn number_66_is_lxvi() { #[test] #[ignore] -fn number_93_is_xciii() { +fn test_93_is_xciii() { let input = 93; let output = Roman::from(input).to_string(); let expected = "XCIII"; @@ -127,7 +127,7 @@ fn number_93_is_xciii() { #[test] #[ignore] -fn number_141_is_cxli() { +fn test_141_is_cxli() { let input = 141; let output = Roman::from(input).to_string(); let expected = "CXLI"; @@ -136,7 +136,7 @@ fn number_141_is_cxli() { #[test] #[ignore] -fn number_163_is_clxiii() { +fn test_163_is_clxiii() { let input = 163; let output = Roman::from(input).to_string(); let expected = "CLXIII"; @@ -145,7 +145,7 @@ fn number_163_is_clxiii() { #[test] #[ignore] -fn number_166_is_clxvi() { +fn test_166_is_clxvi() { let input = 166; let output = Roman::from(input).to_string(); let expected = "CLXVI"; @@ -154,7 +154,7 @@ fn number_166_is_clxvi() { #[test] #[ignore] -fn number_402_is_cdii() { +fn test_402_is_cdii() { let input = 402; let output = Roman::from(input).to_string(); let expected = "CDII"; @@ -163,7 +163,7 @@ fn number_402_is_cdii() { #[test] #[ignore] -fn number_575_is_dlxxv() { +fn test_575_is_dlxxv() { let input = 575; let output = Roman::from(input).to_string(); let expected = "DLXXV"; @@ -172,7 +172,7 @@ fn number_575_is_dlxxv() { #[test] #[ignore] -fn number_666_is_dclxvi() { +fn test_666_is_dclxvi() { let input = 666; let output = Roman::from(input).to_string(); let expected = "DCLXVI"; @@ -181,7 +181,7 @@ fn number_666_is_dclxvi() { #[test] #[ignore] -fn number_911_is_cmxi() { +fn test_911_is_cmxi() { let input = 911; let output = Roman::from(input).to_string(); let expected = "CMXI"; @@ -190,7 +190,7 @@ fn number_911_is_cmxi() { #[test] #[ignore] -fn number_1024_is_mxxiv() { +fn test_1024_is_mxxiv() { let input = 1024; let output = Roman::from(input).to_string(); let expected = "MXXIV"; @@ -199,7 +199,7 @@ fn number_1024_is_mxxiv() { #[test] #[ignore] -fn number_1666_is_mdclxvi() { +fn test_1666_is_mdclxvi() { let input = 1666; let output = Roman::from(input).to_string(); let expected = "MDCLXVI"; @@ -208,7 +208,7 @@ fn number_1666_is_mdclxvi() { #[test] #[ignore] -fn number_3000_is_mmm() { +fn test_3000_is_mmm() { let input = 3000; let output = Roman::from(input).to_string(); let expected = "MMM"; @@ -217,7 +217,7 @@ fn number_3000_is_mmm() { #[test] #[ignore] -fn number_3001_is_mmmi() { +fn test_3001_is_mmmi() { let input = 3001; let output = Roman::from(input).to_string(); let expected = "MMMI"; @@ -226,7 +226,7 @@ fn number_3001_is_mmmi() { #[test] #[ignore] -fn number_3888_is_mmmdccclxxxviii() { +fn test_3888_is_mmmdccclxxxviii() { let input = 3888; let output = Roman::from(input).to_string(); let expected = "MMMDCCCLXXXVIII"; @@ -235,7 +235,7 @@ fn number_3888_is_mmmdccclxxxviii() { #[test] #[ignore] -fn number_3999_is_mmmcmxcix() { +fn test_3999_is_mmmcmxcix() { let input = 3999; let output = Roman::from(input).to_string(); let expected = "MMMCMXCIX"; diff --git a/exercises/practice/rotational-cipher/.meta/test_template.tera b/exercises/practice/rotational-cipher/.meta/test_template.tera index 58f50b754..68c693cd3 100644 --- a/exercises/practice/rotational-cipher/.meta/test_template.tera +++ b/exercises/practice/rotational-cipher/.meta/test_template.tera @@ -2,7 +2,7 @@ use rotational_cipher as cipher; {% for test in cases %} #[test] #[ignore] -fn {{ test.description | snake_case }}() { +fn {{ test.description | make_ident }}() { let text = {{ test.input.text | json_encode() }}; let shift_key = {{ test.input.shiftKey | json_encode() }}; let output = cipher::rotate(text, shift_key); diff --git a/exercises/practice/run-length-encoding/.meta/test_template.tera b/exercises/practice/run-length-encoding/.meta/test_template.tera index 4616df818..8dbfee2e2 100644 --- a/exercises/practice/run-length-encoding/.meta/test_template.tera +++ b/exercises/practice/run-length-encoding/.meta/test_template.tera @@ -4,7 +4,7 @@ use run_length_encoding as rle; {% for test in test_group.cases %} #[test] #[ignore] -fn {{ test.property }}_{{ test.description | snake_case }}() { +fn {{ test.property }}_{{ test.description | make_ident }}() { let input = {{ test.input.string | json_encode() }}; {% if test.property == "consistency" -%} let output = rle::decode(&rle::encode(input)); diff --git a/exercises/practice/saddle-points/.meta/test_template.tera b/exercises/practice/saddle-points/.meta/test_template.tera index 1920506ce..ff597d3e0 100644 --- a/exercises/practice/saddle-points/.meta/test_template.tera +++ b/exercises/practice/saddle-points/.meta/test_template.tera @@ -7,7 +7,7 @@ fn find_sorted_saddle_points(input: &[Vec]) -> Vec<(usize, usize)> { {% for test in cases %} #[test] #[ignore] -fn {{ test.description | snake_case }}() { +fn {{ test.description | make_ident }}() { let input = &[{% for row in test.input.matrix %} vec!{{ row }}, {% endfor %}]; diff --git a/exercises/practice/say/.meta/test_template.tera b/exercises/practice/say/.meta/test_template.tera index ab79d73cd..477939969 100644 --- a/exercises/practice/say/.meta/test_template.tera +++ b/exercises/practice/say/.meta/test_template.tera @@ -3,7 +3,7 @@ use say::*; {% for test in cases %} #[test] #[ignore] -fn {{ test.description | snake_case }}() { +fn {{ test.description | make_ident }}() { let input = {{ test.input.number | fmt_num }}; let output = encode(input); let expected = {{ test.expected | json_encode() }}; diff --git a/exercises/practice/scrabble-score/.meta/test_template.tera b/exercises/practice/scrabble-score/.meta/test_template.tera index f09bc5067..d73cb83fb 100644 --- a/exercises/practice/scrabble-score/.meta/test_template.tera +++ b/exercises/practice/scrabble-score/.meta/test_template.tera @@ -3,7 +3,7 @@ use scrabble_score::*; {% for test in cases %} #[test] #[ignore] -fn {{ test.description | snake_case }}() { +fn {{ test.description | make_ident }}() { let input = {{ test.input.word | json_encode() }}; let output = score(input); let expected = {{ test.expected | json_encode() }}; diff --git a/exercises/practice/series/.meta/test_template.tera b/exercises/practice/series/.meta/test_template.tera index 25e725057..a093d0e2f 100644 --- a/exercises/practice/series/.meta/test_template.tera +++ b/exercises/practice/series/.meta/test_template.tera @@ -3,7 +3,7 @@ use series::*; {% for test in cases %} #[test] #[ignore] -fn {{ test.description | snake_case }}() { +fn {{ test.description | make_ident }}() { let input = {{ test.input.series | json_encode() }}; let length = {{ test.input.sliceLength | json_encode() }}; let output = series(input, length); diff --git a/exercises/practice/sieve/.meta/test_template.tera b/exercises/practice/sieve/.meta/test_template.tera index cd33602d8..fcd7aa4c5 100644 --- a/exercises/practice/sieve/.meta/test_template.tera +++ b/exercises/practice/sieve/.meta/test_template.tera @@ -3,7 +3,7 @@ use sieve::*; {% for test in cases %} #[test] #[ignore] -fn {{ test.description | snake_case }}() { +fn {{ test.description | make_ident }}() { let input = {{ test.input.limit | json_encode() }}; let output = primes_up_to(input); let expected = {{ test.expected | json_encode() }}; diff --git a/exercises/practice/space-age/.meta/test_template.tera b/exercises/practice/space-age/.meta/test_template.tera index a69f248ef..389c6dd1e 100644 --- a/exercises/practice/space-age/.meta/test_template.tera +++ b/exercises/practice/space-age/.meta/test_template.tera @@ -10,7 +10,7 @@ fn assert_in_delta(expected: f64, actual: f64) { {% for test in cases %} #[test] #[ignore] -fn {{ test.description | snake_case }}() { +fn {{ test.description | make_ident }}() { let seconds = {{ test.input.seconds | fmt_num }}; let duration = Duration::from(seconds); let output = {{ test.input.planet }}::years_during(&duration); diff --git a/exercises/practice/spiral-matrix/.meta/test_template.tera b/exercises/practice/spiral-matrix/.meta/test_template.tera index 65637ea9d..7db053341 100644 --- a/exercises/practice/spiral-matrix/.meta/test_template.tera +++ b/exercises/practice/spiral-matrix/.meta/test_template.tera @@ -3,7 +3,7 @@ use spiral_matrix::*; {% for test in cases %} #[test] #[ignore] -fn {{ test.description | snake_case }}() { +fn {{ test.description | make_ident }}() { let input = {{ test.input.size | json_encode() }}; let output = spiral_matrix(input); let expected: [[u32; {{ test.input.size }}]; {{ test.input.size }}] = [ diff --git a/exercises/practice/sublist/.meta/test_template.tera b/exercises/practice/sublist/.meta/test_template.tera index ed6181ece..b4f3540f5 100644 --- a/exercises/practice/sublist/.meta/test_template.tera +++ b/exercises/practice/sublist/.meta/test_template.tera @@ -3,7 +3,7 @@ use sublist::*; {% for test in cases %} #[test] #[ignore] -fn {{ test.description | snake_case }}() { +fn {{ test.description | make_ident }}() { 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); diff --git a/exercises/practice/sum-of-multiples/.meta/test_template.tera b/exercises/practice/sum-of-multiples/.meta/test_template.tera index a4f690cbd..50776e114 100644 --- a/exercises/practice/sum-of-multiples/.meta/test_template.tera +++ b/exercises/practice/sum-of-multiples/.meta/test_template.tera @@ -3,7 +3,7 @@ use sum_of_multiples::*; {% for test in cases %} #[test] #[ignore] -fn {{ test.description | snake_case }}() { +fn {{ test.description | make_ident }}() { let factors = &{{ test.input.factors | json_encode() }}; let limit = {{ test.input.limit | fmt_num }}; let output = sum_of_multiples(limit, factors); diff --git a/exercises/practice/tournament/.meta/test_template.tera b/exercises/practice/tournament/.meta/test_template.tera index c6819eb5f..acc85890a 100644 --- a/exercises/practice/tournament/.meta/test_template.tera +++ b/exercises/practice/tournament/.meta/test_template.tera @@ -3,7 +3,7 @@ use tournament::*; {% for test in cases %} #[test] #[ignore] -fn {{ test.description | snake_case }}() { +fn {{ test.description | make_ident }}() { let input: &[&str] = &{{ test.input.rows | json_encode() }}; let input = input.join("\n"); let output = tally(&input); diff --git a/exercises/practice/triangle/.meta/test_template.tera b/exercises/practice/triangle/.meta/test_template.tera index 329f8ff95..cd13aa6c0 100644 --- a/exercises/practice/triangle/.meta/test_template.tera +++ b/exercises/practice/triangle/.meta/test_template.tera @@ -10,7 +10,7 @@ mod {{ test_group.description | split(pat=" ") | first }} { {% if test.description is containing("float") %} #[cfg(feature = "generic")] {% endif -%} -fn {{ test.description | snake_case }}() { +fn {{ test.description | make_ident }}() { let input = {{ test.input.sides | json_encode() }}; let output = Triangle::build(input).unwrap(); {%- if test.expected %} @@ -26,7 +26,7 @@ fn {{ test.description | snake_case }}() { {% if test.scenarios and test.scenarios is containing("floating-point") %} #[cfg(feature = "generic")] {% endif -%} -fn {{ test.description | snake_case }}() { +fn {{ test.description | make_ident }}() { let input = {{ test.input.sides | json_encode() }}; let output = Triangle::build(input).unwrap(); {%- if test.expected %} @@ -42,7 +42,7 @@ fn {{ test.description | snake_case }}() { {% if test.scenarios and test.scenarios is containing("floating-point") %} #[cfg(feature = "generic")] {% endif -%} -fn {{ test.description | snake_case }}() { +fn {{ test.description | make_ident }}() { let input = {{ test.input.sides | json_encode() }}; let output = Triangle::build(input).unwrap(); {%- if test.expected %} @@ -58,7 +58,7 @@ fn {{ test.description | snake_case }}() { {% if test.scenarios and test.scenarios is containing("floating-point") %} #[cfg(feature = "generic")] {% endif -%} -fn {{ test.description | snake_case }}() { +fn {{ test.description | make_ident }}() { let input = {{ test.input.sides | json_encode() }}; let output = Triangle::build(input); assert!(output.is_none()); diff --git a/exercises/practice/two-bucket/.meta/test_template.tera b/exercises/practice/two-bucket/.meta/test_template.tera index ebf9bb81e..959791f8b 100644 --- a/exercises/practice/two-bucket/.meta/test_template.tera +++ b/exercises/practice/two-bucket/.meta/test_template.tera @@ -11,7 +11,7 @@ use two_bucket::*; {% for test in cases %} #[test] #[ignore] -fn {{ test.description | snake_case }}() { +fn {{ test.description | make_ident }}() { let output = solve( {{ test.input.bucketOne }}, {{ test.input.bucketTwo }}, {{ test.input.goal }}, &{{ self::bucket(label=test.input.startBucket) }}, diff --git a/exercises/practice/variable-length-quantity/.meta/test_template.tera b/exercises/practice/variable-length-quantity/.meta/test_template.tera index f09cf6504..03131daca 100644 --- a/exercises/practice/variable-length-quantity/.meta/test_template.tera +++ b/exercises/practice/variable-length-quantity/.meta/test_template.tera @@ -4,7 +4,7 @@ use variable_length_quantity as vlq; {% for test in test_group.cases %} #[test] #[ignore] -fn {{ test.description | snake_case }}() { +fn {{ test.description | make_ident }}() { {%- if test.property == "encode" %} let input = &[{% for integer in test.input.integers -%} {{ integer | fmt_num }}, diff --git a/exercises/practice/word-count/.meta/test_template.tera b/exercises/practice/word-count/.meta/test_template.tera index 6e313e057..931086036 100644 --- a/exercises/practice/word-count/.meta/test_template.tera +++ b/exercises/practice/word-count/.meta/test_template.tera @@ -3,7 +3,7 @@ use word_count::*; {% for test in cases %} #[test] #[ignore] -fn {{ test.description | snake_case }}() { +fn {{ test.description | make_ident }}() { let input = {{ test.input.sentence | json_encode() }}; let mut output = word_count(input); let expected = [{% for key, value in test.expected -%} diff --git a/exercises/practice/wordy/.meta/test_template.tera b/exercises/practice/wordy/.meta/test_template.tera index b6e729d01..33cebd2ae 100644 --- a/exercises/practice/wordy/.meta/test_template.tera +++ b/exercises/practice/wordy/.meta/test_template.tera @@ -6,7 +6,7 @@ use wordy::*; {% if test.property == "exponentials" -%} #[cfg(feature = "exponentials")] {% endif -%} -fn {{ test.description | snake_case }}() { +fn {{ test.description | make_ident }}() { let input = {{ test.input.question | json_encode() }}; let output = answer(input); let expected = {% if test.expected is object -%} diff --git a/exercises/practice/xorcism/.meta/test_template.tera b/exercises/practice/xorcism/.meta/test_template.tera index 58fdea30c..746d7f093 100644 --- a/exercises/practice/xorcism/.meta/test_template.tera +++ b/exercises/practice/xorcism/.meta/test_template.tera @@ -80,7 +80,7 @@ fn statefulness() { {% for test in cases %} -mod {{ test.description | snake_case }} { +mod {{ test.description | make_ident }} { use super::*; diff --git a/rust-tooling/generate/src/custom_filters.rs b/rust-tooling/generate/src/custom_filters.rs index 302cc8fa9..dcef8b45c 100644 --- a/rust-tooling/generate/src/custom_filters.rs +++ b/rust-tooling/generate/src/custom_filters.rs @@ -6,8 +6,7 @@ type Filter = fn(&Value, &HashMap) -> Result; pub static CUSTOM_FILTERS: &[(&str, Filter)] = &[ ("to_hex", to_hex), - ("snake_case", snake_case), - ("make_test_ident", make_test_ident), + ("make_ident", make_ident), ("fmt_num", fmt_num), ]; @@ -21,32 +20,19 @@ pub fn to_hex(value: &Value, _args: &HashMap) -> Result { Ok(serde_json::Value::String(format!("{:x}", value))) } -pub fn snake_case(value: &Value, _args: &HashMap) -> Result { +pub fn make_ident(value: &Value, _args: &HashMap) -> Result { let Some(value) = value.as_str() else { return Err(tera::Error::call_filter( - "snake_case filter expects a string", - "serde_json::value::Value::as_str", - )); - }; - Ok(serde_json::Value::String( - // slug is the same dependency tera uses for its builtin 'slugify' - slug::slugify(value).replace('-', "_"), - )) -} - -pub fn make_test_ident(value: &Value, _args: &HashMap) -> Result { - let value = snake_case(value, _args)?; - let Some(value) = value.as_str() else { - return Err(tera::Error::call_filter( - "make_test_ident filter expects a string", + "make_ident filter expects a string", "serde_json::value::Value::as_str", )); }; + let value = slug::slugify(value).replace('-', "_"); if !value.chars().next().unwrap_or_default().is_alphabetic() { // identifiers cannot start with digits etc. return Ok(Value::String(format!("test_{value}"))); } - Ok(Value::String(value.into())) + Ok(Value::String(value)) } pub fn fmt_num(value: &Value, _args: &HashMap) -> Result { diff --git a/rust-tooling/generate/templates/default_test_template.tera b/rust-tooling/generate/templates/default_test_template.tera index 448333d3f..d20dde1f6 100644 --- a/rust-tooling/generate/templates/default_test_template.tera +++ b/rust-tooling/generate/templates/default_test_template.tera @@ -3,7 +3,7 @@ use crate_name::*; {% for test in cases %} #[test] #[ignore] -fn {{ test.description | snake_case }}() { +fn {{ test.description | make_ident }}() { let input = {{ test.input | json_encode() }}; let output = function_name(input); let expected = {{ test.expected | json_encode() }};