Skip to content

Commit

Permalink
Sync reverse-string with problem-specifications (#1784)
Browse files Browse the repository at this point in the history
Addittional tests for unicode and grapheme clusters.

[no important files changed]
  • Loading branch information
senekor authored Nov 20, 2023
1 parent 098c092 commit 96f03aa
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 33 deletions.
20 changes: 20 additions & 0 deletions exercises/practice/reverse-string/.meta/additional-tests.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
15 changes: 15 additions & 0 deletions exercises/practice/reverse-string/.meta/test_template.tera
Original file line number Diff line number Diff line change
@@ -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 -%}
31 changes: 28 additions & 3 deletions exercises/practice/reverse-string/.meta/tests.toml
Original file line number Diff line number Diff line change
@@ -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"
62 changes: 32 additions & 30 deletions exercises/practice/reverse-string/tests/reverse-string.rs
Original file line number Diff line number Diff line change
@@ -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);
}

0 comments on commit 96f03aa

Please sign in to comment.