-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathReadmeConstructionCodeSnippetsTest.scala
116 lines (112 loc) · 4.12 KB
/
ReadmeConstructionCodeSnippetsTest.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/*
* Copyright (c) 2018-2025 LaserDisc
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
import org.scalatest.matchers.should.Matchers
import org.scalatest.wordspec.AnyWordSpecLike
final class ReadmeConstructionCodeSnippetsTest extends AnyWordSpecLike with Matchers {
"Cats effect Sync construction snippets should compile" in {
"""
|import java.util.{logging => jul}
|import cats.effect.Sync
|import cats.syntax.functor._
|import log.effect.fs2.SyncLogWriter._
|import log.effect.{LogLevels, LogWriter}
|import org.{log4s => l4s}
|
|sealed abstract class App[F[_]](implicit F: Sync[F]) {
| val log4s1: F[LogWriter[F]] =
| F.delay(l4s.getLogger("test")) map log4sLog[F]
|
| val log4s2: F[LogWriter[F]] = log4sLog("a logger")
|
| val log4s3: F[LogWriter[F]] = {
| case class LoggerClass()
| log4sLog(classOf[LoggerClass])
| }
|
| val jul1: F[LogWriter[F]] =
| F.delay(jul.Logger.getLogger("a logger")) map julLog[F]
|
| val jul2: F[LogWriter[F]] = julLog
|
| val scribe1: F[LogWriter[F]] =
| F.delay(scribe.Logger("a logger")) map scribeLog[F]
|
| val scribe2: F[LogWriter[F]] = scribeLog("a logger")
|
| val scribe3: F[LogWriter[F]] = {
| case class LoggerClass()
| scribeLog(classOf[LoggerClass])
| }
|
| val console1: LogWriter[F] = consoleLog
|
| val console2: LogWriter[F] = consoleLogUpToLevel(LogLevels.Warn)
|
| val noOp: LogWriter[F] = noOpLog[F]
|}
|""".stripMargin should compile
}
"Fs2 streams construction snippets should compile" in {
"""
|import java.util.{logging => jul}
|
|import cats.effect.Sync
|import cats.syntax.flatMap._
|import fs2.Stream
|import log.effect.fs2.Fs2LogWriter._
|import log.effect.{LogLevels, LogWriter}
|import org.{log4s => l4s}
|
|sealed abstract class App[F[_]](implicit F: Sync[F]) {
| val log4s1: fs2.Stream[F, LogWriter[F]] =
| Stream.eval(F.delay(l4s.getLogger("test"))) >>= log4sLogStream[F]
|
| val log4s2: fs2.Stream[F, LogWriter[F]] = log4sLogStream("a logger")
|
| val log4s3: fs2.Stream[F, LogWriter[F]] = {
| case class LoggerClass()
| log4sLogStream(classOf[LoggerClass])
| }
|
| val jul1: fs2.Stream[F, LogWriter[F]] =
| Stream.eval(F.delay(jul.Logger.getLogger("a logger"))) >>= julLogStream[F]
|
| val jul2: fs2.Stream[F, LogWriter[F]] = julLogStream
|
| val scribe1: fs2.Stream[F, LogWriter[F]] =
| Stream.eval(F.delay(scribe.Logger("a logger"))) >>= scribeLogStream[F]
|
| val scribe2: fs2.Stream[F, LogWriter[F]] = scribeLogStream("a logger")
|
| val scribe3: fs2.Stream[F, LogWriter[F]] = {
| case class LoggerClass()
| scribeLogStream(classOf[LoggerClass])
| }
|
| val console1: fs2.Stream[F, LogWriter[F]] = consoleLogStream
|
| val console2: fs2.Stream[F, LogWriter[F]] = consoleLogStreamUpToLevel(LogLevels.Warn)
|
| val noOp: fs2.Stream[F, LogWriter[F]] = noOpLogStream
|}
|""".stripMargin should compile
}
}