Skip to content
Snippets Groups Projects
Select Git revision
  • 41488a6e507a98a9d17098e92f6f4f34880d6590
  • master default protected
  • 1.31
  • 4.38.0
  • 4.37.2
  • 4.37.1
  • 4.37.0
  • 4.36.0
  • 4.35.0
  • 4.34.1
  • 4.34.0
  • 4.33.1
  • 4.33.0
  • 4.32.2
  • 4.32.1
  • 4.32.0
  • 4.31.0
  • 4.30.1
  • 4.30.0
  • 4.29.1
  • 4.29.0
  • 4.28.0
  • 4.27.0
23 results

pnpm-lock.yaml

Blame
  • pathfinder.mjs 12.20 KiB
    "use strict";
    
    import {expect} from "chai"
    import {Pathfinder} from "../../../source/data/pathfinder.mjs";
    
    describe('Pathfinder', function () {
    
        let convertMapResult = function (r) {
            if (r instanceof Map) {
                r = Object.fromEntries(r);
                if (r instanceof Array) {
                    r = r.map((e) => {
                        return convertMapResult(e);
                    })
                } else if (typeof r === "object") {
                    for (const [k, o] of Object.entries(r)) {
                        r[k] = convertMapResult(o);
                    }
                }
            }
    
            return r;
        }
    
    
        describe('with Wildcard and Iterations', function () {
            let pf, obj;
    
            beforeEach(function () {
                obj = {
                    a: [
                        {
                            b: [
                                {
                                    c: "1-1"
                                },
                                {
                                    c: "1-2"
                                }
                            ],
                            d: '!'
    
                        },
                        {
                            b: [
                                {
                                    c: "2-1"
                                },
                                {
                                    c: "2-2"
                                }
                            ],
                            d: '?'
                        }
                    ]
                }
                pf = new Pathfinder(obj);
            });
    
            [
                ['a.*.b.*', '{"0":{"0":{"c":"1-1"},"1":{"c":"1-2"}},"1":{"0":{"c":"2-1"},"1":{"c":"2-2"}}}'],
                ['a.*.b', '{"0":[{"c":"1-1"},{"c":"1-2"}],"1":[{"c":"2-1"},{"c":"2-2"}]}'],
                ['a.1.b', '[{"c":"2-1"},{"c":"2-2"}]'],
                ['a.0.b', '[{"c":"1-1"},{"c":"1-2"}]'],
            ].forEach(function (data) {
    
                let a = data.shift()
                let b = data.shift()