Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

converted underscore #251

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 0 additions & 8 deletions source/underscore.yml

This file was deleted.

33 changes: 33 additions & 0 deletions src/battle_asserts/issues/underscore.clj
@@ -0,0 +1,33 @@
(ns battle-asserts.issues.underscore
(:require [clojure.test.check.generators :as gen]
[clojure.string :as s]
[faker.generate :as faker]))

(def level :elementary)

(def description "Write function, which makes an underscored, lowercase form from the expression in the string")

(defn arguments-generator []
(letfn [(camel-case []
(s/join (rand-nth ["-" "::" ""])
(map #((rand-nth [s/capitalize s/upper-case]) %) (faker/words {:lang :en :n 2}))))]
(gen/tuple (gen/elements (repeatedly 50 camel-case)))))

(def test-data
[{:expected "active_model/errors"
:arguments ["ActiveModel::Errors"]}
{:expected "hello_how_are_you"
:arguments ["HelloHowAreYou"]}
{:expected "my_name_is_bond_james_bond"
:arguments ["MyNAMEIsBOND-JamesBond"]}
{:expected "main_company/best_main_user"
:arguments ["MAINCompany::BEST-MAINUser"]}])

(defn solution [string]
(->
string
(clojure.string/replace #"-" "_")
(clojure.string/replace #"([a-z\d])([A-Z])" "$1_$2")
(clojure.string/replace #"([A-Z+])([A-Z][a-z])" "$1_$2")
(clojure.string/replace #"::" "/")
clojure.string/lower-case))
14 changes: 14 additions & 0 deletions test/battle_asserts/issues/underscore_test.clj
@@ -0,0 +1,14 @@
(ns battle-asserts.issues.underscore-test
(:require [clojure.test :refer :all]
[clojure.test.check.properties :as prop :include-macros true]
[clojure.test.check.clojure-test :as ct :include-macros true]
[test-helper :as h]
[battle-asserts.issues.underscore :as issue]))

(ct/defspec spec-solution
20
(prop/for-all [v (issue/arguments-generator)]
(string? (apply issue/solution v))))

(deftest test-solution
(h/generate-tests issue/test-data issue/solution))
18 changes: 0 additions & 18 deletions test/issues/underscore_test.clj.bak

This file was deleted.