Skip to content

Commit

Permalink
Adds unit tests for _private_hasFirstAnnotation()
Browse files Browse the repository at this point in the history
  • Loading branch information
popematt committed May 24, 2024
1 parent dd39820 commit c9db9b1
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 6 deletions.
34 changes: 33 additions & 1 deletion src/test/java/com/amazon/ion/impl/IonRawTextWriterTest_1_1.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import com.amazon.ion.*
import com.amazon.ion.system.*
import java.math.BigDecimal
import java.math.BigInteger
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertFalse
import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertThrows
Expand All @@ -22,7 +24,7 @@ class IonRawTextWriterTest_1_1 {
private inline fun ionWriter(
out: StringBuilder = StringBuilder(),
builderConfigurator: IonTextWriterBuilder_1_1.() -> Unit = { /* noop */ },
block: IonRawTextWriter_1_1.() -> Unit,
block: IonRawTextWriter_1_1.() -> Unit = {},
): IonRawTextWriter_1_1 {
val b = standardBuilder()
.apply(builderConfigurator)
Expand Down Expand Up @@ -552,6 +554,36 @@ class IonRawTextWriterTest_1_1 {
}
}

@Test
fun `_private_hasFirstAnnotation() should return false when there are no annotations`() {
val rawWriter = ionWriter()
assertFalse(rawWriter._private_hasFirstAnnotation(SystemSymbols.ION_SID, SystemSymbols.ION))
}

@Test
fun `_private_hasFirstAnnotation() should return true if only the sid matches`() {
val rawWriter = ionWriter()
rawWriter.writeAnnotations(SystemSymbols.ION_SID)
assertTrue(rawWriter._private_hasFirstAnnotation(SystemSymbols.ION_SID, null))
}

@Test
fun `_private_hasFirstAnnotation() should return true if only the text matches`() {
val rawWriter = ionWriter()
rawWriter.writeAnnotations(SystemSymbols.ION)
assertTrue(rawWriter._private_hasFirstAnnotation(-1, SystemSymbols.ION))
}

@Test
fun `_private_hasFirstAnnotation() should return false if the first annotation does not match the sid or text`() {
val rawWriter = ionWriter()
rawWriter.writeAnnotations(SystemSymbols.IMPORTS_SID)
rawWriter.writeAnnotations(SystemSymbols.ION)
rawWriter.writeAnnotations(SystemSymbols.ION_SID)
// Matches the second and third annotations, but not the first one.
assertFalse(rawWriter._private_hasFirstAnnotation(SystemSymbols.ION_SID, SystemSymbols.ION))
}

@Test
fun `write int`() {
assertWriterOutputEquals(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import java.io.ByteArrayOutputStream
import java.math.BigDecimal
import java.math.BigInteger
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertFalse
import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertThrows
Expand All @@ -17,13 +18,18 @@ import org.junit.jupiter.params.provider.CsvSource

class IonRawBinaryWriterTest_1_1 {

private fun ionWriter(
baos: ByteArrayOutputStream = ByteArrayOutputStream()
) = IonRawBinaryWriter_1_1(
out = baos,
buffer = WriteBuffer(BlockAllocatorProviders.basicProvider().vendAllocator(32)) {},
lengthPrefixPreallocation = 1,
)


private inline fun writeAsHexString(autoClose: Boolean = true, block: IonRawBinaryWriter_1_1.() -> Unit): String {
val baos = ByteArrayOutputStream()
val rawWriter = IonRawBinaryWriter_1_1(
out = baos,
buffer = WriteBuffer(BlockAllocatorProviders.basicProvider().vendAllocator(32)) {},
lengthPrefixPreallocation = 1,
)
val rawWriter = ionWriter(baos)
block.invoke(rawWriter)
if (autoClose) rawWriter.close()
@OptIn(ExperimentalStdlibApi::class)
Expand Down Expand Up @@ -805,6 +811,36 @@ class IonRawBinaryWriterTest_1_1 {
}
}

@Test
fun `_private_hasFirstAnnotation() should return false when there are no annotations`() {
val rawWriter = ionWriter()
assertFalse(rawWriter._private_hasFirstAnnotation(SystemSymbols.ION_SID, SystemSymbols.ION))
}

@Test
fun `_private_hasFirstAnnotation() should return true if only the sid matches`() {
val rawWriter = ionWriter()
rawWriter.writeAnnotations(SystemSymbols.ION_SID)
assertTrue(rawWriter._private_hasFirstAnnotation(SystemSymbols.ION_SID, null))
}

@Test
fun `_private_hasFirstAnnotation() should return true if only the text matches`() {
val rawWriter = ionWriter()
rawWriter.writeAnnotations(SystemSymbols.ION)
assertTrue(rawWriter._private_hasFirstAnnotation(-1, SystemSymbols.ION))
}

@Test
fun `_private_hasFirstAnnotation() should return false if the first annotation does not match the sid or text`() {
val rawWriter = ionWriter()
rawWriter.writeAnnotations(SystemSymbols.IMPORTS_SID)
rawWriter.writeAnnotations(SystemSymbols.ION)
rawWriter.writeAnnotations(SystemSymbols.ION_SID)
// Matches the second and third annotations, but not the first one.
assertFalse(rawWriter._private_hasFirstAnnotation(SystemSymbols.ION_SID, SystemSymbols.ION))
}

@Test
fun `write int`() {
assertWriterOutputEquals(
Expand Down

0 comments on commit c9db9b1

Please sign in to comment.