team-leader: Added bonus 1 exercise (in rust!) to repo (still to finish)
git-svn-id: svn+ssh://atelier.inf.usi.ch/home/bevilj/group-1@21 a672b425-5310-4d7a-af5c-997e18724b81
This commit is contained in:
parent
55d74bd90e
commit
4aad7e0023
5 changed files with 1281 additions and 9 deletions
2
bonus1/.svnignore
Normal file
2
bonus1/.svnignore
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
target
|
||||||
|
**/*.rs.bk
|
1213
bonus1/Cargo.lock
generated
Normal file
1213
bonus1/Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load diff
9
bonus1/Cargo.toml
Normal file
9
bonus1/Cargo.toml
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
[package]
|
||||||
|
name = "bonus1"
|
||||||
|
version = "0.1.0"
|
||||||
|
authors = ["Claudio Maggioni <claudio@maggioni.xyz>"]
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
reqwest = "0.9.4"
|
||||||
|
regex = "1"
|
||||||
|
lazy_static = "1.1.0"
|
57
bonus1/src/main.rs
Normal file
57
bonus1/src/main.rs
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
/// # Bonus 1: link linter
|
||||||
|
///
|
||||||
|
/// *Authors:* Claudio Maggioni, Joey Bevilacqua
|
||||||
|
///
|
||||||
|
/// Group 1
|
||||||
|
|
||||||
|
extern crate reqwest;
|
||||||
|
extern crate regex;
|
||||||
|
#[macro_use]
|
||||||
|
extern crate lazy_static;
|
||||||
|
|
||||||
|
use std::fs::File;
|
||||||
|
use std::io;
|
||||||
|
use std::io::prelude::*;
|
||||||
|
use regex::Regex;
|
||||||
|
|
||||||
|
fn read_file(path: &str) -> io::Result<String> {
|
||||||
|
let mut file = File::open(path)?;
|
||||||
|
let mut contents = String::new();
|
||||||
|
|
||||||
|
file.read_to_string(&mut contents)?;
|
||||||
|
Ok(contents)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn find_urls(html: &str) -> Vec<String> {
|
||||||
|
let mut results: Vec<String> = Vec::new();
|
||||||
|
|
||||||
|
lazy_static! {
|
||||||
|
static ref RE: Regex = Regex::new("(?:(?:href)|(?:src))=\"([^\"]*)\"").unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
for cap in RE.captures_iter(html) {
|
||||||
|
results.push(cap[1].to_string());
|
||||||
|
}
|
||||||
|
|
||||||
|
results
|
||||||
|
}
|
||||||
|
|
||||||
|
fn is_url_working(url: &str) -> bool {
|
||||||
|
let res: Result<reqwest::Response, reqwest::Error> = reqwest::get(url);
|
||||||
|
match res {
|
||||||
|
Ok(r) => r.status().is_success(),
|
||||||
|
Err(_) => false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_is_url_working() {
|
||||||
|
assert!(is_url_working("https://www.google.com"));
|
||||||
|
assert!(is_url_working("https://xkcd.com"));
|
||||||
|
assert!(!is_url_working("https://xkcd.com/404"));
|
||||||
|
assert!(!is_url_working("notaurl"));
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
|
||||||
|
}
|
|
@ -1,9 +0,0 @@
|
||||||
---
|
|
||||||
---
|
|
||||||
@charset "utf-8";
|
|
||||||
|
|
||||||
@import "syntax-highlighting";
|
|
||||||
|
|
||||||
@import "footer";
|
|
||||||
|
|
||||||
@import "header";
|
|
Loading…
Reference in a new issue