Skip to content

Add tests for when-some, plus one for when-let.#851

Open
alysbrooks wants to merge 1 commit intojank-lang:mainfrom
alysbrooks:alys/add-when-some
Open

Add tests for when-some, plus one for when-let.#851
alysbrooks wants to merge 1 commit intojank-lang:mainfrom
alysbrooks:alys/add-when-some

Conversation

@alysbrooks
Copy link
Contributor

when-some and when-let behave very similarly so this actually reuses a large number of tests from when-let. It also adds the opposite case of one of these tests to when-let.

when-some and when-let behave very similarly. This adds the opposite
case of one of these tests to when-let.
(is (nil? (when-let [x nil] x))))
(testing "basic single-binding tests using seqs"
(is (= '(0 1 2 3 4) (when-let [x (range 5)] x))))
(testing "unlike, when-some, we're looking for not-nil specifically, so false evaluates"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good test but I feel like the testing string is backwards?

(when-var-exists when-some
(deftest test-when-some
(testing "basic single-binding tests using vectors or nil"
(is (= [0 1 2 3 4] (when-some [x [0 1 2 3 4] ] x)))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
(is (= [0 1 2 3 4] (when-some [x [0 1 2 3 4] ] x)))
(is (= [0 1 2 3 4] (when-some [x [0 1 2 3 4]] x)))

(deftest test-when-some
(testing "basic single-binding tests using vectors or nil"
(is (= [0 1 2 3 4] (when-some [x [0 1 2 3 4] ] x)))
(is (not (nil? (when-some [x [nil]] x))))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some? is probably better here than (not (nil? ...))

(is (= [0 1 2 3 4] (when-some [x [0 1 2 3 4] ] x)))
(is (not (nil? (when-some [x [nil]] x))))
(is (= [] (when-some [x []] x)))
(is (nil? (when-some [x nil] x))))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably better to test here that a side-effect doesn't get evaluated since the test condition fails

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is important. You could use an atom for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants