{"id":16701176,"url":"https://github.com/oowekyala/kt-tree-utils","last_synced_at":"2026-04-24T18:05:43.359Z","repository":{"id":57721940,"uuid":"162024066","full_name":"oowekyala/kt-tree-utils","owner":"oowekyala","description":"A testing DSL to specify the structure of a tree in a concise and readable way.","archived":false,"fork":false,"pushed_at":"2019-05-10T15:37:36.000Z","size":175,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-21T00:50:03.600Z","etag":null,"topics":["kotlin-dsl","kotlintest","testing","trees"],"latest_commit_sha":null,"homepage":null,"language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"unlicense","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/oowekyala.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-12-16T17:21:37.000Z","updated_at":"2019-05-10T15:37:38.000Z","dependencies_parsed_at":"2022-09-26T21:51:25.264Z","dependency_job_id":null,"html_url":"https://github.com/oowekyala/kt-tree-utils","commit_stats":null,"previous_names":["oowekyala/kt-tree-matchers"],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oowekyala%2Fkt-tree-utils","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oowekyala%2Fkt-tree-utils/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oowekyala%2Fkt-tree-utils/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oowekyala%2Fkt-tree-utils/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/oowekyala","download_url":"https://codeload.github.com/oowekyala/kt-tree-utils/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243532550,"owners_count":20306155,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["kotlin-dsl","kotlintest","testing","trees"],"created_at":"2024-10-12T18:29:24.723Z","updated_at":"2025-12-27T22:36:58.048Z","avatar_url":"https://github.com/oowekyala.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![](https://img.shields.io/maven-central/v/com.github.oowekyala.treeutils/tree-matchers.svg)](https://search.maven.org/artifact/com.github.oowekyala.treeutils/tree-matchers/2.0.1/jar)\n\n# Tree Matchers for Kotlin tests\n\nThis is a lightweight testing DSL to assert that a tree conforms to an\nexpected structure. Its focus is to maximise readability and provide\ndetailed error messages. It supports any tree-like structure, you just have\nto plug in an adapter.\n\nJump to the [Setup](#setup) section or take a look at the samples below.\n\n\n## Samples\n\n\n```kotlin\n\nnode should matchNode\u003cASTStatement\u003e {\n\n    // nesting matchers allow to specify a whole subtree\n    child\u003cASTForStatement\u003e {\n\n        // This would fail if the first child of the ForStatement wasn't a ForInit\n        child\u003cASTForInit\u003e {\n            child\u003cASTLocalVariableDeclaration\u003e {\n\n                // If the parameter ignoreChildren is set to true, the number of children is not asserted\n                // Calls to \"child\" in the block are forbidden\n                // The only checks carried out here are the type test and the assertions of the block\n                child\u003cASTType\u003e(ignoreChildren = true) {\n\n                    // In a \"child\" block, the tested node can be referred to as \"it\"\n                    // Here, its static type is ASTType, so we can inspect properties\n                    // of the node and make assertions\n\n                    it.typeImage shouldBe \"int\"\n                    it.type shouldNotBe null\n                }\n\n                // We don't care about that node, we only care that there is \"some\" node\n                unspecifiedChild()\n            }\n        }\n\n        // The subtree is ignored, but we check a ForUpdate is present at this child position\n        child\u003cASTForUpdate\u003e(ignoreChildren = true) {}\n\n        // Here, ignoreChildren is not specified and takes its default value of false.\n        // The lambda has no \"child\" calls and the node will be asserted to have no children\n        child\u003cASTBlock\u003e {}\n    }\n}\n\n```\n\n\nSee also the Kotlin docs.\n\n## Setup\n\nYou need JDK 1.8+, but the libraries use your provided dependencies\ninstead of shipping a kotlin standard library and kotlin test framework.\n\n### Maven\n\n```xml\n\u003cdependency\u003e\n  \u003cgroupId\u003ecom.github.oowekyala.treeutils\u003c/groupId\u003e\n  \u003cartifactId\u003etree-matchers\u003c/artifactId\u003e\n  \u003cversion\u003e2.1.0\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\n### Gradle\n\n```groovy\n   implementation 'com.github.oowekyala.treeutils:tree-matchers:2.1.0'\n```\n\nor with the Kotlin DSL:\n\n```kotlin\n   implementation(\"com.github.oowekyala.treeutils:tree-matchers:2.1.0\")\n```\n\n### Provide an adapter\n\nFor example, if your tree type hierarchy is topped by a class named `Node`,\nyou should:\n\n* Implement `TreeLikeAdapter\u003cNode\u003e` on some object\n* Define some shorthand methods, to avoid providing the adapter every time\n\nHere it is in code:\n\n```kotlin\n\nobject NodeTreeLikeAdapter : TreeLikeAdapter\u003cNode\u003e {\n    override fun getChildren(node: Node): List\u003cNode\u003e = /* implementation */\n}\n\n\ntypealias NodeSpec\u003cN\u003e = TreeNodeWrapper\u003cNode, N\u003e.() -\u003e Unit\n\n// This can be used with plain kotlin.test : someNode.shouldMatchNode\u003cFoo\u003e { ... }\ninline fun \u003creified N : Node\u003e Node?.shouldMatchNode(\n                                        ignoreChildren: Boolean = false,\n                                        noinline nodeSpec: NodeSpec\u003cN\u003e\n                                    ) = this.baseShouldMatchSubtree(MatchingConfig(adapter = NodeTreeLikeAdapter), ignoreChildren, nodeSpec = nodeSpec)\n\n// This can be used with kotlintest's \"someNode should matchNode\u003cFoo\u003e { ... }\"\ninline fun \u003creified N : Node\u003e matchNode(\n                                    ignoreChildren: Boolean = false,\n                                    noinline nodeSpec: NodeSpec\u003cN\u003e\n                              ) : (Node?) -\u003e Unit = { it.shouldMatchNode(ignoreChildren, nodeSpec) }\n\n```\n\nMore complete documentation can be found in the Kotlin docs of the project. Happy testing!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foowekyala%2Fkt-tree-utils","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Foowekyala%2Fkt-tree-utils","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foowekyala%2Fkt-tree-utils/lists"}