# Wasot CLI Test Cases

Comprehensive test cases for the `wasot` CLI following Unix/Linux conventions.

---

## 1. Basic Operations

### 1.1 Default (Normalize)
- `wasot file.wasot` — normalize wasot file to stdout
- `wasot file.wasot -o out.wasot` — normalize to file
- `wasot` — read from stdin, normalize to stdout

### 1.2 Format Conversion (-t)
- `wasot file.wasot -t xml` — convert to XML
- `wasot file.wasot -t jsonl` — convert to JSON Lines
- `wasot file.wasot -t binary` — convert to binary protobuf
- `wasot file.wasot -t wasot` — explicit normalize (same as default)

### 1.3 Output File (-o)
- `wasot file.wasot -o out.xml` — format inferred from extension
- `wasot file.wasot -o out.jsonl` — format inferred from extension
- `wasot file.wasot -o out.wasotb` — format inferred from extension
- `wasot file.wasot -t xml -o out.dat` — explicit format overrides extension
- `wasot file.wasot -o /dev/null` — discard output

### 1.4 Input Format (-f)
- `wasot -f wasot file.wasot` — explicit wasot input
- `wasot -f binary file.wasotb` — explicit binary input
- `wasot -f jsonl file.jsonl` — explicit jsonl input

---

## 2. Stdin/Stdout

### 2.1 Stdin Input
- `cat file.wasot | wasot` — pipe input
- `wasot < file.wasot` — redirect input
- `echo ".block" | wasot` — inline input
- `wasot -` — explicit stdin (same as no file)

### 2.2 Stdout Output
- `wasot file.wasot > out.wasot` — redirect output
- `wasot file.wasot | cat` — pipe output
- `wasot file.wasot | head -1` — partial read (SIGPIPE)
- `wasot file.wasot | wc -l` — count lines

### 2.3 Combined
- `cat file.wasot | wasot -t xml > out.xml` — full pipeline
- `wasot file.wasot -t jsonl | jq .` — pipe to jq
- `wasot file.wasot -t xml | xmllint --format -` — pipe to xmllint

---

## 3. Format Conversion Matrix

### 3.1 Wasot Input
- `wasot file.wasot -t wasot` — wasot → wasot (normalize)
- `wasot file.wasot -t xml` — wasot → xml
- `wasot file.wasot -t jsonl` — wasot → jsonl
- `wasot file.wasot -t binary` — wasot → binary

### 3.2 Binary Input
- `wasot file.wasotb` — binary → wasot (auto-detect)
- `wasot -f binary file.wasotb` — binary → wasot (explicit)
- `wasot -f binary file.wasotb -t jsonl` — binary → jsonl

### 3.3 JSONL Input
- `wasot -f jsonl file.jsonl` — jsonl → wasot

### 3.4 Roundtrip
- `wasot file.wasot -t binary | wasot` — wasot → binary → wasot
- `wasot file.wasot -t jsonl | wasot -f jsonl` — wasot → jsonl → wasot
- `wasot file.wasot -t binary -o tmp.bin && wasot tmp.bin` — via file

---

## 4. Format Auto-Detection

### 4.1 By Extension
- `wasot file.wasot` — .wasot → wasot format
- `wasot file.wasotb` — .wasotb → binary format
- `wasot file.xml` — .xml → xml format (if supported)
- `wasot file.jsonl` — .jsonl → jsonl format

### 4.2 By Content (stdin)
- `echo ".block" | wasot` — detects wasot (starts with .)
- `echo "# heading" | wasot` — detects wasot (starts with #)
- `echo "<root/>" | wasot -f xml` — xml needs explicit -f
- `printf '\x08\x01' | wasot` — detects binary (non-UTF8)

### 4.3 Output Extension Detection
- `wasot file.wasot -o out.xml` — detects xml from .xml
- `wasot file.wasot -o out.jsonl` — detects jsonl from .jsonl
- `wasot file.wasot -o out.wasotb` — detects binary from .wasotb
- `wasot file.wasot -o out.txt` — unknown ext → wasot default

---

## 5. Check Subcommand

### 5.1 Single File
- `wasot check file.wasot` — validate one file
- `wasot check file.wasot && echo valid` — use in conditionals
- `wasot check file.wasot || echo invalid` — check failure

### 5.2 Multiple Files
- `wasot check a.wasot b.wasot c.wasot` — validate multiple
- `wasot check *.wasot` — glob expansion
- `wasot check file1.wasot missing.wasot file2.wasot` — partial failure

### 5.3 Stdin
- `cat file.wasot | wasot check` — check from stdin
- `echo ".block" | wasot check` — check inline
- `wasot check -` — explicit stdin

### 5.4 Exit Codes
- `wasot check valid.wasot; echo $?` — expect 0
- `wasot check invalid.wasot; echo $?` — expect 1
- `wasot check missing.wasot; echo $?` — expect 2

### 5.5 Batch Validation
- `find . -name "*.wasot" | xargs wasot check` — find + xargs
- `find . -name "*.wasot" -exec wasot check {} +` — find -exec
- `ls *.wasot | xargs -P4 wasot check` — parallel check

---

## 6. Info Subcommand

### 6.1 File Input
- `wasot info file.wasot` — show stats for file
- `wasot info large.wasot` — stats for large file

### 6.2 Stdin Input
- `cat file.wasot | wasot info` — stats from stdin
- `wasot info -` — explicit stdin

### 6.3 Output Format
- `wasot info file.wasot | grep "blocks:"` — parse block count
- `wasot info file.wasot | grep "depth:"` — parse max depth
- `wasot info file.wasot | awk '/^blocks:/ {print $2}'` — extract value

---

## 7. Selector (--select)

### 7.1 Basic Selectors
- `wasot --select="p" file.wasot` — select by type
- `wasot --select="paragraph" file.wasot` — full type name
- `wasot --select="code" file.wasot` — select code blocks
- `wasot --select="footer" file.wasot` — select footer

### 7.2 With Output Formats
- `wasot --select="p" file.wasot` — selected as wasot
- `wasot --select="p" file.wasot -t jsonl` — selected as jsonl
- `wasot --select="p" file.wasot -t xml` — selected as xml
- `wasot --select="p" file.wasot -t binary` — selected as binary

### 7.3 With Output File
- `wasot --select="p" file.wasot -o selected.wasot` — to file
- `wasot --select="p" file.wasot -t jsonl -o selected.jsonl` — format + file

### 7.4 Count Matches
- `wasot --select="p" file.wasot | grep -c "^\."` — count wasot blocks
- `wasot --select="p" file.wasot -t jsonl | wc -l` — count jsonl lines

### 7.5 Pipeline
- `wasot --select="code" file.wasot -t jsonl | jq -r '.children[].Text.lines[]'` — extract code

---

## 8. Exit Codes

### 8.1 Success (0)
- `wasot file.wasot > /dev/null; echo $?` — normal operation
- `wasot check valid.wasot; echo $?` — valid file
- `wasot info file.wasot > /dev/null; echo $?` — info success

### 8.2 Invalid Input (1)
- `echo "invalid{{" | wasot check; echo $?` — parse error
- `wasot check malformed.wasot; echo $?` — invalid syntax

### 8.3 IO Error (2)
- `wasot missing.wasot; echo $?` — file not found
- `wasot /root/noperm.wasot; echo $?` — permission denied
- `wasot check missing.wasot; echo $?` — check missing file

### 8.4 Invalid Args (3)
- `wasot --invalid-flag; echo $?` — unknown flag
- `wasot -t invalid file.wasot; echo $?` — unknown format

---

## 9. Edge Cases

### 9.1 Empty Input
- `wasot /dev/null` — empty file
- `echo "" | wasot` — empty stdin
- `echo "   " | wasot` — whitespace only
- `wasot check /dev/null` — check empty

### 9.2 Large Files
- `wasot large.wasot > /dev/null` — large file to null
- `wasot large.wasot -t binary | wc -c` — measure binary size
- `wasot large.wasot | head -100` — partial read large file

### 9.3 Special Characters
- `wasot "file with spaces.wasot"` — spaces in filename
- `wasot ./file.wasot` — relative path
- `wasot /absolute/path/file.wasot` — absolute path
- `wasot ../parent/file.wasot` — parent directory

### 9.4 Binary Safety
- `wasot file.wasot -t binary | cat` — binary to terminal (unsafe)
- `wasot file.wasot -t binary > out.wasotb` — binary to file (safe)
- `wasot file.wasot -t binary | xxd | head` — binary inspection

---

## 10. Unix Integration

### 10.1 Pipes
- `wasot file.wasot | head -1` — first line only
- `wasot file.wasot | tail -10` — last 10 lines
- `wasot file.wasot | grep "pattern"` — filter output
- `wasot file.wasot | tee backup.wasot | wc -l` — tee + count

### 10.2 Process Substitution
- `diff <(wasot a.wasot) <(wasot b.wasot)` — compare normalized
- `cat <(wasot a.wasot) <(wasot b.wasot)` — concatenate
- `wasot <(cat a.wasot b.wasot)` — process substitution input

### 10.3 Find/Xargs
- `find . -name "*.wasot" | xargs wasot check` — check all
- `find . -name "*.wasot" -exec wasot {} -o {}.normalized \;` — batch convert
- `find . -name "*.wasot" | xargs -I{} wasot {} -t xml -o {}.xml` — with placeholder

### 10.4 Parallel Processing
- `ls *.wasot | parallel wasot {} -o {.}.xml` — GNU parallel
- `ls *.wasot | xargs -P4 -I{} wasot {} -o {}.normalized` — xargs parallel
- `find . -name "*.wasot" | parallel --bar wasot check` — with progress

### 10.5 Shell Loops
- `for f in *.wasot; do wasot "$f" -t xml > "${f%.wasot}.xml"; done` — batch convert
- `for f in *.wasot; do wasot check "$f" || echo "FAIL: $f"; done` — check with report

---

## 11. Completions

### 11.1 Generate
- `wasot completions bash > wasot.bash` — bash completions
- `wasot completions zsh > _wasot` — zsh completions
- `wasot completions fish > wasot.fish` — fish completions
- `wasot completions powershell > wasot.ps1` — powershell completions

### 11.2 Install (example)
- `wasot completions bash | sudo tee /etc/bash_completion.d/wasot` — system-wide
- `wasot completions bash >> ~/.bashrc` — user bashrc

---

## 12. Combination Tests

### 12.1 Full Pipelines
- `cat *.wasot | wasot -t jsonl | jq -s 'group_by(.meta_line.type_name)'` — aggregate by type
- `wasot --select="code" file.wasot -t jsonl | jq -r '.meta_line.arguments'` — extract args
- `wasot file.wasot -t xml | xsltproc transform.xsl - > out.html` — XSLT transform

### 12.2 Conversion Chains
- `wasot a.wasot -t binary | wasot -t jsonl | jq .` — wasot → binary → jsonl
- `wasot a.wasot -t jsonl | wasot -f jsonl -t xml` — wasot → jsonl → xml (if supported)

### 12.3 Validation Pipelines
- `find . -name "*.wasot" | xargs wasot check && echo "All valid"` — batch validate
- `wasot check *.wasot 2>&1 | grep -c "file not found"` — count missing
- `for f in *.wasot; do wasot info "$f" | head -1; done | sort -t: -k2 -rn` — sort by block count

---

## 13. Error Handling

### 13.1 Graceful Errors
- `wasot missing.wasot 2>&1 | grep -q "not found"` — error message check
- `wasot --select="p" -f binary file.wasotb 2>&1` — select + wrong format
- `wasot -t sqlite file.wasot 2>&1` — sqlite without -o

### 13.2 Stderr vs Stdout
- `wasot file.wasot 2>/dev/null` — suppress errors
- `wasot file.wasot 1>/dev/null` — suppress output
- `wasot check file.wasot 2>&1 >/dev/null` — only errors
- `wasot info file.wasot 2>/dev/null | head -1` — only output

### 13.3 Broken Pipe
- `wasot large.wasot | head -1` — should not error
- `wasot large.wasot -t jsonl | head -1` — jsonl + head
- `yes | wasot --help | head -1` — help with broken pipe

---

## 14. Performance Tests

### 14.1 Throughput
- `time wasot large.wasot > /dev/null` — measure time
- `wasot large.wasot -t binary | pv > /dev/null` — measure throughput
- `time wasot large.wasot -t jsonl | wc -l` — jsonl speed

### 14.2 Memory
- `/usr/bin/time -v wasot huge.wasot > /dev/null 2>&1 | grep "Maximum resident"` — peak memory
- `wasot huge.wasot -t binary | cat > /dev/null` — streaming memory

---

## 15. Idempotency Tests

### 15.1 Normalize Idempotency
- `wasot file.wasot | wasot | diff - <(wasot file.wasot)` — double normalize = single
- `wasot file.wasot > a.wasot && wasot a.wasot > b.wasot && diff a.wasot b.wasot` — file compare

### 15.2 Roundtrip Preservation
- `wasot file.wasot -t binary | wasot | diff - <(wasot file.wasot)` — binary roundtrip
- `wasot file.wasot -t jsonl | wasot -f jsonl | diff - <(wasot file.wasot)` — jsonl roundtrip

---

## Summary

| Category | Count | Priority |
|----------|-------|----------|
| Basic Operations | 12 | High |
| Stdin/Stdout | 12 | High |
| Format Conversion | 12 | High |
| Auto-Detection | 12 | Medium |
| Check Subcommand | 14 | High |
| Info Subcommand | 6 | Medium |
| Selector | 12 | High |
| Exit Codes | 8 | High |
| Edge Cases | 12 | Medium |
| Unix Integration | 16 | High |
| Completions | 6 | Low |
| Combinations | 9 | Medium |
| Error Handling | 10 | High |
| Performance | 5 | Low |
| Idempotency | 4 | Medium |
| **Total** | **~150** | |
