diff --git a/src/errors/prettify_exception.clj b/src/errors/prettify_exception.clj index f927edb..23c5d77 100644 --- a/src/errors/prettify_exception.clj +++ b/src/errors/prettify_exception.clj @@ -3,7 +3,6 @@ [expectations :refer :all] [errors.error_dictionary :refer :all] [errors.error_hints :refer :all]) - ;[clojure.string :refer :all]) (:use [errors.dictionaries] [errors.messageobj] [errors.errorgui] diff --git a/src/intro/core.clj b/src/intro/core.clj index 2707085..191ac4a 100644 --- a/src/intro/core.clj +++ b/src/intro/core.clj @@ -2,11 +2,8 @@ (:use [errors.prettify_exception] [seesaw.core]) (:require [expectations :refer :all] - ;[corefns.corefns :refer :all] - [strings.beginner_string_library :refer :all] [errors.errorgui :refer :all] [intro.student :refer :all] - ;[corefns.collection_fns :refer :all] [utilities.file_IO :refer :all] [errors.prettify_exception :refer :all] [clojure.pprint :refer :all] diff --git a/src/strings/beginner_string_library.clj b/src/strings/beginner_string_library.clj deleted file mode 100644 index 6336f7c..0000000 --- a/src/strings/beginner_string_library.clj +++ /dev/null @@ -1,284 +0,0 @@ -(ns strings.beginner_string_library - (:require [corefns.assert_handling :refer :all] - [corefns.failed_asserts_info :refer :all])) - -;######################### -;### Better String Fns ### -;######################### - -;String Library - -;Author: Emma Sax and Aaron Lemmon - -;;; seq->string: sequence -> string -(defn seq->string - "Takes a word as a sequence, a string, or nil - and returns a string of the characters, returns an empty string for nil." - [sequence] - {:pre [(check-if-seqable? "seq->string" sequence 1)]} - (apply str sequence)) - -;;; index-of: string, string, optional number -> number -(defn index-of - "Takes one string and one character and an optional index number and returns the - index of the first appearance of the character, returns -1 if the character isn't a - substring of the first string or the index is larger than the last index of the first - string or if the index is negative." - ([string character] - {:pre [(check-if-string? "index-of" string 1) - (check-if-character? "index-of" character 2)]} - (.indexOf string (str character))) - ([string character index] - {:pre [(check-if-string? "index-of" string 1) - (check-if-character? "index-of" character 2) - (check-if-number? "index-of" index 3)]} - (.indexOf string (str character) index))) - -;;; last-index-of: string, string, optional number -> number -(defn last-index-of - "Takes one string and one character and an optional index number and returns the - index of the last appearance of the character by searching backward through the - string; else returns -1." - ([string character] - {:pre [(check-if-string? "last-index-of" string 1) - (check-if-character? "last-index-of" character 2)]} - (.lastIndexOf string (str character))) - ([string character index] - {:pre [(check-if-string? "last-index-of" string 1) - (check-if-character? "last-index-of" character 2) - (check-if-number? "last-index-of" index 3)]} - (.lastIndexOf string (str character) index))) - -;;; append: anything -> string -(defn append - "Takes any number of anything and returns a string which appends the arguments - together, returns an empty string for nil." - [& args] - (apply str args)) - -;;; char-at: string, number -> character -(defn char-at - "Takes a string and an index and returns the character at the given index, returns - nil if the index is bigger than the largest index of the string or if the index is - negative." - [string index] - {:pre [(check-if-string? "char-at" string 1) - (check-if-number? "char-at" index 2)]} - (get string index)) - -;;; empty-string?: string -> boolean -(defn empty-string? - "Takes a string and returns true if the length of the string is 0, returns false - otherwise." - [string] - {:pre [(check-if-string? "empty-string?" string 1)]} - (zero? (count string))) - -;;; first-of-string: string -> character -(defn first-of-string - "Takes a string and returns the first character of the string." - [string] - {:pre [(check-if-string? "first-of-string" string 1)]} - (first string)) - -;;; last-of-string: string -> character -(defn last-of-string - "Takes a string and returns the last character of the string." - [string] - {:pre [(check-if-string? "last-of-string" string 1)]} - (last string)) - -;;; rest-of-string: string -> string -(defn rest-of-string - "Takes a string and returns a new string with all of the elements in order - except for the first character." - [string] - {:pre [(check-if-string? "rest-of-string" string 1)]} - (apply str (rest string))) - -;;; second-of-string: string -> character -(defn second-of-string - "Takes a string and returns the second character of the string." - [string] - {:pre [(check-if-string? "second-of-string" string 1)]} - (second string)) - -;;; string-contains?: string, string -> boolean -(defn string-contains? - "Takes either two strings or a string and a character and returns true if the first - string contains the second string/character, returns false otherwise." - [string substring] - {:pre [(check-if-string? "string-contains?" string 1) - (check-if-string-or-character? "string-contains?" substring 2)]} - (.contains string (str substring))) - -;;; drop-from-string: number, string -> string -(defn drop-from-string - "Takes an index and a string and returns a new string which drops all of - the characters from 0-index (inclusive)." - [index string] - {:pre [(check-if-number? "drop-from-string" index 1) - (check-if-string? "drop-from-string" string 2)]} - (apply str (drop index string))) - -;;; take-from-string: number, string -> string -(defn take-from-string - "Takes a string and an index and returns a new string with only the characters - from 0-index (exclusive)." - [index string] - {:pre [(check-if-number? "take-from-string" index 1) - (check-if-string? "take-from-string" string 2)]} - (apply str (take index string))) - -;######################################################################### -;### these are all functions that are usually used with clojure.string ### -;######################################################################### - -;;; reverse-string: string -> string -;(defn reverse-string -; "Takes a string and returns a new string with the charactes reversed." -; [string] -; {:pre [(string? string)] -; :post [(string? %)]} -; (apply str (reverse string))) - -;;; to-upper-case: string -> string -;(defn to-upper-case -; "Takes a string and returns an new string with all of the characters -; as upper case." -; [string] -; {:pre [(string? string)] -; :post [(string? %)]} -; (clojure.string/upper-case string)) - -;;; to-lower-case: string -> string -;(defn to-lower-case -; "Takes a stringa and returns a new string with all of the characters -; as lower case." -; [string] -; {:pre [(string? string)] -; :post [(string? %)]} -; (clojure.string/lower-case string)) - -;;; capitalize: string -> string -;(defn capitalize -; "Takes a string and makes the first character uppercase and the the rest -; lowercase." -; [string] -; {:pre [(string? string)] -; :post [(string? %)]} -; (clojure.string/capitalize string)) - -;;; separate-string: string, string -> string -;(defn separate-string -; "Takes either one string and returns itself or takes two strings and -; returns a new string with the second string's characters separated by -; the first string." -; ([string] -; {:pre [(string? string)] -; :post [(string? %)]} -; (clojure.string/join string)) -; ([separator string] -; {:pre [(string? separator) (string? string)] -; :post [(string? %)]} -; (clojure.string/join separator string))) - -;;; replace-string: string, string, string -> string -;(defn replace-string -; "Takes three strings, finds the substring of the second string in the first -; string, and then returns a new string with the substring of the first string -; replaced with the third string." -; [string match replacement] -; {:pre [(string? string) (string? match) (string? replacement)] -; :post [(string? %)]} -; (clojure.string/replace string match replacement)) - -;;;; there are no developed tests for replace-string-with-chars - -;;; replace-string-with-chars: string, character, character -> string -;(defn replace-string-with-chars -; "Takes one stringa and two characters, finds the substring of the first character -; in the string, and then returns a new string with the first character -; replaced with the second character." -; [string match replacement] -; {:pre [(string? string) (char? match) (char? replacement)] -; :post [(string? %)]} -; (clojure.string/replace string (str match) (str replacement))) - -;;; split-string: string, string, optional number -> vector -;(defn split-string -; "Takes a string and returns a vector which is the string but split on a -; regular expression, or could also take a number limit that is the maximum -; number of splits (puts the rest of the characters into the last split)." -; ([string re] -; {:pre [(string? string)] -; :post [(vector? %)]} -; (clojure.string/split string re)) -; ([string re limit] -; {:pre [(string? string) (number? limit)] -; :post [(vector? %)]} -; (clojure.string/split string re limit))) - -;;; split-lines-string: string -> string -;(defn split-lines-string -; "Takes a string and returns a vector which take the string and splits it -; on \n or \r\n." -; [string] -; {:pre [(string? string)] -; :post [(vector? %)]} -; (clojure.string/split-lines string)) - -;;; replace-first-of-string: string, string, string -> string -;(defn replace-first-of-string -; "Takes a string and returns a string with the first occurrence of the second -; string in the first string replaced by the third string, if the second string -; doesn't occur in the first string, it just returns the first string." -; [string match replacement] -; {:pre [(string? string) (string? match) (string? replacement)] -; :post [(string? %)]} -; (clojure.string/replace-first string match replacement)) - -;;; trim-string: string -> string -;(defn trim-string -; "Takes a string and returns a string with whitespace from both ends of the -; string removed." -; [string] -; {:pre [(string? string)] -; :post [(string? %)]} -; (clojure.string/trim string)) - -;;; triml-string: string -> string -;(defn triml-string -; "Takes a string and returns a string with whitespace from only the left end of the -; string removed." -; [string] -; {:pre [(string? string)] -; :post [(string? %)]} -; (clojure.string/triml string)) - -;;; trimr-string: string -> string -;(defn trimr-string -; "Takes a string and returns a string with whitespace from only the right end of the -; string removed." -; [string] -; {:pre [(string? string)] -; :post [(string? %)]} -; (clojure.string/trimr string)) - -;;; trim-newline-string: string -> string -;(defn trim-newline-string -; "Takes a string and returns a new stirng with all trailing newline \n or return -; \r characters removed." -; [string] -; {:pre [(string? string)] -; :post [(string? %)]} -; (clojure.string/trim-newline string)) - -;;; string-blank?: string -> boolean -;(defn string-blank? -; "Takes a string and returns true if the string is nil, empty, false, or contains -; only whitespace." -; [string] -; {:pre [(or (string? string) (nil? string) (false? string))] -; :post [(or (true? %) (false? %))]} -; (clojure.string/blank? string)) diff --git a/test/corefns/corefns_test.clj b/test/corefns/corefns_test.clj index f033ae2..71a3922 100644 --- a/test/corefns/corefns_test.clj +++ b/test/corefns/corefns_test.clj @@ -1,7 +1,6 @@ (ns corefns.corefns_test (:require [expectations :refer :all] [corefns.corefns :refer :all] - [strings.beginner_string_library :refer :all] [errors.messageobj :refer :all] [errors.exceptions :refer :all] [corefns.collection_fns :refer :all] diff --git a/test/experimental/core_test.clj b/test/experimental/core_test.clj deleted file mode 100644 index 6363fc5..0000000 --- a/test/experimental/core_test.clj +++ /dev/null @@ -1,119 +0,0 @@ -(ns experimental.core_test - (:require [clj-stacktrace.core :as stacktrace] - [expectations :refer :all] - [strings.beginner_string_library :refer :all] - [errors.exceptions :as errors]) - (:import [java.io.FileInputStream] - [java.io.ObjectInputStream] - [java.io.FileOutputStream] - [java.io.ObjectOutputStream])) - -;;;; A space for prototypes, examples, and experimental features. -;; NEVER refer to this file in other files. - -;************************************ -(def ex1 (errors/run-and-catch-raw '(1))) - -(def ex2 (errors/run-and-catch-raw '(+ 2 "pie"))) - -(def ex3 (errors/run-and-catch-raw '(5))) - -(def ex4 (errors/run-and-catch-raw '(def w 4 5))) - -(def ex5 (errors/run-and-catch-raw '(defn foo (q) q))) - -(def ex6 (errors/run-and-catch-raw '(count 6))) - -(def st1 (stacktrace/parse-exception ex3)) - -;(def fst1 (map #(str "\t" (:ns %) "/" (:fn %) " (" (:file %) " line " (:line %) ")")(filter #(and (:clojure %) (not (re-matches ignore-nses (:ns %)))) (:trace-elems st1)))) - -;######################################## -;### Testing for errors with hashmaps ### -;######################################## - -;(every? #(= (count %) 2) coll) -;(every? #(= (count %) 2) [{:one 1 :two 2} {:three 3 :four 4}]) -;(every? #(= (count %) 2) [{:one 1 :two 2 :three 3} {:three 3 :four 4}]) -;(every? #(= (count %) 2) [{:one 1 :two 2} {:three 3 :four 4 :five 5}]) -;(every? #(= (count %) 2) [{:one 1 :two 2} {:three 3 :four 4}, {:eight 8 :nine 9} {:ten 10 :eleven 11}]) - -;(every? #(= (count %) 2) {{:one 1 :two 2} {:three 3 :four 4}}) -;(every? #(= (count %) 2) {:one 1 :two 2 :three 3 :four 4}) -;(every? #(= (count %) 2) {1 3 2 3 3 3}) - -;(into {} [{:one 1 :two 2 :three 3} {:four 4 :five 5} :six 6 :seven 7 :eight 8 :nine 9]) -;(into {} [{:one 1 :two 2} {:three 3 :four 4}, {:eight 8 :nine 9} {:ten 10 :eleven 11}]) - -;(every? odd? {1 1 3 3}) -;(odd? [1 1]) - -;(defn all-elems-are-map-or-vector? [coll] -; (every? #(or (vector? %) (map? %)) coll)) - -;(defn all-elems-have-length-two? [coll] -; (every? #(= (count %) 2) coll)) - -; (every? #(or (vector? %) (map? %)) '()) - -; (every? #(= (count %) 2) '()) - -;(every? odd? [1 1]) -;(every? odd? [3 3]) - -;################################## -;### Other testing in instarepl ### -;################################## - -;(hash-map [1 2] [3 4] [5]) -;(hash-map [1 2] [3 4] [5 6] [7 8]) -;(hash-map 1 2 3) -;(hash-map "c" :d "d") -;(hash-map #{:a :b :c :d} #{:e :f :g :h}) -;(hash-map [:a :b :c :d] '(:e :f :g :h)) -;(hash-map 1 2 1 3) -;(hash-map 1 2 3 5 1) -;(hash-map 1 2 1 5 9) - -;(into {} [[1 2 3 4] [3 5]]) -;(into {} [{2 2} [3]]) -;(into {} [[1 2] [1 3]]) - -;(array-map 1 2) -;(array-map [1 2] [3 4]) -;(array-map #{1 2 4 5} #{10 11 12 13} #{1}) - -;(array-map '(1 2) '(1 4)) -;(array-map 1 2 1 3) -;(apply array-map [:a 1 :b 2 :c]) -;(apply array-map {1 2 2 3}) -;(apply array-map [1 2 3 4]) -;(apply array-map [:a 1 :c 2 :c 3]) -;(apply array-map [:a 1 :c 2 :c]) -;(apply array-map [5 7 5]) -;(apply array-map [5 7 5 3 5 2 9 2 9 11 3 11 25]) -;(array-map 1 2 3 5 1) -;(apply array-map [1 2 1 3]) -;(array-map 1 2 1 3) - -;(zipmap [1 2 3] [:a :b :c]) -;(zipmap [1 2 3] {:a :b}) -;(zipmap #{1 2 3} #{1 2 3}) -;(zipmap '(1 2 3) '(1 2 3)) -;(zipmap {1 2 3 4} { 5 6 7 8}) -;(zipmap [1 2] [1 2 3]) -;(zipmap [1 1 1 1] [2 90 6 4]) -;(zipmap [1 2] {:a :b} [1 23] [1 2 5]) -;(zipmap [1 23 3 5 7 98] {3 1 7 3 0 8}) - -;(frequencies [:a :b :a :a :b]) -;(frequencies {:a :b :c :d :d :d :i :d}) -;(frequencies 1) - -;(group-by count ["d" "6i" "qicsg"]) -;(group-by count '("d" "6i" "qicsg")) -;(group-by count #{"d" "6i" "qicsg"}) -;(group-by count {"9" "d" "6i" "qicsg"}) -;(group-by count {"9sd" "dsdf" "6sdfi" "qsdficsg"}) -;(group-by #(odd? (first %)) {2 4 8 9 1 3}) -;(group-by #(odd? (second %)) {2 4 8 9 1 3}) diff --git a/test/strings/beginner_string_library_test.clj b/test/strings/beginner_string_library_test.clj deleted file mode 100644 index 677b7b0..0000000 --- a/test/strings/beginner_string_library_test.clj +++ /dev/null @@ -1,478 +0,0 @@ -(ns strings.beginner_string_library_test - (:require [expectations :refer :all] - [strings.beginner_string_library :refer :all] - [errors.messageobj :refer :all] - [errors.exceptions :refer :all])) - -;; Testing for our String Library - -;; Author: Emma Sax and Aaron Lemmon - -;; as a note: all clojure characters signified with a \ are stored as java characters - -;######################################### -;### Testing for the better string fns ### -;######################################### - -;; testing for seq->string -(expect "hello world" (seq->string '(\h \e \l \l \o \space \w \o \r \l \d))) -(expect "" (seq->string '())) -(expect "123" (seq->string [1 2 3])) -(expect "[1][2]" (seq->string [[1] [2]])) -(expect "true" (seq->string (list (odd? 3)))) -(expect "hi" (seq->string "hi")) -(expect "" (seq->string nil)) -(expect (more-of x - 4 (count x) - true (string-contains? x "1") - true (string-contains? x "2") - true (string-contains? x "3") - true (string-contains? x "5")) - (seq->string #{3 2 1 5})) -(expect (more-of x - 43 (count x) - true (string-contains? x "[:ten 10]") - true (string-contains? x "[:twenty-two 22]") - true (string-contains? x "[:four 4]") - true (string-contains? x "[:five 5]")) - (seq->string {:ten 10 :twenty-two 22 :four 4 :five 5})) - -;; testing for index-of -(expect 5 (index-of "emmahenryaaronelena" \e 4)) -(expect 0 (index-of "emmahenryaaronelena" \e)) -(expect -1 (index-of "emmahenryaaronelena" \z)) -(expect -1 (index-of "meep" \e 4)) -(expect 3 (index-of "meep" \p -3)) - -;; testing for last-index-of -(expect 16 (last-index-of "emmahenryaaronelena" \e)) -(expect 5 (last-index-of "emmahenryaaronelena" \e 7)) -(expect 2 (last-index-of "meep" \e 10)) -(expect -1 (last-index-of "urgh" \z)) -(expect -1 (last-index-of "negative" \z -2)) - -;; testing for append -(expect "" (append nil)) -(expect "" (append "")) -(expect "" (append)) -(expect "abc" (append "abc")) -(expect "abcdef" (append "abc" "def")) -(expect "abcdefghi" (append "abc" "def" "ghi")) -(expect "" (append "")) -(expect "abcdef" (append "abc" "def" nil)) -(expect "abc123" (append "abc" 123)) -(expect "abc1230[1 3 4]*" (append "abc" 123 \0 nil [1 3 4] \*)) -(expect "abc1230[[1 2] 3 4]*" (append "abc" 123 \0 nil [[1 2] 3 4] \*)) -;; caution: the result of str on a hash map has unspecified order, so we can't hardwire it: -(expect (str (str {:one 1, :three 3, :two 2}) " abc do re mi"(append {:one 1 :two 2 :three 3} \space "abc" \space "do re mi"))) -(expect (more-of x - 35 (count x) - true (string-contains? x "{") - true (string-contains? x ":a") - true (string-contains? x ":b") - true (string-contains? x ":i") - true (string-contains? x ":f") - true (string-contains? x ":l") - true (string-contains? x ":z") - true (string-contains? x ":e") - true (string-contains? x "}") - true (string-contains? x "abc8q[8 5 2]")) - (append #{:a :b :i :f :l :z :e} "abc" nil \8 \q [8 5 2])) - -;; testing for char-at -(expect \p (char-at "happy" 2)) -(expect \e (char-at "me" 1)) -(expect nil (char-at "touch the sky" -1000)) -(expect nil (char-at "touch the sky" 1000)) -(expect nil (char-at "" 6)) - -;; testing for empty-string? -(expect true (empty-string? "")) -(expect false (empty-string? "meep")) - -;; testing for first-of-string -(expect \p (first-of-string "principle")) -(expect \l (first-of-string "lazy")) - -;; testing for last-of-string -(expect \d (last-of-string "decorated")) -(expect \y (last-of-string "freely")) - -;; testing for rest-of-string -(expect "e" (rest-of-string "me")) -(expect "reat Wall of China" (rest-of-string "Great Wall of China")) - -;; testing for second-of-string -(expect \a (second-of-string "Aaron")) -(expect \e (second-of-string "testing!")) - -;; testing for string-contains? -(expect true (string-contains? "Moonrise" "on")) -(expect false (string-contains? "Moo|nrise" "on")) -(expect true (string-contains? "Moonrise" "M")) -(expect true (string-contains? "moonrise" \m)) - -;; testing for drop-from-string -(expect "Lake City" (drop-from-string 5 "Salt Lake City")) -(expect "" (drop-from-string 10 "meep")) -(expect "prophet" (drop-from-string -10 "prophet")) - -;; testing for take-from-string -(expect "Salt" (take-from-string 4 "Salt Lake City")) -(expect "meep" (take-from-string 10 "meep")) -(expect "" (take-from-string -10 "prophet")) - -;############################################### -;### Testing Types for the better string fns ### -;############################################### - -;; type-checking for seq->string - should return a string -(expect (string? (seq->string '(\h \e \l \l \o \space \w \o \r \l \d)))) -(expect (string? (seq->string '()))) -(expect (string? (seq->string [1 2 3]))) -(expect (string? (seq->string [[1] [2]]))) -(expect (string? (seq->string (list (odd? 3))))) -(expect (string? (seq->string "hi"))) -(expect (string? (seq->string nil))) - -;; type-checking for index-of - should return a number -(expect (number? (index-of "emmahenryaaronelena" \e 4))) -(expect (number? (index-of "emmahenryaaronelena" \e))) -(expect (number? (index-of "emmahenryaaronelena" \z))) -(expect (number? (index-of "meep" \e 4))) -(expect (number? (index-of "meep" \p -3))) - -;; type-checking for last-index-of - should return a number -(expect (number? (last-index-of "emmahenryaaronelena" \e))) -(expect (number? (last-index-of "emmahenryaaronelena" \e 7))) -(expect (number? (last-index-of "meep" \e 10))) -(expect (number? (last-index-of "urgh" \z))) -(expect (number? (last-index-of "negative" \z -2))) - -;; type-checking for append - should return a string -(expect (string? (append nil))) -(expect (string? (append ""))) -(expect (string? (append))) -(expect (string? (append "abc"))) -(expect (string? (append "abc" "def"))) -(expect (string? (append "abc" "def" "ghi"))) -(expect (string? (append ""))) -(expect (string? (append "abc" "def" nil))) -(expect (string? (append "abc" 123))) -(expect (string? (append "abc" 123 \0 nil [1 3 4]))) - -;; type-checking for char-at - should return either a character or nil -(expect (#(or (char? %) (nil? %)) (char-at "happy" 2))) -(expect (#(or (char? %) (nil? %)) (char-at "me" 1))) -(expect (#(or (char? %) (nil? %)) (char-at "touch the sky" -1000))) -(expect (#(or (char? %) (nil? %)) (char-at "touch the sky" 1000))) -(expect (#(or (char? %) (nil? %)) (char-at "" 6))) - -;; type-checking for empty-string? - should return either true or false -(expect (#(or (true? %) (false? %)) (empty-string? ""))) -(expect (#(or (true? %) (false? %)) (empty-string? "meep"))) - -;; type-checking for first-of-string - should return a character -(expect (char? (first-of-string "principle"))) -(expect (char? (first-of-string "lazy"))) - -;; type-checking for last-of-string - should return a character -(expect (char? (last-of-string "decorated"))) -(expect (char? (last-of-string "freely"))) - -;; type-checking for rest-of-string - should return a string -(expect (string? (rest-of-string "me"))) -(expect (string? (rest-of-string "Great Wall of China"))) - -;; type-checking for second-of-string - should return a character -(expect (char? (second-of-string "Aaron"))) -(expect (char? (second-of-string "testing!"))) - -;; type-checking for string-contains? - should return either true or false -(expect (#(or (true? %) (false? %)) (string-contains? "Moonrise" "on"))) -(expect (#(or (true? %) (false? %)) (string-contains? "Moo|nrise" "on"))) -(expect (#(or (true? %) (false? %)) (string-contains? "Moonrise" "M"))) -(expect (#(or (true? %) (false? %)) (string-contains? "moonrise" \m))) - -;; type-checking for drop-from-string - should return a string -(expect (string? (drop-from-string 5 "Salt Lake City"))) -(expect (string? (drop-from-string 10 "meep"))) -(expect (string? (drop-from-string -10 "prophet"))) - -;; type-checking for take-from-string - should return a string -(expect (string? (take-from-string 4 "Salt Lake City"))) -(expect (string? (take-from-string 10 "meep"))) -(expect (string? (take-from-string -10 "prophet"))) - -;########################################################## -;### Testing Assertion Errors for the better string fns ### -;########################################################## - -;; assert-checking for seq->string -(expect "In function seq->string, the first argument :not-a-sequence must be a sequence but is a keyword." - (get-text-no-location - (run-and-catch-pretty-no-stacktrace 'strings.beginner_string_library '(seq->string :not-a-sequence)))) - -;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -;; assert-checking for index-of, first precondition when passed 2 args -(expect "In function index-of, the first argument :not-a-string must be a string but is a keyword." - (get-text-no-location - (run-and-catch-pretty-no-stacktrace 'strings.beginner_string_library - '(index-of :not-a-string \e)))) - -;; assert-checking for index-of, second precondition when passed 2 args -(expect "In function index-of, the second argument :not-a-character must be a character but is a keyword." - (get-text-no-location - (run-and-catch-pretty-no-stacktrace 'strings.beginner_string_library - '(index-of "emma" :not-a-character)))) - -;; assert-checking for index-of, first precondition when passed 3 args -(expect "In function index-of, the first argument :not-a-string must be a string but is a keyword." - (get-text-no-location - (run-and-catch-pretty-no-stacktrace 'strings.beginner_string_library - '(index-of :not-a-string \e 2)))) - -;; assert-checking for index-of, second precondition when passed 3 args -(expect "In function index-of, the second argument :not-a-character must be a character but is a keyword." - (get-text-no-location - (run-and-catch-pretty-no-stacktrace 'strings.beginner_string_library - '(index-of "emma" :not-a-character 5)))) - -;; assert-checking for index-of, third precondition when passed 3 args -(expect "In function index-of, the third argument :not-a-number must be a number but is a keyword." - (get-text-no-location - (run-and-catch-pretty-no-stacktrace 'strings.beginner_string_library - '(index-of "emma" \e :not-a-number)))) - -;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -;; assert-checking for last-index-of, first precondition when passed 2 args -(expect "In function last-index-of, the first argument :not-a-string must be a string but is a keyword." - (get-text-no-location - (run-and-catch-pretty-no-stacktrace 'strings.beginner_string_library - '(last-index-of :not-a-string \e)))) - -;; assert-checking for last-index-of, second precondition when passed 2 args -(expect "In function last-index-of, the second argument :not-a-character must be a character but is a keyword." - (get-text-no-location - (run-and-catch-pretty-no-stacktrace 'strings.beginner_string_library - '(last-index-of "emma" :not-a-character)))) - -;; assert-checking for last-index-of, first precondition when passed 3 args -(expect "In function last-index-of, the first argument :not-a-string must be a string but is a keyword." - (get-text-no-location - (run-and-catch-pretty-no-stacktrace 'strings.beginner_string_library - '(last-index-of :not-a-string \e 2)))) - -;; assert-checking for last-index-of, second precondition when passed 3 args -(expect "In function last-index-of, the second argument :not-a-character must be a character but is a keyword." - (get-text-no-location - (run-and-catch-pretty-no-stacktrace 'strings.beginner_string_library - '(last-index-of "emma" :not-a-character 5)))) - -;; assert-checking for last-index-of, third precondition when passed 3 args -(expect "In function last-index-of, the third argument :not-a-number must be a number but is a keyword." - (get-text-no-location - (run-and-catch-pretty-no-stacktrace 'strings.beginner_string_library - '(last-index-of "emma" \e :not-a-number)))) - -;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -; nothing will throw an assertion error for append because append can take anything - -;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -;; assert-checking for char-at, first precondition -(expect "In function char-at, the first argument :not-a-string must be a string but is a keyword." - (get-text-no-location - (run-and-catch-pretty-no-stacktrace 'strings.beginner_string_library - '(char-at :not-a-string 0)))) - -;; assert-checking for char-at, second precondition -(expect "In function char-at, the second argument :not-a-number must be a number but is a keyword." - (get-text-no-location - (run-and-catch-pretty-no-stacktrace 'strings.beginner_string_library - '(char-at "hello world" :not-a-number)))) - -;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -;; assert-checking for empty-string? -(expect "In function empty-string?, the first argument :not-a-string must be a string but is a keyword." - (get-text-no-location - (run-and-catch-pretty-no-stacktrace 'strings.beginner_string_library - '(empty-string? :not-a-string)))) - -;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -;; assert-checking for first-of-string -(expect "In function first-of-string, the first argument :not-a-string must be a string but is a keyword." - (get-text-no-location - (run-and-catch-pretty-no-stacktrace 'strings.beginner_string_library - '(first-of-string :not-a-string)))) - -;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -;; assert-checking for last-of-string -(expect "In function last-of-string, the first argument :not-a-string must be a string but is a keyword." - (get-text-no-location - (run-and-catch-pretty-no-stacktrace 'strings.beginner_string_library - '(last-of-string :not-a-string)))) - -;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -;; assert-checking for rest-of-string -(expect "In function rest-of-string, the first argument :not-a-string must be a string but is a keyword." - (get-text-no-location - (run-and-catch-pretty-no-stacktrace 'strings.beginner_string_library - '(rest-of-string :not-a-string)))) - -;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -;; assert-checking for second-of-string -(expect "In function second-of-string, the first argument :not-a-string must be a string but is a keyword." - (get-text-no-location - (run-and-catch-pretty-no-stacktrace 'strings.beginner_string_library - '(second-of-string :not-a-string)))) - -;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -;; assert-checking for string-contains?, first precondition -(expect "In function string-contains?, the first argument :not-a-string must be a string but is a keyword." - (get-text-no-location - (run-and-catch-pretty-no-stacktrace 'strings.beginner_string_library - '(string-contains? :not-a-string "hello world")))) - -;; assert-checking for string-contains?, second precondition -(expect "In function string-contains?, the second argument :not-a-string-or-character must be either a string or character but is a keyword." - (get-text-no-location - (run-and-catch-pretty-no-stacktrace 'strings.beginner_string_library - '(string-contains? "hello world" :not-a-string-or-character)))) - -;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -;; assert-checking for drop-from-string, first precondition -(expect "In function drop-from-string, the first argument :not-a-number must be a number but is a keyword." - (get-text-no-location - (run-and-catch-pretty-no-stacktrace 'strings.beginner_string_library - '(drop-from-string :not-a-number "hello world")))) - -;; assert-checking for drop-from-string, second precondition -(expect "In function drop-from-string, the second argument :not-a-string must be a string but is a keyword." - (get-text-no-location - (run-and-catch-pretty-no-stacktrace 'strings.beginner_string_library - '(drop-from-string 2 :not-a-string)))) - -;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -;; assert-checking for take-from-string, first precondition -(expect "In function take-from-string, the first argument :not-a-number must be a number but is a keyword." - (get-text-no-location - (run-and-catch-pretty-no-stacktrace 'strings.beginner_string_library - '(take-from-string :not-a-number "hello world")))) - -;; assert-checking for take-from-string, second precondition -(expect "In function take-from-string, the second argument :not-a-string must be a string but is a keyword." - (get-text-no-location - (run-and-catch-pretty-no-stacktrace 'strings.beginner_string_library - '(take-from-string 2 :not-a-string)))) - - -;############################################### -;### Other testing for the better string fns ### -;############################################### - -;; using the functions in combinations with each other -(expect \a (first-of-string (rest-of-string (take-from-string 8 "Salt Lake City")))) -(expect "s" (seq->string (list (char-at (drop-from-string 12 (clojure.string/reverse (append - "The chivalrous knight " "was super brave, " "although that's pretty expected."))) 5)))) -(expect "oo" (seq->string (list (last-of-string "hello") (second-of-string "world")))) -(expect [1 9] (vector (index-of "hello world" \e) (last-index-of "hello world" \l))) -(expect false (and (empty-string? "") (string-contains? "hello world" \z))) -(expect true (or (empty-string? "") (string-contains? "hello world" \z))) - -;; Super easy to use multiple functions at the same time, you just need to watch -;; the type of thing it returns - sometimes this might involve making a list, vector, etc. - -;; non-ASCII tests -(expect "弟子規裡有一個字應該更正首孝悌的「悌」應該是「弟」" (seq->string '(弟子規裡有一個字應該更正首孝悌的「悌」應該是「弟」))) -(expect 2 (index-of "弟子規裡有一個字應該更正首孝悌的「悌」應該是「弟」" \規)) -(expect 21 (last-index-of "弟子規裡有一個字應該更正首孝悌的「悌」應該規是「弟」" \規 82)) -(expect "弟子規裡有一個字應該更正首孝悌的「悌」應該規是「弟」" (append "弟子規裡有一個字應該更" "正首孝悌的「悌」應該規是「弟」")) -(expect \「 (char-at "正首孝悌的「悌」應該規是「弟」" 5)) -(expect false (empty-string? "「")) -(expect \正 (first-of-string "正首孝悌的「悌」應該規是「弟」")) -(expect \」 (last-of-string "正首孝悌的「悌」應該規是「弟」")) -(expect "首孝悌的「悌」應該規是「弟」" (rest-of-string "正首孝悌的「悌」應該規是「弟」")) -(expect \首 (second-of-string "正首孝悌的「悌」應該規是「弟」")) -(expect true (string-contains? "正首孝悌的「悌」應該規是「弟」" \規)) -(expect false (string-contains? "正首孝悌的「悌」應該規是「弟」" \子)) -(expect "正首孝" (take-from-string 3 "正首孝悌的「悌」應該規是「弟」")) -(expect "悌的「悌」應該規是「弟」" (drop-from-string 3 "正首孝悌的「悌」應該規是「弟」")) - -;; If LightTable understands the non-ASCII word, then the functions will work with them. - -;######################################################################### -;### these are all functions that are usually used with clojure.string ### -;######################################################################### - -; testing for reverse-string -;(expect "amme" (reverse-string "emma")) -;(expect "eromhsuR tnuoM" (reverse-string "Mount Rushmore")) - -; testing for to-upper-case -;(expect "HELLO WORLD" (to-upper-case "Hello World")) -;(expect "HIIIIYAH!" (to-upper-case "hiiIiyAh!")) - -; testing for to-lower-case -;(expect "hello world" (to-lower-case "Hello World")) -;(expect "statue of liberty" (to-lower-case "StatUe oF LiBeRty")) - -; testing for capitalize -;(expect "Hello" (capitalize "hEllO")) -;(expect "Eiffel tower" (capitalize "EiFfeL TowEr")) - -; testing for separate-string -;(expect "mesh" (separate-string "mesh")) -;(expect "h.e.l.l.o. .w.o.r.l.d" (separate-string "." "hello world")) - -; testing for replace-string -;(expect "The color is blue." (replace-string "The color is red." "red" "blue")) -;(expect "argh" (replace-string "urgh" "u" "a")) - -; testing for split-string -;(expect ["q" "w" "e" "r" "t" "y" "u" "i" "o" "p"] (split-string -; "q1w2e3r4t5y6u7i8o9p0" #"\d+")) -;(expect ["q" "w" "e" "r" "t5y6u7i8o9p0"] (split-string "q1w2e3r4t5y6u7i8o9p0" #"\d+" 5)) - -; testing for split-lines-string -;(expect ["test " " string"] (split-lines-string "test \n string")) - -; testing for replace-first-of-string -;(expect "hello" (replace-first-of-string "hello" "z" "p")) -;(expect "heylo" (replace-first-of-string "hello" "l" "y")) - -; testing for trim-string -;(expect "k" (trim-string " k ")) -;(expect "" (trim-string " ")) -;(expect "d s i" (trim-string "d s i ")) - -; testing for triml-string -;(expect "k " (triml-string " k ")) -;(expect "" (triml-string " ")) -;(expect "d s i " (triml-string "d s i ")) - -; testing for trimr-string -;(expect " k" (trimr-string " k ")) -;(expect "" (trimr-string " ")) -;(expect "d s i" (trimr-string "d s i ")) - -; testing for trim-newline-string -;(expect "testing " (trim-newline-string "testing \n")) -;(expect "testing again..." (trim-newline-string "testing again...\r")) - -; testing for string-blank? -;(expect true (string-blank? nil)) -;(expect true (string-blank? false)) -;(expect true (string-blank? " ")) -;(expect false (string-blank? " a "))