mirror of
https://github.com/apple/pkl.git
synced 2026-05-25 16:19:20 +02:00
Add support for rendering Bytes values with YamlRenderer (#1276)
This commit is contained in:
@@ -18,6 +18,9 @@ res13 = new Dynamic { name = "pigeon"; age = 30 }
|
||||
res14 = new Person { name = "pigeon" }
|
||||
res15 = null
|
||||
res16 = Pair(1, 2)
|
||||
res17 = Bytes()
|
||||
res18 = Bytes(1, 2, 3)
|
||||
res19 = IntSeq(0, 127).toList().toBytes()
|
||||
|
||||
output {
|
||||
renderer = new YamlRenderer {
|
||||
|
||||
@@ -18,6 +18,7 @@ res13 = new Dynamic { name = "pigeon"; age = 30 }
|
||||
res14 = new Person { name = "pigeon"; age = 30 }
|
||||
res15 = null
|
||||
res16 = Pair(1, 2)
|
||||
res17 = Bytes(1, 2, 3)
|
||||
|
||||
output {
|
||||
renderer = new YamlRenderer {
|
||||
@@ -38,6 +39,7 @@ output {
|
||||
[Null] = (it) -> "converted"
|
||||
[Pair] = (it) -> "converted"
|
||||
[IntSeq] = (it) -> "converted"
|
||||
[Bytes] = (it) -> "converted"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,3 +37,6 @@ res15: String
|
||||
res16:
|
||||
- 2
|
||||
- 3
|
||||
res17: !!binary ''
|
||||
res18: !!binary AQID
|
||||
res19: !!binary AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJCUmJygpKissLS4vMDEyMzQ1Njc4OTo7PD0+P0BBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWltcXV5fYGFiY2RlZmdoaWprbG1ub3BxcnN0dXZ3eHl6e3x9fn8=
|
||||
|
||||
@@ -13,3 +13,4 @@ res13: converted
|
||||
res14: converted
|
||||
res15: converted
|
||||
res16: converted
|
||||
res17: converted
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||
* Copyright © 2024-2025 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -146,4 +146,36 @@ class YamlRendererTest {
|
||||
.trimIndent()
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `render byte array values as binary`() {
|
||||
val evaluator = Evaluator.preconfigured()
|
||||
val module =
|
||||
evaluator.evaluate(
|
||||
ModuleSource.text(
|
||||
"""
|
||||
res1 = Bytes()
|
||||
res2 = Bytes(1, 2, 3)
|
||||
res3 = IntSeq(0, 127).toList().toBytes()
|
||||
"""
|
||||
.trimIndent()
|
||||
)
|
||||
)
|
||||
|
||||
val writer = StringWriter()
|
||||
val renderer = ValueRenderers.yaml(writer, 2, true, false)
|
||||
|
||||
renderer.renderDocument(module)
|
||||
val output = writer.toString()
|
||||
|
||||
assertThat(output.trim())
|
||||
.isEqualTo(
|
||||
"""
|
||||
res1: !!binary ''
|
||||
res2: !!binary 'AQID'
|
||||
res3: !!binary 'AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJCUmJygpKissLS4vMDEyMzQ1Njc4OTo7PD0+P0BBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWltcXV5fYGFiY2RlZmdoaWprbG1ub3BxcnN0dXZ3eHl6e3x9fn8='
|
||||
"""
|
||||
.trimIndent()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user