Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions test/game_record_snapshot_tests/fixtures/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# GameRecord Snapshot Tests

This directory contains snapshot tests for `GameRecord.fromSgf` and `GameRecord.fromGib` methods.

## How It Works

The tests automatically discover all `.sgf` and `.gib` files in the `fixtures/` directory and validate them against their corresponding snapshot JSON files. **No need to write new test cases** - just add your file and regenerate snapshots!

## Structure

- `fixtures/` - Test data files
- `*.sgf` - Sample SGF game files
- `*.gib` - Sample GIB game files
- `snapshots/` - Expected output JSON files for comparison

## Running Tests

Run all snapshot tests:
```bash
flutter test test/game_record_snapshot_tests/
```

Or run all tests:
```bash
flutter test
```

## Regenerating Snapshots

If you modify the `GameRecord` parsing logic or want to update the expected outputs:

```bash
dart run test/game_record_snapshot_tests/generate_snapshots.dart
```

The generator automatically discovers all `.sgf` and `.gib` files in the fixtures directory.

This will regenerate all snapshot JSON files in `fixtures/snapshots/`.

## Snapshot Format

Each snapshot is a JSON file containing:
```json
{
"type": "GameRecordType.sgf",
"moveCount": 14,
"moves": [
{
"color": "B", // "B" for black, "W" for white
"row": 4,
"col": 4
},
...
]
}
```

## Adding New Test Cases

1. Add a new `.sgf` or `.gib` file to `test/game_record_snapshot_tests/fixtures/`
2. Run the generator: `dart run test/game_record_snapshot_tests/generate_snapshots.dart`
3. Run tests to verify: `flutter test test/game_record_snapshot_tests/`

**That's it!** The test framework automatically discovers and tests your new file.
10 changes: 10 additions & 0 deletions test/game_record_snapshot_tests/fixtures/fox_9x9.sgf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
(;GM[1]FF[4]
SZ[9]
GN[]
DT[2025-09-16]
PB[benjito]
PW[V291851863]
BR[1级]
WR[1级]
KM[375]HA[0]RU[Chinese]AP[GNU Go:3.8]RN[12]RE[W+4.25]TM[60]TC[3]TT[20]AP[foxwq]RL[0]
;B[ge];W[de];B[ef];W[df];B[dg];W[ee];B[ff];W[cg];B[fc];W[dh];B[eh];W[eg];B[fg];W[dc];B[eb];W[db];B[da];W[ec];B[fb];W[ca];B[dg];W[fd];B[gd];W[eg];B[cb];W[ea];B[dg];W[ch];B[fa];W[da];B[fe];W[ed];B[eg];W[ei];B[fi];W[di])
38 changes: 38 additions & 0 deletions test/game_record_snapshot_tests/fixtures/ogs_9x9.sgf
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
(;FF[4]
CA[UTF-8]
GM[1]
DT[2025-11-08]
PC[OGS: https://online-go.com/game/19728]
GN[asdfg vs. asdf]
PB[asdfg]
PW[asdf]
BR[9k]
WR[10k]
TM[120]OT[5x30 byo-yomi]
RE[B+2.5]
SZ[9]
KM[6.5]
RU[Japanese]
;B[ea]
(;W[fa]
(;B[eb]
(;W[fb]
(;B[ec]
(;W[fc]
(;B[ed]
(;W[fd]
(;B[ee]
(;W[fe]
(;B[ef]
(;W[ff]
(;B[eg]
(;W[fg]
(;B[eh]
(;W[fh]
(;B[ei]
(;W[fi]
(;B[hh]
(;W[hf]
(;B[]
(;W[]
))))))))))))))))))))))
185 changes: 185 additions & 0 deletions test/game_record_snapshot_tests/fixtures/snapshots/fox_9x9_sgf.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
{
"type": "GameRecordType.sgf",
"moves": [
{
"color": "B",
"row": 4,
"col": 6
},
{
"color": "W",
"row": 4,
"col": 3
},
{
"color": "B",
"row": 5,
"col": 4
},
{
"color": "W",
"row": 5,
"col": 3
},
{
"color": "B",
"row": 6,
"col": 3
},
{
"color": "W",
"row": 4,
"col": 4
},
{
"color": "B",
"row": 5,
"col": 5
},
{
"color": "W",
"row": 6,
"col": 2
},
{
"color": "B",
"row": 2,
"col": 5
},
{
"color": "W",
"row": 7,
"col": 3
},
{
"color": "B",
"row": 7,
"col": 4
},
{
"color": "W",
"row": 6,
"col": 4
},
{
"color": "B",
"row": 6,
"col": 5
},
{
"color": "W",
"row": 2,
"col": 3
},
{
"color": "B",
"row": 1,
"col": 4
},
{
"color": "W",
"row": 1,
"col": 3
},
{
"color": "B",
"row": 0,
"col": 3
},
{
"color": "W",
"row": 2,
"col": 4
},
{
"color": "B",
"row": 1,
"col": 5
},
{
"color": "W",
"row": 0,
"col": 2
},
{
"color": "B",
"row": 6,
"col": 3
},
{
"color": "W",
"row": 3,
"col": 5
},
{
"color": "B",
"row": 3,
"col": 6
},
{
"color": "W",
"row": 6,
"col": 4
},
{
"color": "B",
"row": 1,
"col": 2
},
{
"color": "W",
"row": 0,
"col": 4
},
{
"color": "B",
"row": 6,
"col": 3
},
{
"color": "W",
"row": 7,
"col": 2
},
{
"color": "B",
"row": 0,
"col": 5
},
{
"color": "W",
"row": 0,
"col": 3
},
{
"color": "B",
"row": 4,
"col": 5
},
{
"color": "W",
"row": 3,
"col": 4
},
{
"color": "B",
"row": 6,
"col": 4
},
{
"color": "W",
"row": 8,
"col": 4
},
{
"color": "B",
"row": 8,
"col": 5
},
{
"color": "W",
"row": 8,
"col": 3
}
]
}
Loading