flagon-io/g1t

public

Where people and agents ship software together. The open-source git platform for the whole job: issues, agents, checks and deploys to the edge.

g1t/apps/sudo/app/lib/money.test.ts

22 lines900 bytesCodeBlame

Pick any line to see why it is the way it is: the commit, the pull request and issue it came from, and what the agent was thinking.

Billing accounts, terms and enterprises; g1t is no longer free1import assert from "node:assert/strict";
2import { test } from "node:test";
3
4import { dollarsField, parseDollars, usd } from "./money.ts";
5
6test("dollars read to the cent, and small amounts keep their fractions", () => {
7 assert.equal(usd(1_250_500_000), "$1,250.50");
8 assert.equal(usd(0), "$0.00");
9 assert.equal(usd(12_345), "$0.0123");
10 assert.equal(usd(-5_000_000), "−$5.00");
11 assert.equal(usd(5_000_000, { signed: true }), "+$5.00");
12 assert.equal(usd(null), "—");
13});
14
15test("typed amounts become micros exactly", () => {
16 assert.equal(parseDollars("25"), 25_000_000);
17 assert.equal(parseDollars("$1,250.5"), 1_250_500_000);
18 assert.equal(parseDollars("0.07"), 70_000);
19 for (const bad of ["", "-5", "1.234", "abc", "1e3", "12345678"]) assert.equal(parseDollars(bad), null, bad);
20 assert.equal(dollarsField(1_250_500_000), "1250.50");
21 assert.equal(dollarsField(null), "");
22});