From 96f03aa8a4af88300673c7491cb52bd2cf51f3db Mon Sep 17 00:00:00 2001 From: Remo Senekowitsch Date: Mon, 20 Nov 2023 14:22:59 +0100 Subject: [PATCH] Sync reverse-string with problem-specifications (#1784) Addittional tests for unicode and grapheme clusters. [no important files changed] --- .../.meta/additional-tests.json | 20 ++++++ .../reverse-string/.meta/test_template.tera | 15 +++++ .../practice/reverse-string/.meta/tests.toml | 31 +++++++++- .../reverse-string/tests/reverse-string.rs | 62 ++++++++++--------- 4 files changed, 95 insertions(+), 33 deletions(-) create mode 100644 exercises/practice/reverse-string/.meta/additional-tests.json create mode 100644 exercises/practice/reverse-string/.meta/test_template.tera diff --git a/exercises/practice/reverse-string/.meta/additional-tests.json b/exercises/practice/reverse-string/.meta/additional-tests.json new file mode 100644 index 000000000..69279b378 --- /dev/null +++ b/exercises/practice/reverse-string/.meta/additional-tests.json @@ -0,0 +1,20 @@ +[ + { + "uuid": "01ebf55b-bebb-414e-9dec-06f7bb0bee3c", + "description": "wide characters", + "property": "reverse", + "input": { + "value": "子猫" + }, + "expected": "猫子" + }, + { + "uuid": "01ebf55b-bebb-414e-9dec-06f7bb0bee3c", + "description": "grapheme clusters", + "property": "grapheme", + "input": { + "value": "uüu" + }, + "expected": "uüu" + } +] diff --git a/exercises/practice/reverse-string/.meta/test_template.tera b/exercises/practice/reverse-string/.meta/test_template.tera new file mode 100644 index 000000000..4a14c3264 --- /dev/null +++ b/exercises/practice/reverse-string/.meta/test_template.tera @@ -0,0 +1,15 @@ +{% for test in cases %} +#[test] +{% if loop.index != 1 -%} +#[ignore] +{% endif -%} +{% if test.property == "grapheme" -%} +#[cfg(feature = "grapheme")] +{% endif -%} +fn {{ test.description | slugify | replace(from="-", to="_") }}() { + let input = {{ test.input.value | json_encode() }}; + let output = {{ crate_name }}::{{ fn_names[0] }}(input); + let expected = {{ test.expected | json_encode() }}; + assert_eq!(output, expected); +} +{% endfor -%} diff --git a/exercises/practice/reverse-string/.meta/tests.toml b/exercises/practice/reverse-string/.meta/tests.toml index be690e975..0b04c4cd7 100644 --- a/exercises/practice/reverse-string/.meta/tests.toml +++ b/exercises/practice/reverse-string/.meta/tests.toml @@ -1,3 +1,28 @@ -# This is an auto-generated file. Regular comments will be removed when this -# file is regenerated. Regenerating will not touch any manually added keys, -# so comments can be added in a "comment" key. +# This is an auto-generated file. +# +# Regenerating this file via `configlet sync` will: +# - Recreate every `description` key/value pair +# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications +# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion) +# - Preserve any other key/value pair +# +# As user-added comments (using the # character) will be removed when this file +# is regenerated, comments can be added via a `comment` key. + +[c3b7d806-dced-49ee-8543-933fd1719b1c] +description = "an empty string" + +[01ebf55b-bebb-414e-9dec-06f7bb0bee3c] +description = "a word" + +[0f7c07e4-efd1-4aaa-a07a-90b49ce0b746] +description = "a capitalized word" + +[71854b9c-f200-4469-9f5c-1e8e5eff5614] +description = "a sentence with punctuation" + +[1f8ed2f3-56f3-459b-8f3e-6d8d654a1f6c] +description = "a palindrome" + +[b9e7dec1-c6df-40bd-9fa3-cd7ded010c4c] +description = "an even-sized word" diff --git a/exercises/practice/reverse-string/tests/reverse-string.rs b/exercises/practice/reverse-string/tests/reverse-string.rs index b80eef344..fee55ee39 100644 --- a/exercises/practice/reverse-string/tests/reverse-string.rs +++ b/exercises/practice/reverse-string/tests/reverse-string.rs @@ -1,69 +1,71 @@ -//! Tests for reverse-string -//! -//! Generated by [script][script] using [canonical data][canonical-data] -//! -//! [script]: https://github.com/exercism/rust/blob/b829ce2/bin/init_exercise.py -//! [canonical-data]: https://raw.githubusercontent.com/exercism/problem-specifications/main/exercises/reverse-string/canonical_data.json - -use reverse_string::*; - -/// Process a single test case for the property `reverse` -fn process_reverse_case(input: &str, expected: &str) { - assert_eq!(&reverse(input), expected) -} - #[test] -/// empty string fn an_empty_string() { - process_reverse_case("", ""); + let input = ""; + let output = reverse_string::reverse(input); + let expected = ""; + assert_eq!(output, expected); } #[test] #[ignore] -/// a word fn a_word() { - process_reverse_case("robot", "tobor"); + let input = "robot"; + let output = reverse_string::reverse(input); + let expected = "tobor"; + assert_eq!(output, expected); } #[test] #[ignore] -/// a capitalized word fn a_capitalized_word() { - process_reverse_case("Ramen", "nemaR"); + let input = "Ramen"; + let output = reverse_string::reverse(input); + let expected = "nemaR"; + assert_eq!(output, expected); } #[test] #[ignore] -/// a sentence with punctuation fn a_sentence_with_punctuation() { - process_reverse_case("I'm hungry!", "!yrgnuh m'I"); + let input = "I'm hungry!"; + let output = reverse_string::reverse(input); + let expected = "!yrgnuh m'I"; + assert_eq!(output, expected); } #[test] #[ignore] -/// a palindrome fn a_palindrome() { - process_reverse_case("racecar", "racecar"); + let input = "racecar"; + let output = reverse_string::reverse(input); + let expected = "racecar"; + assert_eq!(output, expected); } #[test] #[ignore] -/// an even-sized word fn an_even_sized_word() { - process_reverse_case("drawer", "reward"); + let input = "drawer"; + let output = reverse_string::reverse(input); + let expected = "reward"; + assert_eq!(output, expected); } #[test] #[ignore] -/// wide characters fn wide_characters() { - process_reverse_case("子猫", "猫子"); + let input = "子猫"; + let output = reverse_string::reverse(input); + let expected = "猫子"; + assert_eq!(output, expected); } #[test] #[ignore] #[cfg(feature = "grapheme")] -/// grapheme clusters fn grapheme_clusters() { - process_reverse_case("uüu", "uüu"); + let input = "uüu"; + let output = reverse_string::reverse(input); + let expected = "uüu"; + assert_eq!(output, expected); }