Files
bare-operating-system/packages/bare-os-coreutils/test/posix-test-int-compare.test.mjs
T
Raven Scott f8ddef7950 docs(ci): rename ctx client script, extend bare-import scan, POSIX tests, and doc sync
- Rename scripts/gen-ctx-client-stub.mjs to gen-ctx-client-helper.mjs; update
  pretest, scripts README, and PLACEHOLDER_BASELINE.
- Scan packages/bare-os-protocol/lib in verify-bare-imports.mjs; clarify scope
  in script header.
- Document bundle health / marker allowlist workflow in bare-os-bare-libs README
  and quarterly upstream notes in docs/release-checklist.md.
- Add ctx API release checklist to docs/reference/ctx-api-versioning.md.
- Add shell param expansion V3 tests in bare-os-booter/test.js; add coreutils
  posix-test-int-compare.test.mjs and wire into bare-os-coreutils test script.
- Sync conformance matrix, environment appendix, handbook ch.9, and add
  pathconf to docs/reference/posix-conformance-matrix.json for verify-compat-matrix.
2026-04-04 19:41:15 -04:00

41 lines
1.1 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* POSIX Issue 7style integer comparison primaries for /bin/test (mirrors
* packages/bare-os-coreutils/src/test.js evalTest three-arg int branch).
*/
import test from 'brittle'
/** @param {string | number} a @param {string} op @param {string | number} b */
function evalIntRel(a, op, b) {
const la = Number.parseInt(String(a), 10)
const lb = Number.parseInt(String(b), 10)
if (!Number.isFinite(la) || !Number.isFinite(lb)) return false
switch (op) {
case '-eq':
return la === lb
case '-ne':
return la !== lb
case '-lt':
return la < lb
case '-le':
return la <= lb
case '-gt':
return la > lb
case '-ge':
return la >= lb
default:
return false
}
}
test('posix test integer relations (-eq -ne -lt -le -gt -ge)', async (t) => {
t.ok(evalIntRel(0, '-eq', 0))
t.ok(evalIntRel(3, '-ne', 4))
t.ok(evalIntRel(2, '-lt', 5))
t.ok(evalIntRel(5, '-le', 5))
t.ok(evalIntRel(9, '-gt', 1))
t.ok(evalIntRel(7, '-ge', 7))
t.absent(evalIntRel(1, '-eq', 2))
t.absent(evalIntRel('x', '-eq', 1))
t.absent(evalIntRel(1, '-eq', 'y'))
})