Skip to content

Commit

Permalink
closes #16, #21 (#22)
Browse files Browse the repository at this point in the history
Co-authored-by: Gupta <shubhendushekhar.gupta@delta.com>
  • Loading branch information
SubhenduShekhar and Gupta authored Jun 11, 2023
1 parent 399a0fc commit 6165625
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
2 changes: 1 addition & 1 deletion npm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{
"type": "commonjs",
"name": "coded-json",
"version": "1.0.2",
"version": "1.0.3",
"description": "Coded JSON source code",
"main": "out/cjson.js",
"types": "out/cjson.d.ts",
Expand Down
7 changes: 4 additions & 3 deletions npm/src/cjson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ export class Cjson extends Is {
this.filePath = filePath;
this.content = read(this.filePath);
this.commaSeparated = this.content.split(",");

this.decodeKeywords();
this.decodeRelativePaths();
this.json = new Json(this.obj);
}
/**
* Root function for decoding keywords
Expand Down Expand Up @@ -70,9 +74,6 @@ export class Cjson extends Is {
* @returns `JSON` if no errors. Else `undefined`
*/
public deserialize() : JSON | undefined {
this.decodeKeywords();
this.json = new Json(this.obj);
this.decodeRelativePaths();
return this.obj;
}
/**
Expand Down
2 changes: 1 addition & 1 deletion tests/npm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"license": "ISC",
"dependencies": {
"@types/jasmine": "^4.3.1",
"coded-json": "file:coded-json-1.0.2.tgz",
"coded-json": "file:coded-json-1.0.3.tgz",
"jasmine": "^4.5.0",
"jasmine-spec-reporter": "^7.0.0",
"ts-node": "^10.9.1",
Expand Down
17 changes: 16 additions & 1 deletion tests/npm/spec/tests/codedJsonTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ const assert = require('assert');
const fs = require('fs');
const path = require('path');

/** Path to target.cjson */
const cjsonfilePath = path.join(__dirname, "..", "..", "..", "\\test-files\\target.cjson");
/** Path to source.json */
const jsonfilePath = path.join(__dirname, "..", "..", "..", "\\test-files\\source.json");
/** Path to pure.json */
const pureJsonfilePath = path.join(__dirname, "..", "..", "..", "\\test-files\\pure.json");

/**
Expand Down Expand Up @@ -37,10 +40,22 @@ describe("CJSON Test 1", () => {
/**
* Tests related to native JSON files
*/
describe("CJSON Test 2", () => {
describe("JSON Test 2", () => {

it("I should be able to use isContentJson()", () => {
var cjson = new Cjson(pureJsonfilePath);
assert.equal(cjson.isContentJson(), true);
});

it("I should be able to parse jpath using `obj< Cjson >.json.parse(\"Valid.JPATH\")`", () => {
var cjson = new Cjson(cjsonfilePath);
var value = cjson.json.parse("source.quiz.sport.q1.question");
assert.equal(value, "Which one is correct team name in NBA?");
});

it("I should be able to parse full json using `obj< Cjson >.json.parse()`", () => {
var cjson = new Cjson(cjsonfilePath);
var value = cjson.json.parse();
assert.equal(value, cjson.deserialize());
});
});

0 comments on commit 6165625

Please # to comment.