# test.govlab/patterns/core/parsers/syntax.fixture.ts

> 15 lines of code and 2 definitions.

Tree: Codebase Testing
Language: typescript
Canonical: https://banes-lab.com/anatomy/testing#file-testing-test-govlab-patterns-core-parsers-syntax-fixture-ts
Source text: https://banes-lab.com/source/testing/test.govlab/patterns/core/parsers/syntax.fixture.ts.txt

Listed in [test.govlab/patterns/core/parsers](https://banes-lab.com/api/source/testing/test.govlab/patterns/core/parsers.md), after [test.govlab/patterns/core/parsers/schema.parser.test.ts](https://banes-lab.com/source/testing/test.govlab/patterns/core/parsers/schema.parser.test.ts.md) and before [test.govlab/patterns/core/parsers/syntax.parser.test.ts](https://banes-lab.com/source/testing/test.govlab/patterns/core/parsers/syntax.parser.test.ts.md).

## Definitions

- `leaf` (lexical_declaration, line 3, exported)
- `branch` (lexical_declaration, line 15, exported)

## Contained in

- [test.govlab/patterns/core/parsers](https://banes-lab.com/anatomy/testing/folder-testing-test-govlab-patterns-core-parsers.md)

## Source

```typescript
import type { CstNode } from "@govlab/code-parse";

export const leaf = function leaf(type: string, fields: Readonly<Record<string, CstNode>> = {}): CstNode {
    return {
        child: () => null,
        childCount: 0,
        childForFieldName: (name: string) => fields[name] ?? null,
        isNamed: true,
        startPosition: { column: 0, row: 0 },
        text: type,
        type,
    };
};

export const branch = function branch(type: string, children: readonly CstNode[]): CstNode {
    return { child: (index: number) => children[index] ?? null, childCount: children.length, isNamed: true, type };
};
```
