Browse Source

Add subject and test for the exercise `to_url`

content-update
Augusto 3 years ago
parent
commit
81d0db3466
  1. 12
      rust/tests/to_url_test/Cargo.lock
  2. 10
      rust/tests/to_url_test/Cargo.toml
  3. 19
      rust/tests/to_url_test/src/main.rs
  4. 31
      subjects/to_url/README.md

12
rust/tests/to_url_test/Cargo.lock diff.generated

@ -0,0 +1,12 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]]
name = "to_url"
version = "0.1.0"
[[package]]
name = "to_url_test"
version = "0.1.0"
dependencies = [
"to_url",
]

10
rust/tests/to_url_test/Cargo.toml

@ -0,0 +1,10 @@
[package]
name = "to_url_test"
version = "0.1.0"
authors = ["Augusto <aug.ornelas@gmail.com>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
to_url = { path = "../../../../rust-piscine-solutions/to_url"}

19
rust/tests/to_url_test/src/main.rs

@ -0,0 +1,19 @@
// Define a function called `to_url` that takes a string and
// substitutes every white-space with '%20'
use to_url::*;
fn main() {
let s = "Hello, world!";
println!("{} to be use as an url is {}", s, to_url(s));
}
#[cfg(test)]
mod test {
use super::*;
#[test]
fn test_url() {
assert_eq!(to_url("this is my search"), "this%20is%20my%20search");
}
}

31
subjects/to_url/README.md

@ -0,0 +1,31 @@
## to_url
### Instructions
Define a function called `to_url` that takes a string and substitutes every white-space with '%20'
### Expected Function
```rust
pub fn to_url(s: &str) -> String {
}
```
### Usage
Here is a program to test your function.
```rust
fn main() {
let s = "Hello, world!";
println!("{} to be use as an url is {}", s, to_url(s));
}
```
And its output
```console
student@ubuntu:~/[[ROOT]]/test$ cargo run
Hello, world! to be use as an url is Hello,%20world!
student@ubuntu:~/[[ROOT]]/test$
```
Loading…
Cancel
Save