Files
five/tests/std_ch/test_total.prg
CharlesKWON 3a7f1dea72 feat(rtl,tests): pre-release UX round (Wave 5)
Three audit findings around polish + a release-readiness commit:

  * #UX1 LIST/DISPLAY output: dropped \r\n (unix terminals showed a
    stray ^M), moved the newline to AFTER each row (no more leading
    blank line), and added the `*` deleted-record marker after the
    record number — matches xBase LIST/DISPLAY convention. With
    SET DELETED ON the marker is unreachable since the row would
    have been skipped at Area.Skip level; with SET DELETED OFF the
    user now sees which rows are tombstoned.

  * #26 temp aliases: `__copytmp` / `__sorttmp` / `__totaltmp` /
    `__jointmp` were process-global string constants. A nested
    invocation (e.g., COPY inside a FOR clause whose expression
    runs another COPY) collided on the alias and the inner Open
    failed with "alias already in use" — surfacing as `.F.` with
    no clear cause. Each Open now goes through a new helper
    `nextTmpAlias(prefix)` backed by an atomic counter, so every
    call gets `__copytmp_1`, `__copytmp_2`, etc. — no collisions.

  * #J test coverage gap: the 13 std.ch regression tests were all
    sitting in `/tmp` — lost on tmpfs reboot, never in git, never
    in CI. Move them into `tests/std_ch/` and add a simple
    `run.sh` runner that builds + executes each one in a temp
    scratch directory and grep-asserts on FAIL / NOT REJECTED /
    expectation-mismatch markers. 13/13 pass against the current
    head:

       PASS  test_pp_stdch       PASS  test_count
       PASS  test_sum_avg        PASS  test_sum_multi
       PASS  test_copy           PASS  test_sort
       PASS  test_list           PASS  test_total
       PASS  test_join           PASS  test_update
       PASS  test_set_deleted    PASS  test_unsupported
       PASS  test_block_comma

    test_block_comma in particular guards the gengo SeqExpr fix
    from Wave 1 — without it the comma-in-block miscompile would
    silently come back.

Gates green:
  go test ./...      : PASS
  FiveSql2 SQL:1999  : 43/43
  Harbour compat     : 56/56
  std.ch suite       : 13/13

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-01 08:07:50 +09:00

50 lines
1.7 KiB
Plaintext

/* TOTAL TO ... ON ... FIELDS ... via PP rule. */
PROCEDURE Main()
LOCAL aStruct, n
FErase( "src.dbf" )
FErase( "dst.dbf" )
/* Sales records, sorted by department. */
aStruct := { ;
{ "DEPT", "C", 12, 0 }, ;
{ "EMP", "C", 12, 0 }, ;
{ "AMT", "N", 8, 2 }, ;
{ "QTY", "N", 4, 0 } }
dbCreate( "src.dbf", aStruct )
USE src.dbf NEW EXCLUSIVE ALIAS s
/* engineering: 100+200=300, qty 5+8=13 */
dbAppend() ; FieldPut(1,"engineering"); FieldPut(2,"alice") ; FieldPut(3,100) ; FieldPut(4,5)
dbAppend() ; FieldPut(1,"engineering"); FieldPut(2,"bob") ; FieldPut(3,200) ; FieldPut(4,8)
/* sales: 50+150+25=225, qty 1+3+1=5 */
dbAppend() ; FieldPut(1,"sales") ; FieldPut(2,"carol") ; FieldPut(3,50) ; FieldPut(4,1)
dbAppend() ; FieldPut(1,"sales") ; FieldPut(2,"dan") ; FieldPut(3,150) ; FieldPut(4,3)
dbAppend() ; FieldPut(1,"sales") ; FieldPut(2,"eve") ; FieldPut(3,25) ; FieldPut(4,1)
/* hr: 80, qty 2 */
dbAppend() ; FieldPut(1,"hr") ; FieldPut(2,"frank") ; FieldPut(3,80) ; FieldPut(4,2)
dbCommit()
? "--- TOTAL TO dst ON dept FIELDS amt, qty ---"
dbGoTop()
TOTAL TO dst.dbf ON s->dept FIELDS amt, qty
dbCloseArea()
USE dst.dbf NEW EXCLUSIVE
COUNT TO n
? "Group rows =", n, "(expect 3 = engineering, sales, hr)"
dbGoTop()
? "1.", AllTrim(FieldGet(1)), "amt:", FieldGet(3), "qty:", FieldGet(4), "(expect engineering 300 13)"
dbSkip()
? "2.", AllTrim(FieldGet(1)), "amt:", FieldGet(3), "qty:", FieldGet(4), "(expect sales 225 5)"
dbSkip()
? "3.", AllTrim(FieldGet(1)), "amt:", FieldGet(3), "qty:", FieldGet(4), "(expect hr 80 2)"
dbCloseArea()
FErase( "src.dbf" )
FErase( "dst.dbf" )
? "DONE"
RETURN