From 6028ab60c90f8e6a36a248b06eb20bc1de75d373 Mon Sep 17 00:00:00 2001 From: Bo Lopker Date: Fri, 21 Feb 2025 14:47:02 -0800 Subject: [PATCH] Fix unittests --- crates/codebook/tests/examples/example.go | 18 ++++++ crates/codebook/tests/examples/example.html | 10 +++ crates/codebook/tests/examples/example.js | 69 +++++++++++++++++++++ crates/codebook/tests/examples/example.md | 5 ++ crates/codebook/tests/examples/example.py | 20 ++++++ crates/codebook/tests/examples/example.rs | 9 +++ crates/codebook/tests/examples/example.ts | 45 ++++++++++++++ crates/codebook/tests/examples/example.txt | 1 + crates/codebook/tests/test_files.rs | 2 +- 9 files changed, 178 insertions(+), 1 deletion(-) create mode 100644 crates/codebook/tests/examples/example.go create mode 100644 crates/codebook/tests/examples/example.html create mode 100644 crates/codebook/tests/examples/example.js create mode 100644 crates/codebook/tests/examples/example.md create mode 100644 crates/codebook/tests/examples/example.py create mode 100644 crates/codebook/tests/examples/example.rs create mode 100644 crates/codebook/tests/examples/example.ts create mode 100644 crates/codebook/tests/examples/example.txt diff --git a/crates/codebook/tests/examples/example.go b/crates/codebook/tests/examples/example.go new file mode 100644 index 0000000..1d1155e --- /dev/null +++ b/crates/codebook/tests/examples/example.go @@ -0,0 +1,18 @@ +package main + +import ( + "fmt" +) + +func main() { + // I'm bad at speling alice + fmt.Println("Hello, Wolrd!") + var alicz = "Alicz" + fmt.Println("Hello, " + alicz) + var rsvp = "RSVP" + fmt.Println("Hello, " + rsvp) +} + +func mispeledFuncion() string { + return "" +} diff --git a/crates/codebook/tests/examples/example.html b/crates/codebook/tests/examples/example.html new file mode 100644 index 0000000..35c2132 --- /dev/null +++ b/crates/codebook/tests/examples/example.html @@ -0,0 +1,10 @@ + + + + + Documentt + + + Spelin sor good. Wolrd + + diff --git a/crates/codebook/tests/examples/example.js b/crates/codebook/tests/examples/example.js new file mode 100644 index 0000000..028912f --- /dev/null +++ b/crates/codebook/tests/examples/example.js @@ -0,0 +1,69 @@ +// Calculater function with spelling mistakes +function calculater(numbr1, numbr2, operashun) { + let resalt; + + switch (operashun) { + case "additshun": + resalt = numbr1 + numbr2; + break; + case "substractshun": + resalt = numbr1 - numbr2; + break; + case "multiplacation": + resalt = numbr1 * numbr2; + break; + case "divishun": + if (numbr2 === 0) { + return "Cannot divde by zero"; + } + resalt = numbr1 / numbr2; + break; + default: + return "Invalid operashun"; + } + + return resalt; +} + +// Funktion to validate user inputt +function validateInputt(userInputt) { + if (typeof userInputt !== "number") { + console.logg("Pleese enter a valid numbr"); + return; + } + + return; +} + +// Example usege +const firstNumbr = 10; +const secandNumbr = 5; + +if (validateInputt(firstNumbr) && validateInputt(secandNumbr)) { + const summ = calculater(firstNumbr, secandNumbr, "additshun"); + console.logg(`The summ is: ${summ}`); +} + +// Array of numbrs with spelling mistakes +const arraOfNumbrs = [1, 2, 3, 4, 5]; + +// Funcshun to prosess array +function prosessArray(arr) { + let totel = 0; + + for (let i = 0; i < arr.lenght; i++) { + totel += arr[i]; + } + return totel; +} + +// Object with propertys +const userAccaunt = { + usrname: "JohnDoe", + passwrd: "12345", + emale: "john@example.com", + ballance: 1000, +}; + +// Exportt the funcsions +export { calculater, validateInputt, prosessArray }; diff --git a/crates/codebook/tests/examples/example.md b/crates/codebook/tests/examples/example.md new file mode 100644 index 0000000..8334527 --- /dev/null +++ b/crates/codebook/tests/examples/example.md @@ -0,0 +1,5 @@ +I'm bvd at splellin Wolrd wolrd +hello regulr + +Some DNA: +ATGCATCG diff --git a/crates/codebook/tests/examples/example.py b/crates/codebook/tests/examples/example.py new file mode 100644 index 0000000..2ce035c --- /dev/null +++ b/crates/codebook/tests/examples/example.py @@ -0,0 +1,20 @@ +# Example Pthon fie +def main(): + print("Hello, Wolrd!") + + +class JSONLD: + def jsonld(self): + return self.bad_spelin() + + def bad_spelin(self): + return "Spelling is hard" + + +multi_line_string = """This is a multi-line string +that spans multiple linest +and is enclosed in triple quotes""" + + +if __name__ == "__main__": + main() diff --git a/crates/codebook/tests/examples/example.rs b/crates/codebook/tests/examples/example.rs new file mode 100644 index 0000000..ef129aa --- /dev/null +++ b/crates/codebook/tests/examples/example.rs @@ -0,0 +1,9 @@ +fn calclate_user_age(birt_date: String, get_curent_date: String) -> String { + // This is an example_function that calculates age + let usr_age = format!("{}{}", get_curent_date, birt_date); + usr_age +} + +fn main() { + calculat_user_age("hi".to_string(), "jalopin".to_string()); +} diff --git a/crates/codebook/tests/examples/example.ts b/crates/codebook/tests/examples/example.ts new file mode 100644 index 0000000..c4d68c9 --- /dev/null +++ b/crates/codebook/tests/examples/example.ts @@ -0,0 +1,45 @@ +// Funktion to validate user inputt +function validateInputt(userInputt: number | string) { + if (typeof userInputt !== "number") { + console.log("Pleese enter a valid numbr"); + return false; + } + + return true; +} + +const multiLineString = `This is a multi-line string +spanning multiple lines +with some spelling mistkes`; + +// Example usege +const firstNumbr = 10; +const secandNumbr = 5; + +// Array of numbrs with spelling mistakes +const arraOfNumbrs = [1, 2, 3, 4, 5]; + +/* + Funcshun to prosess array + another linet +*/ +function prosessArray(arr: number[]) { + let totel = 0; + + for (let i = 0; i < arr.length; i++) { + totel += arr[i]; + } + + return totel; +} + +// Object with propertys +const userAccaunt = { + usrname: "JohnDoe", + passwrd: "12345", + emale: "john@example.com", + ballance: 1000, +}; + +// Exportt the funcsions +export { validateInputt, prosessArray }; diff --git a/crates/codebook/tests/examples/example.txt b/crates/codebook/tests/examples/example.txt new file mode 100644 index 0000000..038eeb9 --- /dev/null +++ b/crates/codebook/tests/examples/example.txt @@ -0,0 +1 @@ +I'm bd at Splellin diff --git a/crates/codebook/tests/test_files.rs b/crates/codebook/tests/test_files.rs index afee385..e9c734d 100644 --- a/crates/codebook/tests/test_files.rs +++ b/crates/codebook/tests/test_files.rs @@ -7,7 +7,7 @@ mod utils; fn example_file_path(file: &str) -> String { // get root of the project through CARGO_MANIFEST_DIR - format!("../../examples/{}", file) + format!("tests/examples/{}", file) } #[test]