"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const assert = require("assert");
const evaluate_1 = require("../../spec/evaluate");
const parser_1 = require("../../spec/parser");
const f_1 = require("../../system/f/comparisson/Equals/f");
const _classes_1 = require("../../system/_classes");
const _specs_1 = require("../../system/_specs");
const id_1 = require("./id");
// getTree
assert((0, parser_1.getTree)('{a:"1,2,3"}').children.length === 1);
assert((0, parser_1.getTree)("{a:'1,2,3'}").children.length === 1);
assert((0, parser_1.getTree)("{a:'(1,2,3)'}").children.length === 1);
assert((0, parser_1.getTree)('[true,true,]').children.length === 3);
assert((0, parser_1.getTree)('[true,true,]').children[2].value === '');
assert((0, parser_1.getTree)('{a:[true,true,]}').children[0].children[1].children[2].value === '');
// getTreeNodeType
assert.deepEqual((0, parser_1.getTreeNodeType)(':'), parser_1.TreeNodeType.Invalid);
assert.deepEqual((0, parser_1.getTreeNodeType)('foo'), parser_1.TreeNodeType.Invalid);
assert.deepEqual((0, parser_1.getTreeNodeType)('[1[]'), parser_1.TreeNodeType.Invalid);
// assert.deepEqual(getTreeNodeType('a:'), TreeNodeType.KeyValue)
// assert.deepEqual(getTreeNodeType(':1'), TreeNodeType.KeyValue)
assert.deepEqual((0, parser_1.getTreeNodeType)('{a:}'), parser_1.TreeNodeType.ObjectLiteral);
assert.deepEqual((0, parser_1.getTreeNodeType)('{:1}'), parser_1.TreeNodeType.ObjectLiteral);
assert.deepEqual((0, parser_1.getTreeNodeType)('"a:b"'), parser_1.TreeNodeType.StringLiteral);
assert.deepEqual((0, parser_1.getTreeNodeType)('"\\""'), parser_1.TreeNodeType.StringLiteral);
assert.deepEqual((0, parser_1.getTreeNodeType)('"\r"'), parser_1.TreeNodeType.StringLiteral);
assert.deepEqual((0, parser_1.getTreeNodeType)(`"v=0\r\no=- 7652727450078372599 2 IN IP4 127.0.0.1\r\ns=-\r\nt=0 0\r\na=group:BUNDLE 0\r\na=extmap-allow-mixed\r\na=msid-semantic: WMS\r\nm=application 61198 UDP/DTLS/SCTP webrtc-datachannel\r\nc=IN IP4 201.26.26.115\r\na=candidate:2612718301 1 udp 2122262783 2804:431:e7c2:b2f3:c94:df00:ed4f:6843 54465 typ host generation 0 network-id 2 network-cost 10\r\na=candidate:1333116113 1 udp 2122194687 192.168.15.5 61198 typ host generation 0 network-id 1 network-cost 10\r\na=candidate:3110454533 1 udp 1685987071 201.26.26.115 61198 typ srflx raddr 192.168.15.5 rport 61198 generation 0 network-id 1 network-cost 10\r\na=candidate:3577288237 1 tcp 1518283007 2804:431:e7c2:b2f3:c94:df00:ed4f:6843 9 typ host tcptype active generation 0 network-id 2 network-cost 10\r\na=candidate:32915489 1 tcp 1518214911 192.168.15.5 9 typ host tcptype active generation 0 network-id 1 network-cost 10\r\na=ice-ufrag:YRMo\r\na=ice-pwd:Fwnv2ZDO0wzeeuDeWu+MVisV\r\na=fingerprint:sha-256 08:85:1D:A9:71:D2:CA:22:DD:76:E0:1D:59:CA:0E:E2:CA:93:3A:24:3B:09:28:F5:42:E5:D5:E7:79:C6:2B:E5\r\na=setup:actpass\r\na=mid:0\r\na=sctp-port:5000\r\na=max-message-size:262144\r\n"`), parser_1.TreeNodeType.StringLiteral);
assert.deepEqual((0, parser_1.getTreeNodeType)('/abc/'), parser_1.TreeNodeType.RegexLiteral);
assert.deepEqual((0, parser_1.getTreeNodeType)('null'), parser_1.TreeNodeType.Null);
assert.deepEqual((0, parser_1.getTreeNodeType)('1+1'), parser_1.TreeNodeType.ArithmeticExpression);
assert.deepEqual((0, parser_1.getTreeNodeType)('`U`'), parser_1.TreeNodeType.Class);
assert.deepEqual((0, parser_1.getTreeNodeType)('`E`'), parser_1.TreeNodeType.Class);
assert.deepEqual((0, parser_1.getTreeNodeType)('`V<T>`'), parser_1.TreeNodeType.Class);
assert.deepEqual((0, parser_1.getTreeNodeType)('<T>[]'), parser_1.TreeNodeType.ArrayExpression);
assert.deepEqual((0, parser_1.getTreeNodeType)('string[]'), parser_1.TreeNodeType.ArrayExpression);
assert.deepEqual((0, parser_1.getTreeNodeType)("'string|number'"), parser_1.TreeNodeType.StringLiteral);
assert.deepEqual((0, parser_1.getTreeNodeType)('(string)'), parser_1.TreeNodeType.Expression);
assert.deepEqual((0, parser_1.getTreeNodeType)("'{a:number}&{b:string}'"), parser_1.TreeNodeType.StringLiteral);
assert.deepEqual((0, parser_1.getTreeNodeType)("'&*::&lt||()><'"), parser_1.TreeNodeType.StringLiteral);
assert.deepEqual((0, parser_1.getTreeNodeType)("'https://preview.redd.it/award_images/t5_22cerq/80j20o397jj41_NarwhalSalute.png?width=128&amp;height=128&amp;auto=webp&amp;s=5d2c75f44f176f430e936204f9a53b8a2957f2fc'"), parser_1.TreeNodeType.StringLiteral);
assert.deepEqual((0, parser_1.getTreeNodeType)('(a:number,b:number)=>(a+b:number)'), parser_1.TreeNodeType.ClassLiteral);
assert.deepEqual((0, parser_1.getTreeNodeType)(`\${${id_1.ID_IDENTITY}}`), parser_1.TreeNodeType.Unit);
assert.deepEqual((0, parser_1.getTreeNodeType)('string|number|{}'), parser_1.TreeNodeType.Or);
assert.deepEqual((0, parser_1.getTreeNodeType)('string|number|{filters?:(string|number|{name?:string,namePrefix?:string})[],optionalServices?:string[],acceptAllDevices?:boolean}'), parser_1.TreeNodeType.Or);
assert.deepEqual((0, parser_1.getTreeNodeType)('<T>["S"]'), parser_1.TreeNodeType.PropExpression);
assert.deepEqual((0, parser_1.getTree)('{,}').children.length, 1);
// isValidType
assert((0, parser_1.isValidType)('/a/'));
assert((0, parser_1.isValidType)('regex'));
assert((0, parser_1.isValidType)('string'));
assert((0, parser_1.isValidType)('number'));
assert((0, parser_1.isValidType)('boolean'));
assert((0, parser_1.isValidType)('string[]'));
assert((0, parser_1.isValidType)('number[]'));
assert((0, parser_1.isValidType)('boolean[]'));
assert((0, parser_1.isValidType)('object[]'));
assert((0, parser_1.isValidType)('(string)'));
assert((0, parser_1.isValidType)('(1)'));
assert((0, parser_1.isValidType)('(string)[]'));
assert((0, parser_1.isValidType)('(string)[]'));
assert((0, parser_1.isValidType)('"foo"'));
assert((0, parser_1.isValidType)("'foo'"));
assert((0, parser_1.isValidType)('string|number'));
assert((0, parser_1.isValidType)('string|1'));
assert((0, parser_1.isValidType)('string|1|3'));
assert((0, parser_1.isValidType)('string&number'));
assert((0, parser_1.isValidType)('(string|number)[]'));
assert((0, parser_1.isValidType)('{number:1}'));
assert((0, parser_1.isValidType)('{}'));
assert((0, parser_1.isValidType)('[]'));
assert((0, parser_1.isValidType)('1+2'));
assert((0, parser_1.isValidType)('1 +2'));
assert((0, parser_1.isValidType)('1 + 2'));
assert((0, parser_1.isValidType)('{a:number,}'));
assert((0, parser_1.isValidType)('{foo:number}'));
assert((0, parser_1.isValidType)('{foo:number,bar:string}'));
assert((0, parser_1.isValidType)('"click"|"mousedown"|"mouseup"|"mouseenter"|"mousemove"|"mouseleave"'));
assert((0, parser_1.isValidType)('{"foo":"number"}'));
assert((0, parser_1.isValidType)('{"foo":"number","bar":{"x":"number","y":"number"}}'));
assert((0, parser_1.isValidType)('{foo:number}[]'));
assert((0, parser_1.isValidType)('[]'));
assert((0, parser_1.isValidType)('[1,2,3]'));
assert((0, parser_1.isValidType)('[string,number]'));
assert((0, parser_1.isValidType)('3.14'));
assert((0, parser_1.isValidType)('<T>'));
assert((0, parser_1.isValidType)('`V<T>`'));
assert((0, parser_1.isValidType)('string[]'));
assert((0, parser_1.isValidType)('number[]'));
assert((0, parser_1.isValidType)('string[][]'));
assert((0, parser_1.isValidType)('string{}'));
assert((0, parser_1.isValidType)('string[]{}'));
assert((0, parser_1.isValidType)('[1,2,[3,4],5]'));
assert((0, parser_1.isValidType)('{name:string}|{namePrefix:string}'));
assert((0, parser_1.isValidType)('string[]|number[]'));
assert((0, parser_1.isValidType)('[]|[0,1,2]'));
assert((0, parser_1.isValidType)('{headers:object,statusCode:number,statusMessage:string,data:string}'));
assert((0, parser_1.isValidType)('{"a":1,"b":true,"c":{"d":"string"}}'));
assert((0, parser_1.isValidType)('(()=>())'));
assert((0, parser_1.isValidType)('()=>()'));
assert((0, parser_1.isValidType)('(a:number)=>()'));
assert((0, parser_1.isValidType)('(a:number,b:number)=>(a+b:number)'));
assert((0, parser_1.isValidType)('any'));
assert((0, parser_1.isValidType)('<T>["S"]'));
assert((0, parser_1.isValidType)('<T>["S","A"]'));
assert(!(0, parser_1.isValidType)("'foo's bar'"));
assert(!(0, parser_1.isValidType)('{{}}'));
assert(!(0, parser_1.isValidType)('{,}'));
assert(!(0, parser_1.isValidType)(':'));
assert(!(0, parser_1.isValidType)('b'));
assert(!(0, parser_1.isValidType)("b'"));
assert(!(0, parser_1.isValidType)("'''"));
assert(!(0, parser_1.isValidType)('()'));
assert(!(0, parser_1.isValidType)('{ foo }'));
assert(!(0, parser_1.isValidType)('{ foo: bar }'));
assert(!(0, parser_1.isValidType)('|'));
assert(!(0, parser_1.isValidType)('string |'));
assert(!(0, parser_1.isValidType)('string | foo'));
assert(!(0, parser_1.isValidType)('foo'));
assert(!(0, parser_1.isValidType)('foo: string'));
assert(!(0, parser_1.isValidType)("{ a: b' }"));
assert(!(0, parser_1.isValidType)('foo:true'));
assert(!(0, parser_1.isValidType)('foo:false'));
assert(!(0, parser_1.isValidType)('<T>["S",K]'));
assert(!(0, parser_1.isValidObjKey)('*'));
assert((0, parser_1.isTypeMatch)('number', 'number|string'));
assert((0, parser_1.isTypeMatch)('string', 'number|string'));
assert((0, parser_1.isTypeMatch)('number', '(number|string)'));
assert((0, parser_1.isTypeMatch)('string', '(number|string)'));
assert((0, parser_1.isTypeMatch)('number[]', '(number|string)[]'));
assert((0, parser_1.isTypeMatch)('string[]', '(number|string)[]'));
assert((0, parser_1.isTypeMatch)("'number|string'", 'string'));
assert((0, parser_1.isTypeMatch)('"number|string"', 'string'));
assert((0, parser_1.isTypeMatch)('"foo"', '"foo"|"bar"'));
assert((0, parser_1.isTypeMatch)('{a:"foo"}', "{a:'foo'|'bar'}"));
assert((0, parser_1.isTypeMatch)('[{a:"bar"}]', "{a:'foo'|'bar'}[]"));
assert((0, parser_1.isTypeMatch)('<T>', '<G>'));
assert((0, parser_1.isTypeMatch)('number', '<T>'));
assert((0, parser_1.isTypeMatch)('<T>', 'number'));
assert((0, parser_1.isTypeMatch)('<T>', 'string'));
assert((0, parser_1.isTypeMatch)('<T>', 'string[]'));
assert((0, parser_1.isTypeMatch)('<T>[]', 'string[]'));
assert((0, parser_1.isTypeMatch)('[]', 'string[]'));
assert((0, parser_1.isTypeMatch)('string', 'string'));
assert((0, parser_1.isTypeMatch)('/abc/', 'regex'));
assert((0, parser_1.isTypeMatch)('number', 'number'));
assert((0, parser_1.isTypeMatch)('boolean', 'boolean'));
assert((0, parser_1.isTypeMatch)('any', 'any'));
assert((0, parser_1.isTypeMatch)('number', 'any'));
assert((0, parser_1.isTypeMatch)('1', 'any'));
assert((0, parser_1.isTypeMatch)('"foo"', 'string'));
assert((0, parser_1.isTypeMatch)("'foo'", '"foo"'));
assert((0, parser_1.isTypeMatch)('"foo"', '"foo"|"bar"'));
assert((0, parser_1.isTypeMatch)('"foo"', "'foo'|'bar'"));
assert((0, parser_1.isTypeMatch)("'foo'", "'foo'|'bar'"));
assert((0, parser_1.isTypeMatch)('<T>', 'any'));
assert((0, parser_1.isTypeMatch)('any', '<T>'));
assert((0, parser_1.isTypeMatch)('null', 'null'));
assert((0, parser_1.isTypeMatch)('null', 'any'));
assert((0, parser_1.isTypeMatch)('string[]', '<T>[]'));
assert((0, parser_1.isTypeMatch)('string[]', 'string[]'));
assert((0, parser_1.isTypeMatch)('string[]', '(string|number)[]'));
assert((0, parser_1.isTypeMatch)('{a:1,}', 'object'));
assert((0, parser_1.isTypeMatch)('{"x":number,"y":number}', 'object'));
assert((0, parser_1.isTypeMatch)('{x:0,y:1}', '{"x":number,"y":number}'));
assert((0, parser_1.isTypeMatch)('{x:10,y:10,width:100,height:100}', '{x:number,y:number,width:number,height:number}'));
assert((0, parser_1.isTypeMatch)('{a:number,b:string}', '{a:number,b:string}'));
assert((0, parser_1.isTypeMatch)('{a:number,b:string}', '{b:string,a:number}'));
assert((0, parser_1.isTypeMatch)('{a:number,b:string}', '{a:number}'));
assert((0, parser_1.isTypeMatch)('{a:number,b:string}', '{}'));
assert((0, parser_1.isTypeMatch)('{a:"foo"}', "{a:'foo'}"));
assert((0, parser_1.isTypeMatch)("{a:'foo'}", '{a:"foo"}'));
assert((0, parser_1.isTypeMatch)('{type:"answer"}', "{type:'answer'}"));
assert((0, parser_1.isTypeMatch)('{type:"answer",sdp:\'\'}', "{type:'answer',sdp:string}"));
assert((0, parser_1.isTypeMatch)('{}', '{a?:number}'));
assert((0, parser_1.isTypeMatch)('string[]&object', 'object'));
assert((0, parser_1.isTypeMatch)('string[]&object', 'string[]'));
assert((0, parser_1.isTypeMatch)('string[]&object', '<A>[]'));
assert((0, parser_1.isTypeMatch)('string[]|object', 'string[]|object'));
assert((0, parser_1.isTypeMatch)('string[]|{foo:"bar"}', 'string[]|object'));
assert((0, parser_1.isTypeMatch)('[]', '[]'));
assert((0, parser_1.isTypeMatch)('{a:"foo"}', 'string{}'));
assert((0, parser_1.isTypeMatch)('{a:1}', 'number{}'));
assert((0, parser_1.isTypeMatch)('[1,2,3]', '[1,2,3]'));
assert((0, parser_1.isTypeMatch)('[1,2,3]', '[number,number,number]'));
assert((0, parser_1.isTypeMatch)('any', 'number'));
assert((0, parser_1.isTypeMatch)('<T>', '<K>[]'));
assert((0, parser_1.isTypeMatch)('any', 'object'));
assert((0, parser_1.isTypeMatch)('object', '{}'));
assert((0, parser_1.isTypeMatch)('object', '{"x":number,"y":number}'));
assert((0, parser_1.isTypeMatch)('<T>', id_1.ID_IDENTITY));
assert((0, parser_1.isTypeMatch)('any', id_1.ID_IDENTITY));
assert((0, parser_1.isTypeMatch)(`\${${id_1.ID_IDENTITY}}`, 'any'));
assert((0, parser_1.isTypeMatch)('`G`', '`G`'));
assert((0, parser_1.isTypeMatch)('`U`&`G`', '`G`'));
assert((0, parser_1.isTypeMatch)('`U`&`G`', '`U`&`G`'));
assert((0, parser_1.isTypeMatch)('`U`&`C`&`G`', '`U`&`G`'));
assert((0, parser_1.isTypeMatch)('`G`', '`EE`'));
assert((0, parser_1.isTypeMatch)('`G`', '`U`'));
assert((0, parser_1.isTypeMatch)('`U`&`G`', '`U`&`C`&`G`'));
assert((0, parser_1.isTypeMatch)(`\${unit:{id:'${id_1.ID_IDENTITY}'}}`, '`U`'));
assert(!(0, parser_1.isTypeMatch)('', 'any'));
assert(!(0, parser_1.isTypeMatch)('abc', 'any'));
assert(!(0, parser_1.isTypeMatch)('', '<T>'));
assert(!(0, parser_1.isTypeMatch)('1', '<T>[]'));
assert(!(0, parser_1.isTypeMatch)('foo', 'string'));
assert(!(0, parser_1.isTypeMatch)('regex', '/abc/'));
assert(!(0, parser_1.isTypeMatch)('foo', '<T>'));
assert(!(0, parser_1.isTypeMatch)('(string|number)[]', 'string[]'));
assert(!(0, parser_1.isTypeMatch)('string[]|object', '<A>[]'));
assert(!(0, parser_1.isTypeMatch)('[]', '[1]'));
assert(!(0, parser_1.isTypeMatch)('[1,2,3]', '[1,2,3,4]'));
assert(!(0, parser_1.isTypeMatch)('[1,2,3]', '[number,number, string]'));
assert(!(0, parser_1.isTypeMatch)('{background: "color"}', 'object'));
assert(!(0, parser_1.isTypeMatch)('null', id_1.ID_IDENTITY));
assert(!(0, parser_1.isTypeMatch)('object', 'class'));
assert(!(0, parser_1.isTypeMatch)('number', 'class'));
assert(!(0, parser_1.isTypeMatch)('number', id_1.ID_IDENTITY));
assert(!(0, parser_1.isTypeMatch)(id_1.ID_IDENTITY, 'number'));
assert(!(0, parser_1.isTypeMatch)('`U`', '`G`'));
assert(!(0, parser_1.isTypeMatch)('`U`', '`G`&`U`'));
assert(!(0, parser_1.isTypeMatch)('`U`&`C`', '`U`&`G`'));
// isValidValue
assert((0, parser_1.isValidValue)('null'));
assert((0, parser_1.isValidValue)('"foo"'));
assert((0, parser_1.isValidValue)("'\\\\'"));
assert((0, parser_1.isValidValue)('"\'foo\'"'));
assert((0, parser_1.isValidValue)("'\\'foo\\''"));
assert((0, parser_1.isValidValue)('"\\\'foo\\\'"'));
assert((0, parser_1.isValidValue)('"\\"foo\\""'));
assert((0, parser_1.isValidValue)('"foo   "'));
assert((0, parser_1.isValidValue)('"\t"'));
assert((0, parser_1.isValidValue)('"\n"'));
assert((0, parser_1.isValidValue)('"web+unit://ioun.it"'));
assert((0, parser_1.isValidValue)('"foo\nbar"'));
assert((0, parser_1.isValidValue)('3.14'));
assert((0, parser_1.isValidValue)('1'));
assert((0, parser_1.isValidValue)('1.'));
assert((0, parser_1.isValidValue)('Infinity'));
assert((0, parser_1.isValidValue)('-Infinity'));
assert((0, parser_1.isValidValue)('/abc/'));
assert((0, parser_1.isValidValue)('true'));
assert((0, parser_1.isValidValue)('[1,2,3]'));
assert((0, parser_1.isValidValue)('[1,2,3,]')); // trailing comma
assert((0, parser_1.isValidValue)('[[1,0],[0,1]]'));
assert((0, parser_1.isValidValue)('{a}'));
assert((0, parser_1.isValidValue)('{a,}'));
assert((0, parser_1.isValidValue)('{a:1,}'));
assert((0, parser_1.isValidValue)('{a:}'));
assert((0, parser_1.isValidValue)('{a,b,c}'));
assert((0, parser_1.isValidValue)('{a,b,}'));
assert((0, parser_1.isValidValue)('{1,2}'));
assert((0, parser_1.isValidValue)('{1,2,}'));
assert((0, parser_1.isValidValue)('[{a},{1,2,}]'));
assert((0, parser_1.isValidValue)('{foo:"bar"}'));
assert((0, parser_1.isValidValue)('{number:1}'));
assert((0, parser_1.isValidValue)('{class:1}'));
assert((0, parser_1.isValidValue)('{foo:"bar",}')); // trailing comma
assert((0, parser_1.isValidValue)("{Ç:'Ç'}"));
assert((0, parser_1.isValidValue)(JSON.stringify(["", "\""]))); // prettier-ignore
assert((0, parser_1.isValidValue)('1e23'));
assert((0, parser_1.isValidValue)('{foo?:"bar"}'));
assert((0, parser_1.isValidValue)("{'{}':1}"));
assert((0, parser_1.isValidValue)("{'{':1}"));
assert((0, parser_1.isValidValue)('{"{}":1}'));
assert((0, parser_1.isValidValue)("{':':1}"));
assert((0, parser_1.isValidValue)('{":":1}'));
assert((0, parser_1.isValidValue)(`"v=0\r\no=- 7652727450078372599 2 IN IP4 127.0.0.1\r\ns=-\r\nt=0 0\r\na=group:BUNDLE 0\r\na=extmap-allow-mixed\r\na=msid-semantic: WMS\r\nm=application 61198 UDP/DTLS/SCTP webrtc-datachannel\r\nc=IN IP4 201.26.26.115\r\na=candidate:2612718301 1 udp 2122262783 2804:431:e7c2:b2f3:c94:df00:ed4f:6843 54465 typ host generation 0 network-id 2 network-cost 10\r\na=candidate:1333116113 1 udp 2122194687 192.168.15.5 61198 typ host generation 0 network-id 1 network-cost 10\r\na=candidate:3110454533 1 udp 1685987071 201.26.26.115 61198 typ srflx raddr 192.168.15.5 rport 61198 generation 0 network-id 1 network-cost 10\r\na=candidate:3577288237 1 tcp 1518283007 2804:431:e7c2:b2f3:c94:df00:ed4f:6843 9 typ host tcptype active generation 0 network-id 2 network-cost 10\r\na=candidate:32915489 1 tcp 1518214911 192.168.15.5 9 typ host tcptype active generation 0 network-id 1 network-cost 10\r\na=ice-ufrag:YRMo\r\na=ice-pwd:Fwnv2ZDO0wzeeuDeWu+MVisV\r\na=fingerprint:sha-256 08:85:1D:A9:71:D2:CA:22:DD:76:E0:1D:59:CA:0E:E2:CA:93:3A:24:3B:09:28:F5:42:E5:D5:E7:79:C6:2B:E5\r\na=setup:actpass\r\na=mid:0\r\na=sctp-port:5000\r\na=max-message-size:262144\r\n"`));
assert((0, parser_1.isValidValue)(JSON.stringify({
    name: 'Samuel Moreira Timbó',
    birthday: '06/17/1992',
    phone: '+55 11 986918999',
    address: 'R. Ana Rosa, 48 - Jardim Bela Vista, São José dos Campos - SP, 12209-050',
})));
assert((0, parser_1.isValidValue)(`'{"error":{"errors":[{"domain":"global","reason":"required","message":"Login Required","locationType":"header","location":"Authorization"}],"code":401,"message":"Login Required"}}'`));
assert((0, parser_1.isValidValue)(`'{ "error": {  "errors": [   {    "domain": "global",    "reason": "required",    "message": "Login Required",    "locationType": "header",    "location": "Authorization"   }  ],  "code": 401,  "message": "Login Required" }}'`));
assert((0, parser_1.isValidValue)('"(?:[a-z0-9!#$%&\'*+/=?^_`{|}~-]+(?:.[a-z0-9!#$%&\'*+/=?^_`{|}~-]+)*|(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*)@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|[(?:(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9])).){3}(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9])|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)])"'));
// assert(isValidValue('\\frac{1}{2+1}'))
assert((0, parser_1.isValidValue)(`\${${id_1.ID_IDENTITY}}`));
assert((0, parser_1.isValidValue)('1+2'));
assert((0, parser_1.isValidValue)('1 +2'));
assert((0, parser_1.isValidValue)('1 + 2'));
assert((0, parser_1.isValidValue)('1 + 2 * 3'));
assert((0, parser_1.isValidValue)('1 + 2 + 3 / 42'));
assert(!(0, parser_1.isValidValue)('foo'));
assert(!(0, parser_1.isValidValue)('{foo:bar}'));
assert(!(0, parser_1.isValidValue)('{{}}'));
assert(!(0, parser_1.isValidValue)('{♥}')); // unicode
assert(!(0, parser_1.isValidValue)('[string]'));
assert(!(0, parser_1.isValidValue)('+123456'));
assert(!(0, parser_1.isValidValue)('[*]'));
assert(!(0, parser_1.isValidValue)('[1,*]'));
assert(!(0, parser_1.isValidValue)('[*,1]'));
assert(!(0, parser_1.isValidValue)('*'));
assert(!(0, parser_1.isValidValue)("{''':1}"));
assert(!(0, parser_1.isValidValue)('{::1}'));
assert(!(0, parser_1.isValidValue)('{""":1}'));
assert(!(0, parser_1.isValidValue)("{{':1}"));
assert(!(0, parser_1.isValidValue)('a + 1'));
assert(!(0, parser_1.isValidValue)('{foo: "bar"}'));
// getValueType
const _getValueType = (str) => (0, parser_1.getValueType)(_specs_1.default, str);
assert.equal(_getValueType('"foo"'), 'string');
assert.equal(_getValueType("'foo'"), 'string');
assert.equal(_getValueType('1'), 'number');
// assert.equal(_getValueType(), 'any[]')
assert.equal(_getValueType('[]'), '<T>[]');
assert.equal(_getValueType('-2e-23'), 'number');
assert.equal(_getValueType('/abc/'), 'regex');
assert.equal(_getValueType('true'), 'boolean');
assert.equal(_getValueType('false'), 'boolean');
assert.equal(_getValueType('{}'), '{}');
assert.equal(_getValueType('{a:1,b:2}'), '{a:number,b:number}');
assert.equal(_getValueType(`'{ "error": {  "errors": [   {    "domain": "global",    "reason": "required",    "message": "Login Required",    "locationType": "header",    "location": "Authorization"   }  ],  "code": 401,  "message": "Login Required" }}'`), 'string');
// findGenerics
assert.deepEqual((0, parser_1.findGenerics)('"foo"'), new Set());
assert.deepEqual((0, parser_1.findGenerics)('<T>'), new Set(['<T>']));
assert.deepEqual((0, parser_1.findGenerics)('<T>[]'), new Set(['<T>']));
assert.deepEqual((0, parser_1.findGenerics)('{foo:<T>,bar:<K>}'), new Set(['<T>', '<K>']));
assert.deepEqual((0, parser_1.findGenerics)('`V<T>`'), new Set(['<T>']));
assert.deepEqual((0, parser_1.findGenerics)('`V`'), new Set());
assert.deepEqual((0, parser_1.findGenerics)('`EE`'), new Set());
// extractGenerics
const _extractGenerics = (value, type) => (0, parser_1.extractGenerics)(_specs_1.default, value, type);
assert.deepEqual(_extractGenerics('number', '<T>'), { '<T>': 'number' });
assert.deepEqual(_extractGenerics('"foo"', '<T>'), { '<T>': 'string' });
assert.deepEqual(_extractGenerics('1', '<T>'), { '<T>': 'number' });
assert.deepEqual(_extractGenerics('{foo:"bar"}', '<T>'), {
    '<T>': '{foo:string}',
});
assert.deepEqual(_extractGenerics('{foo:"bar"}', '{foo:<T>}'), {
    '<T>': 'string',
});
assert.deepEqual(_extractGenerics('<0>[]', '<1>[]'), { '<1>': '<0>' });
assert.deepEqual(_extractGenerics('number|string', '<0>'), {
    '<0>': 'number|string',
});
assert.deepEqual(_extractGenerics('<0>|<1>', '<2>'), { '<2>': '<0>|<1>' });
assert.deepEqual(_extractGenerics('`V<{value:string}>`', '`V<T>`'), {
    '<T>': '{value:string}',
});
// applyGenerics
assert.equal((0, parser_1.applyGenerics)('<T>', {}), '<T>');
assert.equal((0, parser_1.applyGenerics)('<T>', { '<T>': 'string' }), 'string');
assert.equal((0, parser_1.applyGenerics)('<T>[]', { '<T>': 'string' }), 'string[]');
assert.equal((0, parser_1.applyGenerics)('{foo:<A>,bar:<B>}', {
    '<A>': 'object',
    '<B>': 'string',
}), '{foo:object,bar:string}');
assert.equal((0, parser_1.applyGenerics)('<T>', { '<T>': '`CH`' }), '`CH`');
assert.equal((0, parser_1.applyGenerics)('`V<T>`', { '<T>': '{}' }), '`V<{}>`');
assert.equal((0, parser_1.applyGenerics)('`V<T>`', { '<T>': '<A>' }), '`V<A>`');
assert.equal((0, parser_1.getNodeAtPath)('', [1]), undefined);
assert.equal((0, parser_1.getNodeAtPath)('"foo"', []), '"foo"');
assert.equal((0, parser_1.getNodeAtPath)('[0,1,2,3]', []), '[0,1,2,3]');
assert.equal((0, parser_1.getNodeAtPath)('[0,1,2,3]', [1]), '1');
assert.equal((0, parser_1.getNodeAtPath)('{foo:"bar"}', []), '{foo:"bar"}');
assert.equal((0, parser_1.getNodeAtPath)('{foo:"bar"}', [0]), 'foo:"bar"');
assert.equal((0, parser_1.getNodeAtPath)('{foo:"bar"}', [0, 0]), 'foo');
assert.equal((0, parser_1.getNodeAtPath)('string[][]', [0]), 'string[]');
assert.equal((0, parser_1.getNodeAtPath)('string[][]', [0, 0]), 'string');
// getParent
assert.equal((0, parser_1.getParent)('"foo"', []), undefined);
assert.equal((0, parser_1.getParent)('{foo:"bar zaz"}', []), undefined);
assert.equal((0, parser_1.getParent)('{foo:"bar zaz"}', [0]), '{foo:"bar zaz"}');
assert.equal((0, parser_1.getParent)('{foo:"bar zaz"}', [0, 0]), 'foo:"bar zaz"');
assert.equal((0, parser_1.getParent)('{foo:"bar zaz"}', [0, 1]), 'foo:"bar zaz"');
// getNextNodePath
assert.deepEqual((0, parser_1.getNextNodePath)('"foo"', [], 1), undefined);
assert.deepEqual((0, parser_1.getNextNodePath)('"foo"', [], -1), undefined);
assert.deepEqual((0, parser_1.getNextNodePath)('[0,1,2,3]', [], 1), [0]);
assert.deepEqual((0, parser_1.getNextNodePath)('[0,1,2,3]', [1], 1), [2]);
assert.deepEqual((0, parser_1.getNextNodePath)('[0,1,2,3]', [1], -1), [0]);
assert.deepEqual((0, parser_1.getNextNodePath)('{foo:"bar"}', [0], 1), [0, 0]);
assert.deepEqual((0, parser_1.getNextNodePath)('{foo:"bar"}', [0], -1), []);
assert.deepEqual((0, parser_1.getNextNodePath)('{foo:"bar"}', [0, 0], 1), [0, 1]);
// getNextNode
assert.equal((0, parser_1.getNextNode)('"foo"', [], 1), undefined);
assert.equal((0, parser_1.getNextNode)('"foo"', [], -1), undefined);
assert.equal((0, parser_1.getNextNode)('[0,1,2,3]', [1], 1), '2');
assert.equal((0, parser_1.getNextNode)('[0,1,2,3]', [1], -1), '0');
assert.equal((0, parser_1.getNextNode)('{foo:"bar"}', [0], 1), 'foo');
assert.equal((0, parser_1.getNextNode)('{foo:"bar"}', [0], -1), '{foo:"bar"}');
assert.equal((0, parser_1.getNextNode)('{foo:"bar"}', [0, 0], 1), '"bar"');
// getNextLeafPath
assert.deepEqual((0, parser_1.getNextLeafPath)('"foo"', [], 1), undefined);
assert.deepEqual((0, parser_1.getNextLeafPath)('"foo"', [], -1), undefined);
assert.deepEqual((0, parser_1.getNextLeafPath)('[0,1,2,3]', [], 1), [0]);
assert.deepEqual((0, parser_1.getNextLeafPath)('[0,1,2,3]', [1], 1), [2]);
assert.deepEqual((0, parser_1.getNextLeafPath)('[0,1,2,3]', [1], -1), [0]);
assert.deepEqual((0, parser_1.getNextLeafPath)('{foo:"bar"}', [], 1), [0, 0]);
assert.deepEqual((0, parser_1.getNextLeafPath)('{foo:"bar"}', [0], 1), [0, 0]);
assert.deepEqual((0, parser_1.getNextLeafPath)('{foo:"bar"}', [0], -1), undefined);
assert.deepEqual((0, parser_1.getNextLeafPath)('{foo:"bar"}', [0, 0], 1), [0, 1]);
assert.deepEqual((0, parser_1.getNextLeafPath)('{foo:"bar",}', [1], -1), [0, 1]);
assert.deepEqual((0, parser_1.getNextLeafPath)('{foo:{bar:"zaz"},}', [1], -1), [0, 1, 0, 1]);
// getLastLeaf
assert.deepEqual((0, parser_1.getLastLeafPath)('{}'), []);
assert.deepEqual((0, parser_1.getLastLeafPath)('{foo:"bar"}'), [0, 1]);
// insertNodeAt
assert.equal((0, parser_1.insertNodeAt)('[0,1,2,3]', [2], '"foo"'), '[0,1,"foo",2,3]');
assert.equal((0, parser_1.insertNodeAt)('{foo:"bar zaz"}', [0], 'no:"flow"'), '{no:"flow",foo:"bar zaz"}');
assert.equal((0, parser_1.insertNodeAt)('[]', [0], '1'), '[1]');
assert.equal((0, parser_1.updateNodeAt)('{a:}', [0, 1], '1'), '{a:1}');
// updateNodeAt
assert.equal((0, parser_1.updateNodeAt)('"foo"', [], '"bar"'), '"bar"');
assert.equal((0, parser_1.updateNodeAt)('[0,1,2,3]', [2], '"foo"'), '[0,1,"foo",3]');
assert.equal((0, parser_1.updateNodeAt)('{foo:"bar zaz"}', [0, 0], '1'), '{1:"bar zaz"}');
assert.equal((0, parser_1.updateNodeAt)('[]', [0], '1'), '[1]');
assert.equal((0, parser_1.updateNodeAt)('{a:}', [0, 1], '1'), '{a:1}');
// removeNodeAt
assert.equal((0, parser_1.removeNodeAt)('"foo"', []), '');
assert.equal((0, parser_1.removeNodeAt)('[0,1,2,3]', [0]), '[1,2,3]');
assert.equal((0, parser_1.removeNodeAt)('{foo:"bar zaz"}', [0]), '{}');
assert.equal((0, parser_1.removeNodeAt)('{foo:}', [0, 1]), '{foo}');
// evaluate
const _evaluate = (str) => (0, evaluate_1.evaluate)(str, _specs_1.default, _classes_1.default);
assert.deepEqual(_evaluate('1'), 1);
assert.deepEqual(_evaluate('Infinity'), Infinity);
assert.deepEqual(_evaluate('"foo"'), 'foo');
assert.deepEqual(_evaluate("'foo'"), 'foo');
assert.deepEqual(_evaluate('\'"foo"\''), '"foo"');
assert.deepEqual(_evaluate("'\\'foo\\''"), "'foo'");
assert.deepEqual(_evaluate('\'\\"foo\\"\''), '"foo"');
assert.deepEqual(_evaluate('"\\"foo\\""'), '"foo"');
assert.deepEqual(_evaluate("'\\\\'"), '\\');
assert.deepEqual(_evaluate("'\\'\\\\\\''"), "'\\'");
assert.deepEqual(_evaluate('"\\"input/a\\""'), '"input/a"');
assert.deepEqual(_evaluate('true'), true);
assert.deepEqual(_evaluate('false'), false);
assert.deepEqual(_evaluate('null'), null);
assert.deepEqual(_evaluate('[]'), []);
assert.deepEqual(_evaluate('[1,2,3]'), [1, 2, 3]);
assert.deepEqual(_evaluate('[1,2,3,]'), [1, 2, 3]);
assert.deepEqual(_evaluate('{foo:0}'), { foo: 0 });
assert.deepEqual(_evaluate('{foo:0,}'), { foo: 0 });
assert.deepEqual(_evaluate('{foo:"bar zaz"}'), { foo: 'bar zaz' });
assert.deepEqual(_evaluate('{a:1}'), { a: 1 });
assert.deepEqual(_evaluate('{a:"1"}'), { a: '1' });
assert.deepEqual(_evaluate('{1:1}'), { 1: 1 });
assert.deepEqual(_evaluate('{a}'), { a: 'a' });
assert.deepEqual(_evaluate('{a,b}'), { a: 'a', b: 'b' });
assert.deepEqual(_evaluate('{a,}'), { a: 'a' });
assert.deepEqual(_evaluate('{1}'), { 1: '1' });
assert.deepEqual(_evaluate('"\\n"'), '\\n');
assert.deepEqual(_evaluate(`\${unit:{id:'${id_1.ID_IDENTITY}'}}`).__bundle.unit.id, id_1.ID_IDENTITY);
assert.deepEqual(_evaluate(`'{\\n "error": {\\n  "errors": [\\n   {\\n    "domain": "global",\\n    "reason": "required",\\n    "message": "Login Required",\\n    "locationType": "header",\\n    "location": "Authorization"\\n   }\\n  ],\\n  "code": 401,\\n  "message": "Login Required"\\n }\\n}\\n'`), '{\\n "error": {\\n  "errors": [\\n   {\\n    "domain": "global",\\n    "reason": "required",\\n    "message": "Login Required",\\n    "locationType": "header",\\n    "location": "Authorization"\\n   }\\n  ],\\n  "code": 401,\\n  "message": "Login Required"\\n }\\n}\\n');
// isGeneric
assert((0, parser_1.hasGeneric)('<T>'));
assert((0, parser_1.hasGeneric)('<0>'));
assert((0, parser_1.hasGeneric)('<0>[]'));
assert((0, parser_1.hasGeneric)('`V<T>`'));
// matchAllType
assert((0, f_1.default)((0, parser_1.matchAllExcTypes)(['any'], ['any']), [[[0, 0]]]));
assert((0, f_1.default)((0, parser_1.matchAllExcTypes)(['string'], ['any']), [[[0, 0]]]));
assert((0, f_1.default)((0, parser_1.matchAllExcTypes)(['any'], ['string']), [[[0, 0]]]));
assert((0, f_1.default)((0, parser_1.matchAllExcTypes)(['number'], ['string']), []));
assert((0, f_1.default)((0, parser_1.matchAllExcTypes)(['number', 'number'], ['<T>']), [[[0, 0]], [[1, 0]]]));
assert((0, f_1.default)((0, parser_1.matchAllExcTypes)(['number', 'number'], ['number']), [
    [[0, 0]],
    [[1, 0]],
]));
assert((0, f_1.default)((0, parser_1.matchAllExcTypes)(['number', 'string'], ['number']), [[[0, 0]]]));
//# sourceMappingURL=parser.js.map