Commit 01d5d714 authored by Johannes Knödtel's avatar Johannes Knödtel 🎶
Browse files

add validator test cases

parent fff7f65e
(ns gms.test.validators
(:use clojure.test
gms.validators)
(:require [clojure.string :as str]
[bouncer.core :as v]))
(deftest string-length
(testing "empty string should be ok"
(is (v/valid? {:str ""} :str string-length-ok?)))
(testing "exactly 255 long"
(is (v/valid? {:str (str/join (repeat 255 \x))} :str string-length-ok?)))
(testing "longer than 255"
(is (not (v/valid? {:str (str/join (repeat 256 \x))} :str string-length-ok?)))))
(deftest decimal
(testing "positive"
(testing "as much int and float digits as allowed"
(is (v/valid? {:dec 111.11M} :dec [[decimal-ok? 3 2]])))
(testing "too many int digits"
(is (not (v/valid? {:dec 1111.11M} :dec [[decimal-ok? 3 2]]))))
(testing "too many float digits"
(is (not (v/valid? {:dec 111.111M} :dec [[decimal-ok? 3 2]]))))
(testing "too many int and float digits"
(is (not (v/valid? {:dec 1111.111M} :dec [[decimal-ok? 3 2]]))))
(testing "zero"
(is (v/valid? {:dec 0M} :dec [[decimal-ok? 3 2]]))))
(testing "negative"
(is (v/valid? {:dec -111.11M} :dec [[decimal-ok? 3 2]])))
(testing "too many int digits"
(is (not (v/valid? {:dec -1111.11M} :dec [[decimal-ok? 3 2]]))))
(testing "too many float digits"
(is (not (v/valid? {:dec -111.111M} :dec [[decimal-ok? 3 2]]))))
(testing "too many int and float digits"
(is (not (v/valid? {:dec -1111.111M} :dec [[decimal-ok? 3 2]]))))
(testing "zero"
(is (v/valid? {:dec -0M} :dec [[decimal-ok? 3 2]]))))
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment