Skip to content

Commit 3cc4e2e

Browse files
committed
Code and test clean up
1 parent 44d308b commit 3cc4e2e

File tree

3 files changed

+11
-25
lines changed

3 files changed

+11
-25
lines changed

jsoniter-scala-macros/shared/src/main/scala-3/com/github/plokhotnyuk/jsoniter_scala/macros/JsonCodecMaker.scala

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1540,9 +1540,6 @@ object JsonCodecMaker {
15401540
else if (tpe.termSymbol.flags.is(Flags.Enum)) {
15411541
tpe match
15421542
case TermRef(_, name) => name
1543-
case TypeRef(_, name) => name
1544-
case AppliedType(TermRef(_, name), _) => name
1545-
case AppliedType(TypeRef(_, name), _) => name
15461543
case _ => fail(s"Unsupported enum type: '${tpe.show}', tree=$tpe")
15471544
} else if (tpe.typeSymbol.flags.is(Flags.Module)) tpe.termSymbol.fullName
15481545
else tpe.typeSymbol.fullName

jsoniter-scala-macros/shared/src/test/scala-3/com/github/plokhotnyuk/jsoniter_scala/macros/JsonCodecMakerNewEnumSpec.scala

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,9 @@ enum MyEnum(val value: String):
7171
case Mixed extends MyEnum("item1") with Mix
7272
case Simple extends MyEnum("item2")
7373

74-
enum RecursiveEnum:
75-
case Rec(val next: Option[Rec]) extends RecursiveEnum
74+
enum LinkedList[+T]:
75+
case End
76+
case Node(value: T, next: LinkedList[T])
7677

7778
enum ClientOut(@transient val tpe: String):
7879
@named("p") case Ping(@named("l") timestamp: Long) extends ClientOut("p")
@@ -156,21 +157,21 @@ class JsonCodecMakerNewEnumSpec extends VerifyingSpec {
156157
verifySerDeser(make[List[FooEnum[Option]]], List(FooEnum.Bar[Option](Some(1)), FooEnum.Baz[Option](Some("VVV"))),
157158
"""[{"type":"Bar","a":1},{"type":"Baz","a":"VVV"}]""")
158159
}
159-
"serialize and deserialize recursive Scala3 enums if it is allowed" in {
160-
verifySerDeser(make[List[RecursiveEnum]](CodecMakerConfig.withAllowRecursiveTypes(true)),
161-
List(RecursiveEnum.Rec(None), RecursiveEnum.Rec(Some(RecursiveEnum.Rec(None)))),
162-
"""[{"type":"Rec"},{"type":"Rec","next":{}}]""")
163-
}
164160
"serialize and deserialize Scala3 enums with a transient field" in {
165161
verifySerDeser(make[List[ClientOut]](CodecMakerConfig.withDiscriminatorFieldName(Some("t"))),
166162
List(ClientOut.Ping(1), ClientOut.Move(1)), """[{"t":"p","l":1},{"t":"m","m":1}]""")
167163
}
164+
"serialize and deserialize recursive Scala3 enums if it is allowed" in {
165+
verifySerDeser(make[LinkedList[Int]](CodecMakerConfig.withAllowRecursiveTypes(true)),
166+
LinkedList.Node(2, LinkedList.Node(1, LinkedList.End)),
167+
"""{"type":"Node","value":2,"next":{"type":"Node","value":1,"next":{"type":"End"}}}""")
168+
}
168169
"don't generate codecs for recursive Scala3 enums by default" in {
169170
assert(intercept[TestFailedException](assertCompiles {
170-
"""JsonCodecMaker.make[RecursiveEnum]""".stripMargin
171+
"""JsonCodecMaker.make[LinkedList[Int]]""".stripMargin
171172
}).getMessage.contains {
172-
"""Recursive type(s) detected: 'com.github.plokhotnyuk.jsoniter_scala.macros.RecursiveEnum.Rec',
173-
|'scala.Option[com.github.plokhotnyuk.jsoniter_scala.macros.RecursiveEnum.Rec]'.
173+
"""Recursive type(s) detected: 'com.github.plokhotnyuk.jsoniter_scala.macros.LinkedList[scala.Int]',
174+
|'com.github.plokhotnyuk.jsoniter_scala.macros.LinkedList.Node[scala.Int]'.
174175
|Please consider using a custom implicitly accessible codec for this
175176
|type to control the level of recursion or turn on the
176177
|'com.github.plokhotnyuk.jsoniter_scala.macros.CodecMakerConfig.allowRecursiveTypes' for the trusted input

jsoniter-scala-macros/shared/src/test/scala-3/com/github/plokhotnyuk/jsoniter_scala/macros/JsonCodecMakerNewKeywordSpec.scala

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,6 @@ class JsonCodecMakerNewKeywordSpec extends VerifyingSpec {
114114
verifySerDeser(summon[JsonValueCodec[TestEnum]], TestEnum.Value2("VVV"), """{"hint":"Value2","str":"VVV"}""")
115115
}
116116
}
117-
"serialize and deserialize a complex generic types defined with `derives` keyword and a custom compile-time configurations" in {
118-
verifySerDeser(make[LinkedList[Int]](CodecMakerConfig.withAllowRecursiveTypes(true)),
119-
LinkedList.Node2[Int](2, LinkedList.Node[Int](1, LinkedList.End)),
120-
"""{"type":"Node2","value":2,"next":{"value":1,"next":{"type":"End"}}}""")
121-
}
122117
"serialize and deserialize an generic ADT defined with bounded leaf classes using a custom codec" in {
123118
sealed trait TypeBase[T]
124119

@@ -204,10 +199,3 @@ class JsonCodecMakerNewKeywordSpec extends VerifyingSpec {
204199
}
205200
}
206201
}
207-
208-
inline given CodecMakerConfig = CodecMakerConfig.withAllowRecursiveTypes(true)
209-
210-
enum LinkedList[+T] derives ConfiguredJsonValueCodec: // Borrowed from https://github.com/com-lihaoyi/upickle/pull/607
211-
case End
212-
case Node(value: T, next: LinkedList[T])
213-
case Node2(value: T, next: Node[T])

0 commit comments

Comments
 (0)