From 37002407dd8cf6f6770f4478fecdecaaff0e4b99 Mon Sep 17 00:00:00 2001
From: "robinwilliam.hundt" <robinwilliam.hundt@stud.uni-goettingen.de>
Date: Sat, 12 Oct 2019 12:40:03 +0200
Subject: [PATCH] Changed `display_code` to `source_code`

---
 Cargo.lock                          |  2 +-
 Cargo.toml                          |  2 +-
 src/lib.rs                          | 23 +++++++++++--------
 src/main.rs                         | 32 ++++++++++++++------------
 src/parser/ipynb_parser/notebook.rs |  2 +-
 src/submission.rs                   | 11 ++++-----
 src/test_output.rs                  |  2 --
 src/testrunner/mod.rs               | 11 +++++----
 tests/test_xml_parser.rs            | 35 ++++++++++++-----------------
 9 files changed, 60 insertions(+), 60 deletions(-)

diff --git a/Cargo.lock b/Cargo.lock
index b15e8e7..d0040d4 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -998,7 +998,7 @@ dependencies = [
 
 [[package]]
 name = "rusty-hektor"
-version = "4.0.0"
+version = "5.0.0"
 dependencies = [
  "base64 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)",
  "calamine 0.15.5 (registry+https://github.com/rust-lang/crates.io-index)",
diff --git a/Cargo.toml b/Cargo.toml
index 44d321f..8810160 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
 [package]
 name = "rusty-hektor"
-version = "4.0.0"
+version = "5.0.0"
 authors = ["robinwilliam.hundt <robinwilliam.hundt@stud.uni-goettingen.de>"]
 license = "MIT OR Apache-2.0"
 description = "A tool to convert ILIAS exam output"
diff --git a/src/lib.rs b/src/lib.rs
index 4efa1f5..830efc9 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1,12 +1,11 @@
 #[macro_use]
 extern crate serde_derive;
 
-use std::{io, io::Write};
-use std::collections::BTreeSet;
 use std::error::Error;
 use std::fmt::Debug;
 use std::result::Result;
 use std::str::FromStr;
+use std::{io, io::Write};
 
 pub use crate::exam::ExamSerializable;
 use crate::student::StudentSerializable;
@@ -68,13 +67,19 @@ where
     }
 }
 
-
 pub fn run_test(test: Box<dyn Test>, students: &mut [StudentSerializable]) {
     for student in students {
-        student.submissions = student.submissions.clone().into_iter().map(|mut submission| {
-            let test_output = test.run(&submission);
-            submission.tests.insert(test_output.name.clone(), test_output);
-            submission
-        }).collect()
+        student.submissions = student
+            .submissions
+            .clone()
+            .into_iter()
+            .map(|mut submission| {
+                let test_output = test.run(&submission);
+                submission
+                    .tests
+                    .insert(test_output.name.clone(), test_output);
+                submission
+            })
+            .collect()
     }
-}
\ No newline at end of file
+}
diff --git a/src/main.rs b/src/main.rs
index 4e75455..2b0eba7 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -11,17 +11,17 @@ use semver::Version;
 use serde_derive::Deserialize;
 use structopt::StructOpt;
 
-use ParsedData::*;
-use rusty_hektor::{anonymizer, run_test};
 use rusty_hektor::exam::{Exam, ExamSerializable};
 use rusty_hektor::module::Module;
-use rusty_hektor::parser::{Parser, ParserError};
 use rusty_hektor::parser::ipynb_parser::notebook::Notebook;
 use rusty_hektor::parser::xml_parser::XMLParser;
+use rusty_hektor::parser::{Parser, ParserError};
 use rusty_hektor::student::StudentSerializable;
 use rusty_hektor::submission_type::{ProgrammingLang, SubmissionType};
 use rusty_hektor::testrunner::empty_test::EmptyTest;
 use rusty_hektor::testrunner::Test;
+use rusty_hektor::{anonymizer, run_test};
+use ParsedData::*;
 
 /// Parse ILIAS exam export for importing into Grady
 #[derive(Debug, StructOpt)]
@@ -53,20 +53,24 @@ struct Opt {
     tests: Vec<TestEnum>,
 
     /// Where to store the anonymisation map file, if enabled
-    #[structopt(short, long = "map-file", name="MAP_FILE_PATH", default_value = "anon.csv")]
+    #[structopt(
+        short,
+        long = "map-file",
+        name = "MAP_FILE_PATH",
+        default_value = "anon.csv"
+    )]
     map_file_name: PathBuf,
 }
 
-
 #[derive(Clone, Debug)]
 enum TestEnum {
-    Empty
+    Empty,
 }
 
 impl TestEnum {
     fn as_test(&self) -> Box<dyn Test> {
         match self {
-            Self::Empty => Box::new(EmptyTest {})
+            Self::Empty => Box::new(EmptyTest {}),
         }
     }
 }
@@ -75,16 +79,16 @@ impl From<&OsStr> for TestEnum {
     fn from(s: &OsStr) -> Self {
         match s.to_str().expect("Non UTF-8 string in tests") {
             "empty" => Self::Empty,
-            _ => panic!("Unable to parse test. Allowed values: empty")
+            _ => panic!("Unable to parse test. Allowed values: empty"),
         }
     }
 
-//    fn from_str(s: &str) -> Result<Self, Self::Err> {
-//        match s {
-//            "empty" => Ok(Self::Empty),
-//            _ => Err("Unable to parse test. Allowed values: empty")?
-//        }
-//    }
+    //    fn from_str(s: &str) -> Result<Self, Self::Err> {
+    //        match s {
+    //            "empty" => Ok(Self::Empty),
+    //            _ => Err("Unable to parse test. Allowed values: empty")?
+    //        }
+    //    }
 }
 
 enum ParsedData {
diff --git a/src/parser/ipynb_parser/notebook.rs b/src/parser/ipynb_parser/notebook.rs
index b7ed3ae..93421ae 100644
--- a/src/parser/ipynb_parser/notebook.rs
+++ b/src/parser/ipynb_parser/notebook.rs
@@ -4,8 +4,8 @@ use std::error::Error;
 use std::fmt::{Display, Formatter};
 use std::str::FromStr;
 
-use regex::Regex;
 use lazy_static::lazy_static;
+use regex::Regex;
 
 /// Media attachments (e.g. inline images), stored as mimebundle keyed by filename.
 #[derive(Clone, PartialEq, Debug, Deserialize, Serialize)]
diff --git a/src/submission.rs b/src/submission.rs
index a84afe9..37e90a2 100644
--- a/src/submission.rs
+++ b/src/submission.rs
@@ -1,9 +1,9 @@
+use crate::test_output::TestOutput;
 use serde::export::fmt::Display;
 use std::collections::BTreeMap;
 use std::error::Error;
 use std::hash::{Hash, Hasher};
 use std::str::FromStr;
-use crate::test_output::TestOutput;
 
 #[derive(Debug, Eq, PartialEq, Serialize, Default, Clone, PartialOrd, Ord)]
 pub struct Submission {
@@ -11,7 +11,7 @@ pub struct Submission {
     /// This field is populated if the displayed source code differs from the
     /// source. We use this for the correction of `.ipynb` notebooks which we transform
     /// into a python script to display but want to keep the original notebook as json
-    pub display_code: Option<String>,
+    pub source_code: Option<String>,
     pub r#type: String,
     pub tests: BTreeMap<String, TestOutput>,
 }
@@ -20,7 +20,7 @@ impl Submission {
     pub fn new(code: String, r#type: String) -> Self {
         Submission {
             code,
-            display_code: None,
+            source_code: None,
             r#type,
             tests: BTreeMap::new(),
         }
@@ -32,7 +32,8 @@ impl Submission {
         <T as FromStr>::Err: Error + 'static,
     {
         let intermediate: T = self.code.parse()?;
-        self.display_code = Some(intermediate.to_string());
+        let source = std::mem::replace(&mut self.code, intermediate.to_string());
+        self.source_code = Some(source);
         Ok(())
     }
 }
@@ -40,7 +41,7 @@ impl Submission {
 impl Hash for Submission {
     fn hash<H: Hasher>(&self, state: &mut H) {
         self.code.hash(state);
-        self.display_code.hash(state);
+        self.source_code.hash(state);
         self.r#type.hash(state);
     }
 }
diff --git a/src/test_output.rs b/src/test_output.rs
index ead9a43..62bc933 100644
--- a/src/test_output.rs
+++ b/src/test_output.rs
@@ -1,5 +1,3 @@
-
-
 #[derive(Debug, Eq, PartialEq, Serialize, Default, Clone, PartialOrd, Ord)]
 pub struct TestOutput {
     pub name: String,
diff --git a/src/testrunner/mod.rs b/src/testrunner/mod.rs
index e9b15ae..295df0a 100644
--- a/src/testrunner/mod.rs
+++ b/src/testrunner/mod.rs
@@ -5,22 +5,21 @@ pub trait Test {
     fn run(&self, submission: &Submission) -> TestOutput;
 }
 
-
 pub mod empty_test {
-    use crate::testrunner::Test;
     use crate::submission::Submission;
     use crate::test_output::TestOutput;
+    use crate::testrunner::Test;
 
     enum Labels {
         Empty,
-        NotEmpty
+        NotEmpty,
     }
 
     impl Labels {
         fn as_str(&self) -> &'static str {
             match self {
                 Self::Empty => "EMPTY",
-                Self::NotEmpty => "NOT_EMPTY"
+                Self::NotEmpty => "NOT_EMPTY",
             }
         }
     }
@@ -30,12 +29,12 @@ pub mod empty_test {
         fn run(&self, submission: &Submission) -> TestOutput {
             let label = match submission.code.trim().len() {
                 0 => Labels::Empty,
-                _ => Labels::NotEmpty
+                _ => Labels::NotEmpty,
             };
             TestOutput {
                 name: "EmptyTest".to_string(),
                 annotation: "".to_string(),
-                label: label.as_str().to_string()
+                label: label.as_str().to_string(),
             }
         }
     }
diff --git a/tests/test_xml_parser.rs b/tests/test_xml_parser.rs
index c0d9e7f..b534c46 100644
--- a/tests/test_xml_parser.rs
+++ b/tests/test_xml_parser.rs
@@ -2,8 +2,8 @@ use std::error::Error;
 use std::path::Path;
 
 use rusty_hektor::parser::{xml_parser::XMLParser, Parser};
-use std::collections::{HashSet, BTreeSet};
 use rusty_hektor::student::StudentSerializable;
+use std::collections::{BTreeSet, HashSet};
 
 #[test]
 fn can_parse_zipped_xml_data() -> Result<(), Box<dyn Error>> {
@@ -14,7 +14,6 @@ fn can_parse_zipped_xml_data() -> Result<(), Box<dyn Error>> {
     Ok(())
 }
 
-
 #[test]
 fn parsed_xml_contains_correct_submission_types() -> Result<(), Box<dyn Error>> {
     let parsed = XMLParser::parse(Path::new("tests/test.zip"), false)?;
@@ -26,9 +25,7 @@ fn parsed_xml_contains_correct_submission_types() -> Result<(), Box<dyn Error>>
         .map(|st| st.name)
         .collect();
 
-    let expected: HashSet<String> = [
-        "Eine Bibliothek für Permutationen (I1-ID: l120mlc005h0)",
-    ]
+    let expected: HashSet<String> = ["Eine Bibliothek für Permutationen (I1-ID: l120mlc005h0)"]
         .iter()
         .map(|s| s.to_string())
         .collect();
@@ -52,17 +49,15 @@ fn parsed_xls_contains_correct_students() -> Result<(), Box<dyn Error>> {
         })
         .collect();
 
-    let students_expected: BTreeSet<StudentSerializable> = [
-        StudentSerializable {
-            fullname: "Test, User".to_owned(),
-            identifier: "20000000".to_owned(),
-            username: "TU20000000".to_owned(),
-            ..StudentSerializable::default()
-        },
-    ]
-        .into_iter()
-        .cloned()
-        .collect();
+    let students_expected: BTreeSet<StudentSerializable> = [StudentSerializable {
+        fullname: "Test, User".to_owned(),
+        identifier: "20000000".to_owned(),
+        username: "TU20000000".to_owned(),
+        ..StudentSerializable::default()
+    }]
+    .into_iter()
+    .cloned()
+    .collect();
 
     assert_eq!(students_expected, students);
 
@@ -101,9 +96,7 @@ fn correct_mapping_is_generated() -> Result<(), Box<dyn Error>> {
     let find_student_in_map = |num| {
         student_map_items
             .iter()
-            .find(|item| {
-                item[1] == format!("2000000{}", num)
-            })
+            .find(|item| item[1] == format!("2000000{}", num))
             .expect(format!("Unable to find Student{} in mapping", num).as_str())
     };
 
@@ -118,7 +111,7 @@ fn correct_mapping_is_generated() -> Result<(), Box<dyn Error>> {
             .expect("No Student in serializable data")
     };
 
-    for student in [student0, ].iter() {
+    for student in [student0].iter() {
         assert_eq!(
             1,
             find_student_by_key_in_serializable(student[0])
@@ -137,7 +130,7 @@ fn correct_mapping_is_generated() -> Result<(), Box<dyn Error>> {
                     "Unable to find Submission {} for {}",
                     sub_type_name, stud_key
                 )
-                    .as_str(),
+                .as_str(),
             )
             .code
     };
-- 
GitLab