diff options
| author | Andrey Orst <andreyorst@gmail.com> | 2020-10-29 19:55:31 +0300 |
|---|---|---|
| committer | Andrey Orst <andreyorst@gmail.com> | 2020-10-29 20:00:19 +0300 |
| commit | 946378510f1dd542cc2f30efe22a16da69749840 (patch) | |
| tree | eca6e0703908d8266d65d7abc978e20e0749c5b8 /core_test.fnl | |
| parent | e31bc3dcfebe994f41d0ccc8f784adfec568fdcb (diff) | |
feature: functions to access table values
Diffstat (limited to 'core_test.fnl')
| -rw-r--r-- | core_test.fnl | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/core_test.fnl b/core_test.fnl index 9b0359c..d607935 100644 --- a/core_test.fnl +++ b/core_test.fnl @@ -46,7 +46,9 @@ : reverse : inc : dec - : assoc} + : assoc + : get + : get-in} (require :core)) (deftest equality @@ -425,3 +427,19 @@ (testing dec (assert-eq (dec 1) 0) (assert-eq (dec -1) -2))) + +(deftest table-access + (testing get + (assert-eq (get {:key1 10 :key2 20} :key1) 10) + (assert-eq (get {:key1 10 :key2 20} :key1 false) 10) + (assert-eq (get {:key1 10 :key2 20} :key3 false) false) + (assert-eq (get {:key1 10 :key2 20} :key3) nil)) + + (testing get + (local t {:a {:b {:c 10}}}) + (assert-eq (get t [:a]) {:b {:c 10}}) + (assert-eq (get t [:a :b]) {:c 10}) + (assert-eq (get t [:a :b :c]) 10) + (assert-eq (get t [:a :b :c] false) 10) + (assert-eq (get t [:a :b :d] false) false) + (assert-eq (get t [:a :b :d]) nil))) |