You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

70 lines
1.3 KiB

import test from "node:test"
import assert from "node:assert"
import { gronify } from "./ngron.mjs";
test("number", () => {
const result = gronify(3)
assert.strictEqual(result, `json=3;`)
});
test("string", () => {
const result = gronify("hello")
assert.strictEqual(result, `json="hello";`)
});
test("empty obj", () => {
const result = gronify({})
assert.strictEqual(result, `json={};`)
});
test("null", () => {
const result = gronify(null)
assert.strictEqual(result, `json=null;`)
});
test("empty array", () => {
const result = gronify([])
assert.strictEqual(result, `json=[];`)
});
test("nested obj", () => {
const result = gronify({one: 1})
assert.strictEqual(result, `json={};
json.one=1;`)
});
test("nested array", () => {
const result = gronify(["hello", "world"])
assert.strictEqual(result, `json=[];
json[0]="hello";
json[1]="world";`)
});
test("complex", () => {
const result = gronify([
{name: "Alice", startYear: 2001},
{name: "Ralph", startYear: 2010},
{name: "Jesse", startYear: 2007, tired: true},
])
assert.strictEqual(result, `json=[];
json[0]={};
json[0].name="Alice";
json[0].startYear=2001;
json[1]={};
json[1].name="Ralph";
json[1].startYear=2010;
json[2]={};
json[2].name="Jesse";
json[2].startYear=2007;
json[2].tired=true;`);
});