diff --git a/JS/jsonnet/test/package.json b/JS/jsonnet/test/package.json new file mode 100644 index 000000000..953deece6 --- /dev/null +++ b/JS/jsonnet/test/package.json @@ -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" + } +} diff --git a/JS/jsonnet/test/test.js b/JS/jsonnet/test/test.js new file mode 100644 index 000000000..0fa4f0cff --- /dev/null +++ b/JS/jsonnet/test/test.js @@ -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); + }); +}); \ No newline at end of file diff --git a/JS/wasm/crates/cli/Cargo.toml b/JS/wasm/crates/cli/Cargo.toml index 41270e885..fe47acc48 100644 --- a/JS/wasm/crates/cli/Cargo.toml +++ b/JS/wasm/crates/cli/Cargo.toml @@ -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 }