|
1 | 1 | package org.bblfsh.client.v2
|
2 | 2 |
|
3 | 3 | import java.nio.ByteBuffer
|
4 |
| - |
5 | 4 | import scala.io.Source
|
6 | 5 |
|
7 | 6 | class BblfshClientParseTest extends BblfshClientBaseTest {
|
@@ -72,5 +71,33 @@ class BblfshClientParseTest extends BblfshClientBaseTest {
|
72 | 71 | encodedBytes shouldEqual resp.uast.asReadOnlyByteBuffer
|
73 | 72 | }
|
74 | 73 |
|
| 74 | + "BblfshClient.decode" should "decode in binary format" in { |
| 75 | + val defaultDecoded = resp.uast.decode() |
| 76 | + val binaryDecoded = resp.uast.decode(UastBinary) |
| 77 | + val default = defaultDecoded.root().load() |
| 78 | + val binary = binaryDecoded.root().load() |
| 79 | + |
| 80 | + default shouldEqual binary |
| 81 | + } |
| 82 | + |
| 83 | + "BblfshClient.decode" should "be the inverse for ContextExt.encode" in { |
| 84 | + for (fmt <- Seq(UastBinary, UastYaml)) { |
| 85 | + val ctx: ContextExt = resp.uast.decode() |
| 86 | + val tree = ctx.root() |
| 87 | + val bytes = ctx.encode(tree, fmt) |
| 88 | + val decoded = BblfshClient.decode(bytes, fmt) |
| 89 | + |
| 90 | + ctx.root().load() shouldEqual decoded.root().load() |
| 91 | + } |
| 92 | + } |
| 93 | + |
| 94 | + "BblfshClient.decode with invalid number" should "use binary format" in { |
| 95 | + val invalidNumDec = resp.uast.decode(-1) |
| 96 | + val binaryDecoded = resp.uast.decode(UastBinary) |
| 97 | + val invalidNum = invalidNumDec.root().load() |
| 98 | + val binary = binaryDecoded.root().load() |
| 99 | + |
| 100 | + invalidNum shouldEqual binary |
| 101 | + } |
75 | 102 |
|
76 | 103 | }
|
0 commit comments