Skip to content

Commit

Permalink
Added test for jsonnet library
Browse files Browse the repository at this point in the history
  • Loading branch information
redoC-A2k committed Mar 28, 2024
1 parent f00d3fb commit 50064be
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 1 deletion.
17 changes: 17 additions & 0 deletions JS/jsonnet/test/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "test",
"version": "1.0.0",
"description": "",
"main": "test.js",
"type": "module",
"scripts": {
"test": "node --experimental-wasm-modules ./node_modules/mocha/bin/mocha"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"chai": "^5.1.0",
"mocha": "^10.4.0"
}
}
88 changes: 88 additions & 0 deletions JS/jsonnet/test/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import Jsonnet from "../src/jsonnet.js";
import { expect } from "chai";

let jsonnet = new Jsonnet();

describe("Testing evaluateSnippet function of jsonnet library", () => {
it("self reference", () => {
let result = JSON.parse(jsonnet.evaluateSnippet(`{
Martini: {
local drink = self,
ingredients: [
{ kind: "Farmer's Gin", qty: 1 },
{
kind: 'Dry White Vermouth',
qty: drink.ingredients[0].qty,
},
],
garnish: 'Olive',
served: 'Straight Up',
},
}`));
let expected = JSON.parse(`{
"Martini": {
"garnish": "Olive",
"ingredients": [
{
"kind": "Farmer's Gin",
"qty": 1
},
{
"kind": "Dry White Vermouth",
"qty": 1
}
],
"served": "Straight Up"
}
}`);
// expect(JSON.stringify(result)).to.equal(JSON.stringify(expected));
expect(result).to.eql(expected);
});

it("math operations", () => {
let result = JSON.parse(jsonnet.evaluateSnippet(`{
a: 1 + 2,
b: 3 * 4,
c: 5 / 6,
d: 7 % 8,
e: 9 - 10,
}`));
let expected = JSON.parse(`{
"a": 3,
"b": 12,
"c": 0.8333333333333334,
"d": 7,
"e": -1
}`);
// expect(JSON.stringify(result)).to.equal(JSON.stringify(expected));
expect(result).to.eql(expected);
})
});


describe("Testing extString function of jsonnet library", () => {
it("extString", () => {
let result = JSON.parse(jsonnet.extString("name", "Alice").evaluateSnippet(` local username = std.extVar('name');
local Person(name='Alice') = {
name: name,
welcome: 'Hello ' + name + '!',
};
{
person1: Person(username),
person2: Person('Bob'),
}`));
let expected = JSON.parse(`{
"person1": {
"name": "Alice",
"welcome": "Hello Alice!"
},
"person2": {
"name": "Bob",
"welcome": "Hello Bob!"
}
}`);
console.log(result);
// expect(JSON.stringify(result)).to.equal(JSON.stringify(expected));
expect(result).to.eql(expected);
});
});
3 changes: 2 additions & 1 deletion JS/wasm/crates/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ experimental_event_loop = []
wizer = { workspace = true }
structopt = "0.3"
anyhow = { workspace = true }
binaryen = { git = "https://github.com/pepyakin/binaryen-rs", rev = "00c98174843f957681ba0bc5cdcc9d15f5d0cb23" }
binaryen = "0.13.0"
# binaryen = { git = "https://github.com/pepyakin/binaryen-rs", rev = "00c98174843f957681ba0bc5cdcc9d15f5d0cb23" }
brotli = "3.4.0"
wasmprinter = { version = "0.2.75", optional = true }
wasmtime = { workspace = true }
Expand Down

0 comments on commit 50064be

Please sign in to comment.