-
Notifications
You must be signed in to change notification settings - Fork 82
loneElement and loneElementOption: extension methods for Iterable #1827
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
fc9d8a3
loneElement and loneElementOption: extension methods for Iterable
mpollmeier d03cd7f
remove 'hint' from loneElementOption
mpollmeier 32b3ac9
remove 'hint' from loneElementOption
mpollmeier 7fdeee0
moved to flatgraph. only change left: deprecation `onlyChecked`
mpollmeier 633a742
latest fg
mpollmeier File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
codepropertygraph/src/test/scala/io/shiftleft/ImplicitsTests.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| package io.shiftleft | ||
|
|
||
| import io.shiftleft.Implicits.* | ||
| import org.scalatest.matchers.should.Matchers | ||
| import org.scalatest.wordspec.AnyWordSpec | ||
|
|
||
| import scala.collection.mutable.ArrayBuffer | ||
|
|
||
| class ImplicitsTests extends AnyWordSpec with Matchers { | ||
|
|
||
| "loneElement returns the one and only element from an Iterable, and throws an exception otherwise" in { | ||
| Seq(1).loneElement shouldBe 1 | ||
| Seq(1).loneElement("some context") shouldBe 1 | ||
| Seq(null).loneElement shouldBe null | ||
|
|
||
| intercept[NoSuchElementException] { | ||
| Seq.empty.loneElement | ||
| }.getMessage should include("it is empty") | ||
|
|
||
| intercept[NoSuchElementException] { | ||
| Seq.empty.loneElement("some context") | ||
| }.getMessage should include("it is empty. Hint: some context") | ||
|
|
||
| intercept[AssertionError] { | ||
| Seq(1, 2).loneElement | ||
| }.getMessage should include("it has more than one") | ||
|
|
||
| intercept[AssertionError] { | ||
| ArrayBuffer(1, 2).loneElement | ||
| }.getMessage should include( | ||
| "it has 2" | ||
| ) // ArrayBuffer can 'cheaply' compute their size, so we can have it in the exception message | ||
|
|
||
| intercept[AssertionError] { | ||
| Seq(1, 2).loneElement("some context") | ||
| }.getMessage should include("it has more than one. Hint: some context") | ||
| } | ||
|
|
||
| "loneElementOption returns an Option of the one and only element from an Iterable, or else None" in { | ||
| Seq(1).loneElementOption shouldBe Some(1) | ||
| Seq(1).loneElementOption("some context") shouldBe Some(1) | ||
| Seq(null).loneElementOption shouldBe Some(null) | ||
| Seq(null).loneElementOption("some context") shouldBe Some(null) | ||
|
|
||
| Seq.empty.loneElementOption shouldBe None | ||
| Seq.empty.loneElementOption("some context") shouldBe None | ||
|
|
||
| Seq(1, 2).loneElementOption shouldBe None | ||
| Seq(1, 2).loneElementOption("some context") shouldBe None | ||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| sbt.version=1.10.11 | ||
| sbt.version=1.11.2 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.