Skip to content

Commit

Permalink
test(protobuf): add test case for parsing real-world proto file
Browse files Browse the repository at this point in the history
Add a new test case to `ProtobufRealWorldTest` that loads and parses a real-world `.proto` file. This test ensures the correct handling of a specific data structure and its fields. Additionally, the `.gitignore` file is updated to exclude generated `-proto.json` files.
  • Loading branch information
phodal committed Oct 25, 2024
1 parent 17ec31e commit c5d6d35
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions chapi-ast-protobuf/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*-proto.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package chapi.ast.protobuf

import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
import org.intellij.lang.annotations.Language
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test
import java.io.File

class ProtobufRealWorldTest {
@Test
Expand Down Expand Up @@ -78,4 +81,20 @@ message ListBulletReply {
// fourth DataStructure include 2 fields
assertEquals(2, codeContainer.DataStructures[3].Fields.size)
}


/// load resource/gpt-4o-user.proto and parse it
@Test
fun `should parse gpt-4o-user proto and return a CodeContainer`() {
// Given
val filepath = this.javaClass.classLoader.getResource("gpt-4o-user.proto")!!.file
val protobufCode = File(filepath).readText()
val analyser = ProtobufAnalyser()

// When
val codeContainer = analyser.analysis(protobufCode, filepath)

// write to json
File("gpt-proto.json").writeText(Json.encodeToString(codeContainer))
}
}

0 comments on commit c5d6d35

Please sign in to comment.