ocaml: phase 6 Printf.sprintf %d/%s/%f/%c/%b/%% + global string_of_* (+5 tests, 492 total)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 21s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 21s
Replaces the stub sprintf in runtime.sx with a real implementation: walk fmt char-by-char accumulating a prefix; on recognised %X return a one-arg fn that formats the arg and recurses on the rest of fmt. The function self-curries to the spec count — there's no separate arity machinery, just a closure chain. Specs: %d (int), %s (string), %f (float), %c (char/string in our model), %b (bool), %% (literal). Unknown specs pass through. Same expression returns a string (no specs) or a function (>=1 spec) — OCaml proper would reject this; works fine in OCaml-on-SX's dynamic runtime. Also adds top-level aliases: string_of_int = _string_of_int string_of_float = _string_of_float string_of_bool = if b then "true" else "false" int_of_string = _int_of_string Printf.sprintf "x=%d" 42 = "x=42" Printf.sprintf "%s = %d" "answer" 42 = "answer = 42" Printf.sprintf "%d%%" 50 = "50%"
This commit is contained in:
@@ -1210,6 +1210,18 @@ cat > "$TMPFILE" << 'EPOCHS'
|
||||
(epoch 4932)
|
||||
(eval "(ocaml-run \"try (assert false; 0) with _ -> 99\")")
|
||||
|
||||
;; ── Printf.sprintf + global string_of_* ──────────────────────
|
||||
(epoch 4940)
|
||||
(eval "(ocaml-run \"Printf.sprintf \\\"hello\\\"\")")
|
||||
(epoch 4941)
|
||||
(eval "(ocaml-run \"Printf.sprintf \\\"x=%d\\\" 42\")")
|
||||
(epoch 4942)
|
||||
(eval "(ocaml-run \"Printf.sprintf \\\"%s = %d\\\" \\\"answer\\\" 42\")")
|
||||
(epoch 4943)
|
||||
(eval "(ocaml-run \"Printf.sprintf \\\"%d%%\\\" 50\")")
|
||||
(epoch 4944)
|
||||
(eval "(ocaml-run \"string_of_int 7 ^ \\\"-\\\" ^ string_of_bool true\")")
|
||||
|
||||
EPOCHS
|
||||
|
||||
OUTPUT=$(timeout 360 "$SX_SERVER" < "$TMPFILE" 2>/dev/null)
|
||||
@@ -1919,6 +1931,13 @@ check 4930 "assert true; 42" '42'
|
||||
check 4931 "assert (x = 5); x + 1" '6'
|
||||
check 4932 "try (assert false; ...) with" '99'
|
||||
|
||||
# ── Printf.sprintf ───────────────────────────────────────────────
|
||||
check 4940 "sprintf no args" '"hello"'
|
||||
check 4941 "sprintf one %d" '"x=42"'
|
||||
check 4942 "sprintf %s = %d" '"answer = 42"'
|
||||
check 4943 "sprintf %d%% literal percent" '"50%"'
|
||||
check 4944 "string_of_int + string_of_b" '"7-true"'
|
||||
|
||||
TOTAL=$((PASS + FAIL))
|
||||
if [ $FAIL -eq 0 ]; then
|
||||
echo "ok $PASS/$TOTAL OCaml-on-SX tests passed"
|
||||
|
||||
Reference in New Issue
Block a user