<commit_before>"use strict";
var should = require("chai").should();
var rewire = require("rewire");

global.navigator = {};
var CindyJS = require("../build/js/Cindy.plain.js");

var cdy = CindyJS({
    isNode: true,
    csconsole: null,
    geometry: [
        { name: "A", type: "Free", pos: [0, 0] },
        { name: "B", type: "Free", pos: [1, 1] },
        { name: "C", type: "Free", pos: [1, 2] },
    ],
});

function itCmd(command, expected) {
    it(command, function () {
        String(cdy.niceprint(cdy.evalcs(command))).should.equal(expected);
    });
}

function getJSONStr() {
    return '{"age":30, "bool":false, "cars":[{\n "models": [\n  "Fiesta",\n  "Focus",\n  "Mustang"\n ],\n "name": "Ford"\n}, {\n "models": [\n  "320",\n  "X3",\n  "X5"\n ],\n "name": "BMW"\n}, {\n "models": [\n  "500",\n  "Panda"\n ],\n "name": "Fiat"\n}], "name":"Joe"}';
}

function getJSONprettyStr() {
    return "{age:30, bool:false, cars:[{models:[Fiesta, Focus, Mustang], name:Ford}, {models:[320, X3, X5], name:BMW}, {models:[500, Panda], name:Fiat}], name:Joe, test:circle, undef:___}";
}

describe("JSON basic getter / setter", function () {
    before(function () {
        cdy.evalcs("circ = circle(A,1);");
        cdy.evalcs("json = " + getJSONStr());
        cdy.evalcs("json.test = circ;");
        cdy.evalcs("json.undef = undef;");
    });

    itCmd("json.name", "Joe");
    itCmd("json.bool", "false");
    itCmd("json.undef", "___");
    itCmd("json.age", "30");
    itCmd("((json.cars)_1).models_2", "Focus");
    itCmd("json.test", "circle");

    // pretty print
    itCmd("json", getJSONprettyStr());

    // keys
    itCmd("keys(json)", "[age, bool, cars, name, test, undef]");

    // values
    itCmd('values({"a" : 5, "b" : 2})', "[5, 2]");

    // dynamic access
    itCmd('myvar = "name"; json_myvar = "Bob"; json.name', "Bob");
    itCmd("json_undef", "___");
    itCmd('json1 = {"1":2}; json1_1', "2");
    itCmd('json1 = {"1":2}; json1_"1"', "2");<commit_msg>added another test for JSON reference copy, just to be sure<commit_after>"use strict";
var should = require("chai").should();
var rewire = require("rewire");

global.navigator = {};
var CindyJS = require("../build/js/Cindy.plain.js");

var cdy = CindyJS({
    isNode: true,
    csconsole: null,
    geometry: [
        { name: "A", type: "Free", pos: [0, 0] },
        { name: "B", type: "Free", pos: [1, 1] },
        { name: "C", type: "Free", pos: [1, 2] },
    ],
});

function itCmd(command, expected) {
    it(command, function () {
        String(cdy.niceprint(cdy.evalcs(command))).should.equal(expected);
    });
}

function getJSONStr() {
    return '{"age":30, "bool":false, "cars":[{\n "models": [\n  "Fiesta",\n  "Focus",\n  "Mustang"\n ],\n "name": "Ford"\n}, {\n "models": [\n  "320",\n  "X3",\n  "X5"\n ],\n "name": "BMW"\n}, {\n "models": [\n  "500",\n  "Panda"\n ],\n "name": "Fiat"\n}], "name":"Joe"}';
}

function getJSONprettyStr() {
    return "{age:30, bool:false, cars:[{models:[Fiesta, Focus, Mustang], name:Ford}, {models:[320, X3, X5], name:BMW}, {models:[500, Panda], name:Fiat}], name:Joe, refthing:aa, test:circle, undef:___}";
}

describe("JSON basic getter / setter", function () {
    before(function () {
        cdy.evalcs("circ = circle(A,1);");
        cdy.evalcs("json = " + getJSONStr());
        cdy.evalcs("json.test = circ;");
        cdy.evalcs("json.undef = undef;");
        cdy.evalcs("other = json;");
        cdy.evalcs('other.refthing = "aa"');
    });

    itCmd("json.name", "Joe");
    itCmd("json.bool", "false");
    itCmd("json.undef", "___");
    itCmd("json.age", "30");
    itCmd("((json.cars)_1).models_2", "Focus");
    itCmd("json.test", "circle");
    itCmd("json.refthing", "aa");

    // pretty print
    itCmd("json", getJSONprettyStr());

    // keys
    itCmd("keys(json)", "[age, bool, cars, name, test, undef, refthing]");

    // values
    itCmd('values({"a" : 5, "b" : 2})', "[5, 2]");

    // dynamic access
    itCmd('myvar = "name"; json_myvar = "Bob"; json.name', "Bob");
    itCmd("json_undef", "___");
    itCmd('json1 = {"1":2}; json1_1', "2");
    itCmd('json1 = {"1":2}; json1_"1"', "2");
{'fraction_non_alphanumeric': 0.2525884902480135, 'fraction_numerical': 0.022634240308210932, 'mean_word_length': 3.3680336487907465, 'pattern_counts': {'":': 24, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '616111', 'n_tokens_mistral': 1669, 'n_tokens_neox': 1582, 'n_words': 335}