94400d50d4
作为子目录纳入系统,与核心测试管道协同 Co-Authored-By: Claude <noreply@anthropic.com>
76 lines
2.7 KiB
Markdown
76 lines
2.7 KiB
Markdown
# 27-validation-halfwidth: Half-Width Character Validation
|
|
|
|
## 电信业务场景
|
|
|
|
电话号码格式校验。检查电话号码字段是否全为半角数字(0-9),检测全角字符混入和长度超出。
|
|
|
|
## Description
|
|
|
|
Reads FILE-IN and validates that each character in IN-TEXT is
|
|
half-width (ASCII printable: X'20'-X'7E'). Validates length
|
|
constraints: 20 or fewer half-width characters pass; more than 20
|
|
is an error. Full-width characters or control characters cause
|
|
rejection.
|
|
|
|
## Validation Rules
|
|
|
|
| Rule | Result | Error Code |
|
|
|-----------------------------------|--------------|------------|
|
|
| All characters X'20'-X'7E', <= 20 | PASS to GOOD | - |
|
|
| Contains non-half-width character | FAIL to BAD | 01 |
|
|
| All half-width but >20 chars | FAIL to BAD | 02 |
|
|
|
|
## Record Layout
|
|
|
|
### Input / Good Output (30 bytes)
|
|
|
|
| Field | Type | Length | Description |
|
|
|--------|----------|--------|-------------|
|
|
| TEXT | PIC X | 30 | Text to validate |
|
|
|
|
### Bad Output (32 bytes)
|
|
|
|
| Field | Type | Length | Description |
|
|
|----------|----------|--------|----------------|
|
|
| TEXT | PIC X | 30 | Original text |
|
|
| ERR-CODE | PIC X | 2 | Error code |
|
|
|
|
## Files
|
|
|
|
| File | Purpose |
|
|
|-------------------------------|--------------------------------|
|
|
| main-27-validation-halfwidth.cbl | Main COBOL program |
|
|
| data-gen.sh | Generate test data |
|
|
| run.sh | Compile, run, verify |
|
|
| README.md | This file |
|
|
|
|
## Tests
|
|
|
|
| Test Case | Expected |
|
|
|----------------------------------|-----------------------------|
|
|
| 4 half-width chars | PASS to GOOD |
|
|
| 10 half-width chars | PASS to GOOD |
|
|
| 20 half-width chars (boundary) | PASS to GOOD |
|
|
| 25 half-width chars (too long) | FAIL err 02 |
|
|
| Mixed with full-width | FAIL err 01 |
|
|
| Full-width only | FAIL err 01 |
|
|
| Half-width + control char | FAIL err 01 |
|
|
| All spaces (empty) | PASS to GOOD |
|
|
|
|
## Usage
|
|
|
|
```bash
|
|
cd 27-validation-halfwidth
|
|
bash data-gen.sh
|
|
bash run.sh
|
|
```
|
|
|
|
## Expected Behavior
|
|
|
|
- Half-width check uses byte comparison against X'20'-X'7E'.
|
|
- Full-width UTF-8 multi-byte characters have bytes > X'7E'
|
|
and are detected as non-half-width.
|
|
- Length is computed by trimming trailing spaces.
|
|
- Only records meeting both conditions (half-width + <= 20 chars)
|
|
are written to GOOD output.
|