-
-
Notifications
You must be signed in to change notification settings - Fork 366
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Clipboard operations: xclip or pbcopy/pbpaste style operations.
- Loading branch information
Showing
3 changed files
with
87 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
44 changes: 44 additions & 0 deletions
44
amm/repl/src/test/scala/ammonite/unit/ClipboardTests.scala
This file contains 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,44 @@ | ||
package ammonite.unit | ||
|
||
import ammonite.repl.{Clipboard, ClipboardImpl} | ||
|
||
import java.awt.Toolkit | ||
import java.awt.datatransfer.DataFlavor | ||
|
||
import utest._ | ||
|
||
import scala.util.Try | ||
|
||
object ClipboardTests extends TestSuite{ | ||
|
||
val clipboard: Clipboard = ClipboardImpl | ||
|
||
/** | ||
* This test suite requires an environment with access to a window | ||
* service (either under, Windows, MacOs, X11, ...) CI environment | ||
* doesn't satisfy that condition and that is detected in the following | ||
* check in order to skip [[Clipboard]] test when running on CI. | ||
*/ | ||
val canTest = Try( | ||
Toolkit.getDefaultToolkit.getSystemClipboard.isDataFlavorAvailable( | ||
DataFlavor.stringFlavor | ||
) | ||
).getOrElse(false) | ||
|
||
override def tests = Tests { | ||
println("ClipboardTests") | ||
'clipboard { | ||
val newClipboardContents = "hello Ammonite" | ||
'copyandpaste - { | ||
if (canTest) { | ||
clipboard.write(newClipboardContents) | ||
assert(clipboard.read == newClipboardContents) | ||
} else { | ||
println( | ||
"The environment doesn't allow testing clipboard - skipping" | ||
) | ||
} | ||
} | ||
} | ||
} | ||
} |