--- /dev/null
+use std::error::Error;
+use std::fs;
+
+pub struct Config {
+ file_path: String,
+}
+
+impl Config {
+ pub fn new(args: &[String]) -> Result<Config, &'static str> {
+ if args.len() < 2 {
+ return Err("Not enough provided arguments...");
+ }
+ let file_path = args[1].clone();
+ Ok(Config { file_path })
+ }
+}
+
+pub fn run(config: Config) -> Result<(), Box<dyn Error>> {
+ let contents = fs::read_to_string(config.file_path)?;
+ let tokens = tokenize(&contents);
+ println!("{contents}");
+ for line in tokens {
+ println!("{:?}", line);
+ }
+ Ok(())
+}
+
+pub fn tokenize<'a>(contents: &'a str) -> Vec<Vec<&'a str>> {
+ let mut tokens = Vec::new();
+ for line in contents.lines() {
+ let mut line_tokens: Vec<&str> = line.split(' ').collect();
+ line_tokens.retain(|t| t.len() > 0);
+ tokens.push(line_tokens)
+ }
+ tokens
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn single_line_whitespace_simple() {
+ let contents = "\
+ dette er en banal test.";
+
+ let mut left_side = Vec::new();
+ let c = vec!["dette", "er", "en", "banal", "test."];
+ left_side.push(c);
+ let right_side = tokenize(&contents);
+
+ assert_eq!(left_side, right_side);
+ }
+ #[test]
+ fn multi_line_whitespace_simple() {
+ let contents = "\
+ dette er en banal test \n som inneholder to linjer";
+
+ let mut left_side = Vec::new();
+ let c1 = vec!["dette", "er", "en", "banal", "test"];
+ let c2 = vec!["som", "inneholder", "to", "linjer"];
+ left_side.push(c1);
+ left_side.push(c2);
+ let right_side = tokenize(&contents);
+
+ assert_eq!(left_side, right_side);
+ }
+}